Is there a pattern out there for a simple menu system in C for a text LCD. I find myself re-writing code a lot for handling simple text LCD menus.
I find most systems have a main menu and some sub-menus that when selected allow you to set a parameter with within some minimum and maximum value.
Ideally this menu system could be navigated with 4 simple keys such as enter, cancel, up, and down.
In my application I'm using a 2 line x 16 character text LCD though an ideal solution should be able to be applied to any NxM display.
Best Answer
The pattern I use for menu systems in C is something like this:
I then declare an array of
menu
s each containingmenuitem
s and pointers tochild
submenus. Up and down moves through the currently selected array ofmenuitem
s. Back moves to theparent
menu and forward/select either moves to achild
submenu or calls ahandlerFunc
for a leaf node.Rendering a menu just involves iterating through its items.
The advantage of this scheme is that it's fully data driven, the menu structures can be statically declared in ROM independent of the renderer and handler functions.