Hello, I have been working on porting some of my code from other micros that I use to the photon. I’ve recently ported over a menu system that I made a while ago and I thought I would share it here so other people might be able to use it in a project. If anyone has any question, suggestions, or features that they would like to see added, feel free to let me know.
I currently only have it setup to work with ili9341 based displays and its relatively simple to add text to the menu and add functions to those menu items. I have plans to add support for other display types in the future. I’m currently working on getting support for i2c based lcd displays and I should have some examples for that soon.
Here is a link to my project on github.
Adding new menu options
You build your text menus using an array of stings:
char* mainMenu[3] = {" Main Menu",
"Test Menu 1 ",
"Test Menu 2 "
};
Making the associated functions for the menu works by first making an array of function pointers:
typedef void (* MenuFuncPtr) (); // Function pointer for Main Menu
// Main menu function pointer array
MenuFuncPtr menu_func[3] = {0,
buildTestMenu1,
buildTestMenu2};
To set and display your menu you can use the functions I have made:
setMenu(mainMenu, menu_func, sizeof(mainMenu)/sizeof(char *)-1);
displayMenu();
For the menu options you would then setup up functions and make associated string arrays and function pointer arrays for each menu like above:
void buildTestMenu1(void) {
setMenu(testMenu1, test1_func, sizeof(testMenu1)/sizeof(char *)-1);
displayMenu();
}
While your app/code is running you want to set the appRunning
bool to true so the input can be used in your app/code. Then to get back to the menu you can set the bool back to false
and use the same code to return to which ever menu you like.
setMenu(mainMenu, menu_func, sizeof(mainMenu)/sizeof(char *)-1);
displayMenu();