From 96808c4d0a078006bed1ffbd7e81cc5999137084 Mon Sep 17 00:00:00 2001 From: BA <111384732+Bad-Assumptions@users.noreply.github.com> Date: Wed, 15 Mar 2023 10:45:12 -0400 Subject: [PATCH 01/26] copy description of example from sketch --- examples/B_serial_menu/README.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/examples/B_serial_menu/README.md b/examples/B_serial_menu/README.md index af5fa6c..1fbfca2 100644 --- a/examples/B_serial_menu/README.md +++ b/examples/B_serial_menu/README.md @@ -1,5 +1,29 @@ Example 2: serial_menu ================== + This example uses the serial communication to execute commands. + + The available commands will be printed on the serial monitor. + This example uses attached callback functions which are explained + in the functions_menu.ino example. + + The circuit: + https://raw.githubusercontent.com/VaSe7u/LiquidMenu/master/examples/B_serial_menu/serial_menu.png + - LCD RS pin to Arduino pin 12 + - LCD E pin to Arduino pin 11 + - LCD D4 pin to Arduino pin 5 + - LCD D5 pin to Arduino pin 4 + - LCD D6 pin to Arduino pin 3 + - LCD D7 pin to Arduino pin 2 + - LCD R/W pin to ground + - LCD VSS pin to ground + - LCD VDD pin to 5V + - 10k ohm potentiometer: ends to 5V and ground, wiper to LCD V0 + - 150 ohm resistor from 5V to LCD Anode + - LCD Cathode to ground + + Created July 24, 2016 + by Vasil Kalchev + ![schematic](https://github.com/VasilKalchev/LiquidMenu/blob/master/examples/B_serial_menu/serial_menu.png?raw=true) This example uses the serial communication to execute commands. From aef68add0608546606930e3d2b5227c13cf64f69 Mon Sep 17 00:00:00 2001 From: BA <111384732+Bad-Assumptions@users.noreply.github.com> Date: Wed, 15 Mar 2023 10:56:05 -0400 Subject: [PATCH 02/26] copy description of example from sketch --- examples/C_functions_menu/README.md | 49 +++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/examples/C_functions_menu/README.md b/examples/C_functions_menu/README.md index 06be26b..e67e9cb 100644 --- a/examples/C_functions_menu/README.md +++ b/examples/C_functions_menu/README.md @@ -1,5 +1,54 @@ Example 3: functions_menu ================== +his example demonstrates how to attach functions to the + "lines" in the menu. + * + Attaching functions to the different "lines" in the menu makes it + possible to execute an action through the menu (e.g. dimming an LED, + adjusting preferences...). To attach a function to a line you need + to create with signature "void functionName(void)". After creating it, + the function is ready to be attached to a line. To do that call bool + LiquidLine::attach_function(uint8_t number, void (*function)(void)). + LiquidLine is the line object you wish to attach the function to, + number is the "id" of the function for that line, void (*function)(void) + is just the name of the function without the "()". The "id" of the function + makes possible attaching multiple functions to a single line. An example use + of multiple functions on a single line is for incrementing or decrementing + some value (e.g. dimming an LED). It is convenient to attach all the different + incrementing functions (e.g. increase_brightness(), increase_volume()) to the + different lines (e.g. LED brightness: 5, Sound volume: 10) using the same id + (e.g. 1). Same goes for the decrementing functions (e.g. LED brightness: 5 (line) + with attached function decrease_brightness() (function) with id 2, + Sound volume: 10 (line) with attached function decrease_volume() (function) with id 2). + Similar functions should be attached to their corresponding lines with the same "id", + because then they can be called from the same event (e.g. pressing button "UP" + calls the incrementing function of whatever the focused line is). + This example has a line that shows the current PWM of the LED and lines + that allow a fade or blink loop to be turned ON/OFF and configured. + The circuit: + https://raw.githubusercontent.com/VaSe7u/LiquidMenu/master/examples/C_functions_menu/functions_menu.png + - LCD RS pin to Arduino pin 12 + - LCD E pin to Arduino pin 11 + - LCD D4 pin to Arduino pin 5 + - LCD D5 pin to Arduino pin 4 + - LCD D6 pin to Arduino pin 3 + - LCD D7 pin to Arduino pin 2 + - LCD R/W pin to ground + - LCD VSS pin to ground + - LCD VDD pin to 5V + - 10k ohm potentiometer: ends to 5V and ground, wiper to LCD V0 + - 150 ohm resistor from 5V to LCD Anode + - LCD Cathode to ground + - ---- + - Button (left) to Arduino pin A0 and ground + - Button (right) to Arduino pin 7 and ground + - Button (up) to Arduino pin 8 and ground + - Button (down) to Arduino pin 9 and ground + - Button (enter) to Arduino pin 10 and ground + - A PWM controlled device (LED...) to Arduino pin 6 + + Created July 24, 2016 + by Vasil Kalchev ![schematic](https://github.com/VasilKalchev/LiquidMenu/blob/master/examples/C_functions_menu/functions_menu.png?raw=true) This example demonstrates how to attach functions to the "lines" in the menu. From bf9a437076ec5de09cb6925a0820eb7fec3c2675 Mon Sep 17 00:00:00 2001 From: BA <111384732+Bad-Assumptions@users.noreply.github.com> Date: Wed, 15 Mar 2023 10:56:21 -0400 Subject: [PATCH 03/26] typo --- examples/C_functions_menu/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/C_functions_menu/README.md b/examples/C_functions_menu/README.md index e67e9cb..88ad32c 100644 --- a/examples/C_functions_menu/README.md +++ b/examples/C_functions_menu/README.md @@ -1,6 +1,6 @@ Example 3: functions_menu ================== -his example demonstrates how to attach functions to the +This example demonstrates how to attach functions to the "lines" in the menu. * Attaching functions to the different "lines" in the menu makes it From ef210e13a1bd7713edca8966107b9e00aa77d444 Mon Sep 17 00:00:00 2001 From: Brian Alano <111384732+Bad-Assumptions@users.noreply.github.com> Date: Thu, 15 Jun 2023 08:57:15 -0400 Subject: [PATCH 04/26] configuration changes supporting Magnethereal --- CMakeLists.txt | 4 ++++ src/LiquidMenu_config.h | 26 ++++++++++++++------------ 2 files changed, 18 insertions(+), 12 deletions(-) create mode 100644 CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..4577875 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,4 @@ +idf_component_register(SRCS "src/LiquidScreen.cpp" "src/LiquidLine.cpp" "src/LiquidMenu.cpp" "src/recognizeType.cpp" "src/LiquidSystem.cpp" + REQUIRES DFRobot_RGBLCD1602 # component containing LiquidCrystal_I2C.h + INCLUDE_DIRS "./src") + \ No newline at end of file diff --git a/src/LiquidMenu_config.h b/src/LiquidMenu_config.h index 558df82..fb920f0 100644 --- a/src/LiquidMenu_config.h +++ b/src/LiquidMenu_config.h @@ -22,12 +22,12 @@ used in the library, also configures the debugging messages. * @name Arduino's parallel "LiquidCrystal" library * @{ */ -#ifndef LIQUIDMENU_LIBRARY - #define LIQUIDMENU_LIBRARY LiquidCrystal_LIBRARY ///< wrapped library ID -#endif -#ifndef DisplayClass - #define DisplayClass LiquidCrystal ///< name of wrapped library's class -#endif +// #ifndef LIQUIDMENU_LIBRARY +// #define LIQUIDMENU_LIBRARY LiquidCrystal_LIBRARY ///< wrapped library ID +// #endif +// #ifndef DisplayClass +// #define DisplayClass LiquidCrystal ///< name of wrapped library's class +// #endif //!@} /*! @@ -44,13 +44,15 @@ used in the library, also configures the debugging messages. //!@} /*! - * @name Some other library + * @name DFRobot_RGBLCD1602 * @{ */ -// #include -// #ifndef DisplayClass -// #define DisplayClass LIBRARY_CONSTRUCTOR -// #endif +#ifndef LIQUIDMENU_LIBRARY + #define LIQUIDMENU_LIBRARY LiquidCrystal_I2C_LIBRARY +#endif +#ifndef DisplayClass + #define DisplayClass LiquidCrystal_I2C +#endif //!@} //!@} @@ -64,7 +66,7 @@ const uint8_t MAX_VARIABLES = 5; ///< @note Default: 5 const uint8_t MAX_FUNCTIONS = 8; ///< @note Default: 8 /// Configures the number of available lines per screen. -const uint8_t MAX_LINES = 12; ///< @note Default: 12 +const uint8_t MAX_LINES = 2; ///< @note Default: 12 /// Configures the number of available screens per menu. const uint8_t MAX_SCREENS = 14; ///< @note Default: 14 From b799175bb4d673e54f71d05809bd177c39e8bf52 Mon Sep 17 00:00:00 2001 From: Brian Alano <111384732+Bad-Assumptions@users.noreply.github.com> Date: Thu, 15 Jun 2023 14:09:08 -0400 Subject: [PATCH 05/26] config changes --- CMakeLists.txt | 4 ++++ src/LiquidMenu_config.h | 26 ++++++++++++++------------ 2 files changed, 18 insertions(+), 12 deletions(-) create mode 100644 CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..4577875 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,4 @@ +idf_component_register(SRCS "src/LiquidScreen.cpp" "src/LiquidLine.cpp" "src/LiquidMenu.cpp" "src/recognizeType.cpp" "src/LiquidSystem.cpp" + REQUIRES DFRobot_RGBLCD1602 # component containing LiquidCrystal_I2C.h + INCLUDE_DIRS "./src") + \ No newline at end of file diff --git a/src/LiquidMenu_config.h b/src/LiquidMenu_config.h index 558df82..fb920f0 100644 --- a/src/LiquidMenu_config.h +++ b/src/LiquidMenu_config.h @@ -22,12 +22,12 @@ used in the library, also configures the debugging messages. * @name Arduino's parallel "LiquidCrystal" library * @{ */ -#ifndef LIQUIDMENU_LIBRARY - #define LIQUIDMENU_LIBRARY LiquidCrystal_LIBRARY ///< wrapped library ID -#endif -#ifndef DisplayClass - #define DisplayClass LiquidCrystal ///< name of wrapped library's class -#endif +// #ifndef LIQUIDMENU_LIBRARY +// #define LIQUIDMENU_LIBRARY LiquidCrystal_LIBRARY ///< wrapped library ID +// #endif +// #ifndef DisplayClass +// #define DisplayClass LiquidCrystal ///< name of wrapped library's class +// #endif //!@} /*! @@ -44,13 +44,15 @@ used in the library, also configures the debugging messages. //!@} /*! - * @name Some other library + * @name DFRobot_RGBLCD1602 * @{ */ -// #include -// #ifndef DisplayClass -// #define DisplayClass LIBRARY_CONSTRUCTOR -// #endif +#ifndef LIQUIDMENU_LIBRARY + #define LIQUIDMENU_LIBRARY LiquidCrystal_I2C_LIBRARY +#endif +#ifndef DisplayClass + #define DisplayClass LiquidCrystal_I2C +#endif //!@} //!@} @@ -64,7 +66,7 @@ const uint8_t MAX_VARIABLES = 5; ///< @note Default: 5 const uint8_t MAX_FUNCTIONS = 8; ///< @note Default: 8 /// Configures the number of available lines per screen. -const uint8_t MAX_LINES = 12; ///< @note Default: 12 +const uint8_t MAX_LINES = 2; ///< @note Default: 12 /// Configures the number of available screens per menu. const uint8_t MAX_SCREENS = 14; ///< @note Default: 14 From 807d1dc22c76d26ad2c29f105e076673b92ea069 Mon Sep 17 00:00:00 2001 From: Brian Alano <111384732+Bad-Assumptions@users.noreply.github.com> Date: Mon, 19 Jun 2023 16:48:03 -0400 Subject: [PATCH 06/26] removed noisy compiler warnings --- src/LiquidMenu.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/LiquidMenu.h b/src/LiquidMenu.h index 15a2df9..749c7e8 100644 --- a/src/LiquidMenu.h +++ b/src/LiquidMenu.h @@ -52,10 +52,10 @@ Include file for LiquidMenu library. # pragma message ("LiquidMenu: Selected 'LiquidCrystal' (parallel) library. Edit 'LiquidMenu_config.h' file to change it.") #include #elif LIQUIDMENU_LIBRARY == LiquidCrystal_I2C_LIBRARY -# pragma message ("LiquidMenu: Selected 'LiquidCrystal_I2C' (I2C) library. Edit 'LiquidMenu_config.h' file to change it.") +// # pragma message ("LiquidMenu: Selected 'LiquidCrystal_I2C' (I2C) library. Edit 'LiquidMenu_config.h' file to change it.") #include #else -# pragma message ("LiquidMenu: Selected custom library. Edit 'LiquidMenu_config.h' file to change it.") +// # pragma message ("LiquidMenu: Selected custom library. Edit 'LiquidMenu_config.h' file to change it.") #endif #if LIQUIDMENU_DEBUG From b78513677606b7decba48b8701f080f727c1ab59 Mon Sep 17 00:00:00 2001 From: Brian Alano <111384732+Bad-Assumptions@users.noreply.github.com> Date: Fri, 23 Jun 2023 17:50:33 -0400 Subject: [PATCH 07/26] updated example A for local environment --- examples/A_hello_menu/A_hello_menu.ino | 4 ++-- src/LiquidMenu_config.h | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/examples/A_hello_menu/A_hello_menu.ino b/examples/A_hello_menu/A_hello_menu.ino index 55b9b2a..7f79d4d 100644 --- a/examples/A_hello_menu/A_hello_menu.ino +++ b/examples/A_hello_menu/A_hello_menu.ino @@ -38,7 +38,7 @@ */ // The LCD library -#include +#include // The menu wrapper library #include @@ -51,7 +51,7 @@ const byte LCD_D6 = 3; const byte LCD_D7 = 2; //LCD R/W pin to ground //10K potentiometer wiper to VO -LiquidCrystal lcd(LCD_RS, LCD_E, LCD_D4, LCD_D5, LCD_D6, LCD_D7); +DFRobot_RGBLCD1602 lcd(0x68); /* * Variable 'analogReading' is later configured to diff --git a/src/LiquidMenu_config.h b/src/LiquidMenu_config.h index fb920f0..3445cf9 100644 --- a/src/LiquidMenu_config.h +++ b/src/LiquidMenu_config.h @@ -9,7 +9,6 @@ used in the library, also configures the debugging messages. #pragma once #include "LiquidMenu_const.h" - // Select a "LiquidCrystal" library: // --------------------------------- From cc94caf19788ff2a7dd2bf6b63ebbedcc233a1e2 Mon Sep 17 00:00:00 2001 From: Brian Alano <111384732+Bad-Assumptions@users.noreply.github.com> Date: Mon, 26 Jun 2023 16:45:20 -0400 Subject: [PATCH 08/26] hack to allow setting of lcd pointer at runtime --- src/LiquidMenu.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/LiquidMenu.h b/src/LiquidMenu.h index 749c7e8..b2fd7d1 100644 --- a/src/LiquidMenu.h +++ b/src/LiquidMenu.h @@ -1041,8 +1041,8 @@ class LiquidMenu { ///@} + DisplayClass *_p_liquidCrystal; ///< Pointer to the DisplayClass object FIXME private: - DisplayClass *_p_liquidCrystal; ///< Pointer to the DisplayClass object LiquidScreen *_p_liquidScreen[MAX_SCREENS]; ///< The LiquidScreen objects uint8_t _screenCount; ///< Count of the LiquidScreen objects uint8_t _currentScreen; From c8f1e47bc994f7ead10cacc3b4fd2b2b1108062f Mon Sep 17 00:00:00 2001 From: Brian Alano <111384732+Bad-Assumptions@users.noreply.github.com> Date: Tue, 27 Jun 2023 16:32:04 -0400 Subject: [PATCH 09/26] fix change_menu() update() bug --- src/LiquidMenu.h | 2 +- src/LiquidSystem.cpp | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/LiquidMenu.h b/src/LiquidMenu.h index b2fd7d1..06f5f89 100644 --- a/src/LiquidMenu.h +++ b/src/LiquidMenu.h @@ -1129,7 +1129,7 @@ class LiquidSystem { @param *p_liquidMenu - pointer to the LiquidMenu object @returns true on success and false if the menu is not found */ - bool change_menu(LiquidMenu &p_liquidMenu); + bool change_menu(LiquidMenu &p_liquidMenu, bool refresh = true); /// Returns a reference to the current screen. /** diff --git a/src/LiquidSystem.cpp b/src/LiquidSystem.cpp index bddab22..9d3545d 100644 --- a/src/LiquidSystem.cpp +++ b/src/LiquidSystem.cpp @@ -73,14 +73,16 @@ bool LiquidSystem::add_menu(LiquidMenu &liquidMenu) { } -bool LiquidSystem::change_menu(LiquidMenu &p_liquidMenu) { +bool LiquidSystem::change_menu(LiquidMenu &p_liquidMenu, bool refresh) { // _p_liquidMenu[_currentMenu]->_p_liquidCrystal->clear(); for (uint8_t m = 0; m < _menuCount; m++) { // if ((uintptr_t)&p_liquidMenu == (uintptr_t) & (*_p_liquidMenu[m])) { if (reinterpret_cast(&p_liquidMenu) == reinterpret_cast(&(*_p_liquidMenu[m]))) { _currentMenu = m; DEBUG(F("Menu changed to ")); DEBUGLN(_currentMenu); - update(); + if (refresh) { + update(); + } return true; } } @@ -164,7 +166,10 @@ bool LiquidSystem::is_callable(uint8_t number) const { } bool LiquidSystem::call_function(uint8_t number, bool refresh) const { - bool returnValue = _p_liquidMenu[_currentMenu]->call_function(number, refresh); + bool returnValue = _p_liquidMenu[_currentMenu]->call_function(number, false); + if (refresh) { + update(); + } return returnValue; } From d12235dc9ac4906c33afded41e72bac3a170a19b Mon Sep 17 00:00:00 2001 From: Brian Alano <111384732+Bad-Assumptions@users.noreply.github.com> Date: Wed, 28 Jun 2023 16:56:09 -0400 Subject: [PATCH 10/26] add access to current screen of non-current menus. Fix double update() bug in change_menu() --- src/LiquidMenu.cpp | 10 ++++++++-- src/LiquidMenu.h | 31 +++++++++++++++++++------------ src/LiquidSystem.cpp | 10 ++++++++++ 3 files changed, 37 insertions(+), 14 deletions(-) diff --git a/src/LiquidMenu.cpp b/src/LiquidMenu.cpp index e7f02bb..10e9d03 100644 --- a/src/LiquidMenu.cpp +++ b/src/LiquidMenu.cpp @@ -92,7 +92,13 @@ LiquidScreen* LiquidMenu::get_currentScreen() const { return _p_liquidScreen[_currentScreen]; } -void LiquidMenu::next_screen() { +uint8_t LiquidMenu::get_currentScreenNumber() const +{ + return _currentScreen; +} + +void LiquidMenu::next_screen() +{ _p_liquidCrystal->clear(); do { if (_currentScreen < _screenCount - 1) { @@ -159,7 +165,7 @@ bool LiquidMenu::change_screen(LiquidScreen *p_liquidScreen) { update(); DEBUG(F("Switched to screen (")); DEBUG(_currentScreen); DEBUGLN(F(")")); - update(); + // update(); No reason for two calls to update return true; } } diff --git a/src/LiquidMenu.h b/src/LiquidMenu.h index 06f5f89..524cbf8 100644 --- a/src/LiquidMenu.h +++ b/src/LiquidMenu.h @@ -704,6 +704,13 @@ class LiquidScreen { void hide(bool hide); ///@} + /// Directly select focused line. + /** + @param lineIndex - index of the focused line + @return true: on success, false: when the selected line doesn't exist or it isn't focusable + */ + bool set_focusedLine(uint8_t lineIndex); + private: /// Prints the lines pointed by the screen. /** @@ -727,13 +734,6 @@ class LiquidScreen { */ void switch_focus(bool forward = true); - /// Directly select focused line. - /** - @param lineIndex - index of the focused line - @return true: on success, false: when the selected line doesn't exist or it isn't focusable - */ - bool set_focusedLine(uint8_t lineIndex); - /// Get the index of the currently focused line. /** @returns the index of the currently focused line @@ -875,6 +875,8 @@ class LiquidMenu { */ LiquidScreen* get_currentScreen() const; + uint8_t get_currentScreenNumber() const; + /// Switches to the next screen. void next_screen(); @@ -1042,13 +1044,13 @@ class LiquidMenu { ///@} DisplayClass *_p_liquidCrystal; ///< Pointer to the DisplayClass object FIXME + private: LiquidScreen *_p_liquidScreen[MAX_SCREENS]; ///< The LiquidScreen objects - uint8_t _screenCount; ///< Count of the LiquidScreen objects - uint8_t _currentScreen; + uint8_t _screenCount; ///< Count of the LiquidScreen objects + uint8_t _currentScreen; // FIXME DEBUG should be private }; - /// Represents a collection of menus forming a menu system. /** A menu system is made up of LiquidMenu objects. It holds pointers to them @@ -1131,6 +1133,8 @@ class LiquidSystem { */ bool change_menu(LiquidMenu &p_liquidMenu, bool refresh = true); + uint8_t get_currentMenuNumber() const; + /// Returns a reference to the current screen. /** Call this method to obtain a reference to the current screen. @@ -1139,6 +1143,8 @@ class LiquidSystem { */ LiquidScreen* get_currentScreen() const; + uint8_t get_currentScreenNumber() const; + /// Switches to the next screen. void next_screen(); @@ -1297,8 +1303,9 @@ class LiquidSystem { ///@} + private: LiquidMenu *_p_liquidMenu[MAX_MENUS]; ///< The LiquidMenu objects - uint8_t _menuCount; ///< Count of the LiquidMenu objects - uint8_t _currentMenu; + uint8_t _menuCount; ///< Count of the LiquidMenu objects + uint8_t _currentMenu; // FIXME should be private }; diff --git a/src/LiquidSystem.cpp b/src/LiquidSystem.cpp index 9d3545d..1562a95 100644 --- a/src/LiquidSystem.cpp +++ b/src/LiquidSystem.cpp @@ -95,6 +95,16 @@ LiquidScreen* LiquidSystem::get_currentScreen() const { return _p_liquidMenu[_currentMenu]->get_currentScreen(); } +uint8_t LiquidSystem::get_currentScreenNumber() const +{ + return _p_liquidMenu[_currentMenu]->get_currentScreenNumber(); +} + +uint8_t LiquidSystem::get_currentMenuNumber() const +{ + return _currentMenu; +} + void LiquidSystem::next_screen() { _p_liquidMenu[_currentMenu]->next_screen(); } From ef0899a4ff7430cdc25a26433e5b143c2e1cc7fb Mon Sep 17 00:00:00 2001 From: Brian Alano <111384732+Bad-Assumptions@users.noreply.github.com> Date: Fri, 30 Jun 2023 16:29:34 -0400 Subject: [PATCH 11/26] some debug messages --- src/LiquidLine.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/LiquidLine.cpp b/src/LiquidLine.cpp index 17c4a17..92e56ad 100644 --- a/src/LiquidLine.cpp +++ b/src/LiquidLine.cpp @@ -156,6 +156,7 @@ void LiquidLine::print_variable(DisplayClass *p_liquidCrystal, uint8_t number) { case DataType::CHAR_PTR: { char* variable = const_cast(reinterpret_cast(_variable[number])); DEBUG(F("(char*)")); DEBUG(variable); + ESP_LOGD("LiquidLine", "print_variable(char*):%s", variable); p_liquidCrystal->print(variable); break; } //case CHAR_PTR @@ -175,6 +176,7 @@ void LiquidLine::print_variable(DisplayClass *p_liquidCrystal, uint8_t number) { case DataType::UINT8_T: { const uint8_t variable = *static_cast(_variable[number]); DEBUG(F("(uint8_t)")); DEBUG(variable); + ESP_LOGD("LiquidLine", "print_variable(uint8_t):%i", variable); p_liquidCrystal->print(variable); break; } //case UINT8_T From c0530e20c07b76816bdba7348ed163eb0c68f30c Mon Sep 17 00:00:00 2001 From: Brian Alano <111384732+Bad-Assumptions@users.noreply.github.com> Date: Mon, 10 Jul 2023 17:07:47 -0400 Subject: [PATCH 12/26] added get_menu() to LiquidSystem --- src/LiquidMenu.h | 9 ++++++++- src/LiquidSystem.cpp | 5 +++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/LiquidMenu.h b/src/LiquidMenu.h index 524cbf8..908f9c3 100644 --- a/src/LiquidMenu.h +++ b/src/LiquidMenu.h @@ -1133,7 +1133,14 @@ class LiquidSystem { */ bool change_menu(LiquidMenu &p_liquidMenu, bool refresh = true); - uint8_t get_currentMenuNumber() const; + /** + * @brief return a reference to the current menu + * + * @return pointer to menu + */ + LiquidMenu * get_currentMenu() const; + + uint8_t get_currentMenuNumber() const; /// Returns a reference to the current screen. /** diff --git a/src/LiquidSystem.cpp b/src/LiquidSystem.cpp index 1562a95..a6a06a9 100644 --- a/src/LiquidSystem.cpp +++ b/src/LiquidSystem.cpp @@ -100,6 +100,11 @@ uint8_t LiquidSystem::get_currentScreenNumber() const return _p_liquidMenu[_currentMenu]->get_currentScreenNumber(); } +LiquidMenu *LiquidSystem::get_currentMenu() const // TEST +{ + return _p_liquidMenu[_currentMenu]; +} + uint8_t LiquidSystem::get_currentMenuNumber() const { return _currentMenu; From da6d3b36d115b3f899ebd34ff964625f94f2afba Mon Sep 17 00:00:00 2001 From: Brian Alano <111384732+Bad-Assumptions@users.noreply.github.com> Date: Tue, 11 Jul 2023 14:49:58 -0400 Subject: [PATCH 13/26] made menu array public so I can iterate --- src/LiquidMenu.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/LiquidMenu.h b/src/LiquidMenu.h index 908f9c3..5b33eb2 100644 --- a/src/LiquidMenu.h +++ b/src/LiquidMenu.h @@ -1044,9 +1044,9 @@ class LiquidMenu { ///@} DisplayClass *_p_liquidCrystal; ///< Pointer to the DisplayClass object FIXME + LiquidScreen *_p_liquidScreen[MAX_SCREENS]; ///< The LiquidScreen objects private: - LiquidScreen *_p_liquidScreen[MAX_SCREENS]; ///< The LiquidScreen objects uint8_t _screenCount; ///< Count of the LiquidScreen objects uint8_t _currentScreen; // FIXME DEBUG should be private }; From b9ce4a1ab6eedfa40551fcd27247ed6218191fb5 Mon Sep 17 00:00:00 2001 From: Brian Alano <111384732+Bad-Assumptions@users.noreply.github.com> Date: Tue, 11 Jul 2023 16:28:56 -0400 Subject: [PATCH 14/26] public access to screen & line arrays --- src/LiquidLine.cpp | 2 +- src/LiquidMenu.cpp | 5 +++++ src/LiquidMenu.h | 9 ++++++--- src/LiquidScreen.cpp | 4 ++++ 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/LiquidLine.cpp b/src/LiquidLine.cpp index 92e56ad..39f96ae 100644 --- a/src/LiquidLine.cpp +++ b/src/LiquidLine.cpp @@ -156,7 +156,7 @@ void LiquidLine::print_variable(DisplayClass *p_liquidCrystal, uint8_t number) { case DataType::CHAR_PTR: { char* variable = const_cast(reinterpret_cast(_variable[number])); DEBUG(F("(char*)")); DEBUG(variable); - ESP_LOGD("LiquidLine", "print_variable(char*):%s", variable); + ESP_LOGV("LiquidLine", "print_variable(char*):%s", variable); p_liquidCrystal->print(variable); break; } //case CHAR_PTR diff --git a/src/LiquidMenu.cpp b/src/LiquidMenu.cpp index 10e9d03..eaedd26 100644 --- a/src/LiquidMenu.cpp +++ b/src/LiquidMenu.cpp @@ -97,6 +97,11 @@ uint8_t LiquidMenu::get_currentScreenNumber() const return _currentScreen; } +uint8_t LiquidMenu::get_screenCount() const +{ + return _screenCount; +} + void LiquidMenu::next_screen() { _p_liquidCrystal->clear(); diff --git a/src/LiquidMenu.h b/src/LiquidMenu.h index 5b33eb2..ababed4 100644 --- a/src/LiquidMenu.h +++ b/src/LiquidMenu.h @@ -711,6 +711,9 @@ class LiquidScreen { */ bool set_focusedLine(uint8_t lineIndex); + LiquidLine *_p_liquidLine[MAX_LINES]; ///< The LiquidLine objects + uint8_t get_lineCount() const; + private: /// Prints the lines pointed by the screen. /** @@ -764,7 +767,6 @@ class LiquidScreen { */ bool call_function(uint8_t number) const; - LiquidLine *_p_liquidLine[MAX_LINES]; ///< The LiquidLine objects uint8_t _lineCount; ///< Count of the LiquidLine objects uint8_t _focus; ///< Index of the focused line uint8_t _displayLineCount; ///< The number of lines the display supports @@ -1045,10 +1047,11 @@ class LiquidMenu { DisplayClass *_p_liquidCrystal; ///< Pointer to the DisplayClass object FIXME LiquidScreen *_p_liquidScreen[MAX_SCREENS]; ///< The LiquidScreen objects + uint8_t get_screenCount() const; private: - uint8_t _screenCount; ///< Count of the LiquidScreen objects - uint8_t _currentScreen; // FIXME DEBUG should be private + uint8_t _screenCount; ///< Count of the LiquidScreen objects + uint8_t _currentScreen; // FIXME DEBUG should be private }; /// Represents a collection of menus forming a menu system. diff --git a/src/LiquidScreen.cpp b/src/LiquidScreen.cpp index 74d84c7..e5f8fdc 100644 --- a/src/LiquidScreen.cpp +++ b/src/LiquidScreen.cpp @@ -201,6 +201,10 @@ uint8_t LiquidScreen::get_focusedLine() const { return _focus; } +uint8_t LiquidScreen::get_lineCount() const { + return _lineCount; +} + bool LiquidScreen::is_callable(uint8_t number) const { if (_focus != _lineCount) { return _p_liquidLine[_focus]->is_callable(number); From f1cde5195c6f87680011cb62d02c4ec143909484 Mon Sep 17 00:00:00 2001 From: Brian Alano <111384732+Bad-Assumptions@users.noreply.github.com> Date: Wed, 12 Jul 2023 13:50:53 -0400 Subject: [PATCH 15/26] checkpoint working meter menus --- src/LiquidMenu.cpp | 9 ++++++++- src/LiquidMenu_config.h | 6 +++--- src/LiquidMenu_const.h | 1 + src/LiquidSystem.cpp | 3 +++ 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/LiquidMenu.cpp b/src/LiquidMenu.cpp index eaedd26..4714f19 100644 --- a/src/LiquidMenu.cpp +++ b/src/LiquidMenu.cpp @@ -167,13 +167,16 @@ bool LiquidMenu::change_screen(LiquidScreen *p_liquidScreen) { if (p_liquidScreen == _p_liquidScreen[s]) { // if (reinterpret_cast(&p_liquidScreen) == reinterpret_cast(&(*_p_liquidScreen[s]))) { _currentScreen = s; + update(); + ESP_LOGD("LiquidMenu", "Switched to screen:%d pointer:%p", _currentScreen, p_liquidScreen) DEBUG(F("Switched to screen (")); DEBUG(_currentScreen); DEBUGLN(F(")")); // update(); No reason for two calls to update return true; } } + ESP_LOGD("LiquidMenu", "Invalid request for screen change to %p", p_liquidScreen); DEBUG(F("Invalid request for screen change to 0x")); DEBUGLN(reinterpret_cast(&p_liquidScreen)); return false; } @@ -250,13 +253,15 @@ bool LiquidMenu::is_callable(uint8_t number) const { bool LiquidMenu::call_function(uint8_t number, bool refresh) const { bool returnValue = _p_liquidScreen[_currentScreen]->call_function(number); - if (refresh) { + if (refresh) + { update(); } return returnValue; } void LiquidMenu::update() const { + ESP_LOGV("LiquidMenu", "Updating screen:%d, _p_liquidCrystal:%p", _currentScreen, _p_liquidCrystal); _p_liquidCrystal->clear(); softUpdate(); } @@ -269,6 +274,8 @@ void LiquidMenu::softUpdate() const { * Will be removed for version 2.0.0 when `LiquidMenu::init()` will * become mandatory. */ + ESP_LOGV("LiquidMenu", "Soft updating screen:%d, pointer:%p", _currentScreen, _p_liquidScreen[_currentScreen]); + // _p_liquidCrystal->clear(); Isn't the point of softUpdate() no clear()? static bool firstRun = true; if (firstRun) { firstRun = false; diff --git a/src/LiquidMenu_config.h b/src/LiquidMenu_config.h index 3445cf9..d9fbe66 100644 --- a/src/LiquidMenu_config.h +++ b/src/LiquidMenu_config.h @@ -62,16 +62,16 @@ used in the library, also configures the debugging messages. const uint8_t MAX_VARIABLES = 5; ///< @note Default: 5 /// Configures the number of available functions per line. -const uint8_t MAX_FUNCTIONS = 8; ///< @note Default: 8 +const uint8_t MAX_FUNCTIONS = 4; ///< @note Default: 8 /// Configures the number of available lines per screen. const uint8_t MAX_LINES = 2; ///< @note Default: 12 /// Configures the number of available screens per menu. -const uint8_t MAX_SCREENS = 14; ///< @note Default: 14 +const uint8_t MAX_SCREENS = 10; ///< @note Default: 14 /// Configures the number of available menus per menus system. -const uint8_t MAX_MENUS = 8; ///< @note Default: 8 +const uint8_t MAX_MENUS = 12; ///< @note Default: 8 /*! * Enable/disable hiding the focus indicator. diff --git a/src/LiquidMenu_const.h b/src/LiquidMenu_const.h index ab16033..172323e 100644 --- a/src/LiquidMenu_const.h +++ b/src/LiquidMenu_const.h @@ -16,3 +16,4 @@ Constants file for LiquidMenu library. /// https://github.com/johnrickman/LiquidCrystal_I2C library (I2C) #define LiquidCrystal_I2C_LIBRARY (2) //!@} + diff --git a/src/LiquidSystem.cpp b/src/LiquidSystem.cpp index a6a06a9..b647d6b 100644 --- a/src/LiquidSystem.cpp +++ b/src/LiquidSystem.cpp @@ -68,6 +68,7 @@ bool LiquidSystem::add_menu(LiquidMenu &liquidMenu) { DEBUG(F("")); return true; } + ESP_LOGE("LiquidSystem", "failed, edit LiquidMenu_config.h to allow for more menus"); DEBUGLN(F(" failed, edit LiquidMenu_config.h to allow for more menus")); return false; } @@ -79,6 +80,7 @@ bool LiquidSystem::change_menu(LiquidMenu &p_liquidMenu, bool refresh) { // if ((uintptr_t)&p_liquidMenu == (uintptr_t) & (*_p_liquidMenu[m])) { if (reinterpret_cast(&p_liquidMenu) == reinterpret_cast(&(*_p_liquidMenu[m]))) { _currentMenu = m; + ESP_LOGD("LiquidSystem", "Menu changed to: %d", _currentMenu); DEBUG(F("Menu changed to ")); DEBUGLN(_currentMenu); if (refresh) { update(); @@ -189,6 +191,7 @@ bool LiquidSystem::call_function(uint8_t number, bool refresh) const { } void LiquidSystem::update() const { + ESP_LOGD("LiquidSystem", "Updating menu:%d, pointer:%p", _currentMenu, _p_liquidMenu[_currentMenu]); _p_liquidMenu[_currentMenu]->update(); } From 16352829a85d9cb4c3883e49e894e8b06d94218a Mon Sep 17 00:00:00 2001 From: Brian Alano <111384732+Bad-Assumptions@users.noreply.github.com> Date: Mon, 17 Jul 2023 16:37:37 -0400 Subject: [PATCH 16/26] made more privates public --- src/LiquidMenu.h | 6 ++++-- src/LiquidMenu_config.h | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/LiquidMenu.h b/src/LiquidMenu.h index ababed4..1abc675 100644 --- a/src/LiquidMenu.h +++ b/src/LiquidMenu.h @@ -530,6 +530,10 @@ class LiquidLine { bool set_asProgmem(uint8_t number); ///@} + // public for debugging convenience + const void *_variable[MAX_VARIABLES]; ///< Pointers to the variables + DataType _variableType[MAX_VARIABLES]; ///< Data type of the variables + private: /// Prints the line to the display. /** @@ -579,8 +583,6 @@ class LiquidLine { uint8_t _floatDecimalPlaces; uint8_t _variableCount; ///< Count of the variables void (*_function[MAX_FUNCTIONS])(void); ///< Pointers to the functions - const void *_variable[MAX_VARIABLES]; ///< Pointers to the variables - DataType _variableType[MAX_VARIABLES]; ///< Data type of the variables bool _focusable; ///< Determines whether the line is focusable }; diff --git a/src/LiquidMenu_config.h b/src/LiquidMenu_config.h index d9fbe66..8459d44 100644 --- a/src/LiquidMenu_config.h +++ b/src/LiquidMenu_config.h @@ -65,13 +65,13 @@ const uint8_t MAX_VARIABLES = 5; ///< @note Default: 5 const uint8_t MAX_FUNCTIONS = 4; ///< @note Default: 8 /// Configures the number of available lines per screen. -const uint8_t MAX_LINES = 2; ///< @note Default: 12 +const uint8_t MAX_LINES = 3; ///< @note Default: 12 /// Configures the number of available screens per menu. const uint8_t MAX_SCREENS = 10; ///< @note Default: 14 /// Configures the number of available menus per menus system. -const uint8_t MAX_MENUS = 12; ///< @note Default: 8 +const uint8_t MAX_MENUS = 15; ///< @note Default: 8 /*! * Enable/disable hiding the focus indicator. From 61807cf1549bc9d0e450aadcd6b5143b7f651d64 Mon Sep 17 00:00:00 2001 From: Brian Alano <111384732+Bad-Assumptions@users.noreply.github.com> Date: Wed, 26 Jul 2023 23:57:07 -0400 Subject: [PATCH 17/26] workaround conflict with DEBUG definition --- src/LiquidMenu_debug.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/LiquidMenu_debug.h b/src/LiquidMenu_debug.h index 3761d53..2598b2b 100644 --- a/src/LiquidMenu_debug.h +++ b/src/LiquidMenu_debug.h @@ -20,6 +20,9 @@ Contains debug macro definitions for LiquidMenu library. #endif #else /// Debug print + #ifdef DEBUG + #undef DEBUG + #endif #define DEBUG(x) /// Debug print with newline #define DEBUGLN(x) From 2bfd6394914f1fa16599ef3e9daf8dc71499c338 Mon Sep 17 00:00:00 2001 From: hezy0426 Date: Thu, 31 Aug 2023 15:23:35 -0400 Subject: [PATCH 18/26] Fix the issue with printing I should mention that the issue isn't really caused by the library, but rather the i2c communication isn't stable or whatever. --- src/LiquidMenu.cpp | 245 ++++++++++++++++++++++++++-------------- src/LiquidMenu_config.h | 9 +- 2 files changed, 162 insertions(+), 92 deletions(-) diff --git a/src/LiquidMenu.cpp b/src/LiquidMenu.cpp index 4714f19..2cd7114 100644 --- a/src/LiquidMenu.cpp +++ b/src/LiquidMenu.cpp @@ -30,9 +30,11 @@ Contains the LiquidMenu class definition. #include "LiquidMenu.h" #include "glyphs.h" - -void print_me(uintptr_t address) { - DEBUG(F("(0x")); DEBUG2(address, OCT); DEBUG(F("): ")); +void print_me(uintptr_t address) +{ + DEBUG(F("(0x")); + DEBUG2(address, OCT); + DEBUG(F("): ")); return; address = address; } @@ -40,44 +42,55 @@ void print_me(uintptr_t address) { const uint8_t DIVISION_LINE_LENGTH = 40; ///< Sets the length of the division line. LiquidMenu::LiquidMenu(DisplayClass &liquidCrystal, uint8_t startingScreen) - : _p_liquidCrystal(&liquidCrystal), _screenCount(0), - _currentScreen(startingScreen - 1) { + : _p_liquidCrystal(&liquidCrystal), _screenCount(0), + _currentScreen(startingScreen - 1) +{ } LiquidMenu::LiquidMenu(DisplayClass &liquidCrystal, LiquidScreen &liquidScreen, uint8_t startingScreen) - : LiquidMenu(liquidCrystal, startingScreen) { + : LiquidMenu(liquidCrystal, startingScreen) +{ add_screen(liquidScreen); } LiquidMenu::LiquidMenu(DisplayClass &liquidCrystal, LiquidScreen &liquidScreen1, LiquidScreen &liquidScreen2, uint8_t startingScreen) - : LiquidMenu(liquidCrystal, liquidScreen1, startingScreen) { + : LiquidMenu(liquidCrystal, liquidScreen1, startingScreen) +{ add_screen(liquidScreen2); } LiquidMenu::LiquidMenu(DisplayClass &liquidCrystal, LiquidScreen &liquidScreen1, LiquidScreen &liquidScreen2, LiquidScreen &liquidScreen3, uint8_t startingScreen) - : LiquidMenu(liquidCrystal, liquidScreen1, liquidScreen2, startingScreen) { + : LiquidMenu(liquidCrystal, liquidScreen1, liquidScreen2, startingScreen) +{ add_screen(liquidScreen3); } LiquidMenu::LiquidMenu(DisplayClass &liquidCrystal, LiquidScreen &liquidScreen1, LiquidScreen &liquidScreen2, LiquidScreen &liquidScreen3, LiquidScreen &liquidScreen4, uint8_t startingScreen) - : LiquidMenu(liquidCrystal, liquidScreen1, liquidScreen2, liquidScreen3, - startingScreen) { + : LiquidMenu(liquidCrystal, liquidScreen1, liquidScreen2, liquidScreen3, + startingScreen) +{ add_screen(liquidScreen4); } -bool LiquidMenu::add_screen(LiquidScreen &liquidScreen) { - DEBUG(F("LMenu ")); print_me(reinterpret_cast(this)); +bool LiquidMenu::add_screen(LiquidScreen &liquidScreen) +{ + DEBUG(F("LMenu ")); + print_me(reinterpret_cast(this)); - DEBUG(F("Add screen (0x")); DEBUG((uintptr_t)&liquidScreen); - DEBUG(F(") count(")) DEBUG(_screenCount); DEBUG(F(")")); + DEBUG(F("Add screen (0x")); + DEBUG((uintptr_t)&liquidScreen); + DEBUG(F(") count(")) + DEBUG(_screenCount); + DEBUG(F(")")); - if (_screenCount < MAX_SCREENS) { + if (_screenCount < MAX_SCREENS) + { _p_liquidScreen[_screenCount] = &liquidScreen; _screenCount++; @@ -88,7 +101,8 @@ bool LiquidMenu::add_screen(LiquidScreen &liquidScreen) { return false; } -LiquidScreen* LiquidMenu::get_currentScreen() const { +LiquidScreen *LiquidMenu::get_currentScreen() const +{ return _p_liquidScreen[_currentScreen]; } @@ -105,153 +119,202 @@ uint8_t LiquidMenu::get_screenCount() const void LiquidMenu::next_screen() { _p_liquidCrystal->clear(); - do { - if (_currentScreen < _screenCount - 1) { + do + { + if (_currentScreen < _screenCount - 1) + { _currentScreen++; - } else { + } + else + { _currentScreen = 0; } } while (_p_liquidScreen[_currentScreen]->_hidden == true); update(); - DEBUG(F("Switched to the next screen (")); DEBUG(_currentScreen); DEBUG(F(")")); + DEBUG(F("Switched to the next screen (")); + DEBUG(_currentScreen); + DEBUG(F(")")); } -void LiquidMenu::operator++() { +void LiquidMenu::operator++() +{ next_screen(); } -void LiquidMenu::operator++(int) { +void LiquidMenu::operator++(int) +{ next_screen(); } -void LiquidMenu::previous_screen() { +void LiquidMenu::previous_screen() +{ _p_liquidCrystal->clear(); - do { - if (_currentScreen > 0) { + do + { + if (_currentScreen > 0) + { _currentScreen--; - } else { + } + else + { _currentScreen = _screenCount - 1; } } while (_p_liquidScreen[_currentScreen]->_hidden == true); update(); - DEBUG(F("Switched to the previous screen (")); DEBUG(_currentScreen); DEBUGLN(F(")")); + DEBUG(F("Switched to the previous screen (")); + DEBUG(_currentScreen); + DEBUGLN(F(")")); } -void LiquidMenu::operator--() { +void LiquidMenu::operator--() +{ previous_screen(); } -void LiquidMenu::operator--(int) { +void LiquidMenu::operator--(int) +{ previous_screen(); } -bool LiquidMenu::change_screen(uint8_t number) { +bool LiquidMenu::change_screen(uint8_t number) +{ uint8_t index = number - 1; - if (index <= _screenCount) { + if (index <= _screenCount) + { _p_liquidCrystal->clear(); _currentScreen = index; update(); DEBUG(F("Switched to screen (")); - DEBUG(_currentScreen); DEBUGLN(F(")")); + DEBUG(_currentScreen); + DEBUGLN(F(")")); return true; - } else { - DEBUG(F("Invalid request for screen change to ")); DEBUGLN(number); + } + else + { + DEBUG(F("Invalid request for screen change to ")); + DEBUGLN(number); return false; } } -bool LiquidMenu::change_screen(LiquidScreen *p_liquidScreen) { +bool LiquidMenu::change_screen(LiquidScreen *p_liquidScreen) +{ // _p_liquidMenu[_currentMenu]->_p_liquidCrystal->clear(); - for (uint8_t s = 0; s < _screenCount; s++) { + for (uint8_t s = 0; s < _screenCount; s++) + { _p_liquidCrystal->clear(); - if (p_liquidScreen == _p_liquidScreen[s]) { - // if (reinterpret_cast(&p_liquidScreen) == reinterpret_cast(&(*_p_liquidScreen[s]))) { + if (p_liquidScreen == _p_liquidScreen[s]) + { + // if (reinterpret_cast(&p_liquidScreen) == reinterpret_cast(&(*_p_liquidScreen[s]))) { _currentScreen = s; - + update(); ESP_LOGD("LiquidMenu", "Switched to screen:%d pointer:%p", _currentScreen, p_liquidScreen) DEBUG(F("Switched to screen (")); - DEBUG(_currentScreen); DEBUGLN(F(")")); + DEBUG(_currentScreen); + DEBUGLN(F(")")); // update(); No reason for two calls to update return true; } } ESP_LOGD("LiquidMenu", "Invalid request for screen change to %p", p_liquidScreen); - DEBUG(F("Invalid request for screen change to 0x")); DEBUGLN(reinterpret_cast(&p_liquidScreen)); + DEBUG(F("Invalid request for screen change to 0x")); + DEBUGLN(reinterpret_cast(&p_liquidScreen)); return false; } -bool LiquidMenu::operator=(uint8_t number) { +bool LiquidMenu::operator=(uint8_t number) +{ return change_screen(number); } -bool LiquidMenu::operator=(LiquidScreen *p_liquidScreen) { +bool LiquidMenu::operator=(LiquidScreen *p_liquidScreen) +{ return change_screen(p_liquidScreen); } -void LiquidMenu::switch_focus(bool forward) { +void LiquidMenu::switch_focus(bool forward) +{ _p_liquidCrystal->clear(); _p_liquidScreen[_currentScreen]->switch_focus(forward); update(); } -bool LiquidMenu::set_focusedLine(uint8_t lineIndex) { +bool LiquidMenu::set_focusedLine(uint8_t lineIndex) +{ return _p_liquidScreen[_currentScreen]->set_focusedLine(lineIndex); } -uint8_t LiquidMenu::get_focusedLine() const { +uint8_t LiquidMenu::get_focusedLine() const +{ return _p_liquidScreen[_currentScreen]->get_focusedLine(); } -bool LiquidMenu::set_focusPosition(Position position) { - DEBUG(F("LMenu ")); print_me(reinterpret_cast(this)); +bool LiquidMenu::set_focusPosition(Position position) +{ + DEBUG(F("LMenu ")); + print_me(reinterpret_cast(this)); - if (position == Position::CUSTOM) { + if (position == Position::CUSTOM) + { DEBUGLN(F("Can't set a custom focus position for the whole menu at once")); return false; - } else { - DEBUG(F("Focus position set to ")); DEBUGLN((uint8_t)position); - for (uint8_t s = 0; s < _screenCount; s++) { + } + else + { + DEBUG(F("Focus position set to ")); + DEBUGLN((uint8_t)position); + for (uint8_t s = 0; s < _screenCount; s++) + { _p_liquidScreen[s]->set_focusPosition(position); } return true; } } -bool LiquidMenu::set_focusSymbol(Position position, uint8_t symbol[8]) { - switch (position) { - case Position::RIGHT: { +bool LiquidMenu::set_focusSymbol(Position position, uint8_t symbol[8]) +{ + switch (position) + { + case Position::RIGHT: + { _p_liquidCrystal->createChar(15, symbol); DEBUG(F("Right")); break; - } //case RIGHT - case Position::LEFT: { + } // case RIGHT + case Position::LEFT: + { _p_liquidCrystal->createChar(14, symbol); DEBUG(F("Left")); break; - } //case LEFT - case Position::CUSTOM: { + } // case LEFT + case Position::CUSTOM: + { _p_liquidCrystal->createChar(13, symbol); DEBUG(F("Custom")); break; - } //case CUSTOM - default: { + } // case CUSTOM + default: + { DEBUGLN(F("Invalid focus position, options are 'RIGHT', 'LEFT' and 'CUSTOM'")); return false; - } //default - } //switch (position) + } // default + } // switch (position) DEBUGLN(F("Focus symbol changed to:")); - for (uint8_t i = 0; i < 8; i++) { + for (uint8_t i = 0; i < 8; i++) + { DEBUGLN2(symbol[i], BIN); } return true; } -bool LiquidMenu::is_callable(uint8_t number) const { +bool LiquidMenu::is_callable(uint8_t number) const +{ return _p_liquidScreen[_currentScreen]->is_callable(number); } -bool LiquidMenu::call_function(uint8_t number, bool refresh) const { +bool LiquidMenu::call_function(uint8_t number, bool refresh) const +{ bool returnValue = _p_liquidScreen[_currentScreen]->call_function(number); if (refresh) { @@ -260,13 +323,15 @@ bool LiquidMenu::call_function(uint8_t number, bool refresh) const { return returnValue; } -void LiquidMenu::update() const { +void LiquidMenu::update() const +{ ESP_LOGV("LiquidMenu", "Updating screen:%d, _p_liquidCrystal:%p", _currentScreen, _p_liquidCrystal); _p_liquidCrystal->clear(); softUpdate(); } -void LiquidMenu::softUpdate() const { +void LiquidMenu::softUpdate() const +{ /* TEMPORARY FIX! * Calls methods on the `DisplayClass` object only after it is * initialized. This makes it compatible with different @@ -276,28 +341,34 @@ void LiquidMenu::softUpdate() const { */ ESP_LOGV("LiquidMenu", "Soft updating screen:%d, pointer:%p", _currentScreen, _p_liquidScreen[_currentScreen]); // _p_liquidCrystal->clear(); Isn't the point of softUpdate() no clear()? - static bool firstRun = true; - if (firstRun) { - firstRun = false; - _p_liquidCrystal->createChar(15, glyph::rightFocus); - _p_liquidCrystal->createChar(14, glyph::leftFocus); - _p_liquidCrystal->createChar(13, glyph::customFocus); - } - DEBUGLN(F("Updating the LCD")); - for (uint8_t b = 0; b < DIVISION_LINE_LENGTH; b++) { - DEBUG(F("-")); - } - DEBUGLN(); - DEBUG(F("|Screen ")); DEBUGLN(_currentScreen); - _p_liquidScreen[_currentScreen]->print(_p_liquidCrystal); - for (uint8_t b = 0; b < DIVISION_LINE_LENGTH; b++) { - DEBUG(F("-")); - } - DEBUGLN("\n"); + /*This is not needed because 13,14,15 are predefined*/ + // static bool firstRun = true; + // if (firstRun) { + // firstRun = false; + // _p_liquidCrystal->createChar(15, glyph::rightFocus); + // _p_liquidCrystal->createChar(14, glyph::leftFocus); + // _p_liquidCrystal->createChar(13, glyph::customFocus); +// } + +DEBUGLN(F("Updating the LCD")); +for (uint8_t b = 0; b < DIVISION_LINE_LENGTH; b++) +{ + DEBUG(F("-")); +} +DEBUGLN(); +DEBUG(F("|Screen ")); +DEBUGLN(_currentScreen); +_p_liquidScreen[_currentScreen]->print(_p_liquidCrystal); +for (uint8_t b = 0; b < DIVISION_LINE_LENGTH; b++) +{ + DEBUG(F("-")); +} +DEBUGLN("\n"); } -void LiquidMenu::init() const { +void LiquidMenu::init() const +{ _p_liquidCrystal->createChar(15, glyph::rightFocus); _p_liquidCrystal->createChar(14, glyph::leftFocus); _p_liquidCrystal->createChar(13, glyph::customFocus); diff --git a/src/LiquidMenu_config.h b/src/LiquidMenu_config.h index 8459d44..ea753d4 100644 --- a/src/LiquidMenu_config.h +++ b/src/LiquidMenu_config.h @@ -47,17 +47,16 @@ used in the library, also configures the debugging messages. * @{ */ #ifndef LIQUIDMENU_LIBRARY - #define LIQUIDMENU_LIBRARY LiquidCrystal_I2C_LIBRARY +#define LIQUIDMENU_LIBRARY LiquidCrystal_I2C_LIBRARY #endif #ifndef DisplayClass - #define DisplayClass LiquidCrystal_I2C +#define DisplayClass LiquidCrystal_I2C #endif //!@} //!@} // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - /// Configures the number of available variables per line. const uint8_t MAX_VARIABLES = 5; ///< @note Default: 5 @@ -71,11 +70,11 @@ const uint8_t MAX_LINES = 3; ///< @note Default: 12 const uint8_t MAX_SCREENS = 10; ///< @note Default: 14 /// Configures the number of available menus per menus system. -const uint8_t MAX_MENUS = 15; ///< @note Default: 8 +const uint8_t MAX_MENUS = 20; ///< @note Default: 8 /*! * Enable/disable hiding the focus indicator. - * + * * When enabled the focus indicator will disappear for one step after * completing an iteration through the focusable lines. When disabled the focus * indicator will go from the last focusable line directly to the first From 85e15f5a4347b229944cafc713d2fb0a9b4ec78b Mon Sep 17 00:00:00 2001 From: hezy0426 Date: Fri, 1 Sep 2023 08:57:39 -0400 Subject: [PATCH 19/26] Update to use the correct number 127 is the left arrow and 126 is right arrow --- src/LiquidLine.cpp | 4 ++-- src/LiquidMenu.cpp | 57 +++++++++++++++++++++++----------------------- 2 files changed, 30 insertions(+), 31 deletions(-) diff --git a/src/LiquidLine.cpp b/src/LiquidLine.cpp index 39f96ae..3614716 100644 --- a/src/LiquidLine.cpp +++ b/src/LiquidLine.cpp @@ -110,7 +110,7 @@ void LiquidLine::print(DisplayClass *p_liquidCrystal, bool isFocused) { DEBUG(F("\t\twrite((uint8_t)15); + p_liquidCrystal->write((uint8_t)127); DEBUGLN(F("right>")); //p_liquidCrystal->print(NOTHING); break; @@ -118,7 +118,7 @@ void LiquidLine::print(DisplayClass *p_liquidCrystal, bool isFocused) { case Position::LEFT: { //p_liquidCrystal->print(NOTHING); p_liquidCrystal->setCursor(_column - 1, _row); - p_liquidCrystal->write((uint8_t)14); + p_liquidCrystal->write((uint8_t)126); DEBUGLN(F("left>")); break; } //case LEFT diff --git a/src/LiquidMenu.cpp b/src/LiquidMenu.cpp index 2cd7114..9943a4a 100644 --- a/src/LiquidMenu.cpp +++ b/src/LiquidMenu.cpp @@ -278,19 +278,19 @@ bool LiquidMenu::set_focusSymbol(Position position, uint8_t symbol[8]) { case Position::RIGHT: { - _p_liquidCrystal->createChar(15, symbol); + _p_liquidCrystal->createChar(7, symbol); DEBUG(F("Right")); break; } // case RIGHT case Position::LEFT: { - _p_liquidCrystal->createChar(14, symbol); + _p_liquidCrystal->createChar(6, symbol); DEBUG(F("Left")); break; } // case LEFT case Position::CUSTOM: { - _p_liquidCrystal->createChar(13, symbol); + _p_liquidCrystal->createChar(5, symbol); DEBUG(F("Custom")); break; } // case CUSTOM @@ -341,35 +341,34 @@ void LiquidMenu::softUpdate() const */ ESP_LOGV("LiquidMenu", "Soft updating screen:%d, pointer:%p", _currentScreen, _p_liquidScreen[_currentScreen]); // _p_liquidCrystal->clear(); Isn't the point of softUpdate() no clear()? + static bool firstRun = true; + if (firstRun) + { + firstRun = false; + _p_liquidCrystal->createChar(7, glyph::rightFocus); + _p_liquidCrystal->createChar(6, glyph::leftFocus); + _p_liquidCrystal->createChar(5, glyph::customFocus); + } - /*This is not needed because 13,14,15 are predefined*/ - // static bool firstRun = true; - // if (firstRun) { - // firstRun = false; - // _p_liquidCrystal->createChar(15, glyph::rightFocus); - // _p_liquidCrystal->createChar(14, glyph::leftFocus); - // _p_liquidCrystal->createChar(13, glyph::customFocus); -// } - -DEBUGLN(F("Updating the LCD")); -for (uint8_t b = 0; b < DIVISION_LINE_LENGTH; b++) -{ - DEBUG(F("-")); -} -DEBUGLN(); -DEBUG(F("|Screen ")); -DEBUGLN(_currentScreen); -_p_liquidScreen[_currentScreen]->print(_p_liquidCrystal); -for (uint8_t b = 0; b < DIVISION_LINE_LENGTH; b++) -{ - DEBUG(F("-")); -} -DEBUGLN("\n"); + DEBUGLN(F("Updating the LCD")); + for (uint8_t b = 0; b < DIVISION_LINE_LENGTH; b++) + { + DEBUG(F("-")); + } + DEBUGLN(); + DEBUG(F("|Screen ")); + DEBUGLN(_currentScreen); + _p_liquidScreen[_currentScreen]->print(_p_liquidCrystal); + for (uint8_t b = 0; b < DIVISION_LINE_LENGTH; b++) + { + DEBUG(F("-")); + } + DEBUGLN("\n"); } void LiquidMenu::init() const { - _p_liquidCrystal->createChar(15, glyph::rightFocus); - _p_liquidCrystal->createChar(14, glyph::leftFocus); - _p_liquidCrystal->createChar(13, glyph::customFocus); + _p_liquidCrystal->createChar(7, glyph::rightFocus); + _p_liquidCrystal->createChar(6, glyph::leftFocus); + _p_liquidCrystal->createChar(5, glyph::customFocus); } From c7bd526ec3485a7455ea7fcbe1af68b01de02e22 Mon Sep 17 00:00:00 2001 From: hezy0426 Date: Tue, 12 Sep 2023 14:05:02 -0400 Subject: [PATCH 20/26] Update config again --- src/LiquidMenu_config.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/LiquidMenu_config.h b/src/LiquidMenu_config.h index ea753d4..20ba583 100644 --- a/src/LiquidMenu_config.h +++ b/src/LiquidMenu_config.h @@ -70,7 +70,7 @@ const uint8_t MAX_LINES = 3; ///< @note Default: 12 const uint8_t MAX_SCREENS = 10; ///< @note Default: 14 /// Configures the number of available menus per menus system. -const uint8_t MAX_MENUS = 20; ///< @note Default: 8 +const uint8_t MAX_MENUS = 25; ///< @note Default: 8 /*! * Enable/disable hiding the focus indicator. From 3eaa3915e8ad320a199f0a493e569cb629f9aa49 Mon Sep 17 00:00:00 2001 From: hezy0426 Date: Sun, 17 Sep 2023 21:50:40 -0400 Subject: [PATCH 21/26] Update LiquidMenu_config.h --- src/LiquidMenu_config.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/LiquidMenu_config.h b/src/LiquidMenu_config.h index 20ba583..c9efc27 100644 --- a/src/LiquidMenu_config.h +++ b/src/LiquidMenu_config.h @@ -70,7 +70,7 @@ const uint8_t MAX_LINES = 3; ///< @note Default: 12 const uint8_t MAX_SCREENS = 10; ///< @note Default: 14 /// Configures the number of available menus per menus system. -const uint8_t MAX_MENUS = 25; ///< @note Default: 8 +const uint8_t MAX_MENUS = 35; ///< @note Default: 8 /*! * Enable/disable hiding the focus indicator. From 60fd6c29571c18da14ef2cdc7807ca7724cbfe46 Mon Sep 17 00:00:00 2001 From: supRay Date: Mon, 9 Oct 2023 14:25:17 -0400 Subject: [PATCH 22/26] Fix mismatched type --- src/recognizeType.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/recognizeType.cpp b/src/recognizeType.cpp index 293b814..54fdd61 100644 --- a/src/recognizeType.cpp +++ b/src/recognizeType.cpp @@ -91,7 +91,7 @@ DataType recognizeType(int16tFnPtr variable) { } DataType recognizeType(uint16tFnPtr variable) { - return DataType::UINT8_T_GETTER; + return DataType::UINT16_T_GETTER; variable = variable; } From 4e3a7635575daa3f723b27f27cefd8f8009d505b Mon Sep 17 00:00:00 2001 From: supRay Date: Tue, 17 Oct 2023 15:40:49 -0400 Subject: [PATCH 23/26] Update max num of screen --- src/LiquidMenu_config.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/LiquidMenu_config.h b/src/LiquidMenu_config.h index c9efc27..2d4ab21 100644 --- a/src/LiquidMenu_config.h +++ b/src/LiquidMenu_config.h @@ -67,7 +67,7 @@ const uint8_t MAX_FUNCTIONS = 4; ///< @note Default: 8 const uint8_t MAX_LINES = 3; ///< @note Default: 12 /// Configures the number of available screens per menu. -const uint8_t MAX_SCREENS = 10; ///< @note Default: 14 +const uint8_t MAX_SCREENS = 11; ///< @note Default: 14 /// Configures the number of available menus per menus system. const uint8_t MAX_MENUS = 35; ///< @note Default: 8 From deda6a55260dce0f6d696d53b98915f5d6423226 Mon Sep 17 00:00:00 2001 From: supRay Date: Mon, 30 Oct 2023 17:06:41 -0400 Subject: [PATCH 24/26] Update to support the new change menu --- src/LiquidMenu.h | 183 +++++++++++++++++++-------------- src/LiquidScreen.cpp | 240 +++++++++++++++++++++++++++++++------------ 2 files changed, 280 insertions(+), 143 deletions(-) diff --git a/src/LiquidMenu.h b/src/LiquidMenu.h index 1abc675..16b8917 100644 --- a/src/LiquidMenu.h +++ b/src/LiquidMenu.h @@ -39,7 +39,7 @@ Include file for LiquidMenu library. #include #if defined(__AVR__) -# include +#include #endif #include #include @@ -47,9 +47,8 @@ Include file for LiquidMenu library. #include "LiquidMenu_config.h" #include "LiquidMenu_debug.h" - #if LIQUIDMENU_LIBRARY == LiquidCrystal_LIBRARY -# pragma message ("LiquidMenu: Selected 'LiquidCrystal' (parallel) library. Edit 'LiquidMenu_config.h' file to change it.") +#pragma message("LiquidMenu: Selected 'LiquidCrystal' (parallel) library. Edit 'LiquidMenu_config.h' file to change it.") #include #elif LIQUIDMENU_LIBRARY == LiquidCrystal_I2C_LIBRARY // # pragma message ("LiquidMenu: Selected 'LiquidCrystal_I2C' (I2C) library. Edit 'LiquidMenu_config.h' file to change it.") @@ -59,13 +58,11 @@ Include file for LiquidMenu library. #endif #if LIQUIDMENU_DEBUG -# warning "LiquidMenu: Debugging messages are enabled." +#warning "LiquidMenu: Debugging messages are enabled." #endif const char LIQUIDMENU_VERSION[] = "1.6"; ///< The version of the library. - - /// @name Getter function typedefs /** @@ -92,40 +89,45 @@ typedef double (*doubleFnPtr)(); /// `char` typedef char (*charFnPtr)(); /// `char*` -typedef char * (*charPtrFnPtr)(); +typedef char *(*charPtrFnPtr)(); /// `const char*` -typedef const char * (*constcharPtrFnPtr)(); +typedef const char *(*constcharPtrFnPtr)(); ///@} - /// Data type enum. /** Used to store the data type of `void*` so that they can be cast back later. */ -enum class DataType : uint8_t { +enum class DataType : uint8_t +{ NOT_USED = 0, - BOOL = 1, BOOLEAN = 1, + BOOL = 1, + BOOLEAN = 1, INT8_T = 8, UINT8_T = 9, INT16_T = 16, UINT16_T = 17, INT32_T = 32, UINT32_T = 33, - FLOAT = 50, DOUBLE = 50, + FLOAT = 50, + DOUBLE = 50, CHAR = 60, CHAR_PTR = 61, CONST_CHAR_PTR = 62, PROG_CONST_CHAR_PTR = 65, GLYPH = 70, FIRST_GETTER = 200, - BOOL_GETTER = 201, BOOLEAN_GETTER = 201, + BOOL_GETTER = 201, + BOOLEAN_GETTER = 201, INT8_T_GETTER = 208, - UINT8_T_GETTER = 209, BYTE_GETTER = 209, + UINT8_T_GETTER = 209, + BYTE_GETTER = 209, INT16_T_GETTER = 216, UINT16_T_GETTER = 217, INT32_T_GETTER = 232, UINT32_T_GETTER = 233, - FLOAT_GETTER = 240, DOUBLE_GETTER = 240, + FLOAT_GETTER = 240, + DOUBLE_GETTER = 240, CHAR_GETTER = 250, CHAR_PTR_GETTER = 251, CONST_CHAR_PTR_GETTER = 252 @@ -135,8 +137,10 @@ enum class DataType : uint8_t { /* Used to store and set the relative or absolute position of the focus indicator. */ -enum class Position : uint8_t { - RIGHT = 1, NORMAL = 1, +enum class Position : uint8_t +{ + RIGHT = 1, + NORMAL = 1, LEFT = 2, CUSTOM = 3, }; @@ -164,13 +168,13 @@ DataType recognizeType(char variable); @param variable - variable to be checked @returns the data type in `DataType` enum format */ -DataType recognizeType(char* variable); +DataType recognizeType(char *variable); /** @param variable - variable to be checked @returns the data type in `DataType` enum format */ -DataType recognizeType(const char* variable); +DataType recognizeType(const char *variable); /** @param variable - variable to be checked @@ -220,56 +224,48 @@ DataType recognizeType(float variable); */ DataType recognizeType(double variable); - /** @param variable - variable to be checked @returns the data type in `DataType` enum format */ DataType recognizeType(boolFnPtr variable); - /** @param variable - variable to be checked @returns the data type in `DataType` enum format */ DataType recognizeType(int8tFnPtr variable); - /** @param variable - variable to be checked @returns the data type in `DataType` enum format */ DataType recognizeType(uint8tFnPtr variable); - /** @param variable - variable to be checked @returns the data type in `DataType` enum format */ DataType recognizeType(int16tFnPtr variable); - /** @param variable - variable to be checked @returns the data type in `DataType` enum format */ DataType recognizeType(uint16tFnPtr variable); - /** @param variable - variable to be checked @returns the data type in `DataType` enum format */ DataType recognizeType(int32tFnPtr variable); - /** @param variable - variable to be checked @returns the data type in `DataType` enum format */ DataType recognizeType(uint32tFnPtr variable); - /** @param variable - variable to be checked @returns the data type in `DataType` enum format @@ -282,21 +278,18 @@ DataType recognizeType(floatFnPtr variable); */ DataType recognizeType(doubleFnPtr variable); - /** @param variable - variable to be checked @returns the data type in `DataType` enum format */ DataType recognizeType(charFnPtr variable); - /** @param variable - variable to be checked @returns the data type in `DataType` enum format */ DataType recognizeType(charPtrFnPtr variable); - /** @param variable - variable to be checked @returns the data type in `DataType` enum format @@ -304,8 +297,6 @@ DataType recognizeType(charPtrFnPtr variable); DataType recognizeType(constcharPtrFnPtr variable); ///@} - - /// Debug prints an address /** Used for convenience when printing the class's address for identification. @@ -314,6 +305,9 @@ Used for convenience when printing the class's address for identification. */ void print_me(uintptr_t address); +class LiquidLine; +class LiquidScreen; +class LiquidMenu; /// Represents the individual lines printed on the display. /** @@ -323,7 +317,8 @@ where the focus indicator is positioned and pointers to the callback functions. This classes' objects go into a LiquidScreen object which controls them. The public methods are for configuration only. */ -class LiquidLine { +class LiquidLine +{ friend class LiquidScreen; public: @@ -338,16 +333,19 @@ class LiquidLine { @param row - the row at which the line is printed */ LiquidLine(uint8_t column, uint8_t row) - : _row(row), _column(column), _focusRow(row - 1), - _focusColumn(column - 1), _focusPosition(Position::NORMAL), - _floatDecimalPlaces(2), _variableCount(0), _focusable(false) { + : _row(row), _column(column), _focusRow(row - 1), + _focusColumn(column - 1), _focusPosition(Position::NORMAL), + _floatDecimalPlaces(2), _variableCount(0), _focusable(false) + { - for (uint8_t i = 0; i < MAX_VARIABLES; i++) { + for (uint8_t i = 0; i < MAX_VARIABLES; i++) + { _variable[i] = nullptr; _variableType[i] = DataType::NOT_USED; } - for (uint8_t f = 0; f < MAX_FUNCTIONS; f++) { + for (uint8_t f = 0; f < MAX_FUNCTIONS; f++) + { _function[f] = 0; } } @@ -360,7 +358,8 @@ class LiquidLine { */ template LiquidLine(uint8_t column, uint8_t row, A &variableA) - : LiquidLine(column, row) { + : LiquidLine(column, row) + { add_variable(variableA); } @@ -374,7 +373,8 @@ class LiquidLine { template LiquidLine(uint8_t column, uint8_t row, A &variableA, B &variableB) - : LiquidLine(column, row, variableA) { + : LiquidLine(column, row, variableA) + { add_variable(variableB); } @@ -389,7 +389,8 @@ class LiquidLine { template LiquidLine(uint8_t column, uint8_t row, A &variableA, B &variableB, C &variableC) - : LiquidLine(column, row, variableA, variableB) { + : LiquidLine(column, row, variableA, variableB) + { add_variable(variableC); } @@ -405,13 +406,13 @@ class LiquidLine { template LiquidLine(uint8_t column, uint8_t row, A &variableA, B &variableB, C &variableC, D &variableD) - : LiquidLine(column, row, variableA, variableB, variableC) { + : LiquidLine(column, row, variableA, variableB, variableC) + { add_variable(variableD); } ///@} - /// @name Public methods ///@{ @@ -428,31 +429,40 @@ class LiquidLine { @see MAX_VARIABLES */ template - bool add_variable(T &variable) { - DEBUG(F("LLine ")); print_me(reinterpret_cast(this)); + bool add_variable(T &variable) + { + DEBUG(F("LLine ")); + print_me(reinterpret_cast(this)); DataType varType = recognizeType(variable); - #if LIQUIDMENU_DEBUG +#if LIQUIDMENU_DEBUG DEBUG(F("Add ")); - if ((uint8_t)varType < (uint8_t)DataType::FIRST_GETTER) { + if ((uint8_t)varType < (uint8_t)DataType::FIRST_GETTER) + { DEBUG(F("variable \"")); DEBUG(variable); - } else { + } + else + { DEBUG(F("getter \"N/A")); } DEBUG(F("\" of DataType(")); - DEBUG((uint8_t)varType); DEBUG(F(")")); - #endif + DEBUG((uint8_t)varType); + DEBUG(F(")")); +#endif - if (_variableCount < MAX_VARIABLES) { - _variable[_variableCount] = (void*)&variable; + if (_variableCount < MAX_VARIABLES) + { + _variable[_variableCount] = (void *)&variable; _variableType[_variableCount] = varType; _variableCount++; - + DEBUGLN(F("")); return true; - } else { + } + else + { DEBUGLN(F(" failed, edit LiquidMenu_config.h to allow for more variables")); return false; } @@ -531,7 +541,7 @@ class LiquidLine { ///@} // public for debugging convenience - const void *_variable[MAX_VARIABLES]; ///< Pointers to the variables + const void *_variable[MAX_VARIABLES]; ///< Pointers to the variables DataType _variableType[MAX_VARIABLES]; ///< Data type of the variables private: @@ -581,12 +591,11 @@ class LiquidLine { uint8_t _row, _column, _focusRow, _focusColumn; Position _focusPosition; uint8_t _floatDecimalPlaces; - uint8_t _variableCount; ///< Count of the variables + uint8_t _variableCount; ///< Count of the variables void (*_function[MAX_FUNCTIONS])(void); ///< Pointers to the functions - bool _focusable; ///< Determines whether the line is focusable + bool _focusable; ///< Determines whether the line is focusable }; - /// Represents a screen shown on the display. /** A screen is made up of LiquidLine objects. It holds pointers to them and @@ -596,11 +605,11 @@ them. The public methods are for configuration only. @see LiquidLine */ -class LiquidScreen { +class LiquidScreen +{ friend class LiquidMenu; public: - /// @name Constructors ///@{ @@ -715,8 +724,26 @@ class LiquidScreen { LiquidLine *_p_liquidLine[MAX_LINES]; ///< The LiquidLine objects uint8_t get_lineCount() const; - + + /*An array of functions to allow us to not run long if else statements*/ + void set_special_case(bool val); + bool is_special_case(); + void set_prev_menu(LiquidMenu *prev); + LiquidMenu *get_prev_menu(); + void set_prev_screen(LiquidScreen *prev); + LiquidScreen *get_prev_screen(); + void set_next_menu(LiquidMenu *next); + LiquidMenu *get_next_menu(); + void set_next_screen(LiquidScreen *next); + LiquidScreen *get_next_screen(); + private: + LiquidMenu *nextMenu; + LiquidScreen *nextScreen = NULL; + LiquidMenu *prevMenu; + LiquidScreen *prevScreen = NULL; + bool specialCase = false; + /// Prints the lines pointed by the screen. /** Calls the `LiquidLine::print(DisplayClass *p_liquidCrystal, bool isFocused)` @@ -730,7 +757,7 @@ class LiquidScreen { /** Switches the focus to the next or previous line according to the passed parameter. - + @note After one iteration through the focusable lines is completed, the focus indicator will hide for one step. To disable this behavior set `LM_FOCUS_INDICATOR_GHOSTING` to false in `LiquiMenu_config.h` @@ -769,13 +796,12 @@ class LiquidScreen { */ bool call_function(uint8_t number) const; - uint8_t _lineCount; ///< Count of the LiquidLine objects - uint8_t _focus; ///< Index of the focused line + uint8_t _lineCount; ///< Count of the LiquidLine objects + uint8_t _focus; ///< Index of the focused line uint8_t _displayLineCount; ///< The number of lines the display supports - bool _hidden; ///< If hidden skips this screen when cycling + bool _hidden; ///< If hidden skips this screen when cycling }; - /// Represents a collection of screens forming a menu. /** A menu is made up of LiquidScreen objects. It holds pointers to them and @@ -786,11 +812,11 @@ the same public methods. @see LiquidScreen */ -class LiquidMenu { +class LiquidMenu +{ friend class LiquidSystem; public: - /// @name Constructors ///@{ @@ -877,7 +903,7 @@ class LiquidMenu { @returns a pointer to the current screen. */ - LiquidScreen* get_currentScreen() const; + LiquidScreen *get_currentScreen() const; uint8_t get_currentScreenNumber() const; @@ -949,7 +975,7 @@ class LiquidMenu { @param forward - true for forward, false for backward */ void switch_focus(bool forward = true); - + /// Directly select focused line. /** @param lineIndex - index of the focused line @@ -1047,7 +1073,7 @@ class LiquidMenu { ///@} - DisplayClass *_p_liquidCrystal; ///< Pointer to the DisplayClass object FIXME + DisplayClass *_p_liquidCrystal; ///< Pointer to the DisplayClass object FIXME LiquidScreen *_p_liquidScreen[MAX_SCREENS]; ///< The LiquidScreen objects uint8_t get_screenCount() const; @@ -1067,9 +1093,9 @@ for multiple menus. @see LiquidMenu */ -class LiquidSystem { +class LiquidSystem +{ public: - /// @name Constructors ///@{ @@ -1140,12 +1166,12 @@ class LiquidSystem { /** * @brief return a reference to the current menu - * + * * @return pointer to menu */ - LiquidMenu * get_currentMenu() const; + LiquidMenu *get_currentMenu() const; - uint8_t get_currentMenuNumber() const; + uint8_t get_currentMenuNumber() const; /// Returns a reference to the current screen. /** @@ -1153,7 +1179,7 @@ class LiquidSystem { @returns a pointer to the current screen. */ - LiquidScreen* get_currentScreen() const; + LiquidScreen *get_currentScreen() const; uint8_t get_currentScreenNumber() const; @@ -1238,7 +1264,7 @@ class LiquidSystem { @returns the index of the currently focused line */ uint8_t get_focusedLine() const; - + /// Sets the focus position for the whole menu at once. /** The valid positions are `LEFT` and `RIGHT`. `CUSTOM` is not valid @@ -1315,7 +1341,6 @@ class LiquidSystem { ///@} - private: LiquidMenu *_p_liquidMenu[MAX_MENUS]; ///< The LiquidMenu objects uint8_t _menuCount; ///< Count of the LiquidMenu objects diff --git a/src/LiquidScreen.cpp b/src/LiquidScreen.cpp index e5f8fdc..9900aa8 100644 --- a/src/LiquidScreen.cpp +++ b/src/LiquidScreen.cpp @@ -29,7 +29,6 @@ SOFTWARE. #include "LiquidMenu.h" - /// Line count subtrahend for comparison during focus iteration /** 0 - "ghosting" is enabled @@ -38,47 +37,55 @@ SOFTWARE. #define LM_LINE_COUNT_SUBTRAHEND (0) #if LM_FOCUS_INDICATOR_GHOSTING == true - #undef LM_LINE_COUNT_SUBTRAHEND - #define LM_LINE_COUNT_SUBTRAHEND (0) +#undef LM_LINE_COUNT_SUBTRAHEND +#define LM_LINE_COUNT_SUBTRAHEND (0) #elif LM_FOCUS_INDICATOR_GHOSTING == false - #undef LM_LINE_COUNT_SUBTRAHEND - #define LM_LINE_COUNT_SUBTRAHEND (1) +#undef LM_LINE_COUNT_SUBTRAHEND +#define LM_LINE_COUNT_SUBTRAHEND (1) #endif - - LiquidScreen::LiquidScreen() : _lineCount(0), _focus(0), _hidden(false) {} LiquidScreen::LiquidScreen(LiquidLine &liquidLine) - : LiquidScreen() { + : LiquidScreen() +{ add_line(liquidLine); } LiquidScreen::LiquidScreen(LiquidLine &liquidLine1, LiquidLine &liquidLine2) - : LiquidScreen(liquidLine1) { + : LiquidScreen(liquidLine1) +{ add_line(liquidLine2); } LiquidScreen::LiquidScreen(LiquidLine &liquidLine1, LiquidLine &liquidLine2, - LiquidLine &liquidLine3) - : LiquidScreen(liquidLine1, liquidLine2) { + LiquidLine &liquidLine3) + : LiquidScreen(liquidLine1, liquidLine2) +{ add_line(liquidLine3); } LiquidScreen::LiquidScreen(LiquidLine &liquidLine1, LiquidLine &liquidLine2, - LiquidLine &liquidLine3, LiquidLine &liquidLine4) - : LiquidScreen(liquidLine1, liquidLine2, liquidLine3) { + LiquidLine &liquidLine3, LiquidLine &liquidLine4) + : LiquidScreen(liquidLine1, liquidLine2, liquidLine3) +{ add_line(liquidLine4); } -bool LiquidScreen::add_line(LiquidLine &liquidLine) { - DEBUG(F("LScreen ")); print_me(reinterpret_cast(this)); +bool LiquidScreen::add_line(LiquidLine &liquidLine) +{ + DEBUG(F("LScreen ")); + print_me(reinterpret_cast(this)); - DEBUG(F("Add line (0x")); DEBUG((uintptr_t)&liquidLine); - DEBUG(F(") count(")) DEBUG(_lineCount); DEBUG(F(")")); + DEBUG(F("Add line (0x")); + DEBUG((uintptr_t)&liquidLine); + DEBUG(F(") count(")) + DEBUG(_lineCount); + DEBUG(F(")")); - if (_lineCount < MAX_LINES) { + if (_lineCount < MAX_LINES) + { _p_liquidLine[_lineCount] = &liquidLine; _lineCount++; @@ -88,69 +95,91 @@ bool LiquidScreen::add_line(LiquidLine &liquidLine) { // Naively set the number of lines the display has to the // number of added LiquidLine objects. When adding more - // LiquidLine objects that the display's number of lines, - // void LiquidScreen::set_displayLineCount(uint8_t lines) - // must be used to set the number of lines the display has. - _displayLineCount = _lineCount; + // LiquidLine objects that the display's number of lines, + // void LiquidScreen::set_displayLineCount(uint8_t lines) + // must be used to set the number of lines the display has. + _displayLineCount = _lineCount; DEBUGLN(F("")); return true; - } else { + } + else + { DEBUGLN(F(" failed, edit LiquidMenu_config.h to allow for more lines")); return false; } - } -bool LiquidScreen::set_focusPosition(Position position) { - DEBUG(F("LScreen ")); print_me(reinterpret_cast(this)); +bool LiquidScreen::set_focusPosition(Position position) +{ + DEBUG(F("LScreen ")); + print_me(reinterpret_cast(this)); - if (position == Position::CUSTOM) { + if (position == Position::CUSTOM) + { DEBUGLN(F("Can't set focus position to 'CUSTOM' for the whole screen at once")); return false; - } else { - DEBUG(F("Focus position set to : ")); DEBUGLN((uint8_t)position); - for (uint8_t l = 0; l < _lineCount; l++) { + } + else + { + DEBUG(F("Focus position set to : ")); + DEBUGLN((uint8_t)position); + for (uint8_t l = 0; l < _lineCount; l++) + { _p_liquidLine[l]->set_focusPosition(position); } return true; } } -void LiquidScreen::set_displayLineCount(uint8_t lines) { +void LiquidScreen::set_displayLineCount(uint8_t lines) +{ _displayLineCount = lines; } -void LiquidScreen::hide(bool hide) { +void LiquidScreen::hide(bool hide) +{ _hidden = hide; } -void LiquidScreen::print(DisplayClass *p_liquidCrystal) const { +void LiquidScreen::print(DisplayClass *p_liquidCrystal) const +{ uint8_t lOffset = 0; uint8_t displayLineCount = _displayLineCount; - if (displayLineCount == 0) { + if (displayLineCount == 0) + { displayLineCount = _lineCount; - } else if (displayLineCount > _lineCount) { + } + else if (displayLineCount > _lineCount) + { displayLineCount = _lineCount; } - if (_focus >= displayLineCount) { + if (_focus >= displayLineCount) + { lOffset = (_focus - displayLineCount) + 1; - if ((displayLineCount + lOffset) > _lineCount) { + if ((displayLineCount + lOffset) > _lineCount) + { lOffset = (_lineCount - displayLineCount); } } uint8_t offsetRow = 0; - for (uint8_t l = lOffset; l < displayLineCount + lOffset; l++) { + for (uint8_t l = lOffset; l < displayLineCount + lOffset; l++) + { bool focus = true; - if (_focus != l) { + if (_focus != l) + { focus = false; DEBUG(F("|")); - } else { + } + else + { DEBUG(F("| -->")); } - DEBUG(F("\tLine ")); DEBUG(l); - if (displayLineCount < _lineCount) { + DEBUG(F("\tLine ")); + DEBUG(l); + if (displayLineCount < _lineCount) + { _p_liquidLine[l]->_row = offsetRow; } _p_liquidLine[l]->print(p_liquidCrystal, focus); @@ -158,63 +187,146 @@ void LiquidScreen::print(DisplayClass *p_liquidCrystal) const { } } -void LiquidScreen::switch_focus(bool forward) { - DEBUG(F("LScreen ")); print_me(reinterpret_cast(this)); +void LiquidScreen::switch_focus(bool forward) +{ + DEBUG(F("LScreen ")); + print_me(reinterpret_cast(this)); // LM_LINE_COUNT_SUBTRAHEND: // 0 - "ghosting" is enabled // 1 - "ghosting" is disabled - - do { - if (forward) { - if (_focus < (_lineCount - LM_LINE_COUNT_SUBTRAHEND)) { + + do + { + if (forward) + { + if (_focus < (_lineCount - LM_LINE_COUNT_SUBTRAHEND)) + { _focus++; - if (_focus == (_lineCount - LM_LINE_COUNT_SUBTRAHEND)) { + if (_focus == (_lineCount - LM_LINE_COUNT_SUBTRAHEND)) + { break; } - } else { + } + else + { _focus = 0; } - } else { //else (forward) - if (_focus == 0) { + } + else + { // else (forward) + if (_focus == 0) + { _focus = (_lineCount - LM_LINE_COUNT_SUBTRAHEND); break; - } else { + } + else + { _focus--; } - } //else (forward) + } // else (forward) } while (_p_liquidLine[_focus]->_focusable == false); - DEBUG(F("Focus switched to ")); DEBUGLN(_focus); + DEBUG(F("Focus switched to ")); + DEBUGLN(_focus); } -bool LiquidScreen::set_focusedLine(uint8_t lineIndex) { - if (lineIndex < _lineCount && _p_liquidLine[lineIndex]->_focusable == true) { +bool LiquidScreen::set_focusedLine(uint8_t lineIndex) +{ + if (lineIndex < _lineCount && _p_liquidLine[lineIndex]->_focusable == true) + { _focus = lineIndex; return true; - } else { + } + else + { return false; } } -uint8_t LiquidScreen::get_focusedLine() const { +uint8_t LiquidScreen::get_focusedLine() const +{ return _focus; } -uint8_t LiquidScreen::get_lineCount() const { +uint8_t LiquidScreen::get_lineCount() const +{ return _lineCount; } -bool LiquidScreen::is_callable(uint8_t number) const { - if (_focus != _lineCount) { +bool LiquidScreen::is_callable(uint8_t number) const +{ + if (_focus != _lineCount) + { return _p_liquidLine[_focus]->is_callable(number); } return false; } -bool LiquidScreen::call_function(uint8_t number) const { - if (_focus != _lineCount) { +bool LiquidScreen::call_function(uint8_t number) const +{ + if (_focus != _lineCount) + { return _p_liquidLine[_focus]->call_function(number); } return false; } + +void LiquidScreen::set_special_case(bool val) +{ + specialCase = val; +} + +/** + * Default to false + */ +bool LiquidScreen::is_special_case() +{ + return specialCase; +} + +void LiquidScreen::set_prev_menu(LiquidMenu *prev) +{ + prevMenu = prev; +} + +LiquidMenu *LiquidScreen::get_prev_menu() +{ + return prevMenu; +} + +void LiquidScreen::set_prev_screen(LiquidScreen *next) +{ + prevScreen = next; +} + +/** + * Default to NULL. If it's NULL, we use change_menu with true; + */ +LiquidScreen *LiquidScreen::get_prev_screen() +{ + return prevScreen; +} + +void LiquidScreen::set_next_menu(LiquidMenu *next) +{ + nextMenu = next; +} + +LiquidMenu *LiquidScreen::get_next_menu() +{ + return nextMenu; +} + +void LiquidScreen::set_next_screen(LiquidScreen *next) +{ + nextScreen = next; +} + +/** + * Default to NULL. If it's NULL, we use change_menu with true; + */ +LiquidScreen *LiquidScreen::get_next_screen() +{ + return nextScreen; +} \ No newline at end of file From ccbac664142c44cec8c295d21d0ce6c7b8742af1 Mon Sep 17 00:00:00 2001 From: supRay Date: Wed, 1 Nov 2023 13:55:35 -0400 Subject: [PATCH 25/26] Update LiquidMenu.h --- src/LiquidMenu.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/LiquidMenu.h b/src/LiquidMenu.h index 16b8917..2eac4b2 100644 --- a/src/LiquidMenu.h +++ b/src/LiquidMenu.h @@ -738,9 +738,9 @@ class LiquidScreen LiquidScreen *get_next_screen(); private: - LiquidMenu *nextMenu; + LiquidMenu *nextMenu = NULL; LiquidScreen *nextScreen = NULL; - LiquidMenu *prevMenu; + LiquidMenu *prevMenu = NULL; LiquidScreen *prevScreen = NULL; bool specialCase = false; From 53ce76f72eba9152a4e4c745c42ddfc01cb87469 Mon Sep 17 00:00:00 2001 From: supRay Date: Wed, 13 Dec 2023 12:01:30 -0500 Subject: [PATCH 26/26] New change menu function Move the most basic change menu to here --- src/LiquidMenu.h | 6 ++++++ src/LiquidSystem.cpp | 21 +++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/LiquidMenu.h b/src/LiquidMenu.h index 2eac4b2..1424237 100644 --- a/src/LiquidMenu.h +++ b/src/LiquidMenu.h @@ -1186,6 +1186,12 @@ class LiquidSystem /// Switches to the next screen. void next_screen(); + /** + * @brief Change to the next screen + * @return Whether we change the screen correctly or not + */ + bool changeToNextScreen(); + /// Switches to the next screen. /** @note Prefix increment operator overloading. diff --git a/src/LiquidSystem.cpp b/src/LiquidSystem.cpp index b647d6b..8bb3990 100644 --- a/src/LiquidSystem.cpp +++ b/src/LiquidSystem.cpp @@ -116,6 +116,27 @@ void LiquidSystem::next_screen() { _p_liquidMenu[_currentMenu]->next_screen(); } +bool LiquidSystem::changeToNextScreen() +{ + LiquidScreen *currentScreen = _p_liquidMenu[_currentMenu]->get_currentScreen(); + if (currentScreen->get_next_screen() == NULL) + { + if (currentScreen->get_next_menu()) + { + change_menu(*currentScreen->get_next_menu(), true); + return true; + } + } + else + { + change_menu(*currentScreen->get_next_menu(), false); + change_screen(currentScreen->get_next_screen()); + return true; + } + + return false; +} + void LiquidSystem::operator++() { next_screen(); }