try to make menus accessable from driveMode

This commit is contained in:
2023-09-27 15:32:30 +02:00
parent 38e7db7dee
commit d7357d4f95
13 changed files with 128 additions and 47 deletions
+1 -1
View File
@@ -14,7 +14,7 @@
#include <menuIntInput.h> #include <menuIntInput.h>
class MenuSpeed : MenuIntInput { class MenuSpeed : public MenuIntInput {
}; };
@@ -201,7 +201,7 @@ void MenuAutopilot::printPage() const {
this->print(lineOne, lineTwo); this->print(lineOne, lineTwo);
} }
void MenuAutopilot::runCommand() const { void MenuAutopilot::runCommand() {
switch (this->getCurrentPage()) { switch (this->getCurrentPage()) {
case 5: case 5:
this->autopilot->switchLoopMode(); this->autopilot->switchLoopMode();
@@ -226,7 +226,7 @@ void MenuAutopilot::runCommand() const {
} }
} }
void MenuAutopilot::runCommandNo() const { void MenuAutopilot::runCommandNo() {
switch (this->getCurrentPage()) { switch (this->getCurrentPage()) {
case 7: case 7:
this->minDistance = this->autopilot->getNavigation()->decreaseMinDistanceToReachPoint(); this->minDistance = this->autopilot->getNavigation()->decreaseMinDistanceToReachPoint();
@@ -254,4 +254,6 @@ void MenuAutopilot::init() {
//dirty hack to get the val, can be better!!! TODO //dirty hack to get the val, can be better!!! TODO
this->autopilot->getNavigation()->increaseMinDistanceToReachPoint(); this->autopilot->getNavigation()->increaseMinDistanceToReachPoint();
this->minDistance = this->autopilot->getNavigation()->decreaseMinDistanceToReachPoint(); this->minDistance = this->autopilot->getNavigation()->decreaseMinDistanceToReachPoint();
MenuDriveMode::init();
} }
@@ -47,8 +47,8 @@ class MenuAutopilot : public MenuDriveMode {
private: private:
void init() override; void init() override;
void runCommand() const override; void runCommand() override;
void runCommandNo() const override; void runCommandNo() override;
bool mutable targetFreezed = false; bool mutable targetFreezed = false;
double mutable minDistance; double mutable minDistance;
@@ -117,7 +117,7 @@ void MenuCalibrateCompass::init() {
this->updateDelay = 500; this->updateDelay = 500;
} }
void MenuCalibrateCompass::runCommand() const { void MenuCalibrateCompass::runCommand() {
switch (this->getCurrentPage()) { switch (this->getCurrentPage()) {
case 2: case 2:
switch (this->caliCompass->getState()) { switch (this->caliCompass->getState()) {
@@ -42,7 +42,7 @@ class MenuCalibrateCompass : public MenuDriveMode {
protected: protected:
void init() override; void init() override;
void runCommand() const override; void runCommand() override;
private: private:
CalibrateCompassM* caliCompassMode; CalibrateCompassM* caliCompassMode;
@@ -114,7 +114,7 @@ void MenuCaptureRoute::update() {
this->printMenu(); this->printMenu();
} }
void MenuCaptureRoute::runCommand() const { void MenuCaptureRoute::runCommand() {
switch (this->getCurrentPage()) switch (this->getCurrentPage())
{ {
case 7: case 7:
@@ -134,5 +134,5 @@ void MenuCaptureRoute::init() {
this->updateDelay = 500; this->updateDelay = 500;
this->captureRoute = new CaptureRoute(); this->captureRoute = new CaptureRoute();
this->driveManager->changeModus(this->captureRoute); this->driveManager->changeModus(this->captureRoute);
MenuDriveMode::init();
} }
@@ -43,7 +43,7 @@ class MenuCaptureRoute : public MenuDriveMode {
*/ */
void update() override; void update() override;
void runCommand() const override; void runCommand() override;
private: private:
void init() override; void init() override;
@@ -11,7 +11,7 @@
#include "menuManualDrive.h" #include "menuManualDrive.h"
MenuManualControl::MenuManualControl(DriveManager* driveManager) : MenuDriveMode(driveManager) { MenuManualControl::MenuManualControl(DriveManager* driveManager) : MenuDriveMode(driveManager) {
this->noEqualLeft = true;
} }
MenuManualControl::~MenuManualControl() { MenuManualControl::~MenuManualControl() {
@@ -35,15 +35,11 @@ void MenuManualControl::printPage() const {
break; break;
case 2: case 2:
lineOne = "Speed: "; lineOne = "Speed Menu";
lineOne.concat(this->manualControl->getMaxSpeed());
lineTwo = "- dec 0.1 inc +";
break; break;
case 3: case 3:
lineOne = "RotSpeed: "; lineOne = "Sensor Menu";
lineOne.concat(this->manualControl->getMaxRotation());
lineTwo = "- dec 0.1 inc +";
break; break;
default: default:
@@ -60,39 +56,24 @@ void MenuManualControl::init() {
this->driveManager->changeModus(this->manualControl); this->driveManager->changeModus(this->manualControl);
this->setCountPages(4); this->setCountPages(4);
this->updateDelay = 500; this->updateDelay = 500;
MenuDriveMode::init();
} }
void MenuManualControl::runCommand() const { void MenuManualControl::runCommand() {
switch (this->getCurrentPage()) { switch (this->getCurrentPage()) {
case 1: case 1:
this->manualControl->switchInputMode(); this->manualControl->switchInputMode();
break; break;
case 2: case 2:
this->manualControl->increaseMaxSpeed(); this->enterSpeedMenu();
break; break;
case 3: case 3:
this->manualControl->increaseMaxRotation(); this->enterSensorMenu();
break; break;
default: default:
break; break;
} }
} }
void MenuManualControl::runCommandNo() const {
switch (this->getCurrentPage())
{
case 2:
this->manualControl->decreaseMaxSpeed();
break;
case 3:
this->manualControl->decreaseMaxRotation();
break;
default:
break;
}
}
@@ -41,8 +41,7 @@ class MenuManualControl : public MenuDriveMode {
protected: protected:
void init() override; void init() override;
void runCommand() const override; void runCommand() override;
void runCommandNo() const override;
private: private:
ManualControl* manualControl; ManualControl* manualControl;
@@ -173,7 +173,7 @@ void MenuTestMode::init() {
lightMenu->addEntry(lightRedAction); lightMenu->addEntry(lightRedAction);
lightMenu->addEntry(lightGreenAction); lightMenu->addEntry(lightGreenAction);
lightMenu->addEntry(lightBlueAction); lightMenu->addEntry(lightBlueAction);
lightMenu->addEntry(lightOffAction); lightMenu->addEntry(lightOffAction);
} }
void MenuTestMode::update() { void MenuTestMode::update() {
+83 -4
View File
@@ -16,11 +16,90 @@ MenuDriveMode::MenuDriveMode(DriveManager* driveManager) {
} }
void MenuDriveMode::left() { void MenuDriveMode::left() {
if (this->activeMenu) {
if (this->activeMenu)
this->activeMenu->left();
return;
}
this->firstPrint = true; this->firstPrint = true;
this->configureOnLeave(); this->configureOnLeave();
this->driveManager->changeModus(); this->driveManager->changeModus();
if (parentMenu) { MenuInformationSites::left();
this->parentMenu->printMenu(); }
this->leaved = true;
} void MenuDriveMode::right() {
if (this->activeMenu) {
this->activeMenu->right();
return;
}
MenuInformationSites::right();
}
void MenuDriveMode::up() {
if (this->activeMenu) {
this->activeMenu->up();
return;
}
MenuInformationSites::up();
}
void MenuDriveMode::down() {
if (this->activeMenu) {
this->activeMenu->down();
return;
}
MenuInformationSites::down();
}
void MenuDriveMode::yes() {
if (this->activeMenu) {
this->activeMenu->yes();
return;
}
MenuInformationSites::yes();
}
void MenuDriveMode::no() {
if (this->activeMenu) {
this->activeMenu->no();
return;
}
MenuInformationSites::no();
}
void MenuDriveMode::prepareReenterMenu() {
this->activeMenu = nullptr;
}
void MenuDriveMode::printMenu() {
if (this->activeMenu) {
this->activeMenu->printMenu();
return;
}
MenuInformationSites::printMenu();
}
void MenuDriveMode::init() {
this->activeMenu = nullptr;
}
void MenuDriveMode::enterSpeedMenu() {
this->activeMenu = this->menuSpeed;
this->enterMenu();
}
void MenuDriveMode::enterSensorMenu() {
this->activeMenu = this->menuSensor;
this->enterMenu();
}
void MenuDriveMode::enterMenu() {
if (!this->activeMenu)
return
this->activeMenu->printMenu();
std::cout << "Sensor Menu was theretically printed" << std::endl;
this->activeMenu->setParentMenu(this);
} }
+22 -4
View File
@@ -29,19 +29,37 @@ class MenuDriveMode : public MenuInformationSites {
*/ */
MenuDriveMode(DriveManager* driveManager); MenuDriveMode(DriveManager* driveManager);
void addSensorMenu(MenuSensorData* menuSensor) { this->menuSensor = menuSensor; }
void addSpeedMenu(MenuSpeed* menuSpeed) { this->menuSpeed = menuSpeed; }
/** /**
* @brief Goes back to the parentMenu. * @brief Goes back to the parentMenu.
*/ */
void left() override; void left() override;
void right() override;
void up() override;
void down() override;
void yes() override;
void no() override;
void prepareReenterMenu() override;
void printMenu() override;
protected: protected:
void configureOnLeave() {} void init() override;
virtual void configureOnLeave() {}
void enterSpeedMenu();
void enterSensorMenu();
DriveManager* driveManager; DriveManager* driveManager;
MenuSensorData* menuSensor;
MenuSpeed* menuSpeed;
bool firstPrint = true; bool firstPrint = true;
};
private:
void enterMenu();
MenuControl* activeMenu = nullptr;
MenuSensorData* menuSensor = nullptr;
MenuSpeed* menuSpeed = nullptr;
};
#endif // MENU_DRIVE_MODI_H #endif // MENU_DRIVE_MODI_H
+2
View File
@@ -223,6 +223,8 @@ void makeMenu() {
sys_m->setUpdateDelay(1500); sys_m->setUpdateDelay(1500);
sen_m->setUpdateDelay(500); sen_m->setUpdateDelay(500);
man_m->addSensorMenu(sen_m);
// Entry for the main menu // Entry for the main menu
main_m->addEntry(new MenuAction("Mode", mode_m)); main_m->addEntry(new MenuAction("Mode", mode_m));
main_m->addEntry(new MenuAction("Sensor", sen_m)); main_m->addEntry(new MenuAction("Sensor", sen_m));