Serial LCD Menu system with buttons instead of RPG. Based on Peihsun Yeh's work

Fork of Menu by Peihsun Yeh

Revision:
4:343f2993a66b
Parent:
3:920157b558db
Child:
5:70fec61bebaf
--- a/Navigator.cpp	Sun Aug 04 15:18:35 2013 +0000
+++ b/Navigator.cpp	Sun Aug 04 17:19:36 2013 +0000
@@ -1,30 +1,44 @@
 #include "Navigator.h"
 
-Navigator::Navigator(Menu *root, RPG &rpg, SerialLCD *lcd) : activeMenu(root), rpg(rpg), lcd(lcd) 
+Navigator::Navigator(Menu *root, SerialLCD *lcd) : activeMenu(root), lcd(lcd) 
 {
     bottom = root->selections.size();
     cursorPos = 0;
     cursorLine = 1;
     button = 0;
     lastButton = 0;
-    
+    setButtons();
     printMenu();
     printCursor();
 }
-DigitalIn pushbutton(p21);
+
+DigitalIn pbUp(p21);
+DigitalIn pbDown(p22);
+DigitalIn pbSelect(p23);
+
+
+void Navigator::setButtons()
+{
+    pbUp.mode(PullUp);
+    pbDown.mode(PullUp);
+    pbSelect.mode(PullUp);
+}
+
 void Navigator::printMenu()
 { 
     lcd->clear();
     if(bottom == 1){ // the current Menu only has one selection
-        lcd->printf("Mark", activeMenu->selections[0].selText);
+        lcd->printf("%s", activeMenu->selections[0].selText);
     } else {
-        if(cursorLine == 2){ // if we're at the bottom
-            lcd->printf("line2", activeMenu->selections[cursorPos-1].selText);
-            lcd->setPosition(0,2);
-            lcd->printf("line22", activeMenu->selections[cursorPos].selText);
+        if(cursorLine == 2){ 
+            // moving down in menu
+            lcd->printf("%s", activeMenu->selections[cursorPos-1].selText);
+            lcd->setPosition(0,1); // Sparkfun Serial LCD based on PIC16LF88
+            lcd->printf("%s", activeMenu->selections[cursorPos].selText);
         } else {
+            // moving up in menu
             lcd->printf("%s", activeMenu->selections[cursorPos].selText);
-            lcd->setPosition(0,2);
+            lcd->setPosition(0,1); // Sparkfun Serial LCD based on PIC16LF88
             lcd->printf("%s", activeMenu->selections[cursorPos+1].selText);
         }
     }
@@ -32,34 +46,39 @@
 
 void Navigator::printCursor()
 {   
-    if(activeMenu->selections[cursorPos].childMenu == NULL) printf("Ncm");
-    else printf("child menu: %s", activeMenu->selections[cursorPos].childMenu->menuID);
+    //if(activeMenu->selections[cursorPos].childMenu == NULL) printf("No Child Menu");
+    //else printf("%s", activeMenu->selections[cursorPos].childMenu->menuID);
      
     lcd->setPosition(0,0);
     if(cursorLine == 1){
         lcd->printf(">");
-        lcd->setPosition(0,1);
+        lcd->setPosition(0,2);
         lcd->printf(" ");
     } else if(cursorLine == 2){
         lcd->printf(" ");
-        lcd->setPosition(0,1);
-        lcd->printf(">1");
+        lcd->setPosition(0,3);
+        lcd->printf(">");
     }
 }
 
 void Navigator::poll()
 {
-    if((direction = rpg.dir())!=0){ //Get Dir
-        wait(0.2); 
-        if(direction == 1) moveDown();
-        else if(direction == -1) moveUp();
+
+    if(pbUp == 0){
+        wait(0.2);
+        moveUp();
     }
-       
-    if ((button == rpg.pb()) && !lastButton){ //prevents multiple selections when button is held down
+    if(pbDown == 0){
         wait(0.2);
+        moveDown();
+    }
+    if(pbSelect == 0){
+        wait(0.2);
+        
         if(activeMenu->selections[cursorPos].fun != NULL){
             (activeMenu->selections[cursorPos].fun)();
         }
+        
         if(activeMenu->selections[cursorPos].childMenu != NULL){
             activeMenu = activeMenu->selections[cursorPos].childMenu;
             bottom = activeMenu->selections.size();
@@ -70,6 +89,7 @@
         }
     }
     lastButton = button;
+      
 }
 
 void Navigator::moveUp()