Release 1.01
Diff: DisplayCodesMenu.cpp
- Revision:
- 4:7226c43320b5
- Parent:
- 3:8395f7ab6d3e
- Child:
- 5:9f4d4f8ffc00
diff -r 8395f7ab6d3e -r 7226c43320b5 DisplayCodesMenu.cpp --- a/DisplayCodesMenu.cpp Thu Jul 25 00:42:49 2019 +0000 +++ b/DisplayCodesMenu.cpp Thu Sep 12 11:27:50 2019 +0000 @@ -1,85 +1,235 @@ #include "mbed.h" #include "DisplayCodesMenu.h" #include "TimeUtilities.h" +#include "ESCMControlApp.h" -DisplayCodesMenu::DisplayCodesMenu(string id): Menu(id) +DisplayCodesMenu::DisplayCodesMenu(char* id): Menu(id) { - + + active_selection = 0; + row=0; + column=0; + update_needed=1; + current_index=0; + current_line = 1; + top = 0; + +} + + + +void DisplayCodesMenu::init() +{ active_selection = 0; row=0; column=0; update_needed=1; - current_line=0; - + current_index= 0; + current_line = 1; + top = 0; } - + + void DisplayCodesMenu::display(LCD * lcd) { - + static int lastPos = 0; + static int lastSize = 0; + + int update_page = 0; char buf[40]; + + //displayCurrentTime(lcd); - if (update_needed) + if(escmEventLog.head_ != lastPos ) { + + current_index = 0; + top = current_index; + bottom = top + 2; + + lastPos = escmEventLog.head_; + lastSize = escmEventLog.size(); + update_needed=1; + } + + + // paging + if (current_index < top ) + { + top = current_index ; + bottom = current_index + 2; + update_page = 1; + update_needed=1; + } + else if (current_index > bottom) + { + top = current_index - 2; + bottom = current_index; + update_page = 1; + update_needed=1; + } + else { - 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 } + + if (update_needed) { + + lock(); + + switch (active_selection ) { + case 1: + lcd->cls(); + lcd->locate(1,0); + lcd->printf("Are you sure you want to erase"); + lcd->locate(2,0); + lcd->printf("all events (Press Mode)?"); + update_needed = 0; + break; + case 2: + lcd->cls(); + lcd->locate(1,0); + lcd->printf("Deleting Events..."); + erase_log = 0; + escmEventLog.reset(); + escmEventLog.save(); + update_needed = 1; + active_selection = 0; + current_index = 0; + break; + + default: + + lcd->cls(); + lcd->locate(0,0); +#if 1 + lcd->printf(" ID | Port | Unit | Time"); +#else + lcd->locate(0,0); + lcd->printf("size= %d, index=%d, %d, %d %d", escmEventLog.size(), current_index, current_line, top, bottom); +#endif + + // update display + for(int i=0; i<3; i++) { + + int index = top + i; + int line = (1+i); + + int selected = current_index == index; + + + ESCM_Event *event = escmEventLog.index (index) ; + + if (event != NULL && index < escmEventLog.size() ) { + sprintf(buf,"%02d | %02d | %02d | %02d:%02d:%02d %02d/%02d/%04d", + index + 1, + event->port, + event->address, + event->hours, + event->mins, + event->secs, + event->month, + event->day, + event->year + ); + + } else { + sprintf(buf,"%-s | %-s | %-s | %-s", + "--", + "--", + "--", + "- N/A -"); + } + + if(selected) { + lcd->locate(line,0); + lcd->printf(">%-39s",buf); + } else { + lcd->locate(line,0); + lcd->printf(" %-39s",buf); + } + + //lcd->locate(line,2); + //lcd->printf(buf); + + } + update_page = 0; + update_needed=0; + break; + } + + unlock(); + } +} + + +void DisplayCodesMenu::pressSet() +{ + switch(active_selection) { + + case 0: { // normal + /* + ESCM_Event *event = escmEventLog.index(current_index); + if (event!=NULL) + { + ESCMControlApp::say( "%s is open", + addressMap.getDescription(event->address)); + } + */ + update_needed = 0; + break; + } + case 1: // press yes + active_selection = 2; + update_needed = 1; + break; + default: + active_selection = 0; + break; + } } void DisplayCodesMenu::pressMode() -{ +{ -} - -void DisplayCodesMenu::pressSet() -{ - + switch(active_selection) { + case 0: // normal + active_selection = 1; + update_needed = 1; + break; + default: + active_selection = 0; + update_needed = 1; + break; + } } void DisplayCodesMenu::pressDown() -{ - printf("scroll down\n"); - if (current_line < escmEventLog.size() ) - current_line++; - else - current_line = escmEventLog.size()-1; +{ + + current_line++; + current_index++; + + if (current_index >= escmEventLog.size() ) + current_index = 0; + + if (current_line > 3 ) + current_line = 3; + update_needed=1; } - + void DisplayCodesMenu::pressUp() { - printf("scroll up\n"); - if (current_line > 0) - current_line--; - else - current_line = 0; - - update_needed =1; + current_line--; + current_index--; + if (current_index < 0) + current_index = escmEventLog.size()-1; + + if (current_line < 1 ) + current_line = 1; + + update_needed =1; }