mnoved update delay to base class and make

it setAble
This commit is contained in:
2023-04-26 07:54:57 +02:00
parent 1b695b2173
commit db3c25da42
3 changed files with 25 additions and 4 deletions
+24 -1
View File
@@ -45,7 +45,17 @@ class MenuControl {
/** /**
* @brief can be called to update shown data * @brief can be called to update shown data
*/ */
virtual void update() {} virtual void update() {
if (this->updateDelay == 0)
return;
if (millis() - this->lastUpdateMillis < this->updateDelay) {
return;
}
this->printMenu();
this->lastMillis = millis();
}
virtual void printMenu() = 0; virtual void printMenu() = 0;
@@ -69,10 +79,23 @@ class MenuControl {
*/ */
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
*
* 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: protected:
void print(String lineOne, String lineTwo) const; void print(String lineOne, String lineTwo) const;
MenuControl* parentMenu = nullptr; MenuControl* parentMenu = nullptr;
DisplayWrapper* lcd = nullptr; DisplayWrapper* lcd = nullptr;
uint16_t updateDelay = 0;
uint32_t lastUpdateMillis = 0;
}; };
#endif // MENU_CONTROLL_H #endif // MENU_CONTROLL_H
-2
View File
@@ -81,8 +81,6 @@ class MenuIntInput : public MenuControl {
*/ */
void printMenu() override; void printMenu() override;
void update() override {};
private: private:
MenuIntInputWrapper* wrapper; MenuIntInputWrapper* wrapper;
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "Menu", "name": "Menu",
"version": "1.0.1", "version": "1.1.0",
"description": "Build page based menus on uCs", "description": "Build page based menus on uCs",
"keywords": "menu, page, input", "keywords": "menu, page, input",
"repository": "repository":