# Standard text LCD menu system

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.

-
Nothing to do with electronic design! Question will be closed. – Leon Heller Oct 13 '11 at 20:01
I was under the impression programming questions if they applied to embedded systems could be asked here too. Maybe I was wrong... – mjh2007 Oct 13 '11 at 20:11
I was under similar impression too. Is there an official note about that? – AndrejaKo Oct 13 '11 at 20:30
Only very low-level stuff, according to the FAQ. This question is about the user interface. – Leon Heller Oct 13 '11 at 20:39
+1 I would be interested too...I've always hand-brewed them. Are you using a console output or a NxM character display....not that I have an answer for either :) On several embedded 2xN display systems, I've implemented two button interfaces with combining Enter/Cancel and have Next which is a ring buffer and eliminates the need for up/next & down/back. – kenny Oct 13 '11 at 21:17

The pattern I use for menu systems in C is something like this:

struct menuitem
{
const char *name; // name to be rendered
functionPointer handlerFunc; // handler for this leaf node (optionally NULL)
};


I then declare an array of menus each containing menuitems and pointers to child submenus. Up and down moves through the currently selected array of menuitems. Back moves to the parent menu and forward/select either moves to a child submenu or calls a handlerFunc for a leaf node.