Library to display menus on TextLCDs. Interaction with functions Up,Down and Select (Buttons or RPG) Based on menu-library from pyeh9
Fork of Menu by
Library to display menus on TextLCDs. Interaction with functions Up,Down and Select (Buttons or RPG) Based on menu-library from pyeh9
Navigator.h@11:6814cbc83ae0, 2016-01-13 (annotated)
- Committer:
- charly
- Date:
- Wed Jan 13 19:59:21 2016 +0000
- Revision:
- 11:6814cbc83ae0
- Parent:
- 10:2b6ddf53b05e
added show_longtext() to display a long text. With scrollbars.
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 | 5:91b1bc68290b | 49 | /** Move up one line in menu. |
charly | 5:91b1bc68290b | 50 | * call this method when user moves up one line. |
charly | 5:91b1bc68290b | 51 | * can be triggered by RPG or Button (PinDetect) or otherwise. |
charly | 4:67097127da6c | 52 | */ |
charly | 4:67097127da6c | 53 | void moveUp(); |
charly | 4:67097127da6c | 54 | |
charly | 5:91b1bc68290b | 55 | /** Move down one line in menu. |
charly | 5:91b1bc68290b | 56 | * call this method when user moves down one line. |
charly | 5:91b1bc68290b | 57 | * can be triggered by RPG or Button (PinDetect) or otherwise. |
charly | 4:67097127da6c | 58 | */ |
charly | 4:67097127da6c | 59 | void moveDown(); |
charly | 4:67097127da6c | 60 | |
charly | 5:91b1bc68290b | 61 | /** User presses Select Button. |
charly | 5:91b1bc68290b | 62 | * call this method when user wants to select an item. |
charly | 5:91b1bc68290b | 63 | * can be triggered by RPG or Button (PinDetect) or otherwise. |
charly | 4:67097127da6c | 64 | */ |
charly | 4:67097127da6c | 65 | void select(); |
charly | 4:67097127da6c | 66 | |
charly | 4:67097127da6c | 67 | /** print the menu on LCD |
charly | 4:67097127da6c | 68 | */ |
charly | 4:67097127da6c | 69 | void printMenu(); |
charly | 4:67097127da6c | 70 | |
charly | 4:67097127da6c | 71 | /** print cursor on the beginning of line |
charly | 4:67097127da6c | 72 | */ |
charly | 4:67097127da6c | 73 | void printCursor(); |
charly | 5:91b1bc68290b | 74 | |
charly | 5:91b1bc68290b | 75 | private: |
charly | 10:2b6ddf53b05e | 76 | /** Show Yes/No Dialog and wait fo Selection |
charly | 10:2b6ddf53b05e | 77 | */ |
charly | 10:2b6ddf53b05e | 78 | void show_yes_no(bool yesorno); |
charly | 11:6814cbc83ae0 | 79 | /** Show a long Text and wait for Select. Scroll Up/Down in Text |
charly | 11:6814cbc83ae0 | 80 | */ |
charly | 11:6814cbc83ae0 | 81 | void show_longtext(void); |
charly | 10:2b6ddf53b05e | 82 | |
charly | 5:91b1bc68290b | 83 | int _display_rows; // number of rows the LCD can display |
charly | 10:2b6ddf53b05e | 84 | int _display_cols; // number of lines of LCD |
charly | 8:fbaeab73fe1a | 85 | int _cursorPos; // what selection the cursor points to |
charly | 8:fbaeab73fe1a | 86 | int _cursorLine; // what line of the lcd the cursor is on. 1 = first line, 2 = second line |
charly | 11:6814cbc83ae0 | 87 | int _start_line; // display a long text starting from this line |
charly | 10:2b6ddf53b05e | 88 | bool _wait_for_select; // only accept Select Button to go Back |
charly | 10:2b6ddf53b05e | 89 | bool _wait_for_yesno; // up/don change selection ; Select accepts |
charly | 5:91b1bc68290b | 90 | |
pyeh9 | 1:84d263c8932d | 91 | }; |
pyeh9 | 1:84d263c8932d | 92 | |
charly | 4:67097127da6c | 93 | #endif |