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

Revision:
3:f308cd7a34ed
Parent:
2:399e080c4909
Child:
6:e992366d0684
--- a/testconsole.cpp	Fri May 01 13:34:09 2015 +0000
+++ b/testconsole.cpp	Fri May 01 15:08:49 2015 +0000
@@ -41,32 +41,27 @@
     
 //here, using knowledge of the page, we process commands
 int TestConsole::process_cmd(char cmd){
-
-
-       if('x' == cmd) {
-            page_change(previous_page);
-            return 0;
-                }   
-                 
-        for(int index=0; index < page[current_page].num_menuitems; index++){
-
+    if('x' == cmd) {
+        page_change(previous_page);
+        return 0;
+    }   
+    Page* active_page = &page[current_page];
+    for(int index=0; index < active_page->num_menuitems; index++) {
+        MenuItem *item = &active_page->item[index];
+        if(active_page->command_letter[index] != cmd) continue;
             
-        if(page[current_page].command_letter[index] == cmd) {
-           
-           //for menuitems that goto other menus, just change the page
-           if(page[current_page].item[index].type == menu) {
-               page_change(page[current_page].item[index].target_page);
-               return 0;
-               }
-           
-           //otherwise call the callaback    
-           page[current_page].item[index].callback(true);
-           return 0;
-           }
+        if(item->type == menu) {
+            // for menuitems that goto other menus, just change the page
+            page_change(item->target_page);
+        } else if(item->action) {
+            // otherwise call the callaback
+            item->action->doAction();
         }
-        
+        return 0;
+    }
+    
     return 1;
-    }
+}
     
 int TestConsole::tick(void){
     if (term.readable()){   //if there is a character