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
Revision 3:cfc36b42ae75, committed 2015-01-01
- Comitter:
- charly
- Date:
- Thu Jan 01 22:27:30 2015 +0000
- Parent:
- 2:2654dc659298
- Child:
- 4:67097127da6c
- Commit message:
- Removed RPG; added method select.; Interaction can be handled outside Menu with methods Navigator::moveUp, moveDown and select.; Changed from TextLCD to http://developer.mbed.org/cookbook/Text-LCD-Enhanced; Fixed bug to display 15 Chars per line
Changed in this revision
| Navigator.cpp | Show annotated file Show diff for this revision Revisions of this file |
| Navigator.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/Navigator.cpp Tue Mar 05 21:24:37 2013 +0000
+++ b/Navigator.cpp Thu Jan 01 22:27:30 2015 +0000
@@ -1,6 +1,6 @@
#include "Navigator.h"
-Navigator::Navigator(Menu *root, RPG &rpg, TextLCD *lcd) : activeMenu(root), rpg(rpg), lcd(lcd)
+Navigator::Navigator(Menu *root, /*RPG &rpg,*/ TextLCD_Base *lcd) : activeMenu(root), /*rpg(rpg), */ lcd(lcd)
{
bottom = root->selections.size();
cursorPos = 0;
@@ -16,14 +16,16 @@
{
lcd->cls();
if(bottom == 1){ // the current Menu only has one selection
- lcd->printf("%s\n", activeMenu->selections[0].selText);
+ lcd->printf(" %s", activeMenu->selections[0].selText);
} else {
if(cursorLine == 2){ // if we're at the bottom
- lcd->printf("%s\n", activeMenu->selections[cursorPos-1].selText);
- lcd->printf("%s\n", activeMenu->selections[cursorPos].selText);
+ lcd->printf(" %s", activeMenu->selections[cursorPos-1].selText);
+ lcd->locate(0,1);
+ lcd->printf(" %s", activeMenu->selections[cursorPos].selText);
} else {
- lcd->printf("%s\n", activeMenu->selections[cursorPos].selText);
- lcd->printf("%s\n", activeMenu->selections[cursorPos+1].selText);
+ lcd->printf(" %s", activeMenu->selections[cursorPos].selText);
+ lcd->locate(0,1);
+ lcd->printf(" %s", activeMenu->selections[cursorPos+1].selText);
}
}
}
@@ -47,6 +49,7 @@
void Navigator::poll()
{
+/*
if((direction = rpg.dir())!=0){ //Get Dir
wait(0.2);
if(direction == 1) moveDown();
@@ -68,8 +71,23 @@
}
}
lastButton = button;
+*/
}
+void Navigator::select()
+{
+ if(activeMenu->selections[cursorPos].fun != NULL){
+ (activeMenu->selections[cursorPos].fun)();
+ }
+ if(activeMenu->selections[cursorPos].childMenu != NULL){
+ activeMenu = activeMenu->selections[cursorPos].childMenu;
+ bottom = activeMenu->selections.size();
+ cursorPos = 0;
+ cursorLine = 1;
+ printMenu();
+ printCursor();
+ }
+}
void Navigator::moveUp()
{
if(cursorLine == 1){
--- a/Navigator.h Tue Mar 05 21:24:37 2013 +0000
+++ b/Navigator.h Thu Jan 01 22:27:30 2015 +0000
@@ -4,16 +4,16 @@
#include "mbed.h"
#include "Menu.h"
#include "TextLCD.h"
-#include "RPG.h"
+//#include "RPG.h"
class Navigator {
private:
public:
- Navigator(Menu *, RPG &, TextLCD *);
+ Navigator(Menu *, /*RPG &,*/ TextLCD_Base *);
Menu *activeMenu; // the current menu - can change when RPG is pushed on selection with child menu
- RPG rpg;
- TextLCD *lcd;
+// RPG rpg;
+ TextLCD_Base *lcd;
bool lastButton, button;
int direction; // 1 = CW, -1 = CCW
@@ -25,6 +25,7 @@
void poll(); // repeatedly call this function to determine if RPG is being used
void moveUp();
void moveDown();
+ void select();
void printMenu();
void printCursor();
};
