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@10:2b6ddf53b05e, 2015-03-16 (annotated)
- Committer:
- charly
- Date:
- Mon Mar 16 21:05:37 2015 +0000
- Revision:
- 10:2b6ddf53b05e
- Parent:
- 9:c9df0b33d176
- Child:
- 11:6814cbc83ae0
First version of a Yes/No Question with UserInterface and result.
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 | 9:c9df0b33d176 | 16 | * #include "MenuItem.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 | 10:2b6ddf53b05e | 81 | /** Show Yes/No Dialog and wait fo Selection |
| charly | 10:2b6ddf53b05e | 82 | */ |
| charly | 10:2b6ddf53b05e | 83 | void show_yes_no(bool yesorno); |
| charly | 10:2b6ddf53b05e | 84 | |
| charly | 5:91b1bc68290b | 85 | int _display_rows; // number of rows the LCD can display |
| charly | 10:2b6ddf53b05e | 86 | int _display_cols; // number of lines of LCD |
| charly | 8:fbaeab73fe1a | 87 | int _cursorPos; // what selection the cursor points to |
| charly | 8:fbaeab73fe1a | 88 | int _cursorLine; // what line of the lcd the cursor is on. 1 = first line, 2 = second line |
| charly | 10:2b6ddf53b05e | 89 | bool _wait_for_select; // only accept Select Button to go Back |
| charly | 10:2b6ddf53b05e | 90 | bool _wait_for_yesno; // up/don change selection ; Select accepts |
| charly | 5:91b1bc68290b | 91 | |
| pyeh9 | 1:84d263c8932d | 92 | }; |
| pyeh9 | 1:84d263c8932d | 93 | |
| charly | 4:67097127da6c | 94 | #endif |
