#include <menu.h>
Data Fields | |
uint8_t | type |
void * | data |
RESUME ======
The aim of this module is to provide some simple functions to use a tree-based menu in a program. The displaying of the menu can be done in several ways: uart, lcd, ... This module tries to be independant of the way it is displayed.
MAIN FUNCTIONS ==============
The main functions that can be used are : menu_left(), menu_right(), menu_up() and menu_down(). they are used to browse the menu. Each of these functions take a pointer to a menu as an argument and return another one. The directions correspond to (one of) the natural representation of a tree.
root ----- submenu1 ----- leaf1 | | | |--- leaf2 | | | |--- submenu2 ----- leaf3 | | | |--- leaf4 | ---- leaf5
Left goes to the parent. Right goes to the first son Up goes to the menu before, on the same level. Down goes to the menu after, on the same level.
These functions try to be tolerant : for example, doing a menu_left() on the root menu return the root menu. Doing a menu_down() on the last menu of a level returns the first menu on the same level.
The module provide one function for displaying a menu and another to do an action depending on a character. These functions can be reimplemented by the user to be more adapted to his application.
The default display function clear the screen, print the parent of the menu, then all other menus on the same level, highlighting the menu given in parameter.
The default menu_update() function takes a character as parameter.
IMPLEMENTATION ==============
A menu is a static table of a menu element. Each menu element is a struct menu :
struct menu { uint8_t type; void * data; }
An element type can be : MENU_TYPE_ROOT if the element is the root of the menu, MENU_TYPE_MENU if it is a submenu under the root, MENU_TYPE_FCT_HDR, MENU_TYPE_FCT_PTR, MENU_TYPE_FCT_DATA, to declare a leaf that executes a function, or MENU_TYPE_END to mark the end of a submenu or the end of the root menu.
For each of these types, the data field points to different things : MENU_TYPE_ROOT data -> (char *) title of the menu MENU_TYPE_MENU data -> (char *) title of the menu MENU_TYPE_FCT_HDR data -> (char *) title of the menu MENU_TYPE_FCT_PTR data -> void (*f)(void *) function that will be called MENU_TYPE_FCT_DATA data -> (void *) parameter of this function MENU_TYPE_END data -> NULL
Here is an exemple :
root ----- submenu1 ----- leaf1 | | | |--- leaf2 | | | |--- submenu2 ----- leaf3 | | | |--- leaf4 | ---- leaf5
will be represented as :
MENU_TYPE_ROOT, "root" MENU_TYPE_MENU, "submenu1" MENU_TYPE_FCT_HDR, "leaf1" MENU_TYPE_FCT_PTR, fct_leaf1 MENU_TYPE_FCT_DATA, leaf1_data MENU_TYPE_FCT_HDR, "leaf2" MENU_TYPE_FCT_PTR, fct_leaf2 MENU_TYPE_FCT_DATA, leaf2_data MENU_TYPE_MENU, "submenu2" MENU_TYPE_FCT_HDR, "leaf3" MENU_TYPE_FCT_PTR, fct_leaf3 MENU_TYPE_FCT_DATA, leaf3_data MENU_TYPE_FCT_HDR, "leaf4" MENU_TYPE_FCT_PTR, fct_leaf4 MENU_TYPE_FCT_DATA, leaf4_data MENU_TYPE_END, NULL MENU_TYPE_END, NULL MENU_TYPE_FCT_HDR, "leaf5" MENU_TYPE_FCT_PTR, fct_leaf5 MENU_TYPE_FCT_DATA, leaf5_data MENU_TYPE_END, NULL
For AVR version, all is stored in program memory. (TODO : store the menu table in program memory, currently only text is stored there) The structure that defines a menu element. A menu is composed of several struct a this type, see the documentation for more informations
Definition at line 156 of file menu.h.
uint8_t menu::type |
Definition at line 157 of file menu.h.
Referenced by menu_call_fct(), menu_default_update(), menu_get_name(), menu_get_next(), menu_get_parent(), menu_get_previous(), and menu_get_type().
void* menu::data |