Adjust the LCD_Menu to use the mBed Application board resources

Dependents:   class_project_main

Fork of SerialLCD_Menu by Mark Shuck

Committer:
mshuck
Date:
Sun Aug 04 17:19:36 2013 +0000
Revision:
4:343f2993a66b
Parent:
3:920157b558db
Child:
5:70fec61bebaf
Removed RPG and included push buttons

Who changed what in which revision?

UserRevisionLine numberNew contents of line
pyeh9 1:84d263c8932d 1 #include "Navigator.h"
pyeh9 1:84d263c8932d 2
mshuck 4:343f2993a66b 3 Navigator::Navigator(Menu *root, SerialLCD *lcd) : activeMenu(root), lcd(lcd)
pyeh9 1:84d263c8932d 4 {
pyeh9 1:84d263c8932d 5 bottom = root->selections.size();
pyeh9 1:84d263c8932d 6 cursorPos = 0;
pyeh9 1:84d263c8932d 7 cursorLine = 1;
pyeh9 1:84d263c8932d 8 button = 0;
pyeh9 1:84d263c8932d 9 lastButton = 0;
mshuck 4:343f2993a66b 10 setButtons();
pyeh9 2:2654dc659298 11 printMenu();
pyeh9 2:2654dc659298 12 printCursor();
pyeh9 1:84d263c8932d 13 }
mshuck 4:343f2993a66b 14
mshuck 4:343f2993a66b 15 DigitalIn pbUp(p21);
mshuck 4:343f2993a66b 16 DigitalIn pbDown(p22);
mshuck 4:343f2993a66b 17 DigitalIn pbSelect(p23);
mshuck 4:343f2993a66b 18
mshuck 4:343f2993a66b 19
mshuck 4:343f2993a66b 20 void Navigator::setButtons()
mshuck 4:343f2993a66b 21 {
mshuck 4:343f2993a66b 22 pbUp.mode(PullUp);
mshuck 4:343f2993a66b 23 pbDown.mode(PullUp);
mshuck 4:343f2993a66b 24 pbSelect.mode(PullUp);
mshuck 4:343f2993a66b 25 }
mshuck 4:343f2993a66b 26
pyeh9 1:84d263c8932d 27 void Navigator::printMenu()
pyeh9 1:84d263c8932d 28 {
mshuck 3:920157b558db 29 lcd->clear();
pyeh9 1:84d263c8932d 30 if(bottom == 1){ // the current Menu only has one selection
mshuck 4:343f2993a66b 31 lcd->printf("%s", activeMenu->selections[0].selText);
pyeh9 1:84d263c8932d 32 } else {
mshuck 4:343f2993a66b 33 if(cursorLine == 2){
mshuck 4:343f2993a66b 34 // moving down in menu
mshuck 4:343f2993a66b 35 lcd->printf("%s", activeMenu->selections[cursorPos-1].selText);
mshuck 4:343f2993a66b 36 lcd->setPosition(0,1); // Sparkfun Serial LCD based on PIC16LF88
mshuck 4:343f2993a66b 37 lcd->printf("%s", activeMenu->selections[cursorPos].selText);
pyeh9 1:84d263c8932d 38 } else {
mshuck 4:343f2993a66b 39 // moving up in menu
mshuck 3:920157b558db 40 lcd->printf("%s", activeMenu->selections[cursorPos].selText);
mshuck 4:343f2993a66b 41 lcd->setPosition(0,1); // Sparkfun Serial LCD based on PIC16LF88
mshuck 3:920157b558db 42 lcd->printf("%s", activeMenu->selections[cursorPos+1].selText);
pyeh9 1:84d263c8932d 43 }
pyeh9 1:84d263c8932d 44 }
pyeh9 1:84d263c8932d 45 }
pyeh9 1:84d263c8932d 46
pyeh9 1:84d263c8932d 47 void Navigator::printCursor()
pyeh9 1:84d263c8932d 48 {
mshuck 4:343f2993a66b 49 //if(activeMenu->selections[cursorPos].childMenu == NULL) printf("No Child Menu");
mshuck 4:343f2993a66b 50 //else printf("%s", activeMenu->selections[cursorPos].childMenu->menuID);
pyeh9 1:84d263c8932d 51
mshuck 3:920157b558db 52 lcd->setPosition(0,0);
pyeh9 1:84d263c8932d 53 if(cursorLine == 1){
mshuck 3:920157b558db 54 lcd->printf(">");
mshuck 4:343f2993a66b 55 lcd->setPosition(0,2);
mshuck 3:920157b558db 56 lcd->printf(" ");
pyeh9 1:84d263c8932d 57 } else if(cursorLine == 2){
mshuck 3:920157b558db 58 lcd->printf(" ");
mshuck 4:343f2993a66b 59 lcd->setPosition(0,3);
mshuck 4:343f2993a66b 60 lcd->printf(">");
pyeh9 1:84d263c8932d 61 }
pyeh9 1:84d263c8932d 62 }
pyeh9 1:84d263c8932d 63
pyeh9 1:84d263c8932d 64 void Navigator::poll()
pyeh9 1:84d263c8932d 65 {
mshuck 4:343f2993a66b 66
mshuck 4:343f2993a66b 67 if(pbUp == 0){
mshuck 4:343f2993a66b 68 wait(0.2);
mshuck 4:343f2993a66b 69 moveUp();
pyeh9 1:84d263c8932d 70 }
mshuck 4:343f2993a66b 71 if(pbDown == 0){
pyeh9 1:84d263c8932d 72 wait(0.2);
mshuck 4:343f2993a66b 73 moveDown();
mshuck 4:343f2993a66b 74 }
mshuck 4:343f2993a66b 75 if(pbSelect == 0){
mshuck 4:343f2993a66b 76 wait(0.2);
mshuck 4:343f2993a66b 77
pyeh9 1:84d263c8932d 78 if(activeMenu->selections[cursorPos].fun != NULL){
pyeh9 1:84d263c8932d 79 (activeMenu->selections[cursorPos].fun)();
pyeh9 1:84d263c8932d 80 }
mshuck 4:343f2993a66b 81
pyeh9 1:84d263c8932d 82 if(activeMenu->selections[cursorPos].childMenu != NULL){
pyeh9 1:84d263c8932d 83 activeMenu = activeMenu->selections[cursorPos].childMenu;
pyeh9 1:84d263c8932d 84 bottom = activeMenu->selections.size();
pyeh9 1:84d263c8932d 85 cursorPos = 0;
pyeh9 1:84d263c8932d 86 cursorLine = 1;
pyeh9 1:84d263c8932d 87 printMenu();
pyeh9 1:84d263c8932d 88 printCursor();
pyeh9 1:84d263c8932d 89 }
pyeh9 1:84d263c8932d 90 }
pyeh9 1:84d263c8932d 91 lastButton = button;
mshuck 4:343f2993a66b 92
pyeh9 1:84d263c8932d 93 }
pyeh9 1:84d263c8932d 94
pyeh9 1:84d263c8932d 95 void Navigator::moveUp()
pyeh9 1:84d263c8932d 96 {
pyeh9 1:84d263c8932d 97 if(cursorLine == 1){
pyeh9 1:84d263c8932d 98 printMenu();
pyeh9 1:84d263c8932d 99 } else if(cursorLine == 2){
pyeh9 1:84d263c8932d 100 cursorLine = 1;
pyeh9 1:84d263c8932d 101 }
pyeh9 1:84d263c8932d 102
pyeh9 1:84d263c8932d 103 if(cursorPos != 0){
pyeh9 1:84d263c8932d 104 cursorPos--;
pyeh9 1:84d263c8932d 105 printMenu();
pyeh9 1:84d263c8932d 106 }
pyeh9 1:84d263c8932d 107 printCursor();
pyeh9 1:84d263c8932d 108 }
pyeh9 1:84d263c8932d 109
pyeh9 1:84d263c8932d 110 void Navigator::moveDown()
pyeh9 1:84d263c8932d 111 {
pyeh9 1:84d263c8932d 112 if(cursorLine == 1){
pyeh9 1:84d263c8932d 113 cursorLine = 2;
pyeh9 1:84d263c8932d 114 } else if(cursorLine == 2){
pyeh9 1:84d263c8932d 115 printMenu();
pyeh9 1:84d263c8932d 116 }
pyeh9 1:84d263c8932d 117
pyeh9 1:84d263c8932d 118 if(cursorPos != (bottom-1)){
pyeh9 1:84d263c8932d 119 cursorPos++;
pyeh9 1:84d263c8932d 120 printMenu();
pyeh9 1:84d263c8932d 121 }
pyeh9 1:84d263c8932d 122 printCursor();
pyeh9 1:84d263c8932d 123 }