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:
Fri Aug 30 01:22:00 2013 +0000
Revision:
7:9b0298adab99
Parent:
6:a28c1967bb83
Child:
8:a6dc9b1525c7
Child:
10:379a279cd90c
Changed spacing issue
;

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
pyeh9 1:84d263c8932d 62 void Navigator::poll()
pyeh9 1:84d263c8932d 63 {
jakowisp 6:a28c1967bb83 64 wait_ms(10);
jakowisp 6:a28c1967bb83 65 button[0]=pbUp;
jakowisp 6:a28c1967bb83 66 button[1]=pbDown;
jakowisp 6:a28c1967bb83 67 button[2]=pbSelect;
jakowisp 6:a28c1967bb83 68
jakowisp 6:a28c1967bb83 69 if(button[0] == 1 && button[0] != lastButton[0]){
mshuck 4:343f2993a66b 70 moveUp();
pyeh9 1:84d263c8932d 71 }
jakowisp 6:a28c1967bb83 72 if(button[1] == 1 && button[1] != lastButton[1]){
mshuck 4:343f2993a66b 73 moveDown();
mshuck 4:343f2993a66b 74 }
jakowisp 6:a28c1967bb83 75 if(button[2] == 1 && button[2] != lastButton[2]){
pyeh9 1:84d263c8932d 76 if(activeMenu->selections[cursorPos].fun != NULL){
pyeh9 1:84d263c8932d 77 (activeMenu->selections[cursorPos].fun)();
pyeh9 1:84d263c8932d 78 }
mshuck 4:343f2993a66b 79
pyeh9 1:84d263c8932d 80 if(activeMenu->selections[cursorPos].childMenu != NULL){
pyeh9 1:84d263c8932d 81 activeMenu = activeMenu->selections[cursorPos].childMenu;
pyeh9 1:84d263c8932d 82 bottom = activeMenu->selections.size();
pyeh9 1:84d263c8932d 83 cursorPos = 0;
pyeh9 1:84d263c8932d 84 cursorLine = 1;
pyeh9 1:84d263c8932d 85 printMenu();
pyeh9 1:84d263c8932d 86 printCursor();
pyeh9 1:84d263c8932d 87 }
pyeh9 1:84d263c8932d 88 }
jakowisp 6:a28c1967bb83 89 lastButton[0]=button[0];
jakowisp 6:a28c1967bb83 90 lastButton[1]=button[1];
jakowisp 6:a28c1967bb83 91 lastButton[2]=button[2];
mshuck 4:343f2993a66b 92
pyeh9 1:84d263c8932d 93 }
pyeh9 1:84d263c8932d 94
pyeh9 1:84d263c8932d 95 void Navigator::moveUp()
pyeh9 1:84d263c8932d 96 {
jakowisp 6:a28c1967bb83 97 if(cursorLine == 2){
pyeh9 1:84d263c8932d 98 cursorLine = 1;
pyeh9 1:84d263c8932d 99 }
pyeh9 1:84d263c8932d 100
pyeh9 1:84d263c8932d 101 if(cursorPos != 0){
pyeh9 1:84d263c8932d 102 cursorPos--;
pyeh9 1:84d263c8932d 103 }
jakowisp 6:a28c1967bb83 104 printMenu();
pyeh9 1:84d263c8932d 105 printCursor();
pyeh9 1:84d263c8932d 106 }
pyeh9 1:84d263c8932d 107
pyeh9 1:84d263c8932d 108 void Navigator::moveDown()
pyeh9 1:84d263c8932d 109 {
pyeh9 1:84d263c8932d 110 if(cursorLine == 1){
pyeh9 1:84d263c8932d 111 cursorLine = 2;
jakowisp 6:a28c1967bb83 112 }
pyeh9 1:84d263c8932d 113 if(cursorPos != (bottom-1)){
pyeh9 1:84d263c8932d 114 cursorPos++;
pyeh9 1:84d263c8932d 115 }
jakowisp 6:a28c1967bb83 116 printMenu();
pyeh9 1:84d263c8932d 117 printCursor();
pyeh9 1:84d263c8932d 118 }