14 Commits
Author SHA1 Message Date
kleiax 35b1478666 doxygen fix 2023-10-12 19:53:03 +02:00
kleiax 9b8bf22795 doxygen comments 2023-10-12 19:50:26 +02:00
kleiax f05ab56833 call prepareReenter in SpecialMenus 2023-09-27 15:27:44 +02:00
kleiax 52c1fe25c8 add function for prepare rentering a menu 2023-09-27 15:19:32 +02:00
kleiax 230fa1ba62 remove const for runCommand 2023-09-27 13:39:28 +02:00
kleiax cbfbad26ae move the bool for skip from private to protected 2023-09-23 22:13:24 +02:00
kleiax 79b4cd4018 possibility to skip no and do left 2023-09-23 22:03:14 +02:00
kleiax 341add1deb remove multiple definition of function declarition 2023-08-18 16:30:31 +02:00
kleiax 155fd73c81 fix syntax 2023-08-18 16:28:16 +02:00
kleiax 67315f18b3 menuinformation site - add second action
inherit lcd Wrapper
2023-08-18 15:59:00 +02:00
kleiax 7de343d08a Update MenuInfornationSites printDefault() 2023-05-11 12:59:11 +02:00
kleiax 6b57b3fdb4 fix wrong variable name 2023-04-26 08:11:45 +02:00
kleiax 0ab6c829d5 removed old update functions 2023-04-26 07:57:00 +02:00
kleiax db3c25da42 mnoved update delay to base class and make
it setAble
2023-04-26 07:54:57 +02:00
12 changed files with 1345 additions and 987 deletions
+29 -6
View File
@@ -1,7 +1,7 @@
/** /**
* @file displayWrapper.h * @file displayWrapper.h
* @author Alexander Klein (alex@kleiax.de) * @author Alexander Klein (alex@kleiax.de)
* @brief * @brief Contains a interface to presents a display
* @version 0.1 * @version 0.1
* @date 2023-01-08 * @date 2023-01-08
* *
@@ -12,11 +12,34 @@
#ifndef DISPLAY_WRAPPER_H #ifndef DISPLAY_WRAPPER_H
#define DISPLAY_WRAPPER_H #define DISPLAY_WRAPPER_H
class DisplayWrapper { /**
public: * @brief This interface abstracted a display
virtual void clear() = 0; *
virtual void setCursor(uint8_t row, uint8_t line) = 0; * With this inteface a display which works with columns
virtual void print(const char *str) = 0; * 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;
}; };
#endif // DISPLAY_WRAPPER_H #endif // DISPLAY_WRAPPER_H
+44 -24
View File
@@ -19,37 +19,57 @@
class MenuAction; class MenuAction;
/** /**
* @brief A class to build menu structers * @brief A class to build menu structures
*/ */
class Menu : public MenuControl { class Menu : public MenuControl
public: {
Menu(); public:
~Menu() override; Menu();
~Menu() override;
/** /**
* @brief Add a menu action to the menu * @brief Add a MenuAction to the menu
* *
* @param entry * Every MenuAction is an Entry in the Menu
*/ *
void addEntry(MenuAction* entry); * @param entry
bool isInSubmenu(); */
void addEntry(MenuAction *entry);
void printMenu() override; /**
void update() override; * @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();
void down() override; /**
void up() override; * @brief Print the actual screen
void right() override; */
void left() override; void printMenu() override;
void yes() override;
void no() override;
private: /**
bool inSubmenu = false; * @brief Print the screen from the active menu
*/
void update() override;
std::list<MenuAction*> entrys; // User Inputs
std::list<MenuAction*>::iterator selectedEntry; void down() override;
void up() override;
void right() override;
void left() override;
void yes() override;
void no() override;
private:
bool inSubmenu = false;
std::list<MenuAction *> entries;
std::list<MenuAction *>::iterator selectedEntry;
}; };
#endif // MENU_H #endif // MENU_H
+75 -65
View File
@@ -15,10 +15,20 @@
class MenuControl; class MenuControl;
class MenuActionWrapper { /**
public: * @brief An Interface to execute actions
virtual ~MenuActionWrapper() {} *
virtual void action() = 0; * 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,77 +37,77 @@ class MenuActionWrapper {
* In the Menu these are the entries. * In the Menu these are the entries.
* This class can be call an submenu or a function. * This class can be call an submenu or a function.
*/ */
class MenuAction { class MenuAction
public: {
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 * @brief Construct a new Menu Action object
* *
* @param name shown in the Menu * @param name shown in the Menu
* @param function to call when activate the entry * @param action to call when activate the entry
* @param callback to call when leave the entry */
*/ MenuAction(const char *name, MenuActionWrapper *action);
MenuAction(const char* name, void (*function) (), void (*callback) () = nullptr);
/** /**
* @brief Construct a new Menu Action object * @brief Construct a new Menu Action object
* *
* @param name shown in the Menu * This constructor is used for submenus.
* @param action to call when activate the entry *
*/ * @param name shown in the Menu
MenuAction(const char* name, MenuActionWrapper* action); * @param menu to call when activate the entry
*/
MenuAction(const char *name, MenuControl *menu);
/** ~MenuAction();
* @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 activates the entry * @brief Get the Name string
*/ *
void runAction(); * @return const char*
*/
const char *getName();
/** /**
* @brief Get the Name string * @brief Get the Is Menu object
* *
* @return const char* * @return true runAction calls a submenu
*/ * @return false runAction call a function
const char* getName(); */
bool getIsMenu();
/** /**
* @brief Get the Is Menu object * @brief Get the Menu object
* *
* @return true runAction calls a submenu * Before call this function it may be useful
* @return false runAction call a function * to check if is it a submenu with getIsMenu.
*/ *
bool getIsMenu(); * @return MenuControl*
*/
MenuControl *getMenu();
/** private:
* @brief Get the Menu object const char *name;
*
* Before call this function it may be useful
* to check if is it a submenu with getIsMenu.
*
* @return MenuControl*
*/
MenuControl* getMenu();
private: void (*function)() = nullptr;
const char* name; void (*callback)() = nullptr;
void (*function) () = nullptr; bool isMenu = false;
void (*callback) () = nullptr; MenuControl *menu = nullptr;
MenuActionWrapper *action = nullptr;
bool isMenu = false;
MenuControl* menu = nullptr;
MenuActionWrapper* action = nullptr;
}; };
#endif // MENU_ENTRY_H #endif // MENU_ENTRY_H
+84 -44
View File
@@ -23,56 +23,96 @@
* act as a menu, because the menu structure uses polymorphism. * act as a menu, because the menu structure uses polymorphism.
* *
*/ */
class MenuControl { class MenuControl
public: {
virtual ~MenuControl() {}; public:
virtual ~MenuControl(){};
/** @name UserInputs /** @name UserInputs
* @brief This functions should be called be user actions. * @brief This functions should be called be user actions.
* *
* This functions have to be implement in every other menu * This functions have to be implement in every other menu
* class. * class.
*/ */
///@{ ///@{
virtual void down() {}; virtual void down(){};
virtual void up() {}; virtual void up(){};
virtual void right() {}; virtual void right(){};
virtual void left() {}; virtual void left(){};
virtual void yes() {}; virtual void yes(){};
virtual void no() {}; virtual void no(){};
///@} ///@}
/** /**
* @brief can be called to update shown data * @brief can be called to update shown data
*/ *
virtual void update() {} * The data will be only updated if a updateDelay is set
* and delay is reached.
*/
virtual void update();
virtual void printMenu() = 0; /**
* @brief Prepare reenter the this menu
*
* This function must be called separately
*/
virtual void prepareReenterMenu() {}
/** /**
* @brief Set the Parent Menu * @brief Function to print the Menu
* *
* If the parentMenu is set it will be called automaticaly * Have to be overwritten to implement the representation
* when the user left the child menu. * of the menu.
* * This function have to call the print() function to access
* @param menu * the display.
*/ */
void setParentMenu(MenuControl* menu) { this->parentMenu = menu; } virtual void printMenu() = 0;
// MenuControl* getParentMenu() { return this->parentMenu; }
/** /**
* @brief Set the Lcd object * @brief Set the Parent Menu
* *
* If this is set the menu will be print on the display too. * If the parentMenu is set it will be called automaticaly
* * when the user left the child menu.
* @param lcd * If the parentMenu has set a LCD it will be copied to the
*/ * actual instance.
void setLcd(DisplayWrapper* lcd) { this->lcd = lcd; } *
* @param menu
*/
void setParentMenu(MenuControl *menu);
protected: /**
void print(String lineOne, String lineTwo) const; * @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; }
MenuControl* parentMenu = nullptr; /**
DisplayWrapper* lcd = nullptr; * @brief Set the time between each new print to the display
*
* If the delay is zero, no updates will be made.
* The delay is by default zero.
*
* @param delay time in milliseconds
*/
void setUpdateDelay(uint16_t delay = 0) { this->updateDelay = delay; }
protected:
/**
* @brief
*
* @param lineOne
* @param lineTwo
*/
void print(String lineOne, String lineTwo) const;
DisplayWrapper *getLcd() const { return this->lcd; }
MenuControl *parentMenu = nullptr;
DisplayWrapper *lcd = nullptr;
uint16_t updateDelay = 0;
uint32_t lastUpdateMillis = 0;
}; };
#endif // MENU_CONTROLL_H #endif // MENU_CONTROLL_H
+120 -59
View File
@@ -13,80 +13,141 @@
#include "menuControl.h" #include "menuControl.h"
class MenuInformationSites : public MenuControl { /**
public: * @brief A Menu interface to show informations
/** *
* @brief Construct a new Menu Information Sites object * The informations a organized by multiple pages
* */
* @param amount of pages class MenuInformationSites : public MenuControl
*/ {
MenuInformationSites(uint8_t pages = 1); public:
/**
* @brief Construct a new Menu Information Sites object
*
* @param pages amount of the available pages
*/
MenuInformationSites(uint8_t pages = 1);
/** /**
* @brief Next page * @brief Next page
*/ */
void down() override; void down() override;
/** /**
* @brief Previous page * @brief Previous page
*/ */
void up() override; void up() override;
/** /**
* @brief Update information * @brief Update information
*/ */
void right() override; void right() override;
/** /**
* @brief Go to the parent menu * @brief Go to the parent menu
*/ */
void left() override; void left() override;
/** /**
* @brief Go to the parent menu * @brief Calls runCommandNo()
*/ */
void no() override; void no() override;
/** /**
* @brief Update information * @brief Calls runCommand()
*/ */
void yes() override; void yes() override;
/** /**
* @brief Prints the Information to display and console * @brief Prints the Information to display and console
* *
* Prints the selected page. * Prints the selected page.
* The informations are only printed to the display if it */
* set. void printMenu() override;
*/
void printMenu() override;
/** protected:
* @brief can be called to update shown data /**
*/ * @brief Change the amount of available pages
void update() override; *
* @param pages
* @return true successful
* @return false
*/
bool setCountPages(uint8_t pages);
protected: /**
bool setCountPages(uint8_t pages); * @brief Get the amount of available pages
uint8_t getCountPages() const; *
uint8_t getCurrentPage() const; * @return uint8_t
*/
uint8_t getCountPages() const;
virtual void printPage() const = 0; /**
virtual void runCommand() const {} * @brief Get the selected page number
virtual void init() {} *
* @return uint8_t
*/
uint8_t getCurrentPage() const;
void printDefault() 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;
uint8_t lastPageNumber = 0; /**
bool leaved = true; * @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() {}
private: /**
uint8_t countPages; * @brief Function to adds actions
uint8_t currentPage; *
* 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() {}
const uint16_t delay = 5000; /**
uint32_t lastMillis = 0; * @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:
uint8_t countPages;
uint8_t currentPage;
const uint16_t delay = 5000;
uint32_t lastMillis = 0;
}; };
#endif // MENU_INFORMATION_SITES_H #endif // MENU_INFORMATION_SITES_H
+165 -66
View File
@@ -1,7 +1,7 @@
/** /**
* @file menuIntInput.h * @file menuIntInput.h
* @author Alexander Klein (alex@kleiax.de) * @author Alexander Klein (alex@kleiax.de)
* @brief * @brief Contains a class to get integer inputs from the user
* @version 0.1 * @version 0.1
* @date 2022-09-12 * @date 2022-09-12
* *
@@ -16,88 +16,187 @@
#define MAX_NAME_LENGTH 12 #define MAX_NAME_LENGTH 12
class MenuIntInputWrapper { /**
public: * @brief Interface to transfer the integer data
virtual ~MenuIntInputWrapper() {} */
virtual void action(int16_t* values, uint8_t length) = 0; class MenuIntInputWrapper
{
public:
virtual ~MenuIntInputWrapper() {}
/**
* @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: * @brief A Menu class to make integer inputs
MenuIntInput(int16_t values[], char *names, uint8_t length, MenuIntInputWrapper* wrapper); */
MenuIntInput(uint8_t length, MenuIntInputWrapper *wrapper); class MenuIntInput : public MenuControl
~MenuIntInput(); {
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);
void setMin(uint8_t valueNumber, int16_t min); /**
void setMin(int16_t min); * @brief Set the minium for a specific value
void setMax(uint8_t valueNumber, int16_t max); *
void setMax(int16_t max); * @param valueNumber the entry
void setMinMax(uint8_t valueNumber, int16_t min, int16_t max); * @param min
void setMinMax(int16_t min, int16_t max); */
void setMinMaxSteps(uint8_t valueNumber, int16_t min, int16_t max, uint8_t steps); void setMin(uint8_t valueNumber, int16_t min);
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 Set the minimum for all entries
*
* @param min
*/
void setMin(int16_t min);
/** /**
* @brief Decrement selected value * @brief Set the maximum for a specific value
*/ *
void down() override; * @param valueNumber the entry
* @param max
*/
void setMax(uint8_t valueNumber, int16_t max);
/** /**
* @brief Increment selected value * @brief Set the maximum for all entries
*/ *
void up() override; * @param max
*/
void setMax(int16_t max);
/** /**
* @brief Select next value * @brief Set the minium and the maximum for a specific value
*/ *
void right() override; * @param valueNumber the entry
* @param min
* @param max
*/
void setMinMax(uint8_t valueNumber, int16_t min, int16_t max);
/** /**
* @brief Select previous value * @brief Set the minium and the maximum for all entries
*/ *
void left() override; * @param min
* @param max
*/
void setMinMax(int16_t min, int16_t max);
/** /**
* @brief Leave menu without saving * @brief Set the minium, the maximum and the steps for a specific value
*/ *
void no() override; * @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 Leave menu with saving * @brief Set the minium, the maximum and the steps for all entries
*/ *
void yes() override; * @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 Prints the Information to display and console /**
* * @brief Set the steps for a specific value
* The informations are only printed to the display if it *
* set. * @param valueNumber the entry
*/ * @param steps
void printMenu() override; */
void setStepsPerInput(uint8_t valueNumber, uint8_t steps);
void update() override {}; /**
* @brief Set the steps for all entries
*
* @param steps
*/
void setStepsPerInput(uint8_t steps);
private: /**
MenuIntInputWrapper* wrapper; * @brief Decrement selected value
*/
void down() override;
bool printParentMenu = true; /**
* @brief Increment selected value
*/
void up() override;
uint8_t currentPosition = 0; /**
uint8_t length; * @brief Select next value
uint8_t *stepsPerInput; */
uint8_t countSameActions = 0; void right() override;
int16_t *values;
int16_t *originalValues;
int16_t *min;
int16_t *max;
char *names;
/**
* @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;
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 #endif // MENU_INT_INPUT_H
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "Menu", "name": "Menu",
"version": "1.0.1", "version": "1.1.2",
"description": "Build page based menus on uCs", "description": "Build page based menus on uCs",
"keywords": "menu, page, input", "keywords": "menu, page, input",
"repository": "repository":
+60 -36
View File
@@ -10,97 +10,117 @@
*/ */
#include "menu.h" #include "menu.h"
Menu::Menu() { Menu::Menu()
this->selectedEntry = this->entrys.begin(); {
this->selectedEntry = this->entries.begin();
} }
Menu::~Menu() { Menu::~Menu()
for (std::list<MenuAction*>::iterator iter = this->entrys.begin(); iter != this->entrys.end(); iter++) {
for (std::list<MenuAction *>::iterator iter = this->entries.begin(); iter != this->entries.end(); iter++)
delete *iter; delete *iter;
} }
void Menu::addEntry(MenuAction* entry) { void Menu::addEntry(MenuAction *entry)
this->entrys.push_back(entry); {
this->entries.push_back(entry);
if (this->entrys.size() == 2) if (this->entries.size() == 2)
this->selectedEntry = this->entrys.begin(); this->selectedEntry = this->entries.begin();
} }
bool Menu::isInSubmenu() { bool Menu::isInSubmenu()
{
return this->inSubmenu; return this->inSubmenu;
} }
void Menu::printMenu() { void Menu::printMenu()
std::list<MenuAction*>::iterator iter = this->selectedEntry; {
std::list<MenuAction *>::iterator iter = this->selectedEntry;
String lineOne = "-> "; String lineOne = "-> ";
String lineTwo = ""; String lineTwo = "";
lineOne.concat((**iter).getName()); lineOne.concat((**iter).getName());
iter++; iter++;
if (iter != this->entrys.end()) { if (iter != this->entries.end())
{
lineTwo.concat((**iter).getName()); lineTwo.concat((**iter).getName());
} else }
lineTwo.concat((*this->entrys.begin())->getName()); else
lineTwo.concat((*this->entries.begin())->getName());
this->inSubmenu = false; this->inSubmenu = false;
this->print(lineOne, lineTwo); this->print(lineOne, lineTwo);
} }
void Menu::update() { void Menu::update()
if (this->inSubmenu) { {
if (this->inSubmenu)
{
(**this->selectedEntry).getMenu()->update(); (**this->selectedEntry).getMenu()->update();
return; return;
} }
} }
void Menu::down() { void Menu::down()
if (this->inSubmenu) { {
if (this->inSubmenu)
{
(**this->selectedEntry).getMenu()->down(); (**this->selectedEntry).getMenu()->down();
return; return;
} }
// TODO: Why I need the fucking next two lines? here and in the next function // 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++; iter++;
if (iter != this->entrys.end()) if (iter != this->entries.end())
this->selectedEntry++; this->selectedEntry++;
else else
this->selectedEntry = this->entrys.begin(); this->selectedEntry = this->entries.begin();
this->printMenu(); this->printMenu();
} }
void Menu::up() { void Menu::up()
if (this->inSubmenu) { {
if (this->inSubmenu)
{
(**this->selectedEntry).getMenu()->up(); (**this->selectedEntry).getMenu()->up();
return; return;
} }
std::list<MenuAction*>::iterator iter = this->entrys.end(); std::list<MenuAction *>::iterator iter = this->entries.end();
iter--; iter--;
if (this->selectedEntry != this->entrys.begin()) { if (this->selectedEntry != this->entries.begin())
{
this->selectedEntry--; this->selectedEntry--;
} }
else { else
this->selectedEntry = iter; {
this->selectedEntry = iter;
} }
this->printMenu(); this->printMenu();
} }
void Menu::right() { void Menu::right()
if (this->inSubmenu) { {
if (this->inSubmenu)
{
(**this->selectedEntry).getMenu()->right(); (**this->selectedEntry).getMenu()->right();
return; return;
} }
if ((**this->selectedEntry).getIsMenu()) { if ((**this->selectedEntry).getIsMenu())
{
this->inSubmenu = true; this->inSubmenu = true;
(**this->selectedEntry).getMenu()->setParentMenu(this); (**this->selectedEntry).getMenu()->setParentMenu(this);
} }
(**this->selectedEntry).runAction(); (**this->selectedEntry).runAction();
} }
void Menu::left() { void Menu::left()
if (this->inSubmenu) { {
if (this->inSubmenu)
{
(**this->selectedEntry).getMenu()->left(); (**this->selectedEntry).getMenu()->left();
return; return;
} }
@@ -109,8 +129,10 @@ void Menu::left() {
this->parentMenu->printMenu(); this->parentMenu->printMenu();
} }
void Menu::yes() { void Menu::yes()
if (this->inSubmenu) { {
if (this->inSubmenu)
{
(**this->selectedEntry).getMenu()->yes(); (**this->selectedEntry).getMenu()->yes();
return; return;
} }
@@ -118,8 +140,10 @@ void Menu::yes() {
this->right(); this->right();
} }
void Menu::no() { void Menu::no()
if (this->inSubmenu) { {
if (this->inSubmenu)
{
(**this->selectedEntry).getMenu()->no(); (**this->selectedEntry).getMenu()->no();
return; return;
} }
+18 -9
View File
@@ -10,24 +10,28 @@
*/ */
#include "menuAction.h" #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->name = name;
this->function = function; this->function = function;
this->callback = callback; this->callback = callback;
} }
MenuAction::MenuAction(const char* name, MenuControl* menu) { MenuAction::MenuAction(const char *name, MenuControl *menu)
{
this->name = name; this->name = name;
this->menu = menu; this->menu = menu;
this->isMenu = true; this->isMenu = true;
} }
MenuAction::MenuAction(const char* name, MenuActionWrapper* action) { MenuAction::MenuAction(const char *name, MenuActionWrapper *action)
{
this->name = name; this->name = name;
this->action = action; this->action = action;
} }
MenuAction::~MenuAction() { MenuAction::~MenuAction()
{
if (this->menu) if (this->menu)
delete this->menu; delete this->menu;
@@ -35,10 +39,12 @@ MenuAction::~MenuAction() {
delete this->action; delete this->action;
} }
void MenuAction::runAction() { void MenuAction::runAction()
{
if (isMenu) if (isMenu)
this->menu->printMenu(); this->menu->printMenu();
else { else
{
if (this->function) if (this->function)
this->function(); this->function();
else if (this->action) else if (this->action)
@@ -51,15 +57,18 @@ void MenuAction::runAction() {
this->callback(); this->callback();
} }
const char* MenuAction::getName() { const char *MenuAction::getName()
{
return this->name; return this->name;
} }
bool MenuAction::getIsMenu() { bool MenuAction::getIsMenu()
{
return this->isMenu; return this->isMenu;
} }
MenuControl* MenuAction::getMenu() { MenuControl *MenuAction::getMenu()
{
if (isMenu) if (isMenu)
return this->menu; return this->menu;
else else
+25 -2
View File
@@ -10,9 +10,24 @@
*/ */
#include "menuControl.h" #include "menuControl.h"
void MenuControl::update()
{
if (this->updateDelay == 0)
return;
void MenuControl::print(String lineOne, String lineTwo) const { if (millis() - this->lastUpdateMillis < this->updateDelay)
if (this->lcd) { {
return;
}
this->printMenu();
this->lastUpdateMillis = millis();
}
void MenuControl::print(String lineOne, String lineTwo) const
{
if (this->lcd)
{
lcd->clear(); lcd->clear();
lcd->setCursor(0, 0); lcd->setCursor(0, 0);
lcd->print(lineOne.c_str()); lcd->print(lineOne.c_str());
@@ -20,3 +35,11 @@ void MenuControl::print(String lineOne, String lineTwo) const {
lcd->print(lineTwo.c_str()); lcd->print(lineTwo.c_str());
} }
} }
void MenuControl::setParentMenu(MenuControl *menu)
{
this->parentMenu = menu;
DisplayWrapper *lcd = this->parentMenu->getLcd();
if (lcd)
this->lcd = lcd;
}
+41 -27
View File
@@ -11,13 +11,15 @@
#include "menuInformationSites.h" #include "menuInformationSites.h"
MenuInformationSites::MenuInformationSites(uint8_t pages) { MenuInformationSites::MenuInformationSites(uint8_t pages)
{
this->countPages = pages; this->countPages = pages;
this->currentPage = 0; this->currentPage = 0;
this->lastMillis = millis(); this->lastMillis = millis();
} }
void MenuInformationSites::up() { void MenuInformationSites::up()
{
if (this->currentPage == 0) if (this->currentPage == 0)
this->currentPage = this->countPages - 1; this->currentPage = this->countPages - 1;
else else
@@ -25,7 +27,8 @@ void MenuInformationSites::up() {
this->printMenu(); this->printMenu();
} }
void MenuInformationSites::down() { void MenuInformationSites::down()
{
if (this->currentPage == this->countPages - 1) if (this->currentPage == this->countPages - 1)
this->currentPage = 0; this->currentPage = 0;
else else
@@ -33,28 +36,42 @@ void MenuInformationSites::down() {
this->printMenu(); this->printMenu();
} }
void MenuInformationSites::right() { void MenuInformationSites::right()
this->yes(); {
this->printMenu();
} }
void MenuInformationSites::left() { void MenuInformationSites::left()
if (this->parentMenu) { {
if (this->parentMenu)
{
this->parentMenu->prepareReenterMenu();
this->parentMenu->printMenu(); this->parentMenu->printMenu();
this->leaved = true; this->leaved = true;
} }
} }
void MenuInformationSites::no() { void MenuInformationSites::no()
this->left(); {
if (this->noEqualLeft)
{
this->left();
return;
}
this->runCommandNo();
this->printMenu();
} }
void MenuInformationSites::yes() { void MenuInformationSites::yes()
{
this->runCommand(); this->runCommand();
this->printMenu(); this->printMenu();
} }
void MenuInformationSites::printMenu() { void MenuInformationSites::printMenu()
if (this->leaved) { {
if (this->leaved)
{
this->leaved = false; this->leaved = false;
this->lastPageNumber++; this->lastPageNumber++;
this->init(); this->init();
@@ -64,35 +81,32 @@ void MenuInformationSites::printMenu() {
this->lastPageNumber = this->currentPage; this->lastPageNumber = this->currentPage;
} }
void MenuInformationSites::update() { bool MenuInformationSites::setCountPages(uint8_t pages)
if (millis() - this->lastMillis < this->delay) { {
return;
}
this->printMenu();
this->lastMillis = millis();
}
bool MenuInformationSites::setCountPages(uint8_t pages) {
this->countPages = pages; this->countPages = pages;
this->currentPage = 0; this->currentPage = 0;
if (this->countPages == 0) { if (this->countPages == 0)
{
this->countPages = 1; this->countPages = 1;
return false; return false;
} }
return true; return true;
} }
uint8_t MenuInformationSites::getCountPages() const { uint8_t MenuInformationSites::getCountPages() const
{
return this->countPages; return this->countPages;
} }
uint8_t MenuInformationSites::getCurrentPage() const { uint8_t MenuInformationSites::getCurrentPage() const
{
return this->currentPage; return this->currentPage;
} }
void MenuInformationSites::printDefault() const { void MenuInformationSites::printDefault() const
String lineOne = String("Page: ") + (this->currentPage + 1); {
String lineTwo = String("of ") + this->countPages; String lineOne = String("Pagenumber: ") + (this->currentPage + 1);
String lineTwo = String("Pagecount : ") + this->countPages;
this->print(lineOne, lineTwo); this->print(lineOne, lineTwo);
} }
+72 -37
View File
@@ -11,7 +11,8 @@
#include "menuIntInput.h" #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->values = values;
this->names = names; this->names = names;
this->length = length; 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->originalValues = new int16_t[this->length];
this->stepsPerInput = new uint8_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->min[i] = INT16_MIN;
this->max[i] = INT16_MAX; this->max[i] = INT16_MAX;
this->originalValues[i] = this->values[i]; 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->length = length;
this->wrapper = wrapper; this->wrapper = wrapper;
this->values = new int16_t[this->length]; 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->min = new int16_t[this->length];
this->max = new int16_t[this->length]; this->max = new int16_t[this->length];
this->originalValues = new int16_t[this->length]; this->originalValues = new int16_t[this->length];
this->stepsPerInput = new uint8_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->min[i] = INT16_MIN;
this->max[i] = INT16_MAX; this->max[i] = INT16_MAX;
this->values[i] = 0; this->values[i] = 0;
@@ -51,7 +55,8 @@ MenuIntInput::MenuIntInput(uint8_t length, MenuIntInputWrapper *wrapper) {
} }
} }
MenuIntInput::~MenuIntInput() { MenuIntInput::~MenuIntInput()
{
delete this->min; delete this->min;
delete this->max; delete this->max;
delete this->originalValues; delete this->originalValues;
@@ -61,104 +66,117 @@ MenuIntInput::~MenuIntInput() {
delete this->wrapper; 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) if (this->length < valueNumber)
return; return;
if (strlen(name) > MAX_NAME_LENGTH) if (strlen(name) > MAX_NAME_LENGTH)
return; return;
strcpy(this->names + MAX_NAME_LENGTH * valueNumber, name); strcpy(this->names + MAX_NAME_LENGTH * valueNumber, name);
this->values[valueNumber] = startValue; this->values[valueNumber] = startValue;
this->originalValues[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) if (this->length < valueNumber)
return; return;
this->min[valueNumber] = min; 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) if (this->length < valueNumber)
return; return;
this->max[valueNumber] = max; 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->setMin(valueNumber, min);
this->setMax(valueNumber, max); 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++) for (uint8_t i = 0; i < this->length; i++)
this->min[i] = min; 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++) for (uint8_t i = 0; i < this->length; i++)
this->max[i] = max; 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->setMin(min);
this->setMax(max); 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->setMin(valueNumber, min);
this->setMax(valueNumber, max); this->setMax(valueNumber, max);
this->setStepsPerInput(valueNumber, steps); 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->setMin(min);
this->setMax(max); this->setMax(max);
this->setStepsPerInput(steps); 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) if (this->length < valueNumber)
return; return;
this->stepsPerInput[valueNumber] = steps; 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++) for (uint8_t i = 0; i < this->length; i++)
this->stepsPerInput[i] = steps; this->stepsPerInput[i] = steps;
} }
void MenuIntInput::down() { void MenuIntInput::down()
if (this->values[this->currentPosition] {
- this->stepsPerInput[this->currentPosition] if (this->values[this->currentPosition] - this->stepsPerInput[this->currentPosition] >= this->min[currentPosition])
>= this->min[currentPosition])
{ {
this->values[this->currentPosition] -= this->stepsPerInput[this->currentPosition]; this->values[this->currentPosition] -= this->stepsPerInput[this->currentPosition];
} else { }
else
{
this->values[this->currentPosition] = this->max[this->currentPosition]; this->values[this->currentPosition] = this->max[this->currentPosition];
} }
this->printMenu(); this->printMenu();
} }
void MenuIntInput::up() { void MenuIntInput::up()
if (this->values[this->currentPosition] {
+ this->stepsPerInput[this->currentPosition] if (this->values[this->currentPosition] + this->stepsPerInput[this->currentPosition] <= this->max[this->currentPosition])
<= this->max[this->currentPosition])
{ {
this->values[this->currentPosition] += this->stepsPerInput[this->currentPosition]; this->values[this->currentPosition] += this->stepsPerInput[this->currentPosition];
} else { }
else
{
this->values[this->currentPosition] = this->min[this->currentPosition]; this->values[this->currentPosition] = this->min[this->currentPosition];
} }
this->printMenu(); this->printMenu();
} }
void MenuIntInput::right() { void MenuIntInput::right()
{
if (currentPosition < this->length - 1) if (currentPosition < this->length - 1)
currentPosition++; currentPosition++;
else else
@@ -167,7 +185,8 @@ void MenuIntInput::right() {
this->printMenu(); this->printMenu();
} }
void MenuIntInput::left() { void MenuIntInput::left()
{
if (currentPosition > 0) if (currentPosition > 0)
currentPosition--; currentPosition--;
else else
@@ -176,34 +195,50 @@ void MenuIntInput::left() {
this->printMenu(); this->printMenu();
} }
void MenuIntInput::no() { void MenuIntInput::no()
{
for (uint8_t i = 0; i < this->length; i++) for (uint8_t i = 0; i < this->length; i++)
this->values[i] = this->originalValues[i]; this->values[i] = this->originalValues[i];
this->currentPosition = 0; this->currentPosition = 0;
if (this->parentMenu) if (this->parentMenu)
{
this->parentMenu->prepareReenterMenu();
this->parentMenu->printMenu(); this->parentMenu->printMenu();
}
} }
void MenuIntInput::yes() { void MenuIntInput::yes()
{
this->wrapper->action(this->values, this->length); this->wrapper->action(this->values, this->length);
if (this->parentMenu && printParentMenu) if (this->parentMenu && printParentMenu)
{
this->parentMenu->prepareReenterMenu();
this->parentMenu->printMenu(); this->parentMenu->printMenu();
}
} }
void MenuIntInput::printMenu() { void MenuIntInput::printMenu()
{
char bufferName[17]; char bufferName[17];
if (this->currentPosition == 0 && this->length == 1) { if (this->currentPosition == 0 && this->length == 1)
{
// No arrow // No arrow
sprintf(bufferName, " %s ", this->names + MAX_NAME_LENGTH * this->currentPosition); 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 // Left arrow only
sprintf(bufferName, "< %s ", this->names + MAX_NAME_LENGTH * this->currentPosition); 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 // Right arrow only
sprintf(bufferName, " %s >", this->names + MAX_NAME_LENGTH * this->currentPosition); sprintf(bufferName, " %s >", this->names + MAX_NAME_LENGTH * this->currentPosition);
} else { }
else
{
// Both arrow // Both arrow
sprintf(bufferName, "< %s >", this->names + MAX_NAME_LENGTH * this->currentPosition); sprintf(bufferName, "< %s >", this->names + MAX_NAME_LENGTH * this->currentPosition);
} }