Library which creates a serial test console, it supports pages and menu items. The items are added and the pages are added as necessary when the user sets it up. This is a great too for creating an easy to maintain menu system, whether for a test sytem, or anything else.
Dependencies: Terminal
test_main.cpp
- Committer:
- glansberry
- Date:
- 2015-05-01
- Revision:
- 0:907d2d5e77f7
- Child:
- 6:e992366d0684
File content as of revision 0:907d2d5e77f7:
#ifdef TEST //define test to make this an active main #include <mbed.h> #include "Terminal.h" #include "SerialTerm.h" #include "ASCIIGraph.h" #include "testconsole.h" #include "page.h" #include "menuitem.h" Terminal term(SERIAL_TX, SERIAL_RX); Ticker heartbeat; volatile bool tick = false; // this is the primary flag that indicates that it is time to run the control loop static int ERROR_Overrun = 0; //this counts the number of times that the code was still running when the interrupt tried to trigger it again (ie code is running too slow) /*********************************************************************************************** * \brief Interrupt for the main loop timer * **********************************************************************************************/ void tick_int() { if (!tick) tick = true; //detect if interrupt has not yet finished else ERROR_Overrun++ ; } //prototype callback for the menu system, if the command key has been pressed, then cmd is true //otherwise it should simple return a string that gets printed char * test_callback(bool cmd){ static int i; static bool count = true; static char buffer[20]; if(cmd) { term.locate(TERM_LOC_DEBUG); term.printf("test_callback"); } if(cmd) count = !count; if(count) i++; sprintf(buffer, "%d", i); return buffer; } char * null_callback(bool cmd){ return NULL; } int main(void){ term.baud(115200); //create the Pages for the console // term.printf("\nsizeof page %d, menuitem %d\n",sizeof(Page), sizeof(MenuItem)); TestConsole console("Test Program"); Page &pageHome = console.add_page(Page("Home")); Page &pagePower = console.add_page(Page("Page1")); Page &pageBattery = console.add_page(Page("Page2")); Page &pageAccel = console.add_page(Page("Page3")); // pageHome.add_item(MenuItem(pagePower.Name, &pagePower.set_active(), 0, menu)); #define CREATE_PAGE_SELECT_MENU_ITEM(x) add_item(MenuItem(x.Name, x.page_num)); pageHome.CREATE_PAGE_SELECT_MENU_ITEM(pagePower); pageHome.CREATE_PAGE_SELECT_MENU_ITEM(pageBattery); pageHome.CREATE_PAGE_SELECT_MENU_ITEM(pageAccel); pagePower.add_item(MenuItem("Display", NULL, 0, heading)); pagePower.add_item(MenuItem("Eject Button Status", test_callback, 0, display)); pageBattery.add_item(MenuItem("Display", NULL, 0, heading)); pageBattery.add_item(MenuItem("Battery Voltage", test_callback, 0, display)); pageAccel.add_item(MenuItem("Display", NULL, 0, heading)); pageAccel.add_item(MenuItem("Battery Voltage", test_callback, 0, display)); heartbeat.attach(&tick_int, 0.1); // the address of the function to be attached (tick_int) and the interval 10000uS wait(2); //give the man a chance to read the messages, if any while(1) { while(tick){ //put real-time code in here console.tick(); tick=false; //keep this as the last item in the while loop } } } #endif