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
@@ -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
@@ -0,0 +1,78 @@
/**
* @file menuTest.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;
}
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::Finished : {
String res = "";
res.concat(this->result);
this->print("Result: ", res);
}
break;
default:
this->print("Error in", "MenuTest.cpp");
break;
}
}
void SpeedometerTest::left() {
this->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;
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;
default:
break;
}
}
@@ -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;
};