MD_Menu Library  2.1
Library for 1 or 2 line display menu management
MD_Menu Class Reference

#include <MD_Menu.h>

Classes

struct  mnuHeader_t
 
struct  mnuInput_t
 
struct  mnuItem_t
 
struct  value_t
 

Public Types

Enumerated values and Typedefs.
enum  userNavAction_t {
  NAV_NULL, NAV_INC, NAV_DEC, NAV_SEL,
  NAV_ESC
}
 
enum  userDisplayAction_t { DISP_INIT, DISP_CLEAR, DISP_L0, DISP_L1 }
 
enum  inputAction_t {
  INP_LIST, INP_BOOL, INP_INT, INP_FLOAT,
  INP_ENGU, INP_RUN, INP_EXT
}
 
enum  mnuAction_t { MNU_MENU, MNU_INPUT, MNU_INPUT_FB }
 
typedef int8_t mnuId_t
 
typedef userNavAction_t(* cbUserNav) (uint16_t &incDelta)
 
typedef bool(* cbUserDisplay) (userDisplayAction_t action, char *msg)
 
typedef value_t *(* cbValueRequest) (mnuId_t id, bool bGet)
 

Public Member Functions

Class constructor and destructor.
 MD_Menu (cbUserNav cbNav, cbUserDisplay cbDisp, const mnuHeader_t *mnuHdr, uint8_t mnuHdrCount, const mnuItem_t *mnuItm, uint8_t mnuItmCount, const mnuInput_t *mnuInp, uint8_t mnuInpCount)
 
 ~MD_Menu (void)
 
Methods for core object control.
void begin (void)
 
bool runMenu (bool bStart=false)
 
bool isInMenu (void)
 
bool isInEdit (void)
 
Support methods.
void reset (void)
 
void setMenuWrap (bool bSet)
 
void setAutoStart (bool bSet)
 
void setTimeout (uint32_t t)
 
void setUserNavCallback (cbUserNav cbNav)
 
void setUserDisplayCallback (cbUserDisplay cbDisp)
 
List utility methods.
uint8_t getListCount (const char *p)
 
char * getListItem (const char *p, uint8_t idx, char *buf, uint8_t bufLen)
 

Detailed Description

Core object for the MD_Menu library

Member Typedef Documentation

◆ cbUserDisplay

typedef bool(* MD_Menu::cbUserDisplay) (userDisplayAction_t action, char *msg)

User input function prototype

The user input function must handle the physical user interface (eg, switches, rotary encoder) and return one of the userNavAction_t enumerated types to trigger the next menu action.

◆ cbUserNav

typedef userNavAction_t(* MD_Menu::cbUserNav) (uint16_t &incDelta)

User input function prototype

The user input function must handle the physical user interface (eg, switches, rotary encoder) and return one of the userNavAction_t enumerated types to trigger the next menu action. The user function can also specify the incremental change quantity that to be applied for INC and DEC actions when editing a numeric variable (default is 1) by changing the incDelta variable.

◆ cbValueRequest

typedef value_t*(* MD_Menu::cbValueRequest) (mnuId_t id, bool bGet)

Data input/output function prototype

This user function must handle the get/set of the input value currently being handled by the menu. When bGet is true, the function must return the pointer to the data identified by the ID. Return nullptr to stop the menu from editing the value.

◆ mnuId_t

typedef int8_t MD_Menu::mnuId_t

Common Action Id type

Record id numbers link the different parts of the menu together. typedef this to make it easier to change to a different type in future if required. Note that id -1 is used to indicate error or no id, so value must be signed.

Member Enumeration Documentation

◆ inputAction_t

Menu input type enumerated type specification.

Used to define the the type input action a for variable menu item so that it can be appropriately processed by the library.

Enumerator
INP_LIST 

The item is for selection from a defined list of values.

INP_BOOL 

The item is for input of a boolean variable (Y/N)

INP_INT 

The item is for input of an integer.

INP_FLOAT 

The item is for input of a real number representation with 2 decimal digits.

INP_ENGU 

The item is for input of a number in engineering (powers of 10 which are multiples of 3) with 3 decimal digits.

INP_RUN 

The item will run a user function.

INP_EXT 

The item will display numeric input provided by a user function.

◆ mnuAction_t

Menu input type enumerated type specification.

Used to define the the type input action a for variable menu item so that it can be appropriately processed by the library.

Enumerator
MNU_MENU 

The item is for selection of a new menu.

MNU_INPUT 

The item is for input of a value.

MNU_INPUT_FB 

The item is for input with real time feedback of value changes.

◆ userDisplayAction_t

Request values for user display handler

The display handler will receive requests that tell it what needs to be done. The display must implement appropriate actions on the display device to carry out the request.

Enumerator
DISP_INIT 

Initialize the display.

DISP_CLEAR 

Clear the display. Message parameter is not defined.

DISP_L0 

Display the data provided in line 0 (first line). For single line displays, this should be ignored.

DISP_L1 

Display the data provided in line 1 (second line). This must always be implemented.

◆ userNavAction_t

Return values for the user input handler

The menu navigation keys are implemented by user code that must return one of these defined types when it is invoked. The menu navigation in the library and data input is fully controlled by this returned value.

Enumerator
NAV_NULL 

There was no current selection to process.

NAV_INC 

INCREMENT. Move to the next menu item or increment a value.

NAV_DEC 

DECREMENT. Move to the previous menu item or decrement a value.

NAV_SEL 

SELECT the current menu item or confirm a new value.

NAV_ESC 

ESCAPE from current menu or abandon editing a value (remains unchanged).

Constructor & Destructor Documentation

◆ MD_Menu()

MD_Menu::MD_Menu ( cbUserNav  cbNav,
cbUserDisplay  cbDisp,
const mnuHeader_t mnuHdr,
uint8_t  mnuHdrCount,
const mnuItem_t mnuItm,
uint8_t  mnuItmCount,
const mnuInput_t mnuInp,
uint8_t  mnuInpCount 
)

Class Constructor.

Instantiate a new instance of the class. The parameters passed define the data structures defining the menu items and function callbacks required for the library to interact with user code.

Parameters
cbNavnavigation user callback function
cbDispdisplay user callback function
mnuHdraddress of the menu headers data table
mnuHdrCountnumber of elements in the header table
mnuItmaddress of the menu items data table
mnuItmCountnumber of elements in the item table
mnuInpaddress of the input definitions data table
mnuInpCountnumber of elements in the input definitions table

◆ ~MD_Menu()

MD_Menu::~MD_Menu ( void  )

Class Destructor.

Released allocated memory and does the necessary to clean up once the queue is no longer required.

Member Function Documentation

◆ begin()

void MD_Menu::begin ( void  )

Initialize the object.

Initialize the object data. This needs to be called during setup() to initialize new data for the class that cannot be done during the object creation.

◆ getListCount()

uint8_t MD_Menu::getListCount ( const char *  p)

Count the items in a selection list.

Return the count of items in the selection list specified.

Parameters
pPointer to the selection list in PROGMEM.
Returns
the item count.

◆ getListItem()

char * MD_Menu::getListItem ( const char *  p,
uint8_t  idx,
char *  buf,
uint8_t  bufLen 
)

Extract an item from a selection list

Return idx'th item from the list selection string. The first item is numbered 0.

Parameters
ppointer to the selection list in PROGMEM.
idxthe zero based index of the required element.
bufpointer to character buffer for the list item extracted.
bufLenchar size of the buffer at *buf.
Returns
the buf pointer.

◆ isInEdit()

bool MD_Menu::isInEdit ( void  )

Check if library is editing a field.

Returns boolean with the edit status.

Returns
true if editing field, false otherwise

◆ isInMenu()

bool MD_Menu::isInMenu ( void  )

Check if library is running a menu.

Returns boolean with the running status.

Returns
true if running menu, false otherwise

◆ reset()

void MD_Menu::reset ( void  )

Reset the menu.

Change the current menu state to be not running and reset all menu conditions to start state.

◆ runMenu()

bool MD_Menu::runMenu ( bool  bStart = false)

Run the menu.

This should be called each time through the loop() function. The optional parameter should be set to true when the menu display needs to start (or restart) and false (or omitted) for normal running. This allows the user code to trigger the menu starting unless the setAutoStart() option is set to start the menu automatically. When running, the menu code coordinates user callbacks to obtain input and display the menu, as needed.

Parameters
bStartSet to true is the menu needs to be started; defaults to false if not specified
Returns
true if the menu is still running, false otherwise

◆ setAutoStart()

void MD_Menu::setAutoStart ( bool  bSet)

Set the menu auto start option.

Set the menu to start automatically in response to the SEL navigation selection. When set on, pressing SEL when the menu is not running will start the menu display. If the option is not set, the starting trigger needs to be monitored by the user code and the menu started by calling runMenu(). Default is not to auto start.

Parameters
bSettrue to set the option, false to un-set the option (default)

◆ setMenuWrap()

void MD_Menu::setMenuWrap ( bool  bSet)

Set the menu wrap option.

Set the menu wrap option on or off. When set on, reaching the end of the menu will wrap around to the start of the menu. Similarly, reaching the end will restart from the beginning. Default is set to no wrap.

Parameters
bSettrue to set the option, false to un-set the option (default)

◆ setTimeout()

void MD_Menu::setTimeout ( uint32_t  t)

Set the menu inactivity timeout.

Set the menu inactivity timeout to the specified value in milliseconds. The menu will automatically reset is there is no key pressed in the specified time. It is up to the user code to detect the menu is no longer running and transition to normal mode. A value of 0 disables the timeout (default).

Parameters
tthe timeout time in milliseconds, 0 to disable (default)

◆ setUserDisplayCallback()

void MD_Menu::setUserDisplayCallback ( cbUserDisplay  cbDisp)

Set the user display callback function.

Replace the current callback function with the new function.

Parameters
cbDispthe callback function pointer.

◆ setUserNavCallback()

void MD_Menu::setUserNavCallback ( cbUserNav  cbNav)

Set the user navigation callback function.

Replace the current callback function with the new function.

Parameters
cbNavthe callback function pointer.

The documentation for this class was generated from the following files: