From 76ad017475b9b407e820038dfd0793d6ac73f9e7 Mon Sep 17 00:00:00 2001 From: Alexander Klein Date: Mon, 13 Feb 2023 20:55:31 +0100 Subject: [PATCH] refactor, comment and move speedometerTest --- src/SpecialMenus/Test/menuTest.h | 37 ----------- .../driveModi/TestMode/menuTestMode.cpp | 14 ++++ .../driveModi/TestMode/menuTestMode.h | 1 + .../TestMode/speedometerTest.cpp} | 14 ++-- .../driveModi/TestMode/speedometerTest.h | 64 +++++++++++++++++++ src/driveModi/Modi/TestMode/testMode.h | 2 + src/main.cpp | 4 -- 7 files changed, 88 insertions(+), 48 deletions(-) delete mode 100644 src/SpecialMenus/Test/menuTest.h rename src/SpecialMenus/{Test/menuTest.cpp => driveModi/TestMode/speedometerTest.cpp} (84%) create mode 100644 src/SpecialMenus/driveModi/TestMode/speedometerTest.h diff --git a/src/SpecialMenus/Test/menuTest.h b/src/SpecialMenus/Test/menuTest.h deleted file mode 100644 index 0d89c0b..0000000 --- a/src/SpecialMenus/Test/menuTest.h +++ /dev/null @@ -1,37 +0,0 @@ -/** - * @file menuTest.h - * @author Alexander Klein (alex@kleiax.de) - * @brief - * @version 0.1 - * @date 2023-01-24 - * - * @copyright Copyright (c) 2023 - * - */ - -#pragma once - -#include "menuControl.h" -#include "speedometer.h" - -class MenuTest : public MenuControl { - public: - enum State { - Off, - Running, - Finished - }; - MenuTest(Speedometer* speedometer); - - void printMenu() override; - - void left() override; - void no() override; - void yes() override; - - private: - Speedometer* speedometer; - State state = State::Off; - - uint16_t result = 0; -}; diff --git a/src/SpecialMenus/driveModi/TestMode/menuTestMode.cpp b/src/SpecialMenus/driveModi/TestMode/menuTestMode.cpp index 4b8417e..a9fd1b2 100644 --- a/src/SpecialMenus/driveModi/TestMode/menuTestMode.cpp +++ b/src/SpecialMenus/driveModi/TestMode/menuTestMode.cpp @@ -90,6 +90,7 @@ void MenuTestMode::init() { this->mainMenu = new Menu; Menu* engineMenu = new Menu; Menu* lightMenu = new Menu; + Menu* encoderMenu = new Menu; // Sound // Ping google // WheelEncoder @@ -98,6 +99,8 @@ void MenuTestMode::init() { 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()); // Set menus on LCD @@ -108,6 +111,9 @@ void MenuTestMode::init() { engineBothMenu->setLcd(this->lcd); drivingMenu->setLcd(this->lcd); lightMenu->setLcd(this->lcd); + encoderMenu->setLcd(this->lcd); + encoderLeftMenu->setLcd(this->lcd); + encoderRightMenu->setLcd(this->lcd); // Other menu config drivingMenu->setEntry(0, "Centimeter", 100); @@ -140,6 +146,10 @@ void MenuTestMode::init() { MenuAction* drivingAction = new MenuAction("Driving", drivingMenu); + MenuAction* encoderAction = new MenuAction("Encoder", encoderMenu); + MenuAction* encoderLeftAction = new MenuAction("Left", encoderLeftMenu); + MenuAction* encoderRightAction = new MenuAction("Right", encoderRightMenu); + MenuAction* lightAction = new MenuAction("Light", lightMenu); MenuAction* lightFlashAction = new MenuAction("Flash", dummy); MenuAction* lightFadeAction = new MenuAction("Fade", dummy); @@ -151,12 +161,16 @@ void MenuTestMode::init() { // Add entrys to the menus this->mainMenu->addEntry(engineAction); this->mainMenu->addEntry(drivingAction); + this->mainMenu->addEntry(encoderAction); this->mainMenu->addEntry(lightAction); engineMenu->addEntry(engineLeftAction); engineMenu->addEntry(engineRightAction); engineMenu->addEntry(engineBothAction); + encoderMenu->addEntry(encoderLeftAction); + encoderMenu->addEntry(encoderRightAction); + lightMenu->addEntry(lightFlashAction); lightMenu->addEntry(lightFadeAction); lightMenu->addEntry(lightRedAction); diff --git a/src/SpecialMenus/driveModi/TestMode/menuTestMode.h b/src/SpecialMenus/driveModi/TestMode/menuTestMode.h index f795bc4..45e9046 100644 --- a/src/SpecialMenus/driveModi/TestMode/menuTestMode.h +++ b/src/SpecialMenus/driveModi/TestMode/menuTestMode.h @@ -16,6 +16,7 @@ #include "menu.h" #include "menuAction.h" #include "menuIntInput.h" +#include "speedometerTest.h" /** * @brief Interact with the TestMode diff --git a/src/SpecialMenus/Test/menuTest.cpp b/src/SpecialMenus/driveModi/TestMode/speedometerTest.cpp similarity index 84% rename from src/SpecialMenus/Test/menuTest.cpp rename to src/SpecialMenus/driveModi/TestMode/speedometerTest.cpp index 2902b37..bbd7c8f 100644 --- a/src/SpecialMenus/Test/menuTest.cpp +++ b/src/SpecialMenus/driveModi/TestMode/speedometerTest.cpp @@ -1,7 +1,7 @@ /** * @file menuTest.cpp * @author Alexander Klein (alex@kleiax.de) - * @brief + * @brief Contains the implementation of the class SpeedometerTest. * @version 0.1 * @date 2023-01-24 * @@ -9,14 +9,14 @@ * */ -#include "menuTest.h" +#include "speedometerTest.h" -MenuTest::MenuTest(Speedometer* speedometer) { +SpeedometerTest::SpeedometerTest(Speedometer* speedometer) { this->speedometer = speedometer; } -void MenuTest::printMenu() { +void SpeedometerTest::printMenu() { switch (this->state) { case State::Off : this->print("Press Yes (O)", "to start"); @@ -40,11 +40,11 @@ void MenuTest::printMenu() { } -void MenuTest::left() { +void SpeedometerTest::left() { this->no(); } -void MenuTest::no() { +void SpeedometerTest::no() { if (this->state == State::Running) speedometer->calibrationMeasurementStop(); @@ -52,7 +52,7 @@ void MenuTest::no() { this->parentMenu->printMenu(); } -void MenuTest::yes() { +void SpeedometerTest::yes() { switch (this->state) { case State::Off : this->state = State::Running; diff --git a/src/SpecialMenus/driveModi/TestMode/speedometerTest.h b/src/SpecialMenus/driveModi/TestMode/speedometerTest.h new file mode 100644 index 0000000..609e474 --- /dev/null +++ b/src/SpecialMenus/driveModi/TestMode/speedometerTest.h @@ -0,0 +1,64 @@ +/** + * @file menuTest.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 + +#include "menuControl.h" +#include "speedometer.h" + +/** + * @brief Tests the wheel encoder. + * + */ +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 Prints the actual state of the test. + */ + void printMenu() override; + + /** + * @brief Calls no. + */ + void left() override; + + /** + * @brief Exit the menu or end the test. + */ + void no() override; + + /** + * @brief Starts or restarts the test. + */ + void yes() override; + + private: + Speedometer* speedometer; + State state = State::Off; + + uint16_t result = 0; +}; diff --git a/src/driveModi/Modi/TestMode/testMode.h b/src/driveModi/Modi/TestMode/testMode.h index 09bbb74..9fad2b4 100644 --- a/src/driveModi/Modi/TestMode/testMode.h +++ b/src/driveModi/Modi/TestMode/testMode.h @@ -121,6 +121,8 @@ class TestMode : public DriveModi { */ bool getBusy() const { return this->busy; } Maneuver getManeuver() const { return this->maneuver; } + Speedometer* getSpeedometerLeft() { this->moveControl->getSpeedometerLeft(); } + Speedometer* getSpeedometerRight() { this->moveControl->getSpeedometerRight(); } private: bool engineInit(int16_t powerPercentage, int16_t seconds); diff --git a/src/main.cpp b/src/main.cpp index 63b428c..3f28aa4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -275,7 +275,6 @@ void makeMenu() { MenuGPS* gps_m = new MenuGPS(driveManager); MenuSysteminformation* sys_m = new MenuSysteminformation(mainBattery, gamepad); MenuRoute* rout_m = new MenuRoute(driveManager->getNavigation()->getRoute()); - MenuTest* test_m = new MenuTest(moveController.getSpeedometerLeft()); // Set Menus on LCD main_m->setLcd(lcdWrapper); @@ -290,7 +289,6 @@ void makeMenu() { gps_m->setLcd(LcdWrapper); sys_m->setLcd(LcdWrapper); rout_m->setLcd(LcdWrapper); - test_m->setLcd(LcdWrapper); // Entry for the main menu @@ -301,13 +299,11 @@ void makeMenu() { MenuAction* contr_e = new MenuAction("Remove PS3", disconnectController); MenuAction* sys_e = new MenuAction("Systeminfo", sys_m); MenuAction* rout_e = new MenuAction("Route", rout_m); - MenuAction* test_e = new MenuAction("Test", test_m); main_m->addEntry(mode_e); main_m->addEntry(gps_e); main_m->addEntry(rout_e); main_m->addEntry(pid_e); main_m->addEntry(sys_e); - main_m->addEntry(test_e); main_m->addEntry(contr_e); main_m->addEntry(restart_e);