Adjust the LCD_Menu to use the mBed Application board resources

Dependents:   class_project_main

Fork of SerialLCD_Menu by Mark Shuck

Revision:
6:a28c1967bb83
Parent:
5:70fec61bebaf
Child:
7:9b0298adab99
diff -r 70fec61bebaf -r a28c1967bb83 Navigator.cpp
--- a/Navigator.cpp	Sun Aug 04 18:02:39 2013 +0000
+++ b/Navigator.cpp	Fri Aug 30 01:16:16 2013 +0000
@@ -1,44 +1,44 @@
 #include "Navigator.h"
 
-Navigator::Navigator(Menu *root, SerialLCD *lcd) : activeMenu(root), lcd(lcd) 
+Navigator::Navigator(Menu *root, C12832_LCD *lcd) : activeMenu(root), lcd(lcd) 
 {
     bottom = root->selections.size();
     cursorPos = 0;
     cursorLine = 1;
-    button = 0;
-    lastButton = 0;
+    lastButton[0] = 0;
+    lastButton[1] = 0;
+    lastButton[2] = 0;
+    
     setButtons();
     printMenu();
     printCursor();
 }
 
-DigitalIn pbUp(p21);
-DigitalIn pbDown(p22);
-DigitalIn pbSelect(p23);
+DigitalIn pbUp(p15);
+DigitalIn pbDown(p12);
+DigitalIn pbSelect(p14);
 
 
 void Navigator::setButtons()
 {
-    pbUp.mode(PullUp);
-    pbDown.mode(PullUp);
-    pbSelect.mode(PullUp);
 }
 
 void Navigator::printMenu()
 { 
-    lcd->clear();
+    lcd->cls();
+    lcd->locate(4,0);
     if(bottom == 1){ // the current Menu only has one selection
         lcd->printf("%s", activeMenu->selections[0].selText);
     } else {
         if(cursorLine == 2){ 
             // moving down in menu
             lcd->printf("%s", activeMenu->selections[cursorPos-1].selText);
-            lcd->setPosition(1,0); // Sparkfun Serial LCD based on PIC16LF88
+            lcd->locate(4,13); // 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(1,0); // Sparkfun Serial LCD based on PIC16LF88
+            lcd->locate(4,13); // Sparkfun Serial LCD based on PIC16LF88
             lcd->printf("%s", activeMenu->selections[cursorPos+1].selText);
         }
     }
@@ -47,32 +47,32 @@
 void Navigator::printCursor()
 {   
      
-    lcd->setPosition(0,0); // Sparkfun Serial LCD based on PIC16LF88
+    lcd->locate(0,0); // Sparkfun Serial LCD based on PIC16LF88
     if(cursorLine == 1){
         lcd->printf(">");
-        lcd->setPosition(1,0); // Sparkfun Serial LCD based on PIC16LF88
+        lcd->locate(0,13); // Sparkfun Serial LCD based on PIC16LF88
         lcd->printf(" ");
     } else if(cursorLine == 2){
         lcd->printf(" ");
-        lcd->setPosition(1,0); // Sparkfun Serial LCD based on PIC16LF88
+        lcd->locate(0,13); // Sparkfun Serial LCD based on PIC16LF88
         lcd->printf(">");
     }
 }
 
 void Navigator::poll()
 {
-
-    if(pbUp == 0){
-        wait(0.2);
+    wait_ms(10);
+    button[0]=pbUp;
+    button[1]=pbDown;
+    button[2]=pbSelect;
+    
+    if(button[0] == 1 && button[0] != lastButton[0]){
         moveUp();
     }
-    if(pbDown == 0){
-        wait(0.2);
+    if(button[1] == 1 && button[1] != lastButton[1]){
         moveDown();
     }
-    if(pbSelect == 0){
-        wait(0.2);
-        
+    if(button[2] == 1 && button[2] != lastButton[2]){ 
         if(activeMenu->selections[cursorPos].fun != NULL){
             (activeMenu->selections[cursorPos].fun)();
         }
@@ -86,22 +86,22 @@
             printCursor();
         }
     }
-    lastButton = button;
+    lastButton[0]=button[0];
+    lastButton[1]=button[1];
+    lastButton[2]=button[2];
       
 }
 
 void Navigator::moveUp()
 {
-    if(cursorLine == 1){
-        printMenu();
-    } else if(cursorLine == 2){
+    if(cursorLine == 2){
         cursorLine = 1;
     }
     
     if(cursorPos != 0){
         cursorPos--;
-        printMenu();
     }
+    printMenu();
     printCursor();
 }
 
@@ -109,13 +109,10 @@
 {
     if(cursorLine == 1){
         cursorLine = 2;
-    } else if(cursorLine == 2){
-        printMenu();
-    }
-    
+    }     
     if(cursorPos != (bottom-1)){
         cursorPos++;
-        printMenu();
     }
+    printMenu();
     printCursor();
 }
\ No newline at end of file