doxygen comments

This commit is contained in:
2023-10-12 19:50:26 +02:00
parent f05ab56833
commit 9b8bf22795
11 changed files with 1346 additions and 1014 deletions
+26 -3
View File
@@ -1,7 +1,7 @@
/**
* @file displayWrapper.h
* @author Alexander Klein (alex@kleiax.de)
* @brief
* @brief Contains a interface to presents a display
* @version 0.1
* @date 2023-01-08
*
@@ -12,10 +12,33 @@
#ifndef DISPLAY_WRAPPER_H
#define DISPLAY_WRAPPER_H
class DisplayWrapper {
public:
/**
* @brief This interface abstracted a display
*
* With this inteface a display which works with columns
* and lines can be wrapped to be accepted by menus.
*/
class DisplayWrapper
{
public:
/**
* @brief Remove everything from the display
*/
virtual void clear() = 0;
/**
* @brief Set the cursor to specific line and column
*
* @param row
* @param line
*/
virtual void setCursor(uint8_t row, uint8_t line) = 0;
/**
* @brief Print to the position set by setCursor()
*
* @param str
*/
virtual void print(const char *str) = 0;
};
+29 -9
View File
@@ -19,24 +19,45 @@
class MenuAction;
/**
* @brief A class to build menu structers
* @brief A class to build menu structures
*/
class Menu : public MenuControl {
public:
class Menu : public MenuControl
{
public:
Menu();
~Menu() override;
/**
* @brief Add a menu action to the menu
* @brief Add a MenuAction to the menu
*
* Every MenuAction is an Entry in the Menu
*
* @param entry
*/
void addEntry(MenuAction* entry);
void addEntry(MenuAction *entry);
/**
* @brief get information about the active menu
*
* If this is not the active menu, will be passed to
* active menu.
*
* @return true an other menu is active
* @return false this menu is active
*/
bool isInSubmenu();
/**
* @brief Print the actual screen
*/
void printMenu() override;
/**
* @brief Print the screen from the active menu
*/
void update() override;
// User Inputs
void down() override;
void up() override;
void right() override;
@@ -44,12 +65,11 @@ class Menu : public MenuControl {
void yes() override;
void no() override;
private:
private:
bool inSubmenu = false;
std::list<MenuAction*> entrys;
std::list<MenuAction*>::iterator selectedEntry;
std::list<MenuAction *> entries;
std::list<MenuAction *>::iterator selectedEntry;
};
#endif // MENU_H
+27 -17
View File
@@ -15,9 +15,19 @@
class MenuControl;
class MenuActionWrapper {
public:
/**
* @brief An Interface to execute actions
*
* This interface can be inherited to wrap actions
* in it for a MenuAction.
*/
class MenuActionWrapper
{
public:
virtual ~MenuActionWrapper() {}
/**
* @brief Function to be called by the MenuAction
*/
virtual void action() = 0;
};
@@ -27,9 +37,9 @@ class MenuActionWrapper {
* In the Menu these are the entries.
* This class can be call an submenu or a function.
*/
class MenuAction {
public:
class MenuAction
{
public:
/**
* @brief Construct a new Menu Action object
*
@@ -37,7 +47,7 @@ class MenuAction {
* @param function to call when activate the entry
* @param callback to call when leave the entry
*/
MenuAction(const char* name, void (*function) (), void (*callback) () = nullptr);
MenuAction(const char *name, void (*function)(), void (*callback)() = nullptr);
/**
* @brief Construct a new Menu Action object
@@ -45,17 +55,17 @@ class MenuAction {
* @param name shown in the Menu
* @param action to call when activate the entry
*/
MenuAction(const char* name, MenuActionWrapper* action);
MenuAction(const char *name, MenuActionWrapper *action);
/**
* @brief Construct a new Menu Action object
*
* This constructer is used for submenus.
* This constructor is used for submenus.
*
* @param name shown in the Menu
* @param menu to call when activate the entry
*/
MenuAction(const char* name, MenuControl* menu);
MenuAction(const char *name, MenuControl *menu);
~MenuAction();
@@ -69,7 +79,7 @@ class MenuAction {
*
* @return const char*
*/
const char* getName();
const char *getName();
/**
* @brief Get the Is Menu object
@@ -87,17 +97,17 @@ class MenuAction {
*
* @return MenuControl*
*/
MenuControl* getMenu();
MenuControl *getMenu();
private:
const char* name;
private:
const char *name;
void (*function) () = nullptr;
void (*callback) () = nullptr;
void (*function)() = nullptr;
void (*callback)() = nullptr;
bool isMenu = false;
MenuControl* menu = nullptr;
MenuActionWrapper* action = nullptr;
MenuControl *menu = nullptr;
MenuActionWrapper *action = nullptr;
};
#endif // MENU_ENTRY_H
+42 -27
View File
@@ -23,9 +23,10 @@
* act as a menu, because the menu structure uses polymorphism.
*
*/
class MenuControl {
public:
virtual ~MenuControl() {};
class MenuControl
{
public:
virtual ~MenuControl(){};
/** @name UserInputs
* @brief This functions should be called be user actions.
@@ -34,30 +35,37 @@ class MenuControl {
* class.
*/
///@{
virtual void down() {};
virtual void up() {};
virtual void right() {};
virtual void left() {};
virtual void yes() {};
virtual void no() {};
virtual void down(){};
virtual void up(){};
virtual void right(){};
virtual void left(){};
virtual void yes(){};
virtual void no(){};
///@}
/**
* @brief can be called to update shown data
*
* The data will be only updated if a updateDelay is set
* and delay is reached.
*/
virtual void update() {
if (this->updateDelay == 0)
return;
if (millis() - this->lastUpdateMillis < this->updateDelay) {
return;
}
this->printMenu();
this->lastUpdateMillis = millis();
}
virtual void update();
/**
* @brief Prepare reenter the this menu
*
* This function must be called separately
*/
virtual void prepareReenterMenu() {}
/**
* @brief Function to print the Menu
*
* Have to be overwritten to implement the representation
* of the menu.
* This function have to call the print() function to access
* the display.
*/
virtual void printMenu() = 0;
/**
@@ -65,11 +73,12 @@ class MenuControl {
*
* If the parentMenu is set it will be called automaticaly
* when the user left the child menu.
* If the parentMenu has set a LCD it will be copied to the
* actual instance.
*
* @param menu
*/
void setParentMenu(MenuControl* menu);
// MenuControl* getParentMenu() { return this->parentMenu; }
void setParentMenu(MenuControl *menu);
/**
* @brief Set the Lcd object
@@ -78,7 +87,7 @@ class MenuControl {
*
* @param lcd
*/
void setLcd(DisplayWrapper* lcd) { this->lcd = lcd; }
void setLcd(DisplayWrapper *lcd) { this->lcd = lcd; }
/**
* @brief Set the time between each new print to the display
@@ -90,12 +99,18 @@ class MenuControl {
*/
void setUpdateDelay(uint16_t delay = 0) { this->updateDelay = delay; }
protected:
protected:
/**
* @brief
*
* @param lineOne
* @param lineTwo
*/
void print(String lineOne, String lineTwo) const;
DisplayWrapper* getLcd() const { return this->lcd; }
DisplayWrapper *getLcd() const { return this->lcd; }
MenuControl* parentMenu = nullptr;
DisplayWrapper* lcd = nullptr;
MenuControl *parentMenu = nullptr;
DisplayWrapper *lcd = nullptr;
uint16_t updateDelay = 0;
uint32_t lastUpdateMillis = 0;
+74 -9
View File
@@ -13,12 +13,18 @@
#include "menuControl.h"
class MenuInformationSites : public MenuControl {
public:
/**
* @brief A Menu interface to show informations
*
* The informations a organized by multiple pages
*/
class MenuInformationSites : public MenuControl
{
public:
/**
* @brief Construct a new Menu Information Sites object
*
* @param amount of pages
* @param pages amount of the available pages
*/
MenuInformationSites(uint8_t pages = 1);
@@ -43,12 +49,12 @@ class MenuInformationSites : public MenuControl {
void left() override;
/**
* @brief Go to the parent menu
* @brief Calls runCommandNo()
*/
void no() override;
/**
* @brief Update information
* @brief Calls runCommand()
*/
void yes() override;
@@ -56,28 +62,87 @@ class MenuInformationSites : public MenuControl {
* @brief Prints the Information to display and console
*
* Prints the selected page.
* The informations are only printed to the display if it
* set.
*/
void printMenu() override;
protected:
protected:
/**
* @brief Change the amount of available pages
*
* @param pages
* @return true successful
* @return false
*/
bool setCountPages(uint8_t pages);
/**
* @brief Get the amount of available pages
*
* @return uint8_t
*/
uint8_t getCountPages() const;
/**
* @brief Get the selected page number
*
* @return uint8_t
*/
uint8_t getCurrentPage() const;
/**
* @brief Print a page with informations
*
* This function have to be overwritten.
* The function have to use the print() function to access the display.
* The printed informations should be depends from the current page,
* which can determine by call getCurrentPage().
*/
virtual void printPage() const = 0;
/**
* @brief Function to adds actions
*
* If this function is overwritten, the menu can be extended
* with extra functionality. The executed action should be depends on
* the current page, which can determine by call getCurrentPage().
*
* This function is called if no() is called.
*/
virtual void runCommandNo() {}
/**
* @brief Function to adds actions
*
* If this function is overwritten, the menu can be extended
* with extra functionality. The executed action should be depends on
* the current page, which can determine by call getCurrentPage().
*
* This function is called if yes() is called.
*/
virtual void runCommand() {}
/**
* @brief Function to prepare dependencies
*
* This function is called when the menu is entered.
*/
virtual void init() {}
/**
* @brief Prints default informations
*
* The default informations are the current page number
* and the amount of available pages.
*
* Can be used by printPage() if the current page is not available.
*/
void printDefault() const;
uint8_t lastPageNumber = 0;
bool leaved = true;
bool noEqualLeft = false;
private:
private:
uint8_t countPages;
uint8_t currentPage;
+122 -19
View File
@@ -1,7 +1,7 @@
/**
* @file menuIntInput.h
* @author Alexander Klein (alex@kleiax.de)
* @brief
* @brief Contains a class to get integer inputs from the user
* @version 0.1
* @date 2022-09-12
*
@@ -16,31 +16,135 @@
#define MAX_NAME_LENGTH 12
class MenuIntInputWrapper {
public:
/**
* @brief Interface to transfer the integer data
*/
class MenuIntInputWrapper
{
public:
virtual ~MenuIntInputWrapper() {}
virtual void action(int16_t* values, uint8_t length) = 0;
/**
* @brief Transfer function
*
* This function will be called by MenuIntInput, if the input
* are confirmed.
*
* @param values
* @param length amount of integer
*/
virtual void action(int16_t *values, uint8_t length) = 0;
};
class MenuIntInput : public MenuControl {
public:
MenuIntInput(int16_t values[], char *names, uint8_t length, MenuIntInputWrapper* wrapper);
/**
* @brief A Menu class to make integer inputs
*/
class MenuIntInput : public MenuControl
{
public:
/**
* @brief Construct a new Menu Int Input object
*
* @param values the integer values
* @param names names of the values
* @param length amount of values
* @param wrapper MenuIntInputWrapper
*/
MenuIntInput(int16_t values[], char *names, uint8_t length, MenuIntInputWrapper *wrapper);
MenuIntInput(uint8_t length, MenuIntInputWrapper *wrapper);
~MenuIntInput();
void setEntry(uint8_t valueNumber, const char* name, int16_t startValue = 0);
/**
* @brief Set a specific entry
*
* @param valueNumber the entry
* @param name name of entry
* @param startValue default value
*/
void setEntry(uint8_t valueNumber, const char *name, int16_t startValue = 0);
/**
* @brief Set the minium for a specific value
*
* @param valueNumber the entry
* @param min
*/
void setMin(uint8_t valueNumber, int16_t min);
void setMin(int16_t min);
void setMax(uint8_t valueNumber, int16_t max);
void setMax(int16_t max);
void setMinMax(uint8_t valueNumber, int16_t min, int16_t max);
void setMinMax(int16_t min, int16_t max);
void setMinMaxSteps(uint8_t valueNumber, int16_t min, int16_t max, uint8_t steps);
void setMinMaxSteps(int16_t min, int16_t max, uint8_t steps);
void setPrintParentMenu(bool b) { this->printParentMenu = b; }
/**
* @brief Set the minimum for all entries
*
* @param min
*/
void setMin(int16_t min);
/**
* @brief Set the maximum for a specific value
*
* @param valueNumber the entry
* @param max
*/
void setMax(uint8_t valueNumber, int16_t max);
/**
* @brief Set the maximum for all entries
*
* @param max
*/
void setMax(int16_t max);
/**
* @brief Set the minium and the maximum for a specific value
*
* @param valueNumber the entry
* @param min
* @param max
*/
void setMinMax(uint8_t valueNumber, int16_t min, int16_t max);
/**
* @brief Set the minium and the maximum for all entries
*
* @param valueNumber the entry
* @param min
* @param max
*/
void setMinMax(int16_t min, int16_t max);
/**
* @brief Set the minium, the maximum and the steps for a specific value
*
* @param valueNumber the entry
* @param min
* @param max
* @param steps for increment and decrement
*/
void setMinMaxSteps(uint8_t valueNumber, int16_t min, int16_t max, uint8_t steps);
/**
* @brief Set the minium, the maximum and the steps for all entries
*
* @param valueNumber the entry
* @param min
* @param max
* @param steps for increment and decrement
*/
void setMinMaxSteps(int16_t min, int16_t max, uint8_t steps);
void setPrintParentMenu(bool b) { this->printParentMenu = b; }
/**
* @brief Set the steps for a specific value
*
* @param valueNumber the entry
* @param steps
*/
void setStepsPerInput(uint8_t valueNumber, uint8_t steps);
/**
* @brief Set the steps for all entries
*
* @param steps
*/
void setStepsPerInput(uint8_t steps);
/**
@@ -81,8 +185,8 @@ class MenuIntInput : public MenuControl {
*/
void printMenu() override;
private:
MenuIntInputWrapper* wrapper;
private:
MenuIntInputWrapper *wrapper;
bool printParentMenu = true;
@@ -95,7 +199,6 @@ class MenuIntInput : public MenuControl {
int16_t *min;
int16_t *max;
char *names;
};
#endif // MENU_INT_INPUT_H
+59 -35
View File
@@ -10,97 +10,117 @@
*/
#include "menu.h"
Menu::Menu() {
this->selectedEntry = this->entrys.begin();
Menu::Menu()
{
this->selectedEntry = this->entries.begin();
}
Menu::~Menu() {
for (std::list<MenuAction*>::iterator iter = this->entrys.begin(); iter != this->entrys.end(); iter++)
Menu::~Menu()
{
for (std::list<MenuAction *>::iterator iter = this->entries.begin(); iter != this->entries.end(); iter++)
delete *iter;
}
void Menu::addEntry(MenuAction* entry) {
this->entrys.push_back(entry);
void Menu::addEntry(MenuAction *entry)
{
this->entries.push_back(entry);
if (this->entrys.size() == 2)
this->selectedEntry = this->entrys.begin();
if (this->entries.size() == 2)
this->selectedEntry = this->entries.begin();
}
bool Menu::isInSubmenu() {
bool Menu::isInSubmenu()
{
return this->inSubmenu;
}
void Menu::printMenu() {
std::list<MenuAction*>::iterator iter = this->selectedEntry;
void Menu::printMenu()
{
std::list<MenuAction *>::iterator iter = this->selectedEntry;
String lineOne = "-> ";
String lineTwo = "";
lineOne.concat((**iter).getName());
iter++;
if (iter != this->entrys.end()) {
if (iter != this->entries.end())
{
lineTwo.concat((**iter).getName());
} else
lineTwo.concat((*this->entrys.begin())->getName());
}
else
lineTwo.concat((*this->entries.begin())->getName());
this->inSubmenu = false;
this->print(lineOne, lineTwo);
}
void Menu::update() {
if (this->inSubmenu) {
void Menu::update()
{
if (this->inSubmenu)
{
(**this->selectedEntry).getMenu()->update();
return;
}
}
void Menu::down() {
if (this->inSubmenu) {
void Menu::down()
{
if (this->inSubmenu)
{
(**this->selectedEntry).getMenu()->down();
return;
}
// TODO: Why I need the fucking next two lines? here and in the next function
std::list<MenuAction*>::iterator iter = this->selectedEntry;
std::list<MenuAction *>::iterator iter = this->selectedEntry;
iter++;
if (iter != this->entrys.end())
if (iter != this->entries.end())
this->selectedEntry++;
else
this->selectedEntry = this->entrys.begin();
this->selectedEntry = this->entries.begin();
this->printMenu();
}
void Menu::up() {
if (this->inSubmenu) {
void Menu::up()
{
if (this->inSubmenu)
{
(**this->selectedEntry).getMenu()->up();
return;
}
std::list<MenuAction*>::iterator iter = this->entrys.end();
std::list<MenuAction *>::iterator iter = this->entries.end();
iter--;
if (this->selectedEntry != this->entrys.begin()) {
if (this->selectedEntry != this->entries.begin())
{
this->selectedEntry--;
}
else {
else
{
this->selectedEntry = iter;
}
this->printMenu();
}
void Menu::right() {
if (this->inSubmenu) {
void Menu::right()
{
if (this->inSubmenu)
{
(**this->selectedEntry).getMenu()->right();
return;
}
if ((**this->selectedEntry).getIsMenu()) {
if ((**this->selectedEntry).getIsMenu())
{
this->inSubmenu = true;
(**this->selectedEntry).getMenu()->setParentMenu(this);
}
(**this->selectedEntry).runAction();
}
void Menu::left() {
if (this->inSubmenu) {
void Menu::left()
{
if (this->inSubmenu)
{
(**this->selectedEntry).getMenu()->left();
return;
}
@@ -109,8 +129,10 @@ void Menu::left() {
this->parentMenu->printMenu();
}
void Menu::yes() {
if (this->inSubmenu) {
void Menu::yes()
{
if (this->inSubmenu)
{
(**this->selectedEntry).getMenu()->yes();
return;
}
@@ -118,8 +140,10 @@ void Menu::yes() {
this->right();
}
void Menu::no() {
if (this->inSubmenu) {
void Menu::no()
{
if (this->inSubmenu)
{
(**this->selectedEntry).getMenu()->no();
return;
}
+18 -9
View File
@@ -10,24 +10,28 @@
*/
#include "menuAction.h"
MenuAction::MenuAction(const char* name, void (*function) (), void (*callback) ()) {
MenuAction::MenuAction(const char *name, void (*function)(), void (*callback)())
{
this->name = name;
this->function = function;
this->callback = callback;
}
MenuAction::MenuAction(const char* name, MenuControl* menu) {
MenuAction::MenuAction(const char *name, MenuControl *menu)
{
this->name = name;
this->menu = menu;
this->isMenu = true;
}
MenuAction::MenuAction(const char* name, MenuActionWrapper* action) {
MenuAction::MenuAction(const char *name, MenuActionWrapper *action)
{
this->name = name;
this->action = action;
}
MenuAction::~MenuAction() {
MenuAction::~MenuAction()
{
if (this->menu)
delete this->menu;
@@ -35,10 +39,12 @@ MenuAction::~MenuAction() {
delete this->action;
}
void MenuAction::runAction() {
void MenuAction::runAction()
{
if (isMenu)
this->menu->printMenu();
else {
else
{
if (this->function)
this->function();
else if (this->action)
@@ -51,15 +57,18 @@ void MenuAction::runAction() {
this->callback();
}
const char* MenuAction::getName() {
const char *MenuAction::getName()
{
return this->name;
}
bool MenuAction::getIsMenu() {
bool MenuAction::getIsMenu()
{
return this->isMenu;
}
MenuControl* MenuAction::getMenu() {
MenuControl *MenuAction::getMenu()
{
if (isMenu)
return this->menu;
else
+20 -4
View File
@@ -10,9 +10,24 @@
*/
#include "menuControl.h"
void MenuControl::update()
{
if (this->updateDelay == 0)
return;
void MenuControl::print(String lineOne, String lineTwo) const {
if (this->lcd) {
if (millis() - this->lastUpdateMillis < this->updateDelay)
{
return;
}
this->printMenu();
this->lastUpdateMillis = millis();
}
void MenuControl::print(String lineOne, String lineTwo) const
{
if (this->lcd)
{
lcd->clear();
lcd->setCursor(0, 0);
lcd->print(lineOne.c_str());
@@ -21,9 +36,10 @@ void MenuControl::print(String lineOne, String lineTwo) const {
}
}
void MenuControl::setParentMenu(MenuControl* menu) {
void MenuControl::setParentMenu(MenuControl *menu)
{
this->parentMenu = menu;
DisplayWrapper* lcd = this->parentMenu->getLcd();
DisplayWrapper *lcd = this->parentMenu->getLcd();
if (lcd)
this->lcd = lcd;
}
+33 -17
View File
@@ -11,13 +11,15 @@
#include "menuInformationSites.h"
MenuInformationSites::MenuInformationSites(uint8_t pages) {
MenuInformationSites::MenuInformationSites(uint8_t pages)
{
this->countPages = pages;
this->currentPage = 0;
this->lastMillis = millis();
}
void MenuInformationSites::up() {
void MenuInformationSites::up()
{
if (this->currentPage == 0)
this->currentPage = this->countPages - 1;
else
@@ -25,7 +27,8 @@ void MenuInformationSites::up() {
this->printMenu();
}
void MenuInformationSites::down() {
void MenuInformationSites::down()
{
if (this->currentPage == this->countPages - 1)
this->currentPage = 0;
else
@@ -33,20 +36,25 @@ void MenuInformationSites::down() {
this->printMenu();
}
void MenuInformationSites::right() {
this->yes();
void MenuInformationSites::right()
{
this->printMenu();
}
void MenuInformationSites::left() {
if (this->parentMenu) {
void MenuInformationSites::left()
{
if (this->parentMenu)
{
this->parentMenu->prepareReenterMenu();
this->parentMenu->printMenu();
this->leaved = true;
}
}
void MenuInformationSites::no() {
if (this->noEqualLeft) {
void MenuInformationSites::no()
{
if (this->noEqualLeft)
{
this->left();
return;
}
@@ -54,13 +62,16 @@ void MenuInformationSites::no() {
this->printMenu();
}
void MenuInformationSites::yes() {
void MenuInformationSites::yes()
{
this->runCommand();
this->printMenu();
}
void MenuInformationSites::printMenu() {
if (this->leaved) {
void MenuInformationSites::printMenu()
{
if (this->leaved)
{
this->leaved = false;
this->lastPageNumber++;
this->init();
@@ -70,25 +81,30 @@ void MenuInformationSites::printMenu() {
this->lastPageNumber = this->currentPage;
}
bool MenuInformationSites::setCountPages(uint8_t pages) {
bool MenuInformationSites::setCountPages(uint8_t pages)
{
this->countPages = pages;
this->currentPage = 0;
if (this->countPages == 0) {
if (this->countPages == 0)
{
this->countPages = 1;
return false;
}
return true;
}
uint8_t MenuInformationSites::getCountPages() const {
uint8_t MenuInformationSites::getCountPages() const
{
return this->countPages;
}
uint8_t MenuInformationSites::getCurrentPage() const {
uint8_t MenuInformationSites::getCurrentPage() const
{
return this->currentPage;
}
void MenuInformationSites::printDefault() const {
void MenuInformationSites::printDefault() const
{
String lineOne = String("Pagenumber: ") + (this->currentPage + 1);
String lineTwo = String("Pagecount : ") + this->countPages;
+70 -39
View File
@@ -11,7 +11,8 @@
#include "menuIntInput.h"
MenuIntInput::MenuIntInput(int16_t values[], char *names, uint8_t length, MenuIntInputWrapper* wrapper) {
MenuIntInput::MenuIntInput(int16_t values[], char *names, uint8_t length, MenuIntInputWrapper *wrapper)
{
this->values = values;
this->names = names;
this->length = length;
@@ -22,7 +23,8 @@ MenuIntInput::MenuIntInput(int16_t values[], char *names, uint8_t length, MenuIn
this->originalValues = new int16_t[this->length];
this->stepsPerInput = new uint8_t[this->length];
for (uint8_t i = 0; i < this->length; i++) {
for (uint8_t i = 0; i < this->length; i++)
{
this->min[i] = INT16_MIN;
this->max[i] = INT16_MAX;
this->originalValues[i] = this->values[i];
@@ -30,18 +32,20 @@ MenuIntInput::MenuIntInput(int16_t values[], char *names, uint8_t length, MenuIn
}
}
MenuIntInput::MenuIntInput(uint8_t length, MenuIntInputWrapper *wrapper) {
MenuIntInput::MenuIntInput(uint8_t length, MenuIntInputWrapper *wrapper)
{
this->length = length;
this->wrapper = wrapper;
this->values = new int16_t[this->length];
this->names = (char*) new char[this->length][MAX_NAME_LENGTH];
this->names = (char *)new char[this->length][MAX_NAME_LENGTH];
this->min = new int16_t[this->length];
this->max = new int16_t[this->length];
this->originalValues = new int16_t[this->length];
this->stepsPerInput = new uint8_t[this->length];
for (uint8_t i = 0; i < this->length; i++) {
for (uint8_t i = 0; i < this->length; i++)
{
this->min[i] = INT16_MIN;
this->max[i] = INT16_MAX;
this->values[i] = 0;
@@ -51,7 +55,8 @@ MenuIntInput::MenuIntInput(uint8_t length, MenuIntInputWrapper *wrapper) {
}
}
MenuIntInput::~MenuIntInput() {
MenuIntInput::~MenuIntInput()
{
delete this->min;
delete this->max;
delete this->originalValues;
@@ -61,104 +66,117 @@ MenuIntInput::~MenuIntInput() {
delete this->wrapper;
}
void MenuIntInput::setEntry(uint8_t valueNumber, const char* name, int16_t startValue) {
void MenuIntInput::setEntry(uint8_t valueNumber, const char *name, int16_t startValue)
{
if (this->length < valueNumber)
return;
if (strlen(name) > MAX_NAME_LENGTH)
return;
strcpy(this->names + MAX_NAME_LENGTH * valueNumber, name);
this->values[valueNumber] = startValue;
this->originalValues[valueNumber] = startValue;
}
void MenuIntInput::setMin(uint8_t valueNumber, int16_t min) {
void MenuIntInput::setMin(uint8_t valueNumber, int16_t min)
{
if (this->length < valueNumber)
return;
this->min[valueNumber] = min;
}
void MenuIntInput::setMax(uint8_t valueNumber, int16_t max) {
void MenuIntInput::setMax(uint8_t valueNumber, int16_t max)
{
if (this->length < valueNumber)
return;
this->max[valueNumber] = max;
}
void MenuIntInput::setMinMax(uint8_t valueNumber, int16_t min, int16_t max) {
void MenuIntInput::setMinMax(uint8_t valueNumber, int16_t min, int16_t max)
{
this->setMin(valueNumber, min);
this->setMax(valueNumber, max);
}
void MenuIntInput::setMin(int16_t min) {
void MenuIntInput::setMin(int16_t min)
{
for (uint8_t i = 0; i < this->length; i++)
this->min[i] = min;
}
void MenuIntInput::setMax(int16_t max) {
void MenuIntInput::setMax(int16_t max)
{
for (uint8_t i = 0; i < this->length; i++)
this->max[i] = max;
}
void MenuIntInput::setMinMax(int16_t min, int16_t max) {
void MenuIntInput::setMinMax(int16_t min, int16_t max)
{
this->setMin(min);
this->setMax(max);
}
void MenuIntInput::setMinMaxSteps(uint8_t valueNumber, int16_t min, int16_t max, uint8_t steps) {
void MenuIntInput::setMinMaxSteps(uint8_t valueNumber, int16_t min, int16_t max, uint8_t steps)
{
this->setMin(valueNumber, min);
this->setMax(valueNumber, max);
this->setStepsPerInput(valueNumber, steps);
}
void MenuIntInput::setMinMaxSteps(int16_t min, int16_t max, uint8_t steps) {
void MenuIntInput::setMinMaxSteps(int16_t min, int16_t max, uint8_t steps)
{
this->setMin(min);
this->setMax(max);
this->setStepsPerInput(steps);
}
void MenuIntInput::setStepsPerInput(uint8_t valueNumber, uint8_t steps) {
void MenuIntInput::setStepsPerInput(uint8_t valueNumber, uint8_t steps)
{
if (this->length < valueNumber)
return;
this->stepsPerInput[valueNumber] = steps;
}
void MenuIntInput::setStepsPerInput(uint8_t steps) {
void MenuIntInput::setStepsPerInput(uint8_t steps)
{
for (uint8_t i = 0; i < this->length; i++)
this->stepsPerInput[i] = steps;
}
void MenuIntInput::down() {
if (this->values[this->currentPosition]
- this->stepsPerInput[this->currentPosition]
>= this->min[currentPosition])
void MenuIntInput::down()
{
if (this->values[this->currentPosition] - this->stepsPerInput[this->currentPosition] >= this->min[currentPosition])
{
this->values[this->currentPosition] -= this->stepsPerInput[this->currentPosition];
} else {
}
else
{
this->values[this->currentPosition] = this->max[this->currentPosition];
}
this->printMenu();
}
void MenuIntInput::up() {
if (this->values[this->currentPosition]
+ this->stepsPerInput[this->currentPosition]
<= this->max[this->currentPosition])
void MenuIntInput::up()
{
if (this->values[this->currentPosition] + this->stepsPerInput[this->currentPosition] <= this->max[this->currentPosition])
{
this->values[this->currentPosition] += this->stepsPerInput[this->currentPosition];
} else {
}
else
{
this->values[this->currentPosition] = this->min[this->currentPosition];
}
this->printMenu();
}
void MenuIntInput::right() {
void MenuIntInput::right()
{
if (currentPosition < this->length - 1)
currentPosition++;
else
@@ -167,7 +185,8 @@ void MenuIntInput::right() {
this->printMenu();
}
void MenuIntInput::left() {
void MenuIntInput::left()
{
if (currentPosition > 0)
currentPosition--;
else
@@ -176,38 +195,50 @@ void MenuIntInput::left() {
this->printMenu();
}
void MenuIntInput::no() {
void MenuIntInput::no()
{
for (uint8_t i = 0; i < this->length; i++)
this->values[i] = this->originalValues[i];
this->currentPosition = 0;
if (this->parentMenu) {
if (this->parentMenu)
{
this->parentMenu->prepareReenterMenu();
this->parentMenu->printMenu();
}
}
void MenuIntInput::yes() {
void MenuIntInput::yes()
{
this->wrapper->action(this->values, this->length);
if (this->parentMenu && printParentMenu){
if (this->parentMenu && printParentMenu)
{
this->parentMenu->prepareReenterMenu();
this->parentMenu->printMenu();
}
}
void MenuIntInput::printMenu() {
void MenuIntInput::printMenu()
{
char bufferName[17];
if (this->currentPosition == 0 && this->length == 1) {
if (this->currentPosition == 0 && this->length == 1)
{
// No arrow
sprintf(bufferName, " %s ", this->names + MAX_NAME_LENGTH * this->currentPosition);
} else if (this->currentPosition > 0 && this->length - 1 == this->currentPosition) {
}
else if (this->currentPosition > 0 && this->length - 1 == this->currentPosition)
{
// Left arrow only
sprintf(bufferName, "< %s ", this->names + MAX_NAME_LENGTH * this->currentPosition);
} else if (this->currentPosition == 0 && this->length > 1) {
}
else if (this->currentPosition == 0 && this->length > 1)
{
// Right arrow only
sprintf(bufferName, " %s >", this->names + MAX_NAME_LENGTH * this->currentPosition);
} else {
}
else
{
// Both arrow
sprintf(bufferName, "< %s >", this->names + MAX_NAME_LENGTH * this->currentPosition);
}