Adjust the LCD_Menu to use the mBed Application board resources

Dependents:   class_project_main

Fork of SerialLCD_Menu by Mark Shuck

Committer:
jakowisp
Date:
Thu Sep 12 05:52:18 2013 +0000
Revision:
13:98d452550cbe
Parent:
12:5c543a40d9af
Parent:
9:59ec5b7b059d
still merging; ;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
pyeh9 1:84d263c8932d 1 #include "Navigator.h"
pyeh9 1:84d263c8932d 2
jakowisp 6:a28c1967bb83 3 Navigator::Navigator(Menu *root, C12832_LCD *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;
jakowisp 6:a28c1967bb83 8 lastButton[0] = 0;
jakowisp 6:a28c1967bb83 9 lastButton[1] = 0;
jakowisp 6:a28c1967bb83 10 lastButton[2] = 0;
jakowisp 6:a28c1967bb83 11
mshuck 4:343f2993a66b 12 setButtons();
pyeh9 2:2654dc659298 13 printMenu();
pyeh9 2:2654dc659298 14 printCursor();
pyeh9 1:84d263c8932d 15 }
mshuck 4:343f2993a66b 16
jakowisp 6:a28c1967bb83 17 DigitalIn pbUp(p15);
jakowisp 6:a28c1967bb83 18 DigitalIn pbDown(p12);
jakowisp 6:a28c1967bb83 19 DigitalIn pbSelect(p14);
mshuck 4:343f2993a66b 20
mshuck 4:343f2993a66b 21
mshuck 4:343f2993a66b 22 void Navigator::setButtons()
mshuck 4:343f2993a66b 23 {
mshuck 4:343f2993a66b 24 }
mshuck 4:343f2993a66b 25
pyeh9 1:84d263c8932d 26 void Navigator::printMenu()
pyeh9 1:84d263c8932d 27 {
jakowisp 6:a28c1967bb83 28 lcd->cls();
jakowisp 7:9b0298adab99 29 lcd->locate(10,0);
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);
jakowisp 7:9b0298adab99 36 lcd->locate(10,13); // 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);
jakowisp 7:9b0298adab99 41 lcd->locate(10,13); // 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 {
pyeh9 1:84d263c8932d 49
jakowisp 6:a28c1967bb83 50 lcd->locate(0,0); // Sparkfun Serial LCD based on PIC16LF88
pyeh9 1:84d263c8932d 51 if(cursorLine == 1){
mshuck 3:920157b558db 52 lcd->printf(">");
jakowisp 6:a28c1967bb83 53 lcd->locate(0,13); // Sparkfun Serial LCD based on PIC16LF88
mshuck 3:920157b558db 54 lcd->printf(" ");
pyeh9 1:84d263c8932d 55 } else if(cursorLine == 2){
mshuck 3:920157b558db 56 lcd->printf(" ");
jakowisp 6:a28c1967bb83 57 lcd->locate(0,13); // Sparkfun Serial LCD based on PIC16LF88
mshuck 4:343f2993a66b 58 lcd->printf(">");
pyeh9 1:84d263c8932d 59 }
pyeh9 1:84d263c8932d 60 }
pyeh9 1:84d263c8932d 61
jakowisp 11:af7687f1a985 62 void Navigator::poll(uint8_t *returnValue)
pyeh9 1:84d263c8932d 63 {
jakowisp 6:a28c1967bb83 64 button[0]=pbUp;
jakowisp 6:a28c1967bb83 65 button[1]=pbDown;
jakowisp 6:a28c1967bb83 66 button[2]=pbSelect;
jakowisp 6:a28c1967bb83 67
jakowisp 6:a28c1967bb83 68 if(button[0] == 1 && button[0] != lastButton[0]){
mshuck 4:343f2993a66b 69 moveUp();
pyeh9 1:84d263c8932d 70 }
jakowisp 6:a28c1967bb83 71 if(button[1] == 1 && button[1] != lastButton[1]){
mshuck 4:343f2993a66b 72 moveDown();
mshuck 4:343f2993a66b 73 }
jakowisp 6:a28c1967bb83 74 if(button[2] == 1 && button[2] != lastButton[2]){
pyeh9 1:84d263c8932d 75 if(activeMenu->selections[cursorPos].fun != NULL){
pyeh9 1:84d263c8932d 76 (activeMenu->selections[cursorPos].fun)();
pyeh9 1:84d263c8932d 77 }
mshuck 4:343f2993a66b 78
jakowisp 11:af7687f1a985 79 if(returnValue != NULL){
jakowisp 11:af7687f1a985 80 *returnValue = activeMenu->selections[cursorPos].value;
jakowisp 11:af7687f1a985 81 }
jakowisp 11:af7687f1a985 82
pyeh9 1:84d263c8932d 83 if(activeMenu->selections[cursorPos].childMenu != NULL){
pyeh9 1:84d263c8932d 84 activeMenu = activeMenu->selections[cursorPos].childMenu;
pyeh9 1:84d263c8932d 85 bottom = activeMenu->selections.size();
pyeh9 1:84d263c8932d 86 cursorPos = 0;
pyeh9 1:84d263c8932d 87 cursorLine = 1;
pyeh9 1:84d263c8932d 88 }
pyeh9 1:84d263c8932d 89 }
jakowisp 8:a6dc9b1525c7 90 printMenu();
jakowisp 8:a6dc9b1525c7 91 printCursor();
jakowisp 6:a28c1967bb83 92 lastButton[0]=button[0];
jakowisp 6:a28c1967bb83 93 lastButton[1]=button[1];
jakowisp 12:5c543a40d9af 94 lastButton[2]=button[2];
pyeh9 1:84d263c8932d 95 }
pyeh9 1:84d263c8932d 96
pyeh9 1:84d263c8932d 97 void Navigator::moveUp()
pyeh9 1:84d263c8932d 98 {
jakowisp 6:a28c1967bb83 99 if(cursorLine == 2){
pyeh9 1:84d263c8932d 100 cursorLine = 1;
pyeh9 1:84d263c8932d 101 }
pyeh9 1:84d263c8932d 102 if(cursorPos != 0){
pyeh9 1:84d263c8932d 103 cursorPos--;
pyeh9 1:84d263c8932d 104 }
pyeh9 1:84d263c8932d 105 }
pyeh9 1:84d263c8932d 106
pyeh9 1:84d263c8932d 107 void Navigator::moveDown()
pyeh9 1:84d263c8932d 108 {
pyeh9 1:84d263c8932d 109 if(cursorLine == 1){
pyeh9 1:84d263c8932d 110 cursorLine = 2;
jakowisp 6:a28c1967bb83 111 }
pyeh9 1:84d263c8932d 112 if(cursorPos != (bottom-1)){
pyeh9 1:84d263c8932d 113 cursorPos++;
pyeh9 1:84d263c8932d 114 }
jakowisp 11:af7687f1a985 115 }