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.
Fork of Menu by
Navigator.h@8:fbaeab73fe1a, 2015-01-16 (annotated)
- Committer:
- charly
- Date:
- Fri Jan 16 22:23:34 2015 +0000
- Revision:
- 8:fbaeab73fe1a
- Parent:
- 5:91b1bc68290b
- Child:
- 9:c9df0b33d176
Save CurrentSelection of Menu to get back to the correct position.
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| pyeh9 | 1:84d263c8932d | 1 | #ifndef NAVIGATOR_H |
| pyeh9 | 1:84d263c8932d | 2 | #define NAVIGATOR_H |
| pyeh9 | 1:84d263c8932d | 3 | |
| pyeh9 | 1:84d263c8932d | 4 | #include "mbed.h" |
| pyeh9 | 1:84d263c8932d | 5 | #include "Menu.h" |
| pyeh9 | 1:84d263c8932d | 6 | #include "TextLCD.h" |
| charly | 4:67097127da6c | 7 | |
| charly | 5:91b1bc68290b | 8 | /** Class Navigator does the Navigation in the menu and updates the display. |
| charly | 5:91b1bc68290b | 9 | * Interaction from outside is done by calling moveUp(), moveDown() or select(). |
| charly | 5:91b1bc68290b | 10 | * Could be done by an RPG or via Buttons. |
| charly | 5:91b1bc68290b | 11 | * |
| charly | 5:91b1bc68290b | 12 | * Example: |
| charly | 5:91b1bc68290b | 13 | * |
| charly | 5:91b1bc68290b | 14 | * @code |
| charly | 5:91b1bc68290b | 15 | * |
| charly | 5:91b1bc68290b | 16 | * #include "Selection.h" |
| charly | 5:91b1bc68290b | 17 | * #include "Menu.h" |
| charly | 5:91b1bc68290b | 18 | * #include "Navigator.h" |
| charly | 5:91b1bc68290b | 19 | * #include <vector> |
| charly | 5:91b1bc68290b | 20 | * #include <string> |
| charly | 5:91b1bc68290b | 21 | * PinDetect T1 ( p21,PullNone); //Button 1 - UP |
| charly | 5:91b1bc68290b | 22 | * PinDetect T2 ( p22,PullNone); //Button 2 - Down |
| charly | 5:91b1bc68290b | 23 | * PinDetect T3 ( p23,PullNone); //Button 3 - Select |
| charly | 5:91b1bc68290b | 24 | * ... |
| charly | 5:91b1bc68290b | 25 | * // Here is the heart of the system: the navigator. |
| charly | 5:91b1bc68290b | 26 | * // The navigator takes in a reference to the root and a reference to an lcd |
| charly | 5:91b1bc68290b | 27 | * Navigator navigator(&rootMenu, &lcd); |
| charly | 5:91b1bc68290b | 28 | * |
| charly | 5:91b1bc68290b | 29 | * // attach the methods for buttons Up, Down, Select to the navigator |
| charly | 5:91b1bc68290b | 30 | * T1.attach_asserted( &navigator, &Navigator::moveUp); |
| charly | 5:91b1bc68290b | 31 | * T2.attach_asserted( &navigator, &Navigator::moveDown); |
| charly | 5:91b1bc68290b | 32 | * T3.attach_asserted( &navigator, &Navigator::select); |
| charly | 5:91b1bc68290b | 33 | * // do whatever you need to do in your main-loop. |
| charly | 5:91b1bc68290b | 34 | * while( 1 ) { |
| charly | 5:91b1bc68290b | 35 | * led4 = !led4; |
| charly | 5:91b1bc68290b | 36 | * wait( 1 ); |
| charly | 5:91b1bc68290b | 37 | * } |
| charly | 5:91b1bc68290b | 38 | * @endcode |
| charly | 5:91b1bc68290b | 39 | */ |
| charly | 4:67097127da6c | 40 | class Navigator |
| charly | 4:67097127da6c | 41 | { |
| charly | 4:67097127da6c | 42 | |
| charly | 4:67097127da6c | 43 | public: |
| charly | 4:67097127da6c | 44 | Navigator(Menu *, TextLCD_Base *); |
| charly | 5:91b1bc68290b | 45 | Menu *activeMenu; // the current menu - can change when Menue-item is selected on selection with child menu |
| charly | 4:67097127da6c | 46 | |
| charly | 4:67097127da6c | 47 | TextLCD_Base *lcd; |
| charly | 4:67097127da6c | 48 | |
| charly | 4:67097127da6c | 49 | /** no longer used! |
| charly | 4:67097127da6c | 50 | * |
| charly | 4:67097127da6c | 51 | */ |
| charly | 4:67097127da6c | 52 | void poll(); // no longer needed! |
| pyeh9 | 1:84d263c8932d | 53 | |
| charly | 5:91b1bc68290b | 54 | /** Move up one line in menu. |
| charly | 5:91b1bc68290b | 55 | * call this method when user moves up one line. |
| charly | 5:91b1bc68290b | 56 | * can be triggered by RPG or Button (PinDetect) or otherwise. |
| charly | 4:67097127da6c | 57 | */ |
| charly | 4:67097127da6c | 58 | void moveUp(); |
| charly | 4:67097127da6c | 59 | |
| charly | 5:91b1bc68290b | 60 | /** Move down one line in menu. |
| charly | 5:91b1bc68290b | 61 | * call this method when user moves down one line. |
| charly | 5:91b1bc68290b | 62 | * can be triggered by RPG or Button (PinDetect) or otherwise. |
| charly | 4:67097127da6c | 63 | */ |
| charly | 4:67097127da6c | 64 | void moveDown(); |
| charly | 4:67097127da6c | 65 | |
| charly | 5:91b1bc68290b | 66 | /** User presses Select Button. |
| charly | 5:91b1bc68290b | 67 | * call this method when user wants to select an item. |
| charly | 5:91b1bc68290b | 68 | * can be triggered by RPG or Button (PinDetect) or otherwise. |
| charly | 4:67097127da6c | 69 | */ |
| charly | 4:67097127da6c | 70 | void select(); |
| charly | 4:67097127da6c | 71 | |
| charly | 4:67097127da6c | 72 | /** print the menu on LCD |
| charly | 4:67097127da6c | 73 | */ |
| charly | 4:67097127da6c | 74 | void printMenu(); |
| charly | 4:67097127da6c | 75 | |
| charly | 4:67097127da6c | 76 | /** print cursor on the beginning of line |
| charly | 4:67097127da6c | 77 | */ |
| charly | 4:67097127da6c | 78 | void printCursor(); |
| charly | 5:91b1bc68290b | 79 | |
| charly | 5:91b1bc68290b | 80 | private: |
| charly | 5:91b1bc68290b | 81 | int _display_rows; // number of rows the LCD can display |
| charly | 8:fbaeab73fe1a | 82 | int _cursorPos; // what selection the cursor points to |
| charly | 8:fbaeab73fe1a | 83 | int _cursorLine; // what line of the lcd the cursor is on. 1 = first line, 2 = second line |
| charly | 5:91b1bc68290b | 84 | |
| charly | 5:91b1bc68290b | 85 | |
| pyeh9 | 1:84d263c8932d | 86 | }; |
| pyeh9 | 1:84d263c8932d | 87 | |
| charly | 4:67097127da6c | 88 | #endif |
