Merge branch 'main' into projektarbeit
This commit is contained in:
@@ -4,159 +4,167 @@
|
||||
* @brief Contains an implementation of the class MenuManualDrive
|
||||
* @version 0.1
|
||||
* @date 2022-01-20
|
||||
*
|
||||
*
|
||||
* @copyright Copyright (c) 2022
|
||||
*
|
||||
*
|
||||
*/
|
||||
#include "menuCalibrateCompass.h"
|
||||
|
||||
MenuCalibrateCompass::MenuCalibrateCompass(DriveManager* driveManager) : MenuDriveMode(driveManager) {}
|
||||
MenuCalibrateCompass::MenuCalibrateCompass(DriveManager *driveManager) : MenuDriveMode(driveManager) {}
|
||||
|
||||
MenuCalibrateCompass::~MenuCalibrateCompass() {
|
||||
MenuCalibrateCompass::~MenuCalibrateCompass()
|
||||
{
|
||||
delete this->caliCompass;
|
||||
this->caliCompassMode->setCalibrateCompass();
|
||||
}
|
||||
|
||||
void MenuCalibrateCompass::printPage() const {
|
||||
void MenuCalibrateCompass::printPage() const
|
||||
{
|
||||
String lineOne = "";
|
||||
String lineTwo = "";
|
||||
|
||||
switch (this->getCurrentPage()) {
|
||||
case 0:
|
||||
lineOne = "-Ready to drive-";
|
||||
lineTwo = "Compass Mode";
|
||||
switch (this->getCurrentPage())
|
||||
{
|
||||
case 0:
|
||||
lineOne = "-Ready to drive-";
|
||||
lineTwo = "Compass Mode";
|
||||
break;
|
||||
|
||||
case 1:
|
||||
lineOne = "Azimuth:";
|
||||
lineTwo.concat(this->caliCompassMode->getSensorData()->getRealAzimuth());
|
||||
break;
|
||||
|
||||
case 2:
|
||||
switch (this->caliCompass->getState())
|
||||
{
|
||||
case CalibrateCompass::State::Ready:
|
||||
lineOne = "Start compass";
|
||||
lineTwo = "calibration";
|
||||
break;
|
||||
|
||||
case 1:
|
||||
lineOne = "Azimuth:";
|
||||
lineTwo.concat(this->caliCompassMode->getSensorData()->getRealAzimuth());
|
||||
break;
|
||||
|
||||
case 2:
|
||||
switch (this->caliCompass->getState()) {
|
||||
case CalibrateCompass::State::Ready :
|
||||
lineOne = "Start compass";
|
||||
lineTwo = "calibration";
|
||||
break;
|
||||
|
||||
case CalibrateCompass::State::Calibrating :
|
||||
lineOne = "Calibrating...";
|
||||
lineTwo = "Move around";
|
||||
break;
|
||||
|
||||
case CalibrateCompass::State::Finished:
|
||||
lineOne = "Calibration";
|
||||
lineTwo = "finished";
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
case CalibrateCompass::State::Calibrating:
|
||||
lineOne = "Calibrating...";
|
||||
lineTwo = "Move around";
|
||||
break;
|
||||
|
||||
case 3:
|
||||
lineOne = "Save compass";
|
||||
lineTwo = "data in flash";
|
||||
break;
|
||||
|
||||
case 4:
|
||||
lineOne = "Load data";
|
||||
lineTwo = "from flash";
|
||||
break;
|
||||
|
||||
case 5:
|
||||
lineOne = "Remove";
|
||||
lineTwo = "calibration data";
|
||||
break;
|
||||
|
||||
case 6:
|
||||
lineOne = "Use current";
|
||||
lineTwo = "calibration data";
|
||||
break;
|
||||
|
||||
case 7:
|
||||
lineOne = "Reset for new";
|
||||
lineTwo = "calibration run";
|
||||
break;
|
||||
|
||||
case 8:
|
||||
lineOne = "X min: ";
|
||||
lineOne.concat(this->caliCompass->getCallibrationData().data[0][0]);
|
||||
lineTwo = "X max: ";
|
||||
lineTwo.concat(this->caliCompass->getCallibrationData().data[0][1]);
|
||||
break;
|
||||
|
||||
case 9:
|
||||
lineOne = "Y min: ";
|
||||
lineOne.concat(this->caliCompass->getCallibrationData().data[1][0]);
|
||||
lineTwo = "Y max: ";
|
||||
lineTwo.concat(this->caliCompass->getCallibrationData().data[1][1]);
|
||||
break;
|
||||
|
||||
case 10:
|
||||
lineOne = "Z min: ";
|
||||
lineOne.concat(this->caliCompass->getCallibrationData().data[2][0]);
|
||||
lineTwo = "Z max: ";
|
||||
lineTwo.concat(this->caliCompass->getCallibrationData().data[2][1]);
|
||||
case CalibrateCompass::State::Finished:
|
||||
lineOne = "Calibration";
|
||||
lineTwo = "finished";
|
||||
break;
|
||||
|
||||
default:
|
||||
this->printDefault();
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case 3:
|
||||
lineOne = "Save compass";
|
||||
lineTwo = "data in flash";
|
||||
break;
|
||||
|
||||
case 4:
|
||||
lineOne = "Load data";
|
||||
lineTwo = "from flash";
|
||||
break;
|
||||
|
||||
case 5:
|
||||
lineOne = "Remove";
|
||||
lineTwo = "calibration data";
|
||||
break;
|
||||
|
||||
case 6:
|
||||
lineOne = "Use current";
|
||||
lineTwo = "calibration data";
|
||||
break;
|
||||
|
||||
case 7:
|
||||
lineOne = "Reset for new";
|
||||
lineTwo = "calibration run";
|
||||
break;
|
||||
|
||||
case 8:
|
||||
lineOne = "X min: ";
|
||||
lineOne.concat(this->caliCompass->getCalibrationData().data[0][0]);
|
||||
lineTwo = "X max: ";
|
||||
lineTwo.concat(this->caliCompass->getCalibrationData().data[0][1]);
|
||||
break;
|
||||
|
||||
case 9:
|
||||
lineOne = "Y min: ";
|
||||
lineOne.concat(this->caliCompass->getCalibrationData().data[1][0]);
|
||||
lineTwo = "Y max: ";
|
||||
lineTwo.concat(this->caliCompass->getCalibrationData().data[1][1]);
|
||||
break;
|
||||
|
||||
case 10:
|
||||
lineOne = "Z min: ";
|
||||
lineOne.concat(this->caliCompass->getCalibrationData().data[2][0]);
|
||||
lineTwo = "Z max: ";
|
||||
lineTwo.concat(this->caliCompass->getCalibrationData().data[2][1]);
|
||||
break;
|
||||
|
||||
default:
|
||||
this->printDefault();
|
||||
return;
|
||||
}
|
||||
|
||||
this->print(lineOne, lineTwo);
|
||||
}
|
||||
|
||||
void MenuCalibrateCompass::init() {
|
||||
void MenuCalibrateCompass::init()
|
||||
{
|
||||
this->firstPrint = false;
|
||||
this->driveManager->changeModus(Modi::CalibrateCompass);
|
||||
this->caliCompassMode = (CalibrateCompassM*) this->driveManager->getDriveModiPtr();
|
||||
this->caliCompassMode = new CalibrateCompassM();
|
||||
this->driveManager->changeModus(this->caliCompassMode);
|
||||
this->caliCompass = new CalibrateCompass(this->caliCompassMode->getSensorData()->getRealCompass());
|
||||
this->setCountPages(11);
|
||||
this->updateDelay = 500;
|
||||
MenuDriveMode::updateDelay = MenuCalibrateCompass::updateDelay;
|
||||
}
|
||||
|
||||
void MenuCalibrateCompass::runCommand() const {
|
||||
switch (this->getCurrentPage()) {
|
||||
case 2:
|
||||
switch (this->caliCompass->getState()) {
|
||||
case CalibrateCompass::State::Ready :
|
||||
this->caliCompassMode->setCalibrateCompass(this->caliCompass);
|
||||
this->caliCompass->start();
|
||||
break;
|
||||
|
||||
case CalibrateCompass::State::Finished:
|
||||
this->caliCompassMode->setCalibrateCompass();
|
||||
this->caliCompass->useData();
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
void MenuCalibrateCompass::runCommand()
|
||||
{
|
||||
switch (this->getCurrentPage())
|
||||
{
|
||||
case 2:
|
||||
switch (this->caliCompass->getState())
|
||||
{
|
||||
case CalibrateCompass::State::Ready:
|
||||
this->caliCompassMode->setCalibrateCompass(this->caliCompass);
|
||||
this->caliCompass->start();
|
||||
break;
|
||||
|
||||
case 3:
|
||||
this->caliCompass->saveData();
|
||||
break;
|
||||
|
||||
case 4:
|
||||
this->caliCompass->loadData();
|
||||
break;
|
||||
|
||||
case 5:
|
||||
this->caliCompass->removeCalibration();
|
||||
break;
|
||||
|
||||
case 6:
|
||||
case CalibrateCompass::State::Finished:
|
||||
this->caliCompassMode->setCalibrateCompass();
|
||||
this->caliCompass->useData();
|
||||
break;
|
||||
break;
|
||||
|
||||
case 7:
|
||||
this->caliCompass->reset();
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case 3:
|
||||
this->caliCompass->saveData();
|
||||
break;
|
||||
|
||||
case 4:
|
||||
this->caliCompass->loadData();
|
||||
break;
|
||||
|
||||
case 5:
|
||||
this->caliCompass->removeCalibration();
|
||||
break;
|
||||
|
||||
case 6:
|
||||
this->caliCompass->useData();
|
||||
break;
|
||||
|
||||
case 7:
|
||||
this->caliCompass->reset();
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,9 +4,9 @@
|
||||
* @brief Contains a class to print information about the class ManualControl
|
||||
* @version 0.1
|
||||
* @date 2022-01-20
|
||||
*
|
||||
*
|
||||
* @copyright Copyright (c) 2022
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef MENU_CALIBRATE_COMPASS_H
|
||||
@@ -18,35 +18,37 @@
|
||||
|
||||
/**
|
||||
* @brief A class to print informations about the class ManualControl
|
||||
*
|
||||
*
|
||||
*/
|
||||
class MenuCalibrateCompass : public MenuDriveMode {
|
||||
public:
|
||||
/**
|
||||
* @brief Construct a new Menu Manual Control object
|
||||
*
|
||||
* @param driveManager
|
||||
*/
|
||||
MenuCalibrateCompass(DriveManager* driveManager);
|
||||
~MenuCalibrateCompass();
|
||||
class MenuCalibrateCompass : public MenuDriveMode
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief Construct a new Menu Manual Control object
|
||||
*
|
||||
* @param driveManager
|
||||
*/
|
||||
MenuCalibrateCompass(DriveManager *driveManager);
|
||||
~MenuCalibrateCompass();
|
||||
|
||||
/**
|
||||
* @brief Prints the Information to display and console
|
||||
*
|
||||
* The informations are only printed to the display if it
|
||||
* set.
|
||||
*
|
||||
* Changes the DriveModi to Autopilot if it is the first time called.
|
||||
*/
|
||||
void printPage() const override;
|
||||
/**
|
||||
* @brief Prints the Information to display and console
|
||||
*
|
||||
* The informations are only printed to the display if it
|
||||
* set.
|
||||
*
|
||||
* Changes the DriveModi to Autopilot if it is the first time called.
|
||||
*/
|
||||
void printPage() const override;
|
||||
|
||||
protected:
|
||||
void init() override;
|
||||
void runCommand() const override;
|
||||
private:
|
||||
void init() override;
|
||||
void runCommand() override;
|
||||
|
||||
private:
|
||||
CalibrateCompassM* caliCompassMode;
|
||||
CalibrateCompass* caliCompass;
|
||||
CalibrateCompassM *caliCompassMode = nullptr;
|
||||
CalibrateCompass *caliCompass = nullptr;
|
||||
|
||||
static constexpr uint16_t updateDelay = 500;
|
||||
};
|
||||
|
||||
#endif // MENU_CALIBRATE_COMPASS_H
|
||||
|
||||
@@ -4,94 +4,83 @@
|
||||
* @brief Contains an implementation of the class MenuManualDrive
|
||||
* @version 0.1
|
||||
* @date 2022-01-20
|
||||
*
|
||||
*
|
||||
* @copyright Copyright (c) 2022
|
||||
*
|
||||
*
|
||||
*/
|
||||
#include "menuManualDrive.h"
|
||||
|
||||
MenuManualControl::MenuManualControl(DriveManager* driveManager) : MenuDriveMode(driveManager) {
|
||||
|
||||
MenuManualControl::MenuManualControl(DriveManager *driveManager) : MenuDriveMode(driveManager)
|
||||
{
|
||||
this->noEqualLeft = true;
|
||||
}
|
||||
|
||||
MenuManualControl::~MenuManualControl() {
|
||||
}
|
||||
|
||||
void MenuManualControl::printPage() const {
|
||||
void MenuManualControl::printPage() const
|
||||
{
|
||||
String lineOne = "";
|
||||
String lineTwo = "";
|
||||
|
||||
switch (this->getCurrentPage()) {
|
||||
case 0:
|
||||
lineOne = "-Ready to drive-";
|
||||
break;
|
||||
switch (this->getCurrentPage())
|
||||
{
|
||||
case 0:
|
||||
lineOne = "-Ready to drive-";
|
||||
break;
|
||||
|
||||
case 1:
|
||||
lineOne = "Input mode:";
|
||||
if (this->manualControl->getInputMode() == ManualControl::InputMode::Analog)
|
||||
lineTwo = "Analog";
|
||||
else
|
||||
lineTwo = "Digital";
|
||||
break;
|
||||
case 1:
|
||||
lineOne = "Input mode:";
|
||||
if (this->manualControl->getInputMode() == ManualControl::InputMode::Analog)
|
||||
{
|
||||
lineTwo = "Analog";
|
||||
}
|
||||
else
|
||||
{
|
||||
lineTwo = "Digital";
|
||||
}
|
||||
break;
|
||||
|
||||
case 2:
|
||||
lineOne = "Speed: ";
|
||||
lineOne.concat(this->manualControl->getMaxSpeed());
|
||||
lineTwo = "- dec 0.1 inc +";
|
||||
break;
|
||||
case 2:
|
||||
lineOne = "Speed Menu";
|
||||
break;
|
||||
|
||||
case 3:
|
||||
lineOne = "RotSpeed: ";
|
||||
lineOne.concat(this->manualControl->getMaxRotation());
|
||||
lineTwo = "- dec 0.1 inc +";
|
||||
break;
|
||||
case 3:
|
||||
lineOne = "Sensor Menu";
|
||||
break;
|
||||
|
||||
default:
|
||||
this->printDefault();
|
||||
default:
|
||||
this->printDefault();
|
||||
return;
|
||||
}
|
||||
|
||||
this->print(lineOne, lineTwo);
|
||||
}
|
||||
|
||||
void MenuManualControl::init() {
|
||||
void MenuManualControl::init()
|
||||
{
|
||||
this->firstPrint = false;
|
||||
this->driveManager->changeModus(Modi::ManualControl);
|
||||
this->manualControl = (ManualControl*) this->driveManager->getDriveModiPtr();
|
||||
this->manualControl = new ManualControl();
|
||||
this->driveManager->changeModus(this->manualControl);
|
||||
this->setCountPages(4);
|
||||
this->updateDelay = 500;
|
||||
MenuDriveMode::updateDelay = MenuManualControl::updateDelay;
|
||||
this->activateSpeedMenu();
|
||||
MenuDriveMode::init();
|
||||
}
|
||||
|
||||
void MenuManualControl::runCommand() const {
|
||||
switch (this->getCurrentPage()) {
|
||||
case 1:
|
||||
this->manualControl->switchInputMode();
|
||||
break;
|
||||
|
||||
case 2:
|
||||
this->manualControl->increaseMaxSpeed();
|
||||
break;
|
||||
|
||||
case 3:
|
||||
this->manualControl->increaseMaxRotation();
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void MenuManualControl::runCommandNo() const {
|
||||
void MenuManualControl::runCommand()
|
||||
{
|
||||
switch (this->getCurrentPage())
|
||||
{
|
||||
case 1:
|
||||
this->manualControl->switchInputMode();
|
||||
break;
|
||||
|
||||
case 2:
|
||||
this->manualControl->decreaseMaxSpeed();
|
||||
this->enterSpeedMenu();
|
||||
break;
|
||||
|
||||
case 3:
|
||||
this->manualControl->decreaseMaxRotation();
|
||||
this->enterSensorMenu();
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -4,49 +4,49 @@
|
||||
* @brief Contains a class to print information about the class ManualControl
|
||||
* @version 0.1
|
||||
* @date 2022-01-20
|
||||
*
|
||||
*
|
||||
* @copyright Copyright (c) 2022
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef MENU_MANUAL_DRIVE_H
|
||||
#define MENU_MANUAL_DRIVE_H
|
||||
|
||||
#include "SpecialMenus/driveModi/menuDriveMode.h"
|
||||
#include "calibrateCompass.h"
|
||||
#include "driveModi/Modi/ManualControl/manualControl.h"
|
||||
|
||||
/**
|
||||
* @brief A class to print informations about the class ManualControl
|
||||
*
|
||||
*
|
||||
*/
|
||||
class MenuManualControl : public MenuDriveMode {
|
||||
public:
|
||||
/**
|
||||
* @brief Construct a new Menu Manual Control object
|
||||
*
|
||||
* @param driveManager
|
||||
*/
|
||||
MenuManualControl(DriveManager* driveManager);
|
||||
~MenuManualControl();
|
||||
class MenuManualControl : public MenuDriveMode
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief Construct a new Menu Manual Control object
|
||||
*
|
||||
* @param driveManager
|
||||
*/
|
||||
MenuManualControl(DriveManager *driveManager);
|
||||
|
||||
/**
|
||||
* @brief Prints the Information to display and console
|
||||
*
|
||||
* The informations are only printed to the display if it
|
||||
* set.
|
||||
*
|
||||
* Changes the DriveModi to Autopilot if it is the first time called.
|
||||
*/
|
||||
void printPage() const override;
|
||||
/**
|
||||
* @brief Prints the Information to display and console
|
||||
*
|
||||
* The informations are only printed to the display if it
|
||||
* set.
|
||||
*
|
||||
* Changes the DriveModi to Autopilot if it is the first time called.
|
||||
*/
|
||||
void printPage() const override;
|
||||
|
||||
protected:
|
||||
void init() override;
|
||||
void runCommand() const override;
|
||||
void runCommandNo() const override;
|
||||
private:
|
||||
void init() override;
|
||||
void runCommand() override;
|
||||
|
||||
private:
|
||||
ManualControl* manualControl;
|
||||
CalibrateCompass* caliCompass;
|
||||
ManualControl *manualControl = nullptr;
|
||||
CalibrateCompass *caliCompass = nullptr;
|
||||
|
||||
static constexpr uint16_t updateDelay = 500;
|
||||
};
|
||||
|
||||
#endif // MENU_MANUAL_DRIVE_H
|
||||
|
||||
@@ -4,24 +4,29 @@
|
||||
* @brief Contains the implementation of the class MenuTestMode.
|
||||
* @version 0.1
|
||||
* @date 2022-09-08
|
||||
*
|
||||
*
|
||||
* @copyright Copyright (c) 2022
|
||||
*
|
||||
*
|
||||
*/
|
||||
#include "menuTestMode.h"
|
||||
|
||||
MenuTestMode::MenuTestMode(DriveManager* driveManager) {
|
||||
this->driveManager = driveManager;
|
||||
MenuTestMode::MenuTestMode(DriveManager *driveManager)
|
||||
: driveManager{driveManager}
|
||||
{
|
||||
}
|
||||
|
||||
MenuTestMode::~MenuTestMode() {
|
||||
if (isInit) {
|
||||
MenuTestMode::~MenuTestMode()
|
||||
{
|
||||
if (isInit)
|
||||
{
|
||||
delete this->mainMenu;
|
||||
}
|
||||
}
|
||||
|
||||
void MenuTestMode::printMenu() {
|
||||
if (!this->isInit) {
|
||||
void MenuTestMode::printMenu()
|
||||
{
|
||||
if (!this->isInit)
|
||||
{
|
||||
this->isInit = true;
|
||||
this->init();
|
||||
}
|
||||
@@ -29,76 +34,98 @@ void MenuTestMode::printMenu() {
|
||||
this->mainMenu->printMenu();
|
||||
}
|
||||
|
||||
void MenuTestMode::down() {
|
||||
void MenuTestMode::down()
|
||||
{
|
||||
if (this->checkInput())
|
||||
{
|
||||
this->mainMenu->down();
|
||||
}
|
||||
}
|
||||
|
||||
void MenuTestMode::up() {
|
||||
void MenuTestMode::up()
|
||||
{
|
||||
if (this->checkInput())
|
||||
{
|
||||
this->mainMenu->up();
|
||||
}
|
||||
}
|
||||
|
||||
void MenuTestMode::right() {
|
||||
void MenuTestMode::right()
|
||||
{
|
||||
if (this->checkInput())
|
||||
{
|
||||
this->mainMenu->right();
|
||||
}
|
||||
}
|
||||
|
||||
void MenuTestMode::left() {
|
||||
void MenuTestMode::left()
|
||||
{
|
||||
if (this->mainMenu->isInSubmenu())
|
||||
if (this->checkInput())
|
||||
{
|
||||
this->mainMenu->left();
|
||||
else {
|
||||
}
|
||||
else
|
||||
{
|
||||
this->testMode->abortManeuver();
|
||||
this->mainMenu->left();
|
||||
}
|
||||
else
|
||||
{
|
||||
this->parentMenu->printMenu();
|
||||
}
|
||||
}
|
||||
|
||||
void MenuTestMode::yes() {
|
||||
void MenuTestMode::yes()
|
||||
{
|
||||
if (this->checkInput())
|
||||
{
|
||||
this->mainMenu->yes();
|
||||
}
|
||||
}
|
||||
|
||||
void MenuTestMode::no() {
|
||||
void MenuTestMode::no()
|
||||
{
|
||||
if (this->mainMenu->isInSubmenu())
|
||||
{
|
||||
if (this->checkInput())
|
||||
this->mainMenu->no();
|
||||
else {
|
||||
else
|
||||
{
|
||||
this->testMode->abortManeuver();
|
||||
this->mainMenu->no();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this->left();
|
||||
}
|
||||
}
|
||||
|
||||
void MenuTestMode::init() {
|
||||
this->driveManager->changeModus(Modi::TestMode);
|
||||
this->testMode = (TestMode*) this->driveManager->getDriveModiPtr();
|
||||
void MenuTestMode::init()
|
||||
{
|
||||
this->testMode = new TestMode();
|
||||
this->driveManager->changeModus(this->testMode);
|
||||
|
||||
testMode->setMaxSpeed(1);
|
||||
testMode->setMaxRotation(8);
|
||||
|
||||
auto dummy = []() {
|
||||
std::cout << "Dummy in Action" <<std::endl;
|
||||
auto dummy = []()
|
||||
{
|
||||
std::cout << "Dummy in Action" << std::endl;
|
||||
};
|
||||
|
||||
// Create menu
|
||||
this->mainMenu = new Menu;
|
||||
Menu* engineMenu = new Menu;
|
||||
Menu* lightMenu = new Menu;
|
||||
Menu* encoderMenu = new Menu;
|
||||
auto *engineMenu = new Menu;
|
||||
auto *lightMenu = new Menu;
|
||||
auto *encoderMenu = new Menu;
|
||||
// Sound
|
||||
// Ping google
|
||||
|
||||
MenuIntInput* drivingMenu = new MenuIntInput(2, new MenuTestModeWrapper(this, &TestMode::drive));
|
||||
MenuIntInput* engineLeftMenu = new MenuIntInput(2, new MenuTestModeWrapper(this, &TestMode::leftEngine));
|
||||
MenuIntInput* engineRightMenu = new MenuIntInput(2, new MenuTestModeWrapper(this, &TestMode::rightEngine));
|
||||
MenuIntInput* engineBothMenu = new MenuIntInput(2, new MenuTestModeWrapper(this, &TestMode::bothEngine));
|
||||
SpeedometerTest* encoderLeftMenu = new SpeedometerTest(this->testMode->getSpeedometerLeft());
|
||||
SpeedometerTest* 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
|
||||
this->mainMenu->setLcd(this->lcd);
|
||||
@@ -113,49 +140,53 @@ void MenuTestMode::init() {
|
||||
encoderRightMenu->setLcd(this->lcd);
|
||||
|
||||
// Other menu config
|
||||
static constexpr uint8_t percentMax = 100;
|
||||
static constexpr uint16_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
|
||||
// Add entries to the menus
|
||||
this->mainMenu->addEntry(engineAction);
|
||||
this->mainMenu->addEntry(drivingAction);
|
||||
this->mainMenu->addEntry(encoderAction);
|
||||
@@ -173,69 +204,89 @@ void MenuTestMode::init() {
|
||||
lightMenu->addEntry(lightRedAction);
|
||||
lightMenu->addEntry(lightGreenAction);
|
||||
lightMenu->addEntry(lightBlueAction);
|
||||
lightMenu->addEntry(lightOffAction);
|
||||
lightMenu->addEntry(lightOffAction);
|
||||
}
|
||||
|
||||
void MenuTestMode::update() {
|
||||
void MenuTestMode::update()
|
||||
{
|
||||
if (this->maneuverInAction)
|
||||
if (millis() - this->lastUpdateTime > updateDelay) {
|
||||
{
|
||||
if (millis() - this->lastUpdateTime > updateDelay)
|
||||
{
|
||||
this->printManeuverTime();
|
||||
this->lastUpdateTime = millis();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool MenuTestMode::checkInput() {
|
||||
if (this->testMode->getBusy()) {
|
||||
bool MenuTestMode::checkInput()
|
||||
{
|
||||
if (this->testMode->getBusy())
|
||||
{
|
||||
this->printManeuverTime();
|
||||
this->maneuverInAction = true;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this->maneuverInAction)
|
||||
{
|
||||
this->maneuverInAction = false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void MenuTestMode::printManeuverTime() {
|
||||
void MenuTestMode::printManeuverTime()
|
||||
{
|
||||
uint8_t maneuverTime = this->testMode->getRemainingManeuverTime();
|
||||
if (maneuverTime) {
|
||||
if (maneuverTime)
|
||||
{
|
||||
String lineTwo = "";
|
||||
lineTwo.concat(maneuverTime);
|
||||
lineTwo.concat(" secs");
|
||||
this->print("Maneuver time:", lineTwo);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
this->maneuverInAction = false;
|
||||
this->printMenu();
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
void MenuTestModeWrapper::action(int16_t *values, uint8_t length)
|
||||
{
|
||||
// This function calls a member function with a pointer
|
||||
// Very helpful site:
|
||||
// https://isocpp.org/wiki/faq/pointers-to-members#fnptr-vs-memfnptr-types
|
||||
|
||||
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) {
|
||||
if (res)
|
||||
{
|
||||
this->menu->printManeuverTime();
|
||||
this->menu->maneuverStarted();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,9 +4,9 @@
|
||||
* @brief Contains a class to use and print information about the TestMode.
|
||||
* @version 0.1
|
||||
* @date 2022-09-08
|
||||
*
|
||||
*
|
||||
* @copyright Copyright (c) 2022
|
||||
*
|
||||
*
|
||||
*/
|
||||
#ifndef MENU_TEST_MODE_H
|
||||
#define MENU_TEST_MODE_H
|
||||
@@ -20,80 +20,82 @@
|
||||
|
||||
/**
|
||||
* @brief Interact with the TestMode
|
||||
*
|
||||
*
|
||||
*/
|
||||
class MenuTestMode : public MenuControl {
|
||||
public:
|
||||
/**
|
||||
* @brief Construct a new Menu Test Mode object
|
||||
*
|
||||
* @param driveManager
|
||||
*/
|
||||
MenuTestMode(DriveManager *driveManager);
|
||||
~MenuTestMode();
|
||||
class MenuTestMode : public MenuControl
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief Construct a new Menu Test Mode object
|
||||
*
|
||||
* @param driveManager
|
||||
*/
|
||||
MenuTestMode(DriveManager *driveManager);
|
||||
~MenuTestMode();
|
||||
|
||||
/**
|
||||
* @brief Prints the last informations
|
||||
*
|
||||
* On first call this function calls the init function.
|
||||
* On every call this functions call the printMenu function from
|
||||
* the mainMenu of this class.
|
||||
*/
|
||||
void printMenu() override;
|
||||
/**
|
||||
* @brief Prints the last informations
|
||||
*
|
||||
* On first call this function calls the init function.
|
||||
* On every call this functions call the printMenu function from
|
||||
* the mainMenu of this class.
|
||||
*/
|
||||
void printMenu() override;
|
||||
|
||||
/**
|
||||
* @brief Prints maneuver Timer
|
||||
*
|
||||
* Aside from that the function looks if the maneuver is done and
|
||||
* give the user input free.
|
||||
*/
|
||||
void printManeuverTime();
|
||||
/**
|
||||
* @brief Prints maneuver Timer
|
||||
*
|
||||
* Aside from that the function looks if the maneuver is done and
|
||||
* give the user input free.
|
||||
*/
|
||||
void printManeuverTime();
|
||||
|
||||
void down() override;
|
||||
void up() override;
|
||||
void right() override;
|
||||
void left() override;
|
||||
void yes() override;
|
||||
void no() override;
|
||||
void down() override;
|
||||
void up() override;
|
||||
void right() override;
|
||||
void left() override;
|
||||
void yes() override;
|
||||
void no() override;
|
||||
|
||||
/**
|
||||
* @brief Calls the printManeuverTime function if a maneuver is in process.
|
||||
*
|
||||
*/
|
||||
void update() override;
|
||||
/**
|
||||
* @brief Calls the printManeuverTime function if a maneuver is in process.
|
||||
*
|
||||
*/
|
||||
void update() override;
|
||||
|
||||
TestMode* getTestMode() const { return this->testMode; }
|
||||
void maneuverStarted() { this->maneuverInAction = true; }
|
||||
TestMode *getTestMode() const { return this->testMode; }
|
||||
void maneuverStarted() { this->maneuverInAction = true; }
|
||||
|
||||
private:
|
||||
void init();
|
||||
bool checkInput();
|
||||
private:
|
||||
void init();
|
||||
bool checkInput();
|
||||
|
||||
DriveManager* driveManager;
|
||||
TestMode* testMode;
|
||||
Menu* mainMenu;
|
||||
DriveManager *driveManager;
|
||||
TestMode *testMode = nullptr;
|
||||
Menu *mainMenu = nullptr;
|
||||
|
||||
bool isInit = false;
|
||||
bool maneuverInAction = false;
|
||||
bool isInit = false;
|
||||
bool maneuverInAction = false;
|
||||
|
||||
uint32_t lastUpdateTime = 0;
|
||||
uint16_t updateDelay = 1000;
|
||||
uint32_t lastUpdateTime = 0;
|
||||
uint16_t updateDelay = 1000;
|
||||
};
|
||||
|
||||
typedef bool (TestMode::*TestModeFunctionSingle)(int16_t);
|
||||
typedef bool (TestMode::*TestModeFunctionDouble)(int16_t, int16_t);
|
||||
class MenuTestModeWrapper : public MenuIntInputWrapper {
|
||||
public:
|
||||
MenuTestModeWrapper(MenuTestMode* menu, TestModeFunctionSingle testModeFunction);
|
||||
MenuTestModeWrapper(MenuTestMode* menu, TestModeFunctionDouble testModeFunction);
|
||||
typedef bool (TestMode::*TestModeFunctionSingle)(int16_t);
|
||||
typedef bool (TestMode::*TestModeFunctionDouble)(int16_t, int16_t);
|
||||
class MenuTestModeWrapper : public MenuIntInputWrapper
|
||||
{
|
||||
public:
|
||||
MenuTestModeWrapper(MenuTestMode *menu, TestModeFunctionSingle testModeFunction);
|
||||
MenuTestModeWrapper(MenuTestMode *menu, TestModeFunctionDouble testModeFunction);
|
||||
|
||||
void action(int16_t* values, uint8_t length) override;
|
||||
void action(int16_t *values, uint8_t length) override;
|
||||
|
||||
private:
|
||||
MenuTestMode* menu;
|
||||
TestMode* testMode;
|
||||
TestModeFunctionSingle testModeFunctionSingle = nullptr;
|
||||
TestModeFunctionDouble testModeFunctionDouble = nullptr;
|
||||
private:
|
||||
MenuTestMode *menu;
|
||||
TestMode *testMode;
|
||||
TestModeFunctionSingle testModeFunctionSingle = nullptr;
|
||||
TestModeFunctionDouble testModeFunctionDouble = nullptr;
|
||||
};
|
||||
|
||||
#endif // MENU_TEST_MODE_H
|
||||
|
||||
@@ -1,79 +1,87 @@
|
||||
/**
|
||||
* @file menuTest.cpp
|
||||
* @file speedometerTest.cpp
|
||||
* @author Alexander Klein (alex@kleiax.de)
|
||||
* @brief Contains the implementation of the class SpeedometerTest.
|
||||
* @version 0.1
|
||||
* @date 2023-01-24
|
||||
*
|
||||
*
|
||||
* @copyright Copyright (c) 2023
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#include "speedometerTest.h"
|
||||
|
||||
SpeedometerTest::SpeedometerTest(Speedometer* speedometer) {
|
||||
this->speedometer = speedometer;
|
||||
SpeedometerTest::SpeedometerTest(Speedometer *speedometer)
|
||||
: speedometer{speedometer}
|
||||
{
|
||||
this->speedometer->setDirection(Speedometer::Forward);
|
||||
}
|
||||
|
||||
void SpeedometerTest::printMenu()
|
||||
{
|
||||
switch (this->state)
|
||||
{
|
||||
case State::Off:
|
||||
this->print("Press Yes (O)", "to start");
|
||||
break;
|
||||
|
||||
void SpeedometerTest::printMenu() {
|
||||
switch (this->state) {
|
||||
case State::Off :
|
||||
this->print("Press Yes (O)", "to start");
|
||||
break;
|
||||
case State::Running:
|
||||
this->print("Running, Yes (O)", "to stop");
|
||||
break;
|
||||
|
||||
case State::Running :
|
||||
this->print("Running, Yes (O)", "to stop");
|
||||
break;
|
||||
case State::Finished:
|
||||
{
|
||||
String res = "";
|
||||
res.concat(this->result);
|
||||
this->print("Result: ", res);
|
||||
}
|
||||
break;
|
||||
|
||||
case State::Finished : {
|
||||
String res = "";
|
||||
res.concat(this->result);
|
||||
this->print("Result: ", res);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
this->print("Error in", "MenuTest.cpp");
|
||||
break;
|
||||
default:
|
||||
this->print("Error in", "MenuTest.cpp");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void SpeedometerTest::left() {
|
||||
void SpeedometerTest::left()
|
||||
{
|
||||
this->no();
|
||||
}
|
||||
|
||||
void SpeedometerTest::no() {
|
||||
void SpeedometerTest::no()
|
||||
{
|
||||
if (this->state == State::Running)
|
||||
{
|
||||
speedometer->calibrationMeasurementStop();
|
||||
}
|
||||
|
||||
this->state = State::Off;
|
||||
this->parentMenu->printMenu();
|
||||
}
|
||||
|
||||
void SpeedometerTest::yes() {
|
||||
switch (this->state) {
|
||||
case State::Off :
|
||||
this->state = State::Running;
|
||||
this->speedometer->calibrationMeasurementStart();
|
||||
this->printMenu();
|
||||
break;
|
||||
void SpeedometerTest::yes()
|
||||
{
|
||||
switch (this->state)
|
||||
{
|
||||
case State::Off:
|
||||
this->state = State::Running;
|
||||
this->speedometer->calibrationMeasurementStart();
|
||||
this->printMenu();
|
||||
break;
|
||||
|
||||
case State::Running :
|
||||
this->state = State::Finished;
|
||||
this->result = this->speedometer->calibrationMeasurementStop();
|
||||
this->printMenu();
|
||||
break;
|
||||
|
||||
case State::Finished :
|
||||
this->state = State::Running;
|
||||
this->speedometer->calibrationMeasurementStart();
|
||||
this->printMenu();
|
||||
break;
|
||||
case State::Running:
|
||||
this->state = State::Finished;
|
||||
this->result = this->speedometer->calibrationMeasurementStop();
|
||||
this->printMenu();
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
case State::Finished:
|
||||
this->state = State::Running;
|
||||
this->speedometer->calibrationMeasurementStart();
|
||||
this->printMenu();
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/**
|
||||
* @file menuTest.h
|
||||
* @file speedometerTest.h
|
||||
* @author Alexander Klein (alex@kleiax.de)
|
||||
* @brief Contains a class to test the wheel encoder.
|
||||
* @version 0.1
|
||||
* @date 2023-01-24
|
||||
*
|
||||
*
|
||||
* @copyright Copyright (c) 2023
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
@@ -16,49 +16,51 @@
|
||||
|
||||
/**
|
||||
* @brief Tests the wheel encoder.
|
||||
*
|
||||
*
|
||||
*/
|
||||
class SpeedometerTest : public MenuControl {
|
||||
public:
|
||||
/**
|
||||
* @brief The states of the test.
|
||||
*/
|
||||
enum State {
|
||||
Off,
|
||||
Running,
|
||||
Finished
|
||||
};
|
||||
class SpeedometerTest : public MenuControl
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief The states of the test.
|
||||
*/
|
||||
enum State
|
||||
{
|
||||
Off,
|
||||
Running,
|
||||
Finished
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Construct a new Speedometer Test object
|
||||
*
|
||||
* @param speedometer
|
||||
*/
|
||||
SpeedometerTest(Speedometer* speedometer);
|
||||
/**
|
||||
* @brief Construct a new Speedometer Test object
|
||||
*
|
||||
* @param speedometer
|
||||
*/
|
||||
SpeedometerTest(Speedometer *speedometer);
|
||||
|
||||
/**
|
||||
* @brief Prints the actual state of the test.
|
||||
*/
|
||||
void printMenu() override;
|
||||
/**
|
||||
* @brief Prints the actual state of the test.
|
||||
*/
|
||||
void printMenu() override;
|
||||
|
||||
/**
|
||||
* @brief Calls no.
|
||||
*/
|
||||
void left() override;
|
||||
/**
|
||||
* @brief Calls no.
|
||||
*/
|
||||
void left() override;
|
||||
|
||||
/**
|
||||
* @brief Exit the menu or end the test.
|
||||
*/
|
||||
void no() override;
|
||||
/**
|
||||
* @brief Exit the menu or end the test.
|
||||
*/
|
||||
void no() override;
|
||||
|
||||
/**
|
||||
* @brief Starts or restarts the test.
|
||||
*/
|
||||
void yes() override;
|
||||
/**
|
||||
* @brief Starts or restarts the test.
|
||||
*/
|
||||
void yes() override;
|
||||
|
||||
private:
|
||||
Speedometer* speedometer;
|
||||
State state = State::Off;
|
||||
private:
|
||||
Speedometer *speedometer;
|
||||
State state = State::Off;
|
||||
|
||||
uint16_t result = 0;
|
||||
uint16_t result = 0;
|
||||
};
|
||||
|
||||
@@ -4,27 +4,168 @@
|
||||
* @brief Contains an implementation of the class MenuDriveMode
|
||||
* @version 0.1
|
||||
* @date 2022-01-31
|
||||
*
|
||||
*
|
||||
* @copyright Copyright (c) 2022
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#include "menuDriveMode.h"
|
||||
|
||||
MenuDriveMode::MenuDriveMode(DriveManager* driveManager) {
|
||||
this->driveManager = driveManager;
|
||||
MenuDriveMode::MenuDriveMode(DriveManager *driveManager)
|
||||
: driveManager{driveManager}
|
||||
{
|
||||
}
|
||||
|
||||
void MenuDriveMode::left() {
|
||||
this->firstPrint = true;
|
||||
this->configureOnLeave();
|
||||
this->driveManager->changeModus(Modi::Off);
|
||||
if (parentMenu) {
|
||||
this->parentMenu->printMenu();
|
||||
this->leaved = true;
|
||||
MenuDriveMode::~MenuDriveMode()
|
||||
{
|
||||
if (this->selfCreatedMenuSpeed)
|
||||
{
|
||||
delete this->menuSpeed;
|
||||
}
|
||||
}
|
||||
|
||||
void MenuDriveMode::no() {
|
||||
this->left();
|
||||
void MenuDriveMode::addSpeedMenu(MenuIntInput *menuSpeed)
|
||||
{
|
||||
if (this->selfCreatedMenuSpeed)
|
||||
{
|
||||
delete this->menuSpeed;
|
||||
this->selfCreatedMenuSpeed = false;
|
||||
}
|
||||
|
||||
this->menuSpeed = menuSpeed;
|
||||
}
|
||||
|
||||
void MenuDriveMode::left()
|
||||
{
|
||||
if (static_cast<bool>(this->activeMenu))
|
||||
{
|
||||
if (static_cast<bool>(this->activeMenu))
|
||||
{
|
||||
this->activeMenu->left();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
this->firstPrint = true;
|
||||
this->configureOnLeave();
|
||||
delete this->menuSpeed;
|
||||
this->driveManager->changeModus();
|
||||
MenuInformationSites::left();
|
||||
}
|
||||
|
||||
void MenuDriveMode::right()
|
||||
{
|
||||
if (static_cast<bool>(this->activeMenu))
|
||||
{
|
||||
this->activeMenu->right();
|
||||
return;
|
||||
}
|
||||
MenuInformationSites::right();
|
||||
}
|
||||
|
||||
void MenuDriveMode::up()
|
||||
{
|
||||
if (static_cast<bool>(this->activeMenu))
|
||||
{
|
||||
this->activeMenu->up();
|
||||
return;
|
||||
}
|
||||
MenuInformationSites::up();
|
||||
}
|
||||
|
||||
void MenuDriveMode::down()
|
||||
{
|
||||
if (static_cast<bool>(this->activeMenu))
|
||||
{
|
||||
this->activeMenu->down();
|
||||
return;
|
||||
}
|
||||
MenuInformationSites::down();
|
||||
}
|
||||
|
||||
void MenuDriveMode::yes()
|
||||
{
|
||||
if (static_cast<bool>(this->activeMenu))
|
||||
{
|
||||
this->activeMenu->yes();
|
||||
return;
|
||||
}
|
||||
MenuInformationSites::yes();
|
||||
}
|
||||
|
||||
void MenuDriveMode::no()
|
||||
{
|
||||
if (static_cast<bool>(this->activeMenu))
|
||||
{
|
||||
this->activeMenu->no();
|
||||
return;
|
||||
}
|
||||
MenuInformationSites::no();
|
||||
}
|
||||
|
||||
void MenuDriveMode::prepareReenterMenu()
|
||||
{
|
||||
this->activeMenu = nullptr;
|
||||
}
|
||||
|
||||
void MenuDriveMode::printMenu()
|
||||
{
|
||||
if (static_cast<bool>(this->activeMenu))
|
||||
{
|
||||
this->activeMenu->printMenu();
|
||||
return;
|
||||
}
|
||||
|
||||
MenuInformationSites::printMenu();
|
||||
}
|
||||
|
||||
void MenuDriveMode::init()
|
||||
{
|
||||
this->activeMenu = nullptr;
|
||||
}
|
||||
|
||||
void MenuDriveMode::activateSpeedMenu()
|
||||
{
|
||||
if (!this->driveManager->isActive())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (this->selfCreatedMenuSpeed)
|
||||
{
|
||||
delete this->menuSpeed;
|
||||
}
|
||||
|
||||
DrivingSpeeds &speeds = this->driveManager->getDriveModiPtr()->getSpeedsRef();
|
||||
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);
|
||||
menu->setEntry(1, "z rad/s e-1", driveManager->getDrivingSpeedsRef().rot * 10);
|
||||
|
||||
this->selfCreatedMenuSpeed = true;
|
||||
this->addSpeedMenu(menu);
|
||||
}
|
||||
|
||||
void MenuDriveMode::enterSpeedMenu()
|
||||
{
|
||||
this->activeMenu = this->menuSpeed;
|
||||
this->enterMenu();
|
||||
}
|
||||
|
||||
void MenuDriveMode::enterSensorMenu()
|
||||
{
|
||||
this->activeMenu = this->menuSensor;
|
||||
this->enterMenu();
|
||||
}
|
||||
|
||||
void MenuDriveMode::enterMenu()
|
||||
{
|
||||
if (!static_cast<bool>(this->activeMenu))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
this->activeMenu->printMenu();
|
||||
this->activeMenu->setParentMenu(this);
|
||||
}
|
||||
|
||||
@@ -4,44 +4,94 @@
|
||||
* @brief Contains a base class for Menus about DriveModi
|
||||
* @version 0.1
|
||||
* @date 2022-01-31
|
||||
*
|
||||
*
|
||||
* @copyright Copyright (c) 2022
|
||||
*
|
||||
*
|
||||
*/
|
||||
#ifndef MENU_DRIVE_MODI_H
|
||||
#define MENU_DRIVE_MODI_H
|
||||
|
||||
#include "menuInformationSites.h"
|
||||
#include "driveModi/driveManager.h"
|
||||
#include "SpecialMenus/SensorData/menuSensorData.h"
|
||||
#include "SpecialMenus/Speed/menuSpeed.h"
|
||||
|
||||
/**
|
||||
* @brief A base class for Menus about DriveModi
|
||||
*
|
||||
*
|
||||
*/
|
||||
class MenuDriveMode : public MenuInformationSites {
|
||||
public:
|
||||
/**
|
||||
* @brief Construct a new Menu Drive Mode object
|
||||
*
|
||||
* @param driveManager
|
||||
*/
|
||||
MenuDriveMode(DriveManager* driveManager);
|
||||
class MenuDriveMode : public MenuInformationSites
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief Construct a new Menu Drive Mode object
|
||||
*
|
||||
* @param driveManager
|
||||
*/
|
||||
MenuDriveMode(DriveManager *driveManager);
|
||||
|
||||
/**
|
||||
* @brief Goes back to the parentMenu.
|
||||
*/
|
||||
void left() override;
|
||||
~MenuDriveMode();
|
||||
|
||||
/**
|
||||
* @brief Calls left.
|
||||
*/
|
||||
void no() override;
|
||||
void addSensorMenu(MenuSensorData *menuSensor) { this->menuSensor = menuSensor; }
|
||||
void addSpeedMenu(MenuIntInput *menuSpeed);
|
||||
|
||||
protected:
|
||||
void configureOnLeave() {}
|
||||
/**
|
||||
* @brief Goes back to the parentMenu.
|
||||
*/
|
||||
void left() override;
|
||||
void right() override;
|
||||
void up() override;
|
||||
void down() override;
|
||||
void yes() override;
|
||||
void no() override;
|
||||
|
||||
DriveManager* driveManager;
|
||||
bool firstPrint = true;
|
||||
void prepareReenterMenu() override;
|
||||
void printMenu() override;
|
||||
|
||||
protected:
|
||||
void init() override;
|
||||
|
||||
/**
|
||||
* @brief Prepare leaving the menu
|
||||
*
|
||||
* Can be overwritten to add extra functionality to safely
|
||||
* exit the menu. This function is called before the parentMenu
|
||||
* is printed.
|
||||
*/
|
||||
virtual void configureOnLeave() {}
|
||||
|
||||
/**
|
||||
* @brief Creates an own SpeedMenu
|
||||
*
|
||||
* This function uses addSpeedMenu() at the end to that the new menu
|
||||
*/
|
||||
void activateSpeedMenu();
|
||||
|
||||
/**
|
||||
* @brief Enter a Menu to edit the speeds
|
||||
*
|
||||
* To enter this menu it has to be set by addSpeedMenu() or activateSpeedMenu()
|
||||
*/
|
||||
void enterSpeedMenu();
|
||||
|
||||
/**
|
||||
* @brief Enter a Menu with the SensorData
|
||||
*
|
||||
* To enter this menu it has to be set by addSensorMenu()
|
||||
*/
|
||||
void enterSensorMenu();
|
||||
|
||||
DriveManager *driveManager;
|
||||
|
||||
bool firstPrint = true;
|
||||
|
||||
private:
|
||||
void enterMenu();
|
||||
|
||||
MenuControl *activeMenu = nullptr;
|
||||
MenuSensorData *menuSensor = nullptr;
|
||||
MenuIntInput *menuSpeed = nullptr;
|
||||
|
||||
bool selfCreatedMenuSpeed = false;
|
||||
};
|
||||
|
||||
#endif // MENU_DRIVE_MODI_H
|
||||
|
||||
Reference in New Issue
Block a user