Adjust the LCD_Menu to use the mBed Application board resources
Dependents: class_project_main
Fork of SerialLCD_Menu by
Navigator.cpp@5:70fec61bebaf, 2013-08-04 (annotated)
- Committer:
- mshuck
- Date:
- Sun Aug 04 18:02:39 2013 +0000
- Revision:
- 5:70fec61bebaf
- Parent:
- 4:343f2993a66b
- Child:
- 6:a28c1967bb83
Serial LCD based; removed RPG and hard defined buttons
Who changed what in which revision?
User | Revision | Line number | New 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 | 5:70fec61bebaf | 36 | lcd->setPosition(1,0); // 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 | 5:70fec61bebaf | 41 | lcd->setPosition(1,0); // 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 | |
mshuck | 5:70fec61bebaf | 50 | lcd->setPosition(0,0); // Sparkfun Serial LCD based on PIC16LF88 |
pyeh9 | 1:84d263c8932d | 51 | if(cursorLine == 1){ |
mshuck | 3:920157b558db | 52 | lcd->printf(">"); |
mshuck | 5:70fec61bebaf | 53 | lcd->setPosition(1,0); // 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(" "); |
mshuck | 5:70fec61bebaf | 57 | lcd->setPosition(1,0); // 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 | { |
mshuck | 4:343f2993a66b | 64 | |
mshuck | 4:343f2993a66b | 65 | if(pbUp == 0){ |
mshuck | 4:343f2993a66b | 66 | wait(0.2); |
mshuck | 4:343f2993a66b | 67 | moveUp(); |
pyeh9 | 1:84d263c8932d | 68 | } |
mshuck | 4:343f2993a66b | 69 | if(pbDown == 0){ |
pyeh9 | 1:84d263c8932d | 70 | wait(0.2); |
mshuck | 4:343f2993a66b | 71 | moveDown(); |
mshuck | 4:343f2993a66b | 72 | } |
mshuck | 4:343f2993a66b | 73 | if(pbSelect == 0){ |
mshuck | 4:343f2993a66b | 74 | wait(0.2); |
mshuck | 4:343f2993a66b | 75 | |
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 | } |
pyeh9 | 1:84d263c8932d | 89 | lastButton = button; |
mshuck | 4:343f2993a66b | 90 | |
pyeh9 | 1:84d263c8932d | 91 | } |
pyeh9 | 1:84d263c8932d | 92 | |
pyeh9 | 1:84d263c8932d | 93 | void Navigator::moveUp() |
pyeh9 | 1:84d263c8932d | 94 | { |
pyeh9 | 1:84d263c8932d | 95 | if(cursorLine == 1){ |
pyeh9 | 1:84d263c8932d | 96 | printMenu(); |
pyeh9 | 1:84d263c8932d | 97 | } else 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 | printMenu(); |
pyeh9 | 1:84d263c8932d | 104 | } |
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; |
pyeh9 | 1:84d263c8932d | 112 | } else if(cursorLine == 2){ |
pyeh9 | 1:84d263c8932d | 113 | printMenu(); |
pyeh9 | 1:84d263c8932d | 114 | } |
pyeh9 | 1:84d263c8932d | 115 | |
pyeh9 | 1:84d263c8932d | 116 | if(cursorPos != (bottom-1)){ |
pyeh9 | 1:84d263c8932d | 117 | cursorPos++; |
pyeh9 | 1:84d263c8932d | 118 | printMenu(); |
pyeh9 | 1:84d263c8932d | 119 | } |
pyeh9 | 1:84d263c8932d | 120 | printCursor(); |
pyeh9 | 1:84d263c8932d | 121 | } |