MD_Menu Library
2.1
Library for 1 or 2 line display menu management
|
#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) |
Core object for the MD_Menu library
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.
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.
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.
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.
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.
enum MD_Menu::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. |
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.
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.
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.
cbNav | navigation user callback function |
cbDisp | display user callback function |
mnuHdr | address of the menu headers data table |
mnuHdrCount | number of elements in the header table |
mnuItm | address of the menu items data table |
mnuItmCount | number of elements in the item table |
mnuInp | address of the input definitions data table |
mnuInpCount | number of elements in the input definitions table |
MD_Menu::~MD_Menu | ( | void | ) |
Class Destructor.
Released allocated memory and does the necessary to clean up once the queue is no longer required.
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.
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.
p | Pointer to the selection list in PROGMEM. |
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.
p | pointer to the selection list in PROGMEM. |
idx | the zero based index of the required element. |
buf | pointer to character buffer for the list item extracted. |
bufLen | char size of the buffer at *buf. |
bool MD_Menu::isInEdit | ( | void | ) |
Check if library is editing a field.
Returns boolean with the edit status.
bool MD_Menu::isInMenu | ( | void | ) |
Check if library is running a menu.
Returns boolean with the running status.
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.
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.
bStart | Set to true is the menu needs to be started; defaults to false if not specified |
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.
bSet | true to set the option, false to un-set the option (default) |
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.
bSet | true to set the option, false to un-set the option (default) |
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).
t | the timeout time in milliseconds, 0 to disable (default) |
void MD_Menu::setUserDisplayCallback | ( | cbUserDisplay | cbDisp | ) |
Set the user display callback function.
Replace the current callback function with the new function.
cbDisp | the callback function pointer. |
void MD_Menu::setUserNavCallback | ( | cbUserNav | cbNav | ) |
Set the user navigation callback function.
Replace the current callback function with the new function.
cbNav | the callback function pointer. |