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 15:18:35 2013 +0000
Revision:
3:920157b558db
Parent:
2:2654dc659298
Child:
4:343f2993a66b
LCD Menu System Success

Who changed what in which revision?

UserRevisionLine numberNew contents of line
pyeh9 1:84d263c8932d 1 #include "Navigator.h"
pyeh9 1:84d263c8932d 2
mshuck 3:920157b558db 3 Navigator::Navigator(Menu *root, RPG &rpg, SerialLCD *lcd) : activeMenu(root), rpg(rpg), 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;
pyeh9 2:2654dc659298 10
pyeh9 2:2654dc659298 11 printMenu();
pyeh9 2:2654dc659298 12 printCursor();
pyeh9 1:84d263c8932d 13 }
mshuck 3:920157b558db 14 DigitalIn pushbutton(p21);
pyeh9 1:84d263c8932d 15 void Navigator::printMenu()
pyeh9 1:84d263c8932d 16 {
mshuck 3:920157b558db 17 lcd->clear();
pyeh9 1:84d263c8932d 18 if(bottom == 1){ // the current Menu only has one selection
mshuck 3:920157b558db 19 lcd->printf("Mark", activeMenu->selections[0].selText);
pyeh9 1:84d263c8932d 20 } else {
pyeh9 1:84d263c8932d 21 if(cursorLine == 2){ // if we're at the bottom
mshuck 3:920157b558db 22 lcd->printf("line2", activeMenu->selections[cursorPos-1].selText);
mshuck 3:920157b558db 23 lcd->setPosition(0,2);
mshuck 3:920157b558db 24 lcd->printf("line22", activeMenu->selections[cursorPos].selText);
pyeh9 1:84d263c8932d 25 } else {
mshuck 3:920157b558db 26 lcd->printf("%s", activeMenu->selections[cursorPos].selText);
mshuck 3:920157b558db 27 lcd->setPosition(0,2);
mshuck 3:920157b558db 28 lcd->printf("%s", activeMenu->selections[cursorPos+1].selText);
pyeh9 1:84d263c8932d 29 }
pyeh9 1:84d263c8932d 30 }
pyeh9 1:84d263c8932d 31 }
pyeh9 1:84d263c8932d 32
pyeh9 1:84d263c8932d 33 void Navigator::printCursor()
pyeh9 1:84d263c8932d 34 {
mshuck 3:920157b558db 35 if(activeMenu->selections[cursorPos].childMenu == NULL) printf("Ncm");
mshuck 3:920157b558db 36 else printf("child menu: %s", activeMenu->selections[cursorPos].childMenu->menuID);
pyeh9 1:84d263c8932d 37
mshuck 3:920157b558db 38 lcd->setPosition(0,0);
pyeh9 1:84d263c8932d 39 if(cursorLine == 1){
mshuck 3:920157b558db 40 lcd->printf(">");
mshuck 3:920157b558db 41 lcd->setPosition(0,1);
mshuck 3:920157b558db 42 lcd->printf(" ");
pyeh9 1:84d263c8932d 43 } else if(cursorLine == 2){
mshuck 3:920157b558db 44 lcd->printf(" ");
mshuck 3:920157b558db 45 lcd->setPosition(0,1);
mshuck 3:920157b558db 46 lcd->printf(">1");
pyeh9 1:84d263c8932d 47 }
pyeh9 1:84d263c8932d 48 }
pyeh9 1:84d263c8932d 49
pyeh9 1:84d263c8932d 50 void Navigator::poll()
pyeh9 1:84d263c8932d 51 {
pyeh9 1:84d263c8932d 52 if((direction = rpg.dir())!=0){ //Get Dir
pyeh9 1:84d263c8932d 53 wait(0.2);
pyeh9 1:84d263c8932d 54 if(direction == 1) moveDown();
pyeh9 1:84d263c8932d 55 else if(direction == -1) moveUp();
pyeh9 1:84d263c8932d 56 }
pyeh9 1:84d263c8932d 57
mshuck 3:920157b558db 58 if ((button == rpg.pb()) && !lastButton){ //prevents multiple selections when button is held down
pyeh9 1:84d263c8932d 59 wait(0.2);
pyeh9 1:84d263c8932d 60 if(activeMenu->selections[cursorPos].fun != NULL){
pyeh9 1:84d263c8932d 61 (activeMenu->selections[cursorPos].fun)();
pyeh9 1:84d263c8932d 62 }
pyeh9 1:84d263c8932d 63 if(activeMenu->selections[cursorPos].childMenu != NULL){
pyeh9 1:84d263c8932d 64 activeMenu = activeMenu->selections[cursorPos].childMenu;
pyeh9 1:84d263c8932d 65 bottom = activeMenu->selections.size();
pyeh9 1:84d263c8932d 66 cursorPos = 0;
pyeh9 1:84d263c8932d 67 cursorLine = 1;
pyeh9 1:84d263c8932d 68 printMenu();
pyeh9 1:84d263c8932d 69 printCursor();
pyeh9 1:84d263c8932d 70 }
pyeh9 1:84d263c8932d 71 }
pyeh9 1:84d263c8932d 72 lastButton = button;
pyeh9 1:84d263c8932d 73 }
pyeh9 1:84d263c8932d 74
pyeh9 1:84d263c8932d 75 void Navigator::moveUp()
pyeh9 1:84d263c8932d 76 {
pyeh9 1:84d263c8932d 77 if(cursorLine == 1){
pyeh9 1:84d263c8932d 78 printMenu();
pyeh9 1:84d263c8932d 79 } else if(cursorLine == 2){
pyeh9 1:84d263c8932d 80 cursorLine = 1;
pyeh9 1:84d263c8932d 81 }
pyeh9 1:84d263c8932d 82
pyeh9 1:84d263c8932d 83 if(cursorPos != 0){
pyeh9 1:84d263c8932d 84 cursorPos--;
pyeh9 1:84d263c8932d 85 printMenu();
pyeh9 1:84d263c8932d 86 }
pyeh9 1:84d263c8932d 87 printCursor();
pyeh9 1:84d263c8932d 88 }
pyeh9 1:84d263c8932d 89
pyeh9 1:84d263c8932d 90 void Navigator::moveDown()
pyeh9 1:84d263c8932d 91 {
pyeh9 1:84d263c8932d 92 if(cursorLine == 1){
pyeh9 1:84d263c8932d 93 cursorLine = 2;
pyeh9 1:84d263c8932d 94 } else if(cursorLine == 2){
pyeh9 1:84d263c8932d 95 printMenu();
pyeh9 1:84d263c8932d 96 }
pyeh9 1:84d263c8932d 97
pyeh9 1:84d263c8932d 98 if(cursorPos != (bottom-1)){
pyeh9 1:84d263c8932d 99 cursorPos++;
pyeh9 1:84d263c8932d 100 printMenu();
pyeh9 1:84d263c8932d 101 }
pyeh9 1:84d263c8932d 102 printCursor();
pyeh9 1:84d263c8932d 103 }