Baseline for testing
Revision 3:8395f7ab6d3e, committed 2019-07-25
- Comitter:
- foxbrianr
- Date:
- Thu Jul 25 00:42:49 2019 +0000
- Parent:
- 2:2654dc659298
- Commit message:
- Baseline for testing
Changed in this revision
diff -r 2654dc659298 -r 8395f7ab6d3e DisplayCodesMenu.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/DisplayCodesMenu.cpp Thu Jul 25 00:42:49 2019 +0000 @@ -0,0 +1,85 @@ +#include "mbed.h" +#include "DisplayCodesMenu.h" +#include "TimeUtilities.h" + + +DisplayCodesMenu::DisplayCodesMenu(string id): Menu(id) +{ + + active_selection = 0; + row=0; + column=0; + update_needed=1; + current_line=0; + +} + +void DisplayCodesMenu::display(LCD * lcd) +{ + + char buf[40]; + + if (update_needed) + { + + lcd->cls(); + lcd->writeLine(0,"ID | ## | Time"); +#if 1 + for(int i=0;i<3;i++) + { + int index = (current_line+i); + int line = (1+i); + if (index < escmEventLog.size() ) + { + sprintf(buf,"%02d | %02d | %-16s", + index + 1, + escmEventLog.events[index].address, + escmEventLog.events[index].timeStr); + + } else { + sprintf(buf,"%s | %s | %-16s", + "--", + "--", + "- N/A -"); + } + + lcd->writeLine(line,buf); + + } + update_needed=0; +#endif + } + +} + +void DisplayCodesMenu::pressMode() +{ + +} + +void DisplayCodesMenu::pressSet() +{ + +} + +void DisplayCodesMenu::pressDown() +{ + printf("scroll down\n"); + if (current_line < escmEventLog.size() ) + current_line++; + else + current_line = escmEventLog.size()-1; + + update_needed=1; +} + +void DisplayCodesMenu::pressUp() +{ + printf("scroll up\n"); + if (current_line > 0) + current_line--; + else + current_line = 0; + + update_needed =1; +}
diff -r 2654dc659298 -r 8395f7ab6d3e DisplayCodesMenu.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/DisplayCodesMenu.h Thu Jul 25 00:42:49 2019 +0000 @@ -0,0 +1,29 @@ +#ifndef DISPLAYCODE_MENU_H +#define DISPLAYCODE_MENU_H + +#include "mbed.h" +#include "Menu.h" +#include "LCD.h" +#include "ESCMControlApp.h" + +class DisplayCodesMenu :public Menu +{ + public : + int row; + int column; + + int active_selection; + int current_line; + + DisplayCodesMenu(string id); + + virtual void display(LCD * lcd); + + virtual void pressMode(); + virtual void pressSet(); + virtual void pressDown(); + virtual void pressUp(); +}; + + +#endif \ No newline at end of file
diff -r 2654dc659298 -r 8395f7ab6d3e EditTimeMenu.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/EditTimeMenu.cpp Thu Jul 25 00:42:49 2019 +0000 @@ -0,0 +1,181 @@ +#include "mbed.h" +#include "EditTimeMenu.h" +#include "TimeUtilities.h" + + +RealTimeClock rtc; + + +EditTimeMenu::EditTimeMenu(string id): Menu(id) +{ + + active_selection = 0; + row=0; + column=0; + + time_t rawtime; + struct tm * timeinfo; + + time ( &rawtime ); + timeinfo = localtime ( &rawtime ); timeinfo = localtime (&rawtime); + + hours = timeinfo->tm_hour; + mins = timeinfo->tm_min; + secs = timeinfo->tm_sec; + + years = timeinfo->tm_year + 1900; + months = timeinfo->tm_mon + 1 ; + days = timeinfo->tm_mday; + + +} + + + +void EditTimeMenu::display(LCD * lcd) +{ + char setTime = 1; + char setDate = 1; + + char current[40]; + + time_t rawtime; + struct tm * timeinfo; + + time ( &rawtime ); + timeinfo = localtime ( &rawtime ); timeinfo = localtime (&rawtime); + + if (!active_selection){ + hours = timeinfo->tm_hour; + mins = timeinfo->tm_min; + secs = timeinfo->tm_sec; + years = timeinfo->tm_year+1900; + months = timeinfo->tm_mon + 1; + days = timeinfo->tm_mday; + lcd->setCursorMode (0) ; + } + else + { + // edit mode + secs = timeinfo->tm_sec; + lcd->setCursorMode (1) ; + } + + switch(active_selection) + { + case 1: + lcd->writeLine(0,"Set Time (hours) :"); + break; + case 2: + lcd->writeLine(0,"Set Time (min) :"); + break; + case 3: + lcd->writeLine(0,"Set Time (sec) :"); + break; + case 4: + lcd->writeLine(0,"Set Date (month) :"); + break; + case 5: + lcd->writeLine(0,"Set Date (day) :"); + break; + case 6: + lcd->writeLine(0,"Set Date (year) :"); + break; + default: + lcd->writeLine(0,"Current Time/Date :"); + break; + }; + //rtc.GetTimeString(buf); + //sprintf(current,"%02d:%02d:%02d", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec); + + if (setTime) { + sprintf(current,"%02d:%02d", hours,mins); + lcd->writeLine(1,current); + } + + if (setDate) { + sprintf(current,"%02d/%02d/%02d", months, days, years); + lcd->writeLine(2,current); + } + + +} + +void EditTimeMenu::pressMode() +{ + // advance thru + if (active_selection++ > 6 ) + active_selection = 0; + + update_needed = 1; +} + +void EditTimeMenu::pressSet() +{ + + struct tm t; + + t.tm_hour = hours; + t.tm_min = mins; + t.tm_sec = 0; + + t.tm_year = years - 1900; + t.tm_mon = months - 1; + t.tm_mday = days; + + // set the time + set_time(mktime(&t)); + + + // go back to normal display + // --------------------------------- + active_selection = 0; + update_needed = 1; +} + +void EditTimeMenu::pressUp() +{ + switch(active_selection) + { + case 1: hours++;break; + case 2: mins++;break; + case 3: secs++;break; + case 4: months++;break; + case 5: days++;break; + case 6: years++;break; + default:break; + + } + if (hours > 23) hours = 0; + if (mins > 60) mins = 0; + if (secs > 60) secs = 0; + if (months > 12) months = 1; + if (days > 31) days = 1; + if (years > 2050) years =2011; + + update_needed = 1; +} + +void EditTimeMenu::pressDown() +{ + switch(active_selection) + { + case 1: hours--;break; + case 2: mins--;break; + case 3: secs--;break; + case 4: months--;break; + case 5: days--;break; + case 6: years--;break; + default:break; + + } + + if (hours < 0) hours += 23; + if (mins < 0) mins += 60; + if (secs < 0) secs += 60; + if (months < 1) months += 12; + if (days < 1) days += 31; + if (years < 2011) years =2050; + + update_needed = 1; +}
diff -r 2654dc659298 -r 8395f7ab6d3e EditTimeMenu.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/EditTimeMenu.h Thu Jul 25 00:42:49 2019 +0000 @@ -0,0 +1,34 @@ +#ifndef EDITTIME_MENU_H +#define EDITTIME_MENU_H + +#include "mbed.h" +#include "Menu.h" +#include "LCD.h" + +class EditTimeMenu :public Menu +{ + public : + int row; + int column; + + int active_selection; + int hours; + int mins; + int secs; + + int months; + int days; + int years; + + EditTimeMenu(string id); + + virtual void display(LCD * lcd); + + virtual void pressMode(); + virtual void pressSet(); + virtual void pressDown(); + virtual void pressUp(); +}; + + +#endif \ No newline at end of file
diff -r 2654dc659298 -r 8395f7ab6d3e Menu.cpp --- a/Menu.cpp Tue Mar 05 21:24:37 2013 +0000 +++ b/Menu.cpp Thu Jul 25 00:42:49 2019 +0000 @@ -2,7 +2,12 @@ #include "Menu.h" #include "Selection.h" -Menu::Menu(char *id) : menuID(id) +Menu::Menu(char *id) : menuID(id), parent(NULL),update_needed(1) +{ + selections.clear(); +} + +Menu::Menu(string id) : menuID(id), parent(NULL),update_needed(1) { selections.clear(); } @@ -13,3 +18,130 @@ } +void Menu::select(void) +{ +} + +void Menu::display(LCD * lcd) +{ + lcd->writeLine(0,"Default Menu"); +#if 0 + for ( int i=0; i< lcd->rows();i++) + { + if ( i < selections.size()) + { + //if (i==cursorLine) { + // lcd->character(i,0,'>'); + //} + fprintf(stdout, "(%d) i = %s\n\r", selections[i].getText()); + lcd->writeLine(i,selections[i].getText()); + } + } +#endif +} + + +void Menu::moveUp() +{ + cursorLine--; + if (cursorLine < 0 ) { + cursorLine = lcd->rows() -1 ; + //if (top > 0 ) top -=4; // page menu if needed + } + + + if(cursorPos > 0) + { + cursorPos--; + } + + printCursor(); + //printMenu(); + + + printf ("UP:%d %d ", cursorLine , cursorPos ); +} + +void Menu::moveDown() +{ + + cursorLine++; + if (cursorLine >= lcd->rows() ) { + cursorLine = 0; + //if (top < activeMenu->selections.size() ) top +=4; // page menu if needed + } + + if(cursorPos < selections.size()){ + cursorPos++; + } + + printCursor(); + //printMenu(); + + printf ("DOWN:%d %d ", + cursorLine , cursorPos ); +} + +void Menu::pressMode() +{ + +} + +void Menu::pressSet() +{ + +} + +void Menu::pressUp() +{ + +} + +void Menu::pressDown() +{ + +} + + +void Menu::pressClear() +{ + +} + + +void Menu::printMenu() +{ + for (int i=0;i<lcd->rows();i++) + { + if ((i) < selections.size()) + { + lcd->writeLine(i,selections[i].selText); + } + else + { + lcd->writeLine(i,""); + } + } + + lcd->dump(NULL); +} + +void Menu::printCursor() +{ + + for(int i=0;i<lcd->rows();i++) + { + lcd->locate(i,0); + + if (i==cursorLine) { + lcd->character(i,0,'>'); + } + else + { + lcd->character(i,0,' '); + } + } + + lcd->dump(NULL); + +}
diff -r 2654dc659298 -r 8395f7ab6d3e Menu.h --- a/Menu.h Tue Mar 05 21:24:37 2013 +0000 +++ b/Menu.h Thu Jul 25 00:42:49 2019 +0000 @@ -3,7 +3,10 @@ #include "mbed.h" #include "Selection.h" +#include "LCD.h" + #include <vector> +#include <string> class Selection; @@ -11,12 +14,42 @@ private: public: + + LCD * lcd; + Menu * parent; + + int update_needed; + + int cursorPos; // what selection the cursor points to + int cursorLine; // what line of the lcd the cursor is one + vector<Selection> selections; - char *menuID; + string menuID; - Menu(char *); + Menu(char *id); + Menu(string id); + + void add(const Selection &toAdd); - char *getText(int); + + virtual void select(); + + //char * getText() { return menuID.c_str(); }; + + virtual void display(LCD * lcd); + + void moveUp(); + void moveDown(); + + virtual void pressClear(); + virtual void pressMode(); + virtual void pressSet(); + virtual void pressDown(); + virtual void pressUp(); + + void printMenu(); + void printCursor(); + }; #endif \ No newline at end of file
diff -r 2654dc659298 -r 8395f7ab6d3e Navigator.cpp --- a/Navigator.cpp Tue Mar 05 21:24:37 2013 +0000 +++ b/Navigator.cpp Thu Jul 25 00:42:49 2019 +0000 @@ -1,5 +1,5 @@ #include "Navigator.h" - +/* Navigator::Navigator(Menu *root, RPG &rpg, TextLCD *lcd) : activeMenu(root), rpg(rpg), lcd(lcd) { bottom = root->selections.size(); @@ -11,42 +11,122 @@ printMenu(); printCursor(); } - +*/ +Navigator::Navigator(Menu *root, LCD *lcd) : activeMenu(root), lcd(lcd) +{ + top = 0; + bottom = root->selections.size(); + cursorPos = 0; + cursorLine = 0; + button = 0; + lastButton = 0; +} void Navigator::printMenu() { - lcd->cls(); - if(bottom == 1){ // the current Menu only has one selection - lcd->printf("%s\n", 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); - } else { - lcd->printf("%s\n", activeMenu->selections[cursorPos].selText); - lcd->printf("%s\n", activeMenu->selections[cursorPos+1].selText); + for (int i=0;i<lcd->rows();i++) + { + if ((top+i) < activeMenu->selections.size()) + { + lcd->writeLine(i,activeMenu->selections[top+i].selText); } + else + { + lcd->writeLine(i,""); + } } + + lcd->dump(NULL); } void Navigator::printCursor() { - if(activeMenu->selections[cursorPos].childMenu == NULL) printf("No child menu\n"); - else printf("child menu: %s\n", activeMenu->selections[cursorPos].childMenu->menuID); - - lcd->locate(0,0); - if(cursorLine == 1){ - lcd->putc('>'); - lcd->locate(0,1); - lcd->putc(' '); - } else if(cursorLine == 2){ - lcd->putc(' '); - lcd->locate(0,1); - lcd->putc('>'); + + + int tmp = activeMenu->selections.size() - cursorPos; + fprintf(stdout,"%d %d %d \n\r", tmp, cursorPos, activeMenu->selections.size() ); + + for(int i=0;i<lcd->rows();i++) + { + lcd->locate(i,0); + + if (i==cursorLine) { + lcd->character(i,0,'>'); + } + else + { + lcd->character(i,0,' '); + } + } + + lcd->dump(NULL); + +} + + +void Navigator::selectMenu() +{ + + printf ("SEL:%d %d ", + cursorLine , cursorPos ); + + if(activeMenu->selections[cursorPos].childMenu != NULL) + { + activeMenu = activeMenu->selections[cursorPos].childMenu; + + cursorPos = 0; + cursorLine = 0; + + printMenu(); + printCursor(); + } + else + { + activeMenu->selections[cursorPos].select(); } -} + + -void Navigator::poll() + +} + +void Navigator::update(char cmd) { + /* + switch (cmd) + { + case 'U' : + case 'u' : + moveUp(); + break; + case 'D' : + case 'd' : + moveDown(); + break; + case 'a' : + case 'A' : + case '0x32' : + 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(); + } + break; + default: + break; + }; + */ + + + /* + if((direction = rpg.dir())!=0){ //Get Dir wait(0.2); if(direction == 1) moveDown(); @@ -67,35 +147,66 @@ printCursor(); } } + */ + lastButton = button; } +void Navigator::pageDown () +{ + if(cursorPos < bottom ) + { + bottom -= lcd->rows(); + top -= lcd->rows(); + } +} + +void Navigator::pageUp () +{ + if(cursorPos >= top ) + { + bottom += lcd->rows(); + top += lcd->rows(); + } +} + void Navigator::moveUp() -{ - if(cursorLine == 1){ - printMenu(); - } else if(cursorLine == 2){ - cursorLine = 1; +{ + cursorLine--; + if (cursorLine < 0 ) { + cursorLine = lcd->rows() -1 ; + if (top > 0 ) top -=4; // page menu if needed } - - if(cursorPos != 0){ + + + if(cursorPos > 0) + { cursorPos--; - printMenu(); - } + } + printCursor(); + //printMenu(); + + + printf ("UP:%d %d ", cursorLine , cursorPos ); } void Navigator::moveDown() { - if(cursorLine == 1){ - cursorLine = 2; - } else if(cursorLine == 2){ - printMenu(); + + cursorLine++; + if (cursorLine >= lcd->rows() ) { + cursorLine = 0; + if (top < activeMenu->selections.size() ) top +=4; // page menu if needed + } + + if(cursorPos < activeMenu->selections.size()){ + cursorPos++; } - if(cursorPos != (bottom-1)){ - cursorPos++; - printMenu(); - } printCursor(); + //printMenu(); + + printf ("DOWN:%d %d ", + cursorLine , cursorPos ); } \ No newline at end of file
diff -r 2654dc659298 -r 8395f7ab6d3e Navigator.h --- a/Navigator.h Tue Mar 05 21:24:37 2013 +0000 +++ b/Navigator.h Thu Jul 25 00:42:49 2019 +0000 @@ -3,30 +3,36 @@ #include "mbed.h" #include "Menu.h" -#include "TextLCD.h" -#include "RPG.h" +#include "LCD.h" class Navigator { private: public: - Navigator(Menu *, RPG &, TextLCD *); + Navigator(Menu *, LCD *); + //Navigator(Menu *, RPG &, TextLCD *); Menu *activeMenu; // the current menu - can change when RPG is pushed on selection with child menu - RPG rpg; - TextLCD *lcd; + + LCD *lcd; bool lastButton, button; int direction; // 1 = CW, -1 = CCW + int top; // the index of the last item of current menu int bottom; // the index of the last item of current menu + int cursorPos; // what selection the cursor points to - int cursorLine; // what line of the lcd the cursor is on. 1 = first line, 2 = second line + int cursorLine; // what line of the lcd the cursor is one - void poll(); // repeatedly call this function to determine if RPG is being used + void update(char cmd); // repeatedly call this function to determine if RPG is being used void moveUp(); void moveDown(); + void selectMenu(); void printMenu(); void printCursor(); + + void pageUp (); + void pageDown (); }; #endif \ No newline at end of file
diff -r 2654dc659298 -r 8395f7ab6d3e Selection.cpp --- a/Selection.cpp Tue Mar 05 21:24:37 2013 +0000 +++ b/Selection.cpp Thu Jul 25 00:42:49 2019 +0000 @@ -1,6 +1,14 @@ #include "mbed.h" #include "Selection.h" -#include "TextLCD.h" +#include "LCD.h" + +Selection::Selection(Selection_Callback callback, int position, Menu *child, char* text) : + callback(callback), selText(text), pos(position), childMenu(child) {} + -Selection::Selection(void (*fun)(), int position, Menu *child, char* text) : - fun(fun), selText(text), pos(position), childMenu(child) {} + +void Selection::select() +{ + printf("A->%s\n\r", selText); + if (callback) callback(this); +} \ No newline at end of file
diff -r 2654dc659298 -r 8395f7ab6d3e Selection.h --- a/Selection.h Tue Mar 05 21:24:37 2013 +0000 +++ b/Selection.h Thu Jul 25 00:42:49 2019 +0000 @@ -5,17 +5,28 @@ class Menu; +typedef void (*Selection_Callback)(void* obj); + class Selection { private: public: - void (*fun)(); // pointer to a function to execute + + Selection_Callback callback; // pointer to a function to execute + char* selText; // selection text + int pos; // selection position + Menu *childMenu; - Selection(void (*)(), int, Menu *, char *); + Selection( Selection_Callback callback, int, Menu *, char * text); + + virtual void select(); + + virtual char * getText () { return selText; } }; + #endif \ No newline at end of file