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:33:18 2013 +0000
Revision:
11:af7687f1a985
Parent:
10:379a279cd90c
Child:
12:5c543a40d9af
Added ability to set a uint8_t directly, instead of having a multiple wrapper functions.

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 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
jakowisp 11:af7687f1a985 80 if(returnValue != NULL){
jakowisp 11:af7687f1a985 81 *returnValue = activeMenu->selections[cursorPos].value;
jakowisp 11:af7687f1a985 82 }
jakowisp 11:af7687f1a985 83
pyeh9 1:84d263c8932d 84 if(activeMenu->selections[cursorPos].childMenu != NULL){
pyeh9 1:84d263c8932d 85 activeMenu = activeMenu->selections[cursorPos].childMenu;
pyeh9 1:84d263c8932d 86 bottom = activeMenu->selections.size();
pyeh9 1:84d263c8932d 87 cursorPos = 0;
pyeh9 1:84d263c8932d 88 cursorLine = 1;
pyeh9 1:84d263c8932d 89 }
pyeh9 1:84d263c8932d 90 }
jakowisp 10:379a279cd90c 91 printMenu();
jakowisp 10:379a279cd90c 92 printCursor();
jakowisp 6:a28c1967bb83 93 lastButton[0]=button[0];
jakowisp 6:a28c1967bb83 94 lastButton[1]=button[1];
jakowisp 6:a28c1967bb83 95 lastButton[2]=button[2];
mshuck 4:343f2993a66b 96
pyeh9 1:84d263c8932d 97 }
pyeh9 1:84d263c8932d 98
pyeh9 1:84d263c8932d 99 void Navigator::moveUp()
pyeh9 1:84d263c8932d 100 {
jakowisp 6:a28c1967bb83 101 if(cursorLine == 2){
pyeh9 1:84d263c8932d 102 cursorLine = 1;
pyeh9 1:84d263c8932d 103 }
pyeh9 1:84d263c8932d 104
pyeh9 1:84d263c8932d 105 if(cursorPos != 0){
pyeh9 1:84d263c8932d 106 cursorPos--;
pyeh9 1:84d263c8932d 107 }
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;
jakowisp 6:a28c1967bb83 114 }
pyeh9 1:84d263c8932d 115 if(cursorPos != (bottom-1)){
pyeh9 1:84d263c8932d 116 cursorPos++;
pyeh9 1:84d263c8932d 117 }
jakowisp 11:af7687f1a985 118 }