-
-
Notifications
You must be signed in to change notification settings - Fork 195
Initialization
Menu inputs are regular streams that deliver some navigation special meaning characters. Therefore Serial is a candidate for input when constructing the central navigation object.
serialIn in(Serial);//changed on version 4
NAVROOT(nav,main_menu,MAX_DEPTH,in,out);
from version 4 serial is not accepted directly as an input, a serialIn object must be created to wrap it
To enable multiple inputs the chainStream can be used, see details on the Input wiki page.
const Menu::panel panels[] MEMMODE={{0,0,40,2}};
Menu::navNode* nodes[sizeof(panels)/sizeof(Menu::panel)];//navNodes to store navigation status
Menu::panelsList pList(panels,nodes,1);//a list of panels and nodes
We need:
- A static list of panels placed on flash memory for describing the output area available for the menu system.
- A dynamic list (RAM) of navNode pointers with size equal to the number of panels (above just 1) for internal use of the panels system. The expression [sizeof(panels)/sizeof(Menu::panel)] calculates that size automatically.
Then we can build the panel list manager providing the location of both the static list and the dynamic RAM space along with the list size (equal for both).
Menu::idx_t serialTops[MAX_DEPTH];
Menu::serialOut outSerial(Serial,serialTops);
Menu::idx_t lcdTops[MAX_DEPTH];
Menu::liquidCrystalOut outLCD(lcd,lcdTops,pList);
This code initializes two output devices.
We need an array of idx_t (small integers) on RAM with size equal to the maximnum allowed navigation depth. To be used by the navigation system but dedicated to each device. With that we can initialize the menu device driver object usually by providing the original Arduino device driver and the list of small integers. Please note that menu device driver parameters depends on the driver itself, so each will require specific information. See the driver doc. for details.
Menu::menuOut* const outputs[] MEMMODE={&outSerial,&outLCD};//list of output devices
Menu::outputsList out(outputs,2);//outputs list controller
We need a static list of output pointers (menuOut*) to provide to the outputList controller along with the list size.
Using macro
MENU_OUTPUTS(«name»,«MAX_DEPTH» ,«output device» ,«output device» [,«output device»] );
example:
MENU_OUTPUTS(simpleOut,MAX_DEPTH
,SERIAL_OUT(Serial)
,NONE//must have 2 items at least, if using this macro
);
If using this macro we have to have at least two outputs. The macro creates an outputs list named simpleOut. In this case you can refer to the given name when referring to this list. This macro defines both the outputs list and the needed menu output drivers, here just SERIAL_OUT(Serial) and NONE.
if you need no outputs:
Menu::outputsList out(NULL,0);
here defining and outputsList name out with length zero.
This object will control all navigation coordinating inputs and outputs lists along with a menu definition.
This object uses an array of aux objects that control each depth layer of the navigation process to a maximum of the defined MAX_DEPTH.
At this moment there can only be one of such object in your code. It should be allocated outside your main, setup or loop functions.
If you feel this a serious constraint please let me know, its just an actual design option that can be changed with low RAM cost.
Menu::navNode nav_cursors[MAX_DEPTH];//aux objects to control each level of navigation
Menu::navRoot nav(main_menu, nav_cursors, MAX_DEPTH-1, Serial, out);
This construction can be replaced by the following macro:
NAVROOT(nav,main_menu,MAX_DEPTH,in,out);
where:
main_menu refers to an existing menu definition.