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 Peihsun Yeh

Library to display menus on TextLCDs. Interaction with functions Up,Down and Select (Buttons or RPG) Based on menu-library from pyeh9

Committer:
charly
Date:
Thu Jan 01 23:00:06 2015 +0000
Revision:
4:67097127da6c
Parent:
3:cfc36b42ae75
Child:
5:91b1bc68290b
removed old code for poll method

Who changed what in which revision?

UserRevisionLine numberNew contents of line
pyeh9 1:84d263c8932d 1 #include "Navigator.h"
pyeh9 1:84d263c8932d 2
charly 4:67097127da6c 3 Navigator::Navigator(Menu *root, TextLCD_Base *lcd) : activeMenu(root), 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 2:2654dc659298 8
pyeh9 2:2654dc659298 9 printMenu();
pyeh9 2:2654dc659298 10 printCursor();
pyeh9 1:84d263c8932d 11 }
pyeh9 1:84d263c8932d 12
pyeh9 1:84d263c8932d 13 void Navigator::printMenu()
pyeh9 1:84d263c8932d 14 {
pyeh9 1:84d263c8932d 15 lcd->cls();
pyeh9 1:84d263c8932d 16 if(bottom == 1){ // the current Menu only has one selection
charly 3:cfc36b42ae75 17 lcd->printf(" %s", activeMenu->selections[0].selText);
pyeh9 1:84d263c8932d 18 } else {
pyeh9 1:84d263c8932d 19 if(cursorLine == 2){ // if we're at the bottom
charly 3:cfc36b42ae75 20 lcd->printf(" %s", activeMenu->selections[cursorPos-1].selText);
charly 3:cfc36b42ae75 21 lcd->locate(0,1);
charly 3:cfc36b42ae75 22 lcd->printf(" %s", activeMenu->selections[cursorPos].selText);
pyeh9 1:84d263c8932d 23 } else {
charly 3:cfc36b42ae75 24 lcd->printf(" %s", activeMenu->selections[cursorPos].selText);
charly 3:cfc36b42ae75 25 lcd->locate(0,1);
charly 3:cfc36b42ae75 26 lcd->printf(" %s", 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()
pyeh9 1:84d263c8932d 32 {
pyeh9 1:84d263c8932d 33 if(activeMenu->selections[cursorPos].childMenu == NULL) printf("No child menu\n");
pyeh9 1:84d263c8932d 34 else printf("child menu: %s\n", activeMenu->selections[cursorPos].childMenu->menuID);
pyeh9 1:84d263c8932d 35
pyeh9 1:84d263c8932d 36 lcd->locate(0,0);
pyeh9 1:84d263c8932d 37 if(cursorLine == 1){
pyeh9 1:84d263c8932d 38 lcd->putc('>');
pyeh9 1:84d263c8932d 39 lcd->locate(0,1);
pyeh9 1:84d263c8932d 40 lcd->putc(' ');
pyeh9 1:84d263c8932d 41 } else if(cursorLine == 2){
pyeh9 1:84d263c8932d 42 lcd->putc(' ');
pyeh9 1:84d263c8932d 43 lcd->locate(0,1);
pyeh9 1:84d263c8932d 44 lcd->putc('>');
pyeh9 1:84d263c8932d 45 }
pyeh9 1:84d263c8932d 46 }
pyeh9 1:84d263c8932d 47
pyeh9 1:84d263c8932d 48 void Navigator::poll()
pyeh9 1:84d263c8932d 49 {
charly 4:67097127da6c 50 // no longer needed
pyeh9 1:84d263c8932d 51 }
pyeh9 1:84d263c8932d 52
charly 3:cfc36b42ae75 53 void Navigator::select()
charly 3:cfc36b42ae75 54 {
charly 3:cfc36b42ae75 55 if(activeMenu->selections[cursorPos].fun != NULL){
charly 3:cfc36b42ae75 56 (activeMenu->selections[cursorPos].fun)();
charly 3:cfc36b42ae75 57 }
charly 3:cfc36b42ae75 58 if(activeMenu->selections[cursorPos].childMenu != NULL){
charly 3:cfc36b42ae75 59 activeMenu = activeMenu->selections[cursorPos].childMenu;
charly 3:cfc36b42ae75 60 bottom = activeMenu->selections.size();
charly 3:cfc36b42ae75 61 cursorPos = 0;
charly 3:cfc36b42ae75 62 cursorLine = 1;
charly 3:cfc36b42ae75 63 printMenu();
charly 3:cfc36b42ae75 64 printCursor();
charly 3:cfc36b42ae75 65 }
charly 3:cfc36b42ae75 66 }
pyeh9 1:84d263c8932d 67 void Navigator::moveUp()
pyeh9 1:84d263c8932d 68 {
pyeh9 1:84d263c8932d 69 if(cursorLine == 1){
pyeh9 1:84d263c8932d 70 printMenu();
pyeh9 1:84d263c8932d 71 } else if(cursorLine == 2){
pyeh9 1:84d263c8932d 72 cursorLine = 1;
pyeh9 1:84d263c8932d 73 }
pyeh9 1:84d263c8932d 74
pyeh9 1:84d263c8932d 75 if(cursorPos != 0){
pyeh9 1:84d263c8932d 76 cursorPos--;
pyeh9 1:84d263c8932d 77 printMenu();
pyeh9 1:84d263c8932d 78 }
pyeh9 1:84d263c8932d 79 printCursor();
pyeh9 1:84d263c8932d 80 }
pyeh9 1:84d263c8932d 81
pyeh9 1:84d263c8932d 82 void Navigator::moveDown()
pyeh9 1:84d263c8932d 83 {
pyeh9 1:84d263c8932d 84 if(cursorLine == 1){
pyeh9 1:84d263c8932d 85 cursorLine = 2;
pyeh9 1:84d263c8932d 86 } else if(cursorLine == 2){
pyeh9 1:84d263c8932d 87 printMenu();
pyeh9 1:84d263c8932d 88 }
pyeh9 1:84d263c8932d 89
pyeh9 1:84d263c8932d 90 if(cursorPos != (bottom-1)){
pyeh9 1:84d263c8932d 91 cursorPos++;
pyeh9 1:84d263c8932d 92 printMenu();
pyeh9 1:84d263c8932d 93 }
pyeh9 1:84d263c8932d 94 printCursor();
pyeh9 1:84d263c8932d 95 }