diff --git a/lib/DisplayWrapper/displayWrapper.h b/lib/DisplayWrapper/displayWrapper.h deleted file mode 100644 index 722b272..0000000 --- a/lib/DisplayWrapper/displayWrapper.h +++ /dev/null @@ -1,42 +0,0 @@ -/** - * @file displayWrapper.h - * @author Alexander Klein (alex@kleiax.de) - * @brief - * @version 0.1 - * @date 2023-01-08 - * - * @copyright Copyright (c) 2023 - * - */ - -#ifndef DISPLAY_WRAPPER_H -#define DISPLAY_WRAPPER_H - -#include -#include - -#define DISPLAY_WRAPPER_ROWS 16 -#define DISPLAY_WRAPPER_LINES 2 - -class DisplayWrapper { - public: - DisplayWrapper(LiquidCrystal_I2C* lcd); - - void loop(); - - void clear(); - void setCursor(uint8_t row, uint8_t line); - void print(const char *str); - - - private: - LiquidCrystal_I2C* lcd; - char data[DISPLAY_WRAPPER_LINES][DISPLAY_WRAPPER_ROWS]; - - uint8_t cursorRow = 0; - uint8_t cursorLine = 0; - - bool changed = false; -}; - -#endif // DISPLAY_WRAPPER_H diff --git a/lib/DisplayWrapper/displayWrapper.cpp b/lib/LcdWrapper/LcdWrapper.cpp similarity index 81% rename from lib/DisplayWrapper/displayWrapper.cpp rename to lib/LcdWrapper/LcdWrapper.cpp index 3c07121..9823153 100644 --- a/lib/DisplayWrapper/displayWrapper.cpp +++ b/lib/LcdWrapper/LcdWrapper.cpp @@ -1,7 +1,7 @@ /** * @file displayWrapper.cpp * @author Alexander Klein (alex@kleiax.de) - * @brief + * @brief Contains the implementation of the class LcdWrapper * @version 0.1 * @date 2023-01-08 * @@ -9,15 +9,15 @@ * */ -#include "displayWrapper.h" +#include "LcdWrapper.h" -DisplayWrapper::DisplayWrapper(LiquidCrystal_I2C* lcd) { +LcdWrapper::LcdWrapper(LiquidCrystal_I2C* lcd) { this->lcd = lcd; this->clear(); this->changed = false; } -void DisplayWrapper::loop() { +void LcdWrapper::loop() { if (this->changed) { this->lcd->clear(); for (uint8_t i = 0; i < DISPLAY_WRAPPER_LINES; i++) { @@ -28,7 +28,7 @@ void DisplayWrapper::loop() { } } -void DisplayWrapper::clear() { +void LcdWrapper::clear() { for (uint8_t i = 0; i < DISPLAY_WRAPPER_LINES; i++) { for (uint8_t j = 0; j < DISPLAY_WRAPPER_ROWS; j++) { data[i][j] = ' '; @@ -37,7 +37,7 @@ void DisplayWrapper::clear() { this->changed = true; } -void DisplayWrapper::setCursor(uint8_t row, uint8_t line) { +void LcdWrapper::setCursor(uint8_t row, uint8_t line) { if (row > DISPLAY_WRAPPER_ROWS - 1) row = DISPLAY_WRAPPER_ROWS - 1; @@ -48,7 +48,7 @@ void DisplayWrapper::setCursor(uint8_t row, uint8_t line) { this->cursorLine = line; } -void DisplayWrapper::print(const char *str) { +void LcdWrapper::print(const char *str) { uint8_t inputStringPosition = 0; for (uint8_t i = this->cursorRow; i < DISPLAY_WRAPPER_ROWS; i++) { if (str[inputStringPosition] == '\0') diff --git a/lib/LcdWrapper/LcdWrapper.h b/lib/LcdWrapper/LcdWrapper.h new file mode 100644 index 0000000..40f4408 --- /dev/null +++ b/lib/LcdWrapper/LcdWrapper.h @@ -0,0 +1,76 @@ +/** + * @file displayWrapper.h + * @author Alexander Klein (alex@kleiax.de) + * @brief Contains the LcdWrapper class + * @version 0.1 + * @date 2023-01-08 + * + * @copyright Copyright (c) 2023 + * + */ + +#ifndef LCD_WRAPPER_H +#define LCD_WRAPPER_H + +#include +#include +#include + +#define DISPLAY_WRAPPER_ROWS 16 +#define DISPLAY_WRAPPER_LINES 2 + +/** + * @brief A class for the Menu class to print information + * + * This class inherits the DisplayWrapper class as a interface. + * The class takes the information to print from any thread. The + * loop function has to be called to print the data. + */ +class LcdWrapper : public DisplayWrapper { + public: + /** + * @brief Construct a new Lcd Wrapper object + * + * @param lcd + */ + LcdWrapper(LiquidCrystal_I2C* lcd); + + /** + * @brief Print the saved data + * + */ + void loop(); + + /** + * @brief Empty the buffer + * + */ + void clear() override; + + /** + * @brief Set point where data to be saved + * + * @param row + * @param line + */ + void setCursor(uint8_t row, uint8_t line) override; + + /** + * @brief Save the data to be printed + * + * @param str + */ + void print(const char *str) override; + + + private: + LiquidCrystal_I2C* lcd; + char data[DISPLAY_WRAPPER_LINES][DISPLAY_WRAPPER_ROWS]; + + uint8_t cursorRow = 0; + uint8_t cursorLine = 0; + + bool changed = false; +}; + +#endif // DISPLAY_WRAPPER_H diff --git a/lib/Menu/menu.cpp b/lib/Menu/menu.cpp deleted file mode 100644 index 33c30e0..0000000 --- a/lib/Menu/menu.cpp +++ /dev/null @@ -1,128 +0,0 @@ -/** - * @file menu.cpp - * @author Alexander Klein (alex@kleiax.de) - * @brief Implementation of the class Menu - * @version 0.1 - * @date 2022-01-12 - * - * @copyright Copyright (c) 2022 - * - */ -#include "menu.h" - -Menu::Menu() { - this->selectedEntry = this->entrys.begin(); -} - -Menu::~Menu() { - for (std::list::iterator iter = this->entrys.begin(); iter != this->entrys.end(); iter++) - delete *iter; -} - -void Menu::addEntry(MenuAction* entry) { - this->entrys.push_back(entry); - - if (this->entrys.size() == 2) - this->selectedEntry = this->entrys.begin(); -} - -bool Menu::isInSubmenu() { - return this->inSubmenu; -} - -void Menu::printMenu() { - std::list::iterator iter = this->selectedEntry; - - String lineOne = "-> "; - String lineTwo = ""; - - lineOne.concat((**iter).getName()); - iter++; - if (iter != this->entrys.end()) { - lineTwo.concat((**iter).getName()); - } else - lineTwo.concat((*this->entrys.begin())->getName()); - - this->inSubmenu = false; - this->print(lineOne, lineTwo); -} - -void Menu::update() { - if (this->inSubmenu) { - (**this->selectedEntry).getMenu()->update(); - return; - } -} - -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::iterator iter = this->selectedEntry; - iter++; - if (iter != this->entrys.end()) - this->selectedEntry++; - else - this->selectedEntry = this->entrys.begin(); - this->printMenu(); -} - -void Menu::up() { - if (this->inSubmenu) { - (**this->selectedEntry).getMenu()->up(); - return; - } - std::list::iterator iter = this->entrys.end(); - iter--; - if (this->selectedEntry != this->entrys.begin()) { - this->selectedEntry--; - } - else { - this->selectedEntry = iter; - } - this->printMenu(); -} - -void Menu::right() { - if (this->inSubmenu) { - (**this->selectedEntry).getMenu()->right(); - return; - } - - if ((**this->selectedEntry).getIsMenu()) { - this->inSubmenu = true; - (**this->selectedEntry).getMenu()->setParentMenu(this); - } - (**this->selectedEntry).runAction(); -} - -void Menu::left() { - if (this->inSubmenu) { - (**this->selectedEntry).getMenu()->left(); - return; - } - - if (parentMenu) - this->parentMenu->printMenu(); -} - -void Menu::yes() { - if (this->inSubmenu) { - (**this->selectedEntry).getMenu()->yes(); - return; - } - - this->right(); -} - -void Menu::no() { - if (this->inSubmenu) { - (**this->selectedEntry).getMenu()->no(); - return; - } - - this->left(); -} diff --git a/lib/Menu/menu.h b/lib/Menu/menu.h deleted file mode 100644 index 832b055..0000000 --- a/lib/Menu/menu.h +++ /dev/null @@ -1,55 +0,0 @@ -/** - * @file menu.h - * @author Alexander Klein (alex@kleiax.de) - * @brief Contains the Menu class - * @version 0.1 - * @date 2022-01-12 - * - * @copyright Copyright (c) 2022 - * - */ -#ifndef MENU_H -#define MENU_H - -#include - -#include "menuAction.h" -#include "menuControl.h" - -class MenuAction; - -/** - * @brief A class to build menu structers - */ -class Menu : public MenuControl { - public: - Menu(); - ~Menu() override; - - /** - * @brief Add a menu action to the menu - * - * @param entry - */ - void addEntry(MenuAction* entry); - bool isInSubmenu(); - - void printMenu() override; - void update() override; - - void down() override; - void up() override; - void right() override; - void left() override; - void yes() override; - void no() override; - - private: - bool inSubmenu = false; - - std::list entrys; - std::list::iterator selectedEntry; - -}; - -#endif // MENU_H diff --git a/lib/Menu/menuAction.cpp b/lib/Menu/menuAction.cpp deleted file mode 100644 index f4bda6a..0000000 --- a/lib/Menu/menuAction.cpp +++ /dev/null @@ -1,67 +0,0 @@ -/** - * @file menuAction.cpp - * @author Alexander Klein (alex@kleiax.de) - * @brief Implentation of the class MenuAction - * @version 0.1 - * @date 2022-01-12 - * - * @copyright Copyright (c) 2022 - * - */ -#include "menuAction.h" - -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) { - this->name = name; - this->menu = menu; - this->isMenu = true; -} - -MenuAction::MenuAction(const char* name, MenuActionWrapper* action) { - this->name = name; - this->action = action; -} - -MenuAction::~MenuAction() { - if (this->menu) - delete this->menu; - - if (this->action) - delete this->action; -} - -void MenuAction::runAction() { - if (isMenu) - this->menu->printMenu(); - else { - if (this->function) - this->function(); - else if (this->action) - this->action->action(); - else - std::cout << "Error in MenuAction::runAction" << std::endl; - } - - if (this->callback) - this->callback(); -} - -const char* MenuAction::getName() { - return this->name; -} - -bool MenuAction::getIsMenu() { - return this->isMenu; -} - -MenuControl* MenuAction::getMenu() { - if (isMenu) - return this->menu; - else - return nullptr; -} diff --git a/lib/Menu/menuAction.h b/lib/Menu/menuAction.h deleted file mode 100644 index f4bf046..0000000 --- a/lib/Menu/menuAction.h +++ /dev/null @@ -1,103 +0,0 @@ -/** - * @file menuAction.h - * @author Alexander Klein (alex@kleiax.de) - * @brief Contains the MenuAction class - * @version 0.1 - * @date 2022-01-12 - * - * @copyright Copyright (c) 2022 - * - */ -#ifndef MENU_ENTRY_H -#define MENU_ENTRY_H - -#include "menu.h" - -class MenuControl; - -class MenuActionWrapper { - public: - virtual ~MenuActionWrapper() {} - virtual void action() = 0; -}; - -/** - * @brief This class forms the transition between menus. - * - * In the Menu these are the entries. - * This class can be call an submenu or a function. - */ -class MenuAction { - public: - - /** - * @brief Construct a new Menu Action object - * - * @param name shown in the Menu - * @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); - - /** - * @brief Construct a new Menu Action object - * - * @param name shown in the Menu - * @param action to call when activate the entry - */ - MenuAction(const char* name, MenuActionWrapper* action); - - /** - * @brief Construct a new Menu Action object - * - * This constructer 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(); - - /** - * @brief activates the entry - */ - void runAction(); - - /** - * @brief Get the Name string - * - * @return const char* - */ - const char* getName(); - - /** - * @brief Get the Is Menu object - * - * @return true runAction calls a submenu - * @return false runAction call a function - */ - bool getIsMenu(); - - /** - * @brief Get the Menu object - * - * Before call this function it may be useful - * to check if is it a submenu with getIsMenu. - * - * @return MenuControl* - */ - MenuControl* getMenu(); - - private: - const char* name; - - void (*function) () = nullptr; - void (*callback) () = nullptr; - - bool isMenu = false; - MenuControl* menu = nullptr; - MenuActionWrapper* action = nullptr; -}; - -#endif // MENU_ENTRY_H diff --git a/lib/Menu/menuControl.cpp b/lib/Menu/menuControl.cpp deleted file mode 100644 index 36facc1..0000000 --- a/lib/Menu/menuControl.cpp +++ /dev/null @@ -1,22 +0,0 @@ -/** - * @file menuControl.cpp - * @author Alexander Klein (alex@kleiax.de) - * @brief - * @version 0.1 - * @date 2022-12-28 - * - * @copyright Copyright (c) 2022 - * - */ - -#include "menuControl.h" - -void MenuControl::print(String lineOne, String lineTwo) const { - if (this->lcd) { - lcd->clear(); - lcd->setCursor(0, 0); - lcd->print(lineOne.c_str()); - lcd->setCursor(0, 1); - lcd->print(lineTwo.c_str()); - } -} diff --git a/lib/Menu/menuControl.h b/lib/Menu/menuControl.h deleted file mode 100644 index 3cbd2f2..0000000 --- a/lib/Menu/menuControl.h +++ /dev/null @@ -1,77 +0,0 @@ -/** - * @file menuControl.h - * @author Alexander Klein (alex@kleiax.de) - * @brief Contains a abstract class for Menu - * @version 0.1 - * @date 2022-01-19 - * - * @copyright Copyright (c) 2022 - * - */ - -#ifndef MENU_CONTROLL_H -#define MENU_CONTROLL_H - -#include -#include "displayWrapper.h" - -/** - * @brief Baseclass to build Menus - * - * This class have to be inherited by other classes which want to be - * act as a menu, because the menu structure uses polymorphism. - * - */ -class MenuControl { - public: - virtual ~MenuControl() {}; - - /** @name UserInputs - * @brief This functions should be called be user actions. - * - * This functions have to be implement in every other menu - * class. - */ - ///@{ - 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 - */ - virtual void update() {} - - virtual void printMenu() = 0; - - /** - * @brief Set the Parent Menu - * - * If the parentMenu is set it will be called automaticaly - * when the user left the child menu. - * - * @param menu - */ - void setParentMenu(MenuControl* menu) { this->parentMenu = menu; } - // MenuControl* getParentMenu() { return this->parentMenu; } - - /** - * @brief Set the Lcd object - * - * If this is set the menu will be print on the display too. - * - * @param lcd - */ - void setLcd(DisplayWrapper* lcd) { this->lcd = lcd; } - - protected: - void print(String lineOne, String lineTwo) const; - - MenuControl* parentMenu = nullptr; - DisplayWrapper* lcd = nullptr; -}; -#endif // MENU_CONTROLL_H diff --git a/lib/Menu/menuInformationSites.cpp b/lib/Menu/menuInformationSites.cpp deleted file mode 100644 index fbafc0f..0000000 --- a/lib/Menu/menuInformationSites.cpp +++ /dev/null @@ -1,98 +0,0 @@ -/** - * @file menuInformationSites.cpp - * @author Alexander Klein (alex@kleiax.de) - * @brief Contains an implementation of the class MenuInformationSites - * @version 0.1 - * @date 2022-12-27 - * - * @copyright Copyright (c) 2022 - * - */ - -#include "menuInformationSites.h" - -MenuInformationSites::MenuInformationSites(uint8_t pages) { - this->countPages = pages; - this->currentPage = 0; - this->lastMillis = millis(); -} - -void MenuInformationSites::up() { - if (this->currentPage == 0) - this->currentPage = this->countPages - 1; - else - this->currentPage--; - this->printMenu(); -} - -void MenuInformationSites::down() { - if (this->currentPage == this->countPages - 1) - this->currentPage = 0; - else - this->currentPage++; - this->printMenu(); -} - -void MenuInformationSites::right() { - this->yes(); -} - -void MenuInformationSites::left() { - if (this->parentMenu) { - this->parentMenu->printMenu(); - this->leaved = true; - } -} - -void MenuInformationSites::no() { - this->left(); -} - -void MenuInformationSites::yes() { - this->runCommand(); - this->printMenu(); -} - -void MenuInformationSites::printMenu() { - if (this->leaved) { - this->leaved = false; - this->lastPageNumber++; - this->init(); - } - - this->printPage(); - this->lastPageNumber = this->currentPage; -} - -void MenuInformationSites::update() { - if (millis() - this->lastMillis < this->delay) { - return; - } - this->printMenu(); - this->lastMillis = millis(); -} - -bool MenuInformationSites::setCountPages(uint8_t pages) { - this->countPages = pages; - this->currentPage = 0; - if (this->countPages == 0) { - this->countPages = 1; - return false; - } - return true; -} - -uint8_t MenuInformationSites::getCountPages() const { - return this->countPages; -} - -uint8_t MenuInformationSites::getCurrentPage() const { - return this->currentPage; -} - -void MenuInformationSites::printDefault() const { - String lineOne = String("Page: ") + (this->currentPage + 1); - String lineTwo = String("of ") + this->countPages; - - this->print(lineOne, lineTwo); -} diff --git a/lib/Menu/menuInformationSites.h b/lib/Menu/menuInformationSites.h deleted file mode 100644 index 5ea1462..0000000 --- a/lib/Menu/menuInformationSites.h +++ /dev/null @@ -1,92 +0,0 @@ -/** - * @file menuInformationSites.h - * @author Alexander Klein (alex@kleiax.de) - * @brief Contains a class to print informations over more pages - * @version 0.1 - * @date 2022-12-27 - * - * @copyright Copyright (c) 2022 - * - */ -#ifndef MENU_INFORMATION_SITES_H -#define MENU_INFORMATION_SITES_H - -#include "menuControl.h" - -class MenuInformationSites : public MenuControl { - public: - /** - * @brief Construct a new Menu Information Sites object - * - * @param amount of pages - */ - MenuInformationSites(uint8_t pages = 1); - - /** - * @brief Next page - */ - void down() override; - - /** - * @brief Previous page - */ - void up() override; - - /** - * @brief Update information - */ - void right() override; - - /** - * @brief Go to the parent menu - */ - void left() override; - - /** - * @brief Go to the parent menu - */ - void no() override; - - /** - * @brief Update information - */ - void yes() override; - - /** - * @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; - - /** - * @brief can be called to update shown data - */ - void update() override; - - protected: - bool setCountPages(uint8_t pages); - uint8_t getCountPages() const; - uint8_t getCurrentPage() const; - - virtual void printPage() const = 0; - virtual void runCommand() const {} - virtual void init() {} - - void printDefault() const; - - uint8_t lastPageNumber = 0; - bool leaved = true; - - private: - uint8_t countPages; - uint8_t currentPage; - - - const uint16_t delay = 5000; - uint32_t lastMillis = 0; -}; - -#endif // MENU_INFORMATION_SITES_H diff --git a/lib/Menu/menuIntInput.cpp b/lib/Menu/menuIntInput.cpp deleted file mode 100644 index 3f8675b..0000000 --- a/lib/Menu/menuIntInput.cpp +++ /dev/null @@ -1,218 +0,0 @@ -/** - * @file menuIntInput.cpp - * @author Alexander Klein (alex@kleiax.de) - * @brief - * @version 0.1 - * @date 2022-09-12 - * - * @copyright Copyright (c) 2022 - * - */ - -#include "menuIntInput.h" - -MenuIntInput::MenuIntInput(int16_t values[], char *names, uint8_t length, MenuIntInputWrapper* wrapper) { - this->values = values; - this->names = names; - this->length = length; - this->wrapper = wrapper; - - 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++) { - this->min[i] = INT16_MIN; - this->max[i] = INT16_MAX; - this->originalValues[i] = this->values[i]; - this->stepsPerInput[i] = 1; - } -} - -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->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++) { - this->min[i] = INT16_MIN; - this->max[i] = INT16_MAX; - this->values[i] = 0; - this->originalValues[i] = 0; - this->stepsPerInput[i] = 1; - strcpy(this->names + MAX_NAME_LENGTH * i, "Default"); - } -} - -MenuIntInput::~MenuIntInput() { - delete this->min; - delete this->max; - delete this->originalValues; - delete this->stepsPerInput; - delete this->values; - delete this->names; - delete this->wrapper; -} - -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) { - if (this->length < valueNumber) - return; - - this->min[valueNumber] = min; -} - -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) { - this->setMin(valueNumber, min); - this->setMax(valueNumber, max); -} - -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) { - for (uint8_t i = 0; i < this->length; i++) - this->max[i] = 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) { - this->setMin(valueNumber, min); - this->setMax(valueNumber, max); - this->setStepsPerInput(valueNumber, 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) { - if (this->length < valueNumber) - return; - - this->stepsPerInput[valueNumber] = 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]) - { - this->values[this->currentPosition] -= this->stepsPerInput[this->currentPosition]; - } 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]) - { - this->values[this->currentPosition] += this->stepsPerInput[this->currentPosition]; - } else { - this->values[this->currentPosition] = this->min[this->currentPosition]; - } - - this->printMenu(); -} - -void MenuIntInput::right() { - if (currentPosition < this->length - 1) - currentPosition++; - else - currentPosition = 0; - - this->printMenu(); -} - -void MenuIntInput::left() { - if (currentPosition > 0) - currentPosition--; - else - currentPosition = this->length - 1; - - this->printMenu(); -} - -void MenuIntInput::no() { - for (uint8_t i = 0; i < this->length; i++) - this->values[i] = this->originalValues[i]; - this->currentPosition = 0; - - if (this->parentMenu) - this->parentMenu->printMenu(); -} - -void MenuIntInput::yes() { - this->wrapper->action(this->values, this->length); - if (this->parentMenu && printParentMenu) - this->parentMenu->printMenu(); -} - -void MenuIntInput::printMenu() { - char bufferName[17]; - - 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) { - // Left arrow only - sprintf(bufferName, "< %s ", this->names + MAX_NAME_LENGTH * this->currentPosition); - } else if (this->currentPosition == 0 && this->length > 1) { - // Right arrow only - sprintf(bufferName, " %s >", this->names + MAX_NAME_LENGTH * this->currentPosition); - } else { - // Both arrow - sprintf(bufferName, "< %s >", this->names + MAX_NAME_LENGTH * this->currentPosition); - } - - char bufferValue[17]; - if (this->values[this->currentPosition]) - sprintf(bufferValue, " -> %5.d", this->values[this->currentPosition]); - else - sprintf(bufferValue, " -> 0"); - - this->print(bufferName, bufferValue); -} diff --git a/lib/Menu/menuIntInput.h b/lib/Menu/menuIntInput.h deleted file mode 100644 index 75934ad..0000000 --- a/lib/Menu/menuIntInput.h +++ /dev/null @@ -1,103 +0,0 @@ -/** - * @file menuIntInput.h - * @author Alexander Klein (alex@kleiax.de) - * @brief - * @version 0.1 - * @date 2022-09-12 - * - * @copyright Copyright (c) 2022 - * - */ -#ifndef MENU_INT_INPUT_H -#define MENU_INT_INPUT_H - -#include "menuControl.h" -#include - -#define MAX_NAME_LENGTH 12 - -class MenuIntInputWrapper { - public: - virtual ~MenuIntInputWrapper() {} - 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); - MenuIntInput(uint8_t length, MenuIntInputWrapper *wrapper); - ~MenuIntInput(); - - void setEntry(uint8_t valueNumber, const char* name, int16_t startValue = 0); - - 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; } - - void setStepsPerInput(uint8_t valueNumber, uint8_t steps); - void setStepsPerInput(uint8_t steps); - - /** - * @brief Decrement selected value - */ - void down() override; - - /** - * @brief Increment selected value - */ - void up() override; - - /** - * @brief Select next value - */ - void right() override; - - /** - * @brief Select previous value - */ - void left() override; - - /** - * @brief Leave menu without saving - */ - void no() override; - - /** - * @brief Leave menu with saving - */ - void yes() override; - - /** - * @brief Prints the Information to display and console - * - * The informations are only printed to the display if it - * set. - */ - void printMenu() override; - - void update() override {}; - - private: - MenuIntInputWrapper* wrapper; - - bool printParentMenu = true; - - uint8_t currentPosition = 0; - uint8_t length; - uint8_t *stepsPerInput; - uint8_t countSameActions = 0; - int16_t *values; - int16_t *originalValues; - int16_t *min; - int16_t *max; - char *names; - -}; - -#endif // MENU_INT_INPUT_H