refactor, comment and move speedometerTest

This commit is contained in:
2023-02-13 20:55:31 +01:00
parent deecf7724c
commit 76ad017475
7 changed files with 88 additions and 48 deletions
-37
View File
@@ -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;
};
@@ -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);
@@ -16,6 +16,7 @@
#include "menu.h"
#include "menuAction.h"
#include "menuIntInput.h"
#include "speedometerTest.h"
/**
* @brief Interact with the TestMode
@@ -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;
@@ -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;
};
+2
View File
@@ -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);
-4
View File
@@ -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);