Dwayne Dilbeck / LCD_Menu

Dependents:   class_project_main

Fork of SerialLCD_Menu by Mark Shuck

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Navigator.cpp Source File

Navigator.cpp

00001 #include "Navigator.h"
00002 
00003 Navigator::Navigator(Menu *root, C12832_LCD *lcd) : activeMenu(root), lcd(lcd) 
00004 {
00005     bottom = root->selections.size();
00006     cursorPos = 0;
00007     cursorLine = 1;
00008     lastButton[0] = 0;
00009     lastButton[1] = 0;
00010     lastButton[2] = 0;
00011     
00012     setButtons();
00013     printMenu();
00014     printCursor();
00015 }
00016 
00017 DigitalIn pbUp(p15);
00018 DigitalIn pbDown(p12);
00019 DigitalIn pbSelect(p14);
00020 
00021 
00022 void Navigator::setButtons()
00023 {
00024 }
00025 
00026 void Navigator::printMenu()
00027 { 
00028     lcd->cls();
00029     lcd->locate(10,0);
00030     if(bottom == 1){ // the current Menu only has one selection
00031         lcd->printf("%s", activeMenu->selections[0].selText);
00032     } else {
00033         if(cursorLine == 2){ 
00034             // moving down in menu
00035             lcd->printf("%s", activeMenu->selections[cursorPos-1].selText);
00036             lcd->locate(10,13); // Sparkfun Serial LCD based on PIC16LF88
00037             lcd->printf("%s", activeMenu->selections[cursorPos].selText);
00038         } else {
00039             // moving up in menu
00040             lcd->printf("%s", activeMenu->selections[cursorPos].selText);
00041             lcd->locate(10,13); // Sparkfun Serial LCD based on PIC16LF88
00042             lcd->printf("%s", activeMenu->selections[cursorPos+1].selText);
00043         }
00044     }
00045 }
00046 
00047 void Navigator::printCursor()
00048 {   
00049      
00050     lcd->locate(0,0); // Sparkfun Serial LCD based on PIC16LF88
00051     if(cursorLine == 1){
00052         lcd->printf(">");
00053         lcd->locate(0,13); // Sparkfun Serial LCD based on PIC16LF88
00054         lcd->printf(" ");
00055     } else if(cursorLine == 2){
00056         lcd->printf(" ");
00057         lcd->locate(0,13); // Sparkfun Serial LCD based on PIC16LF88
00058         lcd->printf(">");
00059     }
00060 }
00061 
00062 void Navigator::poll(uint8_t *returnValue)
00063 {
00064     button[0]=pbUp;
00065     button[1]=pbDown;
00066     button[2]=pbSelect;
00067     
00068     if(button[0] == 1 && button[0] != lastButton[0]){
00069         moveUp();
00070     }
00071     if(button[1] == 1 && button[1] != lastButton[1]){
00072         moveDown();
00073     }
00074     if(button[2] == 1 && button[2] != lastButton[2]){ 
00075         if(activeMenu->selections[cursorPos].fun != NULL){
00076             (activeMenu->selections[cursorPos].fun)();
00077         }
00078         
00079         if(returnValue != NULL){
00080            *returnValue = activeMenu->selections[cursorPos].value;
00081         }
00082         
00083         if(activeMenu->selections[cursorPos].childMenu != NULL){
00084             activeMenu = activeMenu->selections[cursorPos].childMenu;
00085             bottom = activeMenu->selections.size();
00086             cursorPos = 0;
00087             cursorLine = 1;
00088         }
00089     }
00090     printMenu();
00091     printCursor();
00092     lastButton[0]=button[0];
00093     lastButton[1]=button[1];
00094     lastButton[2]=button[2];      
00095 }
00096 
00097 void Navigator::moveUp()
00098 {
00099     if(cursorLine == 2){
00100         cursorLine = 1;
00101     }
00102     if(cursorPos != 0){
00103         cursorPos--;
00104     }
00105 }
00106 
00107 void Navigator::moveDown()
00108 {
00109     if(cursorLine == 1){
00110         cursorLine = 2;
00111     }     
00112     if(cursorPos != (bottom-1)){
00113         cursorPos++;
00114     }
00115 }