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
Diff: test_main.cpp
- Revision:
- 6:e992366d0684
- Parent:
- 0:907d2d5e77f7
diff -r 4a240f717b9d -r e992366d0684 test_main.cpp --- a/test_main.cpp Sat May 02 00:41:23 2015 +0000 +++ b/test_main.cpp Mon May 04 14:43:35 2015 +0000 @@ -1,13 +1,13 @@ #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); + + +Terminal term(DEBUG_TX, DEBUG_RX); Ticker heartbeat; @@ -23,31 +23,6 @@ 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){ @@ -55,34 +30,48 @@ //create the Pages for the console // term.printf("\nsizeof page %d, menuitem %d\n",sizeof(Page), sizeof(MenuItem)); - TestConsole console("Test Program"); + TestConsole console("KV2 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)); + Page &page1 = console.add_page(Page("Page1")); + Page &page2 = console.add_page(Page("Page2")); + + // pageHome.add(pagePower.Name, &pagePower.set_active(), 0, menu)); + pageHome + .add(page1) + .add(page2) + +//These macros are actually in the menuitem.h file but commented here below for reference +//#define MAKE_PORT(x, io) (new Menu##io(#x, io(x))) //use this macro to create a port (it saves name as well as creatign the IO +//#define REUSE_PORT(x, io, port) (new Menu##io(#x, port)) //use this macro if you created the port externally + - pageBattery.add_item(MenuItem("Display", NULL, 0, heading)); - pageBattery.add_item(MenuItem("Battery Voltage", test_callback, 0, display)); + page1 + .add("DISPLAY") + .add("Eject Button Status", MAKE_PORT(PA_1, DigitalIn)) + .add("Push button status", MAKE_PORT(PUSH_BUT_IN, DigitalIn)) + .add("Battery voltage", MAKE_PORT(A1, AnalogIn)) + .add("Dock sense", MAKE_PORT(PA_2, DigitalIn)) + .add("CONTROL") + .add("MCU regulator disable", MAKE_PORT(PA_3, DigitalOut)) + .add("Battery Read Enable", MAKE_PORT(PA_4, DigitalOut)) + .add("Dock Read Enable", MAKE_PORT(PA_5, DigitalOut)); - pageAccel.add_item(MenuItem("Display", NULL, 0, heading)); - pageAccel.add_item(MenuItem("Battery Voltage", test_callback, 0, display)); + + page2 + .add("DISPLAY") + .add("Battery voltage", MAKE_PORT(A0, AnalogIn)) + .add("Accumulated Charge", new MenuNotImplementedAction("N/A")) + .add("CHRG line", MAKE_PORT(PA_0, DigitalIn)) + .add("High/Low Charge thresholds", new MenuNotImplementedAction("N/A")) + .add("Status Register", new MenuNotImplementedAction("N/A")) + .add("Control Register", new MenuNotImplementedAction("N/A")); 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 + wait(2); while(1) {