Jomelo / LCDMenuLib2

Create a tree menu. Use it with different lcd types / console output / ssh console.
MIT License
249 stars 46 forks source link

Jumping to another menu #83

Closed pompetardo closed 1 year ago

pompetardo commented 2 years ago

Hi, I'm learning to use this library, and I'm not sure if there is a way to jump from one menu to another. The problem I have is I'm running out of program memory, so to optimize the space I want to eliminate redundant strings, specifically from menu names because I have multiple menus with multiple childs with the same name:

As the labels are exactly the same in the same order for "device 1" and "device 2" I was thinking to just eliminate the childs of "device 2" and use an mFunction to jump to "device 1" submenus, obviously I would just use a simple global variable to indicate I'm affecting "device 2" variables instead of "device 1"'s. So I would like to know if there is a way to jump like LCDML.FUNC_goBackToMenu(1); but instead maybe specifying the ID of the menu where I want to jump. Thanks.

Jomelo commented 2 years ago

Hello, yes there are some function to jump between function.

void LCDML.OTHER_jumpToFunc(LCDML_FuncPtr_pu8 p_search, uint8_t p_para = 0); // jumpTo a defined function based on the function name

Example: LCDML.OTHER_jumpToFunc(FUNC_NAME); Example: LCDML.OTHER_jumpToFunc(FUNC_NAME, parameter);

void LCDML.OTHER_jumpToID(uint8_t p_search, uint8_t p_para = 0); // jumpTo a defined function based on the function id

Example: LCDML.OTHER_jumpToID(FUNC_ID); Example: LCDML.OTHER_jumpToID(FUNC_ID, parameter);

void LCDML.OTHER_setCursorToID(uint8_t p_search); // set the cursor to a defined function based on the id

Example: LCDML.OTHER_setCursorToID(FUNC_ID);

void LCDML.OTHER_setCursorToFunc(LCDML_FuncPtr_pu8 p_search); // set the cursor to a defined function based on the function name

Example: LCDML.OTHER_setCursorToFunc(FUNC_ID);

When you have many strings in your program like "hello world" please use the F(..) Makro to save the string content on the flash m emory and not on the dynamic memory

Example: F("Hello world");

You can also look into the examples where the jump to Function is used: https://github.com/Jomelo/LCDMenuLib2/blob/master/examples/00_beginners/LCDML_000_serialMonitor/LCDML_display_menuFunction.ino#L278