Skip to content
Pierre Hilson edited this page Dec 26, 2020 · 42 revisions

ArduinoMenu Library 3.x/4.x Wiki

Menu library basics

This library is divided in parts, such as device drivers, to be included on your project as needed, this is a way of minimizing compile time. Some examples of this wiki refer to some parts like the menu serial output driver. Parts are usually in menuIO/... folder. So be sure to include the parts needs to support your hardware and application.

The code is focused on lower resource usage profile.

The menu is statically constructed to allow PROGMEM usage (PROGMEM only on avr devices). On other devices it can allocate all needed memory at compile time or use runtime dynamic allocated items, as preferred.

The menu system does not store field variables; instead it uses references to variables already in your code. This makes integration easier and avoids translations and extra functions.

Objects organization

Objects can be IO devices, navigation controllers or menu structure. All is organized around the root navigation object.

Navigation

The root navigation object uses a set of navigation level controllers and deals with all aspects of navigation, selected options, active menus etc... It also responds to commands and does navigation status by sending navigation commands to the navigation objects.

Menu Structure

These objects deal with the menu text and structure along with user iteration hooks.

IO Objects

Store information about IO device. The root navigation needs access to them to do its job.

Menu software components

menuIO files

include these files as needed, for example #include <menuIO/serialOut.h>

menuIO/adafruitGfxOut.h - use Adafruit output devices.

menuIO/ansiSerialOut.h - use serial output with an ANSI terminal

menuIO/chainStream.h - join multiple input streams into one.

menuIO/clickEncoderIn.h - use PCINT wired encoder

menuIO/encoderIn.h - use generic encoder

menuIO/rotaryEventIn.h - use generic rotary/button input (example with QDEC and AceButton easing encoder and button handling/debouncing)

menuIO/esp8266Out.h - for ESP8266 web output (experimental)

menuIO/htmlFmt.h - experimental file (ESP8266)

menuIO/jsFmt.h - experimental, ESP8266 javascript

menuIO/keyIn.h - use generic buttons

menuIO/keyMapDef.h - keymap definition aux file, you should not need to include this file

menuIO/altKeyIn.h - use generic buttons and allows specification of PULL resistors.

menuIO/altKeyMapDef.h - keymap definition aux file, you should not need to include this file

menuIO/lcdOut.h - use Malpartida's LCD's drivers

menuIO/liquidCrystalOut.h - standard LCD output

menuIO/PCF8574Out.h - Arduino I²C LCD output (v4.x)

menuIO/serialOut.h - use standard serial output.

menuIO/softKeyIn.h - use generic buttons with software debounce

menuIO/SSD1306AsciiOut.h - SSD1306 ASCII quick driver output

menuIO/tftOut.h - Arduino TFT output (v4.x)

menuIO/u8g2Out.h - use U8g² screen device.

menuIO/U8GLibOut.h - use U8GLib screen device.

menuIO/U8x8Out.h - U8G2/U8x8 text quick driver output. (v4.x)

menuIO/UCGLibOut.h - UCGLib Color displays output. (v4.x)

menuIO/utftOut.h - use utf screen device.

menuIO/utouchIn.h - use touch input device.

menuIO/xmlFmt.h - formatter to write menu as XML, used by ESP8266 web interface

menuIO/jsonFmt.h - formatter to write menu as JSON, used by ESP8266 web interface

Menu structure

This is done using a set of macros to define menus, numeric fields and choice/selection fields and to attach menus to other menus to form sub-menus. Macros are used to define most of the menu data as static and stored on flash memory, because RAM is critical on AVR devices. Also all menu-used RAM is allocated at startup, avoiding dynamic RAM allocation and making memory usage more predictable.

Inputs

We support multiple parallel inputs, so the input is usually either a single stream or an array of streams concatenated with chainStream object.

see inputs and initialization for more details.

Outputs

We support multiple parallel output devices, this is useful on final products because it provides alternatives in case of failure of the main output device. Usually an LCD or TFT as main output and serial output as a maintenance/backup output device.

See output and initialization for more details.

Navigation control

All navigation is centrally controlled by a navigation root object.

The navigation root object holds the lists of inputs and outputs as well as a list layer navigation status auxiliary object, used to navigate down on sub-menus and to preserve status when we navigate back. Because this menu avoids dynamic memory allocation, we need to tell beforehand the maximum nested depth level. Any sub-menu or choice/select field counts as one depth layer.

See navigation and initialization for more details.

Menu execution

The menu system depends on your code to call one of its functions to iterate the system. So if none is currently called the menu system is not executing any I/O and your code is free to use the I/O devices. Also if the menu system calls one of your functions as a result of iteration, then the menu will not be executing while your function does not return--unless of course you define some other interrupt-driven method that calls the menu meanwhile.

Menu execution/iteration is done by using some API functions as members of the main navigation object (navRoot). One of these functions must be called regularly because the system just verifies if there is available input or output need and returns.

void poll();

the most simple and powerful menu execution function, it deals with all I/O, driving the menu on a full automated mode.

inline void doInput();

check inputs list for available data

void doInput(const char*in);

call the menu system to consider one given character as input

inline void doOutput();

verify the need of output and satisfy it. This function also checks user values for changes and reflects the changes by redrawing the values.