diff --git a/include/menuControl.h b/include/menuControl.h index 725b3d2..aa7e466 100644 --- a/include/menuControl.h +++ b/include/menuControl.h @@ -45,7 +45,17 @@ class MenuControl { /** * @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; @@ -69,10 +79,23 @@ class MenuControl { */ 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: void print(String lineOne, String lineTwo) const; MenuControl* parentMenu = nullptr; DisplayWrapper* lcd = nullptr; + + uint16_t updateDelay = 0; + uint32_t lastUpdateMillis = 0; }; #endif // MENU_CONTROLL_H diff --git a/include/menuIntInput.h b/include/menuIntInput.h index 75934ad..db0cb7a 100644 --- a/include/menuIntInput.h +++ b/include/menuIntInput.h @@ -81,8 +81,6 @@ class MenuIntInput : public MenuControl { */ void printMenu() override; - void update() override {}; - private: MenuIntInputWrapper* wrapper; diff --git a/library.json b/library.json index 9ea95f0..6e22d0a 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "Menu", - "version": "1.0.1", + "version": "1.1.0", "description": "Build page based menus on uCs", "keywords": "menu, page, input", "repository":