clangtidy corrections part 1

This commit is contained in:
2023-10-11 17:35:40 +02:00
parent 77a52b82c3
commit 23d854a826
36 changed files with 2383 additions and 1165 deletions
@@ -10,8 +10,9 @@
*/
#include "menuTestMode.h"
MenuTestMode::MenuTestMode(DriveManager* driveManager) {
this->driveManager = driveManager;
MenuTestMode::MenuTestMode(DriveManager* driveManager)
: driveManager {driveManager}
{
}
MenuTestMode::~MenuTestMode() {
@@ -30,73 +31,77 @@ void MenuTestMode::printMenu() {
}
void MenuTestMode::down() {
if (this->checkInput())
if (this->checkInput()) {
this->mainMenu->down();
}
}
void MenuTestMode::up() {
if (this->checkInput())
if (this->checkInput()) {
this->mainMenu->up();
}
}
void MenuTestMode::right() {
if (this->checkInput())
if (this->checkInput()) {
this->mainMenu->right();
}
}
void MenuTestMode::left() {
if (this->mainMenu->isInSubmenu())
if (this->checkInput())
if (this->checkInput()) {
this->mainMenu->left();
}
else {
this->testMode->abortManeuver();
this->mainMenu->left();
}
else
else {
this->parentMenu->printMenu();
}
}
void MenuTestMode::yes() {
if (this->checkInput())
if (this->checkInput()) {
this->mainMenu->yes();
}
}
void MenuTestMode::no() {
if (this->mainMenu->isInSubmenu())
if (this->mainMenu->isInSubmenu()) {
if (this->checkInput())
this->mainMenu->no();
else {
this->testMode->abortManeuver();
this->mainMenu->no();
}
else
this->left();
}}
else{
this->left();}
}
void MenuTestMode::init() {
this->testMode = new TestMode();
this->driveManager->changeModus(this->testMode);
this->testMode->setSpeeds(DrivingSpeeds{1, 8});
auto dummy = []() {
std::cout << "Dummy in Action" <<std::endl;
};
// Create menu
this->mainMenu = new Menu;
auto engineMenu = new Menu;
auto lightMenu = new Menu;
auto encoderMenu = new Menu;
auto *engineMenu = new Menu;
auto *lightMenu = new Menu;
auto *encoderMenu = new Menu;
// Sound
// Ping google
auto drivingMenu = new MenuIntInput(2, new MenuTestModeWrapper(this, &TestMode::drive));
auto engineLeftMenu = new MenuIntInput(2, new MenuTestModeWrapper(this, &TestMode::leftEngine));
auto engineRightMenu = new MenuIntInput(2, new MenuTestModeWrapper(this, &TestMode::rightEngine));
auto engineBothMenu = new MenuIntInput(2, new MenuTestModeWrapper(this, &TestMode::bothEngine));
auto encoderLeftMenu = new SpeedometerTest(this->testMode->getSpeedometerLeft());
auto encoderRightMenu = new SpeedometerTest(this->testMode->getSpeedometerRight());
auto *drivingMenu = new MenuIntInput(2, new MenuTestModeWrapper(this, &TestMode::drive));
auto *engineLeftMenu = new MenuIntInput(2, new MenuTestModeWrapper(this, &TestMode::leftEngine));
auto *engineRightMenu = new MenuIntInput(2, new MenuTestModeWrapper(this, &TestMode::rightEngine));
auto *engineBothMenu = new MenuIntInput(2, new MenuTestModeWrapper(this, &TestMode::bothEngine));
auto *encoderLeftMenu = new SpeedometerTest(this->testMode->getSpeedometerLeft());
auto *encoderRightMenu = new SpeedometerTest(this->testMode->getSpeedometerRight());
// Set menus on LCD
@@ -112,47 +117,52 @@ void MenuTestMode::init() {
encoderRightMenu->setLcd(this->lcd);
// Other menu config
static constexpr uint8_t percentMax = 100;
static constexpr uint8_t degreeMax = 360;
static constexpr uint8_t secondsMax = 120;
static constexpr uint8_t steps = 5;
drivingMenu->setEntry(0, "Centimeter", 100);
drivingMenu->setMinMaxSteps(0, -1000, 1000, 25);
drivingMenu->setMinMaxSteps(0, -1000, 1000, steps * 5);
drivingMenu->setEntry(1, "Degree");
drivingMenu->setMinMaxSteps(1, -360, 360, 15);
drivingMenu->setMinMaxSteps(1, -degreeMax, degreeMax, steps * 3);
drivingMenu->setPrintParentMenu(false);
engineLeftMenu->setEntry(0, "Percentage");
engineLeftMenu->setMinMaxSteps(0, -100, 100, 5);
engineLeftMenu->setEntry(1, "Seconds", 5);
engineLeftMenu->setMinMaxSteps(1, 0, 120, 1);
engineLeftMenu->setMinMaxSteps(0, -percentMax, percentMax, steps);
engineLeftMenu->setEntry(1, "Seconds", steps);
engineLeftMenu->setMinMaxSteps(1, 0, secondsMax, 1);
engineLeftMenu->setPrintParentMenu(false);
engineRightMenu->setEntry(0, "Percentage");
engineRightMenu->setMinMaxSteps(0, -100, 100, 5);
engineRightMenu->setEntry(1, "Seconds", 5);
engineRightMenu->setMinMaxSteps(1, 0, 120, 1);
engineRightMenu->setMinMaxSteps(0, -percentMax, percentMax, steps);
engineRightMenu->setEntry(1, "Seconds", steps);
engineRightMenu->setMinMaxSteps(1, 0, secondsMax, 1);
engineRightMenu->setPrintParentMenu(false);
engineBothMenu->setEntry(0, "Percentage");
engineBothMenu->setMinMaxSteps(0, -100, 100, 5);
engineBothMenu->setEntry(1, "Seconds", 5);
engineBothMenu->setMinMaxSteps(1, 0, 120, 1);
engineBothMenu->setMinMaxSteps(0, -percentMax, percentMax, steps);
engineBothMenu->setEntry(1, "Seconds", steps);
engineBothMenu->setMinMaxSteps(1, 0, secondsMax, 1);
engineBothMenu->setPrintParentMenu(false);
// Entrys for the menus
MenuAction* engineAction = new MenuAction("Engine", engineMenu);
MenuAction* engineLeftAction = new MenuAction("Left", engineLeftMenu);
MenuAction* engineRightAction = new MenuAction("Right", engineRightMenu);
MenuAction* engineBothAction = new MenuAction("Both", engineBothMenu);
auto *engineAction = new MenuAction("Engine", engineMenu);
auto *engineLeftAction = new MenuAction("Left", engineLeftMenu);
auto *engineRightAction = new MenuAction("Right", engineRightMenu);
auto *engineBothAction = new MenuAction("Both", engineBothMenu);
MenuAction* drivingAction = new MenuAction("Driving", drivingMenu);
auto *drivingAction = new MenuAction("Driving", drivingMenu);
MenuAction* encoderAction = new MenuAction("Encoder", encoderMenu);
MenuAction* encoderLeftAction = new MenuAction("Left", encoderLeftMenu);
MenuAction* encoderRightAction = new MenuAction("Right", encoderRightMenu);
auto *encoderAction = new MenuAction("Encoder", encoderMenu);
auto *encoderLeftAction = new MenuAction("Left", encoderLeftMenu);
auto *encoderRightAction = new MenuAction("Right", encoderRightMenu);
MenuAction* lightAction = new MenuAction("Light", lightMenu);
MenuAction* lightFlashAction = new MenuAction("Flash", dummy);
MenuAction* lightFadeAction = new MenuAction("Fade", dummy);
MenuAction* lightRedAction = new MenuAction("Red", dummy);
MenuAction* lightGreenAction = new MenuAction("Green", dummy);
MenuAction* lightBlueAction = new MenuAction("Blue", dummy);
MenuAction* lightOffAction = new MenuAction("Off", dummy);
auto *lightAction = new MenuAction("Light", lightMenu);
auto *lightFlashAction = new MenuAction("Flash", dummy);
auto *lightFadeAction = new MenuAction("Fade", dummy);
auto *lightRedAction = new MenuAction("Red", dummy);
auto *lightGreenAction = new MenuAction("Green", dummy);
auto *lightBlueAction = new MenuAction("Blue", dummy);
auto *lightOffAction = new MenuAction("Off", dummy);
// Add entrys to the menus
this->mainMenu->addEntry(engineAction);
@@ -176,11 +186,11 @@ void MenuTestMode::init() {
}
void MenuTestMode::update() {
if (this->maneuverInAction)
if (this->maneuverInAction) {
if (millis() - this->lastUpdateTime > updateDelay) {
this->printManeuverTime();
this->lastUpdateTime = millis();
}
}}
}
bool MenuTestMode::checkInput() {
@@ -190,8 +200,9 @@ bool MenuTestMode::checkInput() {
return false;
}
if (this->maneuverInAction)
if (this->maneuverInAction) {
this->maneuverInAction = false;
}
return true;
}
@@ -209,16 +220,18 @@ void MenuTestMode::printManeuverTime() {
}
}
MenuTestModeWrapper::MenuTestModeWrapper(MenuTestMode* menu, TestModeFunctionSingle testModeFunction) {
this->menu = menu;
this->testMode = this->menu->getTestMode();
this->testModeFunctionSingle = testModeFunction;
MenuTestModeWrapper::MenuTestModeWrapper(MenuTestMode* menu, TestModeFunctionSingle testModeFunction)
: menu {menu},
testModeFunctionSingle {testModeFunction},
testMode {menu->getTestMode()}
{
}
MenuTestModeWrapper::MenuTestModeWrapper(MenuTestMode* menu, TestModeFunctionDouble testModeFunction) {
this->menu = menu;
this->testMode = this->menu->getTestMode();
this->testModeFunctionDouble = testModeFunction;
MenuTestModeWrapper::MenuTestModeWrapper(MenuTestMode* menu, TestModeFunctionDouble testModeFunction)
: menu {menu},
testModeFunctionDouble {testModeFunction},
testMode {menu->getTestMode()}
{
}
void MenuTestModeWrapper::action(int16_t* values, uint8_t length) {
@@ -228,10 +241,12 @@ void MenuTestModeWrapper::action(int16_t* values, uint8_t length) {
bool res = false;
if (length == 2 && this->testModeFunctionDouble)
if (length == 2 && static_cast<bool>(this->testModeFunctionDouble)) {
res = (this->testMode->*this->testModeFunctionDouble)(values[0], values[1]);
else if (length == 1 && this->testModeFunctionSingle)
}
else if (length == 1 && static_cast<bool>(this->testModeFunctionSingle)) {
res = (this->testMode->*this->testModeFunctionSingle)(values[0]);
}
if (res) {
this->menu->printManeuverTime();
@@ -70,8 +70,8 @@ class MenuTestMode : public MenuControl {
bool checkInput();
DriveManager* driveManager;
TestMode* testMode;
Menu* mainMenu;
TestMode* testMode = nullptr;
Menu* mainMenu = nullptr;
bool isInit = false;
bool maneuverInAction = false;
@@ -11,8 +11,9 @@
#include "speedometerTest.h"
SpeedometerTest::SpeedometerTest(Speedometer* speedometer) {
this->speedometer = speedometer;
SpeedometerTest::SpeedometerTest(Speedometer* speedometer)
: speedometer {speedometer}
{
this->speedometer->setDirection(Speedometer::Forward);
}
@@ -46,8 +47,9 @@ void SpeedometerTest::left() {
}
void SpeedometerTest::no() {
if (this->state == State::Running)
if (this->state == State::Running){
speedometer->calibrationMeasurementStop();
}
this->state = State::Off;
this->parentMenu->printMenu();
+17 -14
View File
@@ -11,27 +11,28 @@
#include "menuDriveMode.h"
MenuDriveMode::MenuDriveMode(DriveManager* driveManager) {
this->driveManager = driveManager;
MenuDriveMode::MenuDriveMode(DriveManager* driveManager)
: driveManager {driveManager}
{
}
void MenuDriveMode::left() {
if (this->activeMenu) {
if (this->activeMenu)
if (static_cast<bool>(this->activeMenu)) {
if (static_cast<bool>(this->activeMenu)) {
this->activeMenu->left();
}
return;
}
this->firstPrint = true;
this->configureOnLeave();
if (this->menuSpeed)
delete this->menuSpeed;
this->driveManager->changeModus();
MenuInformationSites::left();
}
void MenuDriveMode::right() {
if (this->activeMenu) {
if (static_cast<bool>(this->activeMenu)) {
this->activeMenu->right();
return;
}
@@ -39,7 +40,7 @@ void MenuDriveMode::right() {
}
void MenuDriveMode::up() {
if (this->activeMenu) {
if (static_cast<bool>(this->activeMenu)) {
this->activeMenu->up();
return;
}
@@ -47,7 +48,7 @@ void MenuDriveMode::up() {
}
void MenuDriveMode::down() {
if (this->activeMenu) {
if (static_cast<bool>(this->activeMenu)) {
this->activeMenu->down();
return;
}
@@ -55,7 +56,7 @@ void MenuDriveMode::down() {
}
void MenuDriveMode::yes() {
if (this->activeMenu) {
if (static_cast<bool>(this->activeMenu)) {
this->activeMenu->yes();
return;
}
@@ -63,7 +64,7 @@ void MenuDriveMode::yes() {
}
void MenuDriveMode::no() {
if (this->activeMenu) {
if (static_cast<bool>(this->activeMenu)) {
this->activeMenu->no();
return;
}
@@ -75,7 +76,7 @@ void MenuDriveMode::prepareReenterMenu() {
}
void MenuDriveMode::printMenu() {
if (this->activeMenu) {
if (static_cast<bool>(this->activeMenu)) {
this->activeMenu->printMenu();
return;
}
@@ -88,11 +89,12 @@ void MenuDriveMode::init() {
}
void MenuDriveMode::activateSpeedMenu() {
if (!this->driveManager->isActive())
if (!this->driveManager->isActive()) {
return;
}
DrivingSpeeds& speeds = this->driveManager->getDriveModiPtr()->getSpeedsRef();
MenuIntInput* menu = new MenuIntInput(2, new MenuSpeed(speeds));
auto *menu = new MenuIntInput(2, new MenuSpeed(speeds));
menu->setMinMax(5, UINT8_MAX);
menu->setEntry(0, "x m/s e-1", driveManager->getDrivingSpeedsRef().x * 10);
@@ -112,8 +114,9 @@ void MenuDriveMode::enterSensorMenu() {
}
void MenuDriveMode::enterMenu() {
if (!this->activeMenu)
if (!static_cast<bool>(this->activeMenu)) {
return;
}
this->activeMenu->printMenu();
this->activeMenu->setParentMenu(this);