Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Navigator.cpp@3:3c6551467d77, 2019-12-03 (annotated)
- Committer:
- austinterrell
- Date:
- Tue Dec 03 19:37:11 2019 +0000
- Revision:
- 3:3c6551467d77
- Parent:
- 2:2654dc659298
Removed some unwanted debug code
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 | |
pyeh9 | 1:84d263c8932d | 3 | Navigator::Navigator(Menu *root, RPG &rpg, TextLCD *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 | } |
pyeh9 | 1:84d263c8932d | 14 | |
pyeh9 | 1:84d263c8932d | 15 | void Navigator::printMenu() |
pyeh9 | 1:84d263c8932d | 16 | { |
pyeh9 | 1:84d263c8932d | 17 | lcd->cls(); |
pyeh9 | 1:84d263c8932d | 18 | if(bottom == 1){ // the current Menu only has one selection |
pyeh9 | 1:84d263c8932d | 19 | lcd->printf("%s\n", activeMenu->selections[0].selText); |
pyeh9 | 1:84d263c8932d | 20 | } else { |
pyeh9 | 1:84d263c8932d | 21 | if(cursorLine == 2){ // if we're at the bottom |
pyeh9 | 1:84d263c8932d | 22 | lcd->printf("%s\n", activeMenu->selections[cursorPos-1].selText); |
pyeh9 | 1:84d263c8932d | 23 | lcd->printf("%s\n", activeMenu->selections[cursorPos].selText); |
pyeh9 | 1:84d263c8932d | 24 | } else { |
pyeh9 | 1:84d263c8932d | 25 | lcd->printf("%s\n", activeMenu->selections[cursorPos].selText); |
pyeh9 | 1:84d263c8932d | 26 | lcd->printf("%s\n", activeMenu->selections[cursorPos+1].selText); |
pyeh9 | 1:84d263c8932d | 27 | } |
pyeh9 | 1:84d263c8932d | 28 | } |
pyeh9 | 1:84d263c8932d | 29 | } |
pyeh9 | 1:84d263c8932d | 30 | |
pyeh9 | 1:84d263c8932d | 31 | void Navigator::printCursor() |
austinterrell | 3:3c6551467d77 | 32 | { |
pyeh9 | 1:84d263c8932d | 33 | lcd->locate(0,0); |
pyeh9 | 1:84d263c8932d | 34 | if(cursorLine == 1){ |
pyeh9 | 1:84d263c8932d | 35 | lcd->putc('>'); |
pyeh9 | 1:84d263c8932d | 36 | lcd->locate(0,1); |
pyeh9 | 1:84d263c8932d | 37 | lcd->putc(' '); |
pyeh9 | 1:84d263c8932d | 38 | } else if(cursorLine == 2){ |
pyeh9 | 1:84d263c8932d | 39 | lcd->putc(' '); |
pyeh9 | 1:84d263c8932d | 40 | lcd->locate(0,1); |
pyeh9 | 1:84d263c8932d | 41 | lcd->putc('>'); |
pyeh9 | 1:84d263c8932d | 42 | } |
pyeh9 | 1:84d263c8932d | 43 | } |
pyeh9 | 1:84d263c8932d | 44 | |
pyeh9 | 1:84d263c8932d | 45 | void Navigator::poll() |
pyeh9 | 1:84d263c8932d | 46 | { |
pyeh9 | 1:84d263c8932d | 47 | if((direction = rpg.dir())!=0){ //Get Dir |
pyeh9 | 1:84d263c8932d | 48 | wait(0.2); |
pyeh9 | 1:84d263c8932d | 49 | if(direction == 1) moveDown(); |
pyeh9 | 1:84d263c8932d | 50 | else if(direction == -1) moveUp(); |
pyeh9 | 1:84d263c8932d | 51 | } |
pyeh9 | 1:84d263c8932d | 52 | |
pyeh9 | 1:84d263c8932d | 53 | if ((button = rpg.pb()) && !lastButton){ //prevents multiple selections when button is held down |
pyeh9 | 1:84d263c8932d | 54 | wait(0.2); |
pyeh9 | 1:84d263c8932d | 55 | if(activeMenu->selections[cursorPos].fun != NULL){ |
pyeh9 | 1:84d263c8932d | 56 | (activeMenu->selections[cursorPos].fun)(); |
pyeh9 | 1:84d263c8932d | 57 | } |
pyeh9 | 1:84d263c8932d | 58 | if(activeMenu->selections[cursorPos].childMenu != NULL){ |
pyeh9 | 1:84d263c8932d | 59 | activeMenu = activeMenu->selections[cursorPos].childMenu; |
pyeh9 | 1:84d263c8932d | 60 | bottom = activeMenu->selections.size(); |
pyeh9 | 1:84d263c8932d | 61 | cursorPos = 0; |
pyeh9 | 1:84d263c8932d | 62 | cursorLine = 1; |
pyeh9 | 1:84d263c8932d | 63 | printMenu(); |
pyeh9 | 1:84d263c8932d | 64 | printCursor(); |
pyeh9 | 1:84d263c8932d | 65 | } |
pyeh9 | 1:84d263c8932d | 66 | } |
pyeh9 | 1:84d263c8932d | 67 | lastButton = button; |
pyeh9 | 1:84d263c8932d | 68 | } |
pyeh9 | 1:84d263c8932d | 69 | |
pyeh9 | 1:84d263c8932d | 70 | void Navigator::moveUp() |
pyeh9 | 1:84d263c8932d | 71 | { |
pyeh9 | 1:84d263c8932d | 72 | if(cursorLine == 1){ |
pyeh9 | 1:84d263c8932d | 73 | printMenu(); |
pyeh9 | 1:84d263c8932d | 74 | } else if(cursorLine == 2){ |
pyeh9 | 1:84d263c8932d | 75 | cursorLine = 1; |
pyeh9 | 1:84d263c8932d | 76 | } |
pyeh9 | 1:84d263c8932d | 77 | |
pyeh9 | 1:84d263c8932d | 78 | if(cursorPos != 0){ |
pyeh9 | 1:84d263c8932d | 79 | cursorPos--; |
pyeh9 | 1:84d263c8932d | 80 | printMenu(); |
pyeh9 | 1:84d263c8932d | 81 | } |
pyeh9 | 1:84d263c8932d | 82 | printCursor(); |
pyeh9 | 1:84d263c8932d | 83 | } |
pyeh9 | 1:84d263c8932d | 84 | |
pyeh9 | 1:84d263c8932d | 85 | void Navigator::moveDown() |
pyeh9 | 1:84d263c8932d | 86 | { |
pyeh9 | 1:84d263c8932d | 87 | if(cursorLine == 1){ |
pyeh9 | 1:84d263c8932d | 88 | cursorLine = 2; |
pyeh9 | 1:84d263c8932d | 89 | } else if(cursorLine == 2){ |
pyeh9 | 1:84d263c8932d | 90 | printMenu(); |
pyeh9 | 1:84d263c8932d | 91 | } |
pyeh9 | 1:84d263c8932d | 92 | |
pyeh9 | 1:84d263c8932d | 93 | if(cursorPos != (bottom-1)){ |
pyeh9 | 1:84d263c8932d | 94 | cursorPos++; |
pyeh9 | 1:84d263c8932d | 95 | printMenu(); |
pyeh9 | 1:84d263c8932d | 96 | } |
pyeh9 | 1:84d263c8932d | 97 | printCursor(); |
pyeh9 | 1:84d263c8932d | 98 | } |