Suggestion for a flexible menu system

Hello everyone,

I'm having a tricky moment where I can't decide what would be the best approach for a menu system on my project. The initial method I've used just to get the major routines working, is my own "system", which is rather messy and requires a lot of work to modify and add options as I move on with it.

It's running on a Mega2560 and have a 128x64 (ST7920) display connected via SPI. The display show a lot of sensor data that I need (household light, heat and climate control system). The menu system have to be non-blocking and rather responsive, most likely have to use interrupts for the input. I use a rotary encoder for it now, but it's not a must.

I've looked at the M2tklib, but I feel it's not suited for the different UI elements and calls I need. I need basic options I can set on or off (boolean states), values I have to change (integers and longs), groups of integers (as in a clock, hh:mm:ss) and some of the options have to call a function after the value has been set. The menu should normally not be visible as the display shows other things (press a key to bring up the menu).

A structure might look like this:

MENU
System
Backlight
127
Alarms
Off
Set time
hh:mm:ss
Set date
dd:mm:yy
Set GMT
+3
Set DST
+1
Room 1
Temp
20
Light
Auto low
Heater
Auto
Fan
Auto
Hysteresis
4
Room 2
Temp
18
Light
Auto high
Heater
Off
Fan
Auto
Hysteresis
4

Of course, there will be a lot more elements - this is just the basic structure.
Any ideas for a menu library/system would be greatly appreciated :slight_smile:

Thanks in advance.

Depending on whether you want quick access to each menu command or not, here's a suggestion. I built a fancy four output lab power supply with settable current limits and voltages, and some other functions such as battery charging, load testing, zener diode testing, and controllable up-down ramp voltages. That's a fair number of parameters to set, but most of them don't need to be set very often.

I control the whole thing with a toggle switch and a pushbutton. The pushbutton advances me through menu items, and when I reach the desired item, the toggle switch allows me to step through the options. In some cases (such as battery charging) I have to set more than one parameter, so in that case after a parameter has been set, the push button moves me to the next parameter.

The toggle switch is a springloaded normally off switch, and it is wired to an analog pin on the arduino. When it is off (center position), a voltage divider holds the analog pin at 2.5 volts. The toggle, when flipped one way or the other, sets the voltage on the pin at 5 v., or 0 v.

At any rate, it works perfectly, and avoids what elsewise would be a very cluttered front to my power supply.

A rotary encoder would be even better.

Thank you, jrdoner. That sounds like a smart and uncluttered way to do it.
I don't have any issues with the number of buttons that I use as there will be a few for other direct functions aswell.

My biggest challenge is finding a way to generate the menu structure with the customization that I need without too much fragile and labour-intensive code. I'm currently at about 3000 lines already - and that's only for all the processing and interfacing is has to do (not considering the code for two other 328P "helpers" for peripheral duties such as weather station and logging).

I've spent some more time trying to become friends with the M2tklib, but my brain just cannot adapt to the philosophy around it. A PC program to visually build and configure elements for M2tklib could come in handy when you're in a construction phase.

Maybe I just should add a character display, 40x4 or something. I would be alot easier to manipulate it the way I want..