Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
DisplayCodesMenu.cpp
00001 /************************************************************************** 00002 * @file DisplayCodeMenu.cpp 00003 * @brief Base class for implementing the Display Code Menu display 00004 * @version: V1.0 00005 * @date: 9/17/2019 00006 00007 * 00008 * @note 00009 * Copyright (C) 2019 E3 Design. All rights reserved. 00010 * 00011 * @par 00012 * E3 Designers LLC is supplying this software for use with Cortex-M3 LPC1768 00013 * processor based microcontroller for the ESCM 2000 Monitor and Display. 00014 * * 00015 * @par 00016 * THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED 00017 * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF 00018 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. 00019 * ARM SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR 00020 * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. 00021 * 00022 ******************************************************************************/ 00023 #include "mbed.h" 00024 #include "DisplayCodesMenu.h" 00025 #include "TimeUtilities.h" 00026 #include "ESCMControlApp.h" 00027 00028 00029 /******************************************************************************/ 00030 DisplayCodesMenu::DisplayCodesMenu(char* id): Menu(id) 00031 { 00032 00033 active_selection = 0; 00034 row=0; 00035 column=0; 00036 update_needed=1; 00037 current_index=0; 00038 current_line = 1; 00039 top = 0; 00040 00041 } 00042 00043 00044 00045 /******************************************************************************/ 00046 void DisplayCodesMenu::init() 00047 { 00048 active_selection = 0; 00049 row=0; 00050 column=0; 00051 update_needed=1; 00052 current_index= 0; 00053 current_line = 1; 00054 top = 0; 00055 } 00056 00057 00058 /******************************************************************************/ 00059 void DisplayCodesMenu::display(LCD * lcd) 00060 { 00061 static int lastPos = 0; 00062 static int lastSize = 0; 00063 00064 int hr = 0; 00065 int update_page = 0; 00066 char buf[40]; 00067 00068 //displayCurrentTime(lcd); 00069 00070 if(escmEventLog.head_ != lastPos ) { 00071 00072 current_index = 0; 00073 top = current_index; 00074 bottom = top + 2; 00075 00076 lastPos = escmEventLog.head_; 00077 lastSize = escmEventLog.size(); 00078 update_needed=1; 00079 } 00080 00081 00082 // paging 00083 if (current_index < top ) 00084 { 00085 top = current_index ; 00086 bottom = current_index + 2; 00087 update_page = 1; 00088 update_needed=1; 00089 } 00090 else if (current_index > bottom) 00091 { 00092 top = current_index - 2; 00093 bottom = current_index; 00094 update_page = 1; 00095 update_needed=1; 00096 } 00097 else 00098 { 00099 00100 } 00101 00102 00103 if (update_needed) { 00104 00105 lock(); 00106 00107 switch (active_selection ) { 00108 case 2: 00109 lcd->cls(); 00110 lcd->locate(1,0); 00111 lcd->printf("Are you sure you want to erase"); 00112 lcd->locate(2,0); 00113 lcd->printf("all events (Press Set)?"); 00114 update_needed = 0; 00115 break; 00116 case 3: 00117 lcd->cls(); 00118 lcd->locate(1,0); 00119 lcd->printf("Deleting Events..."); 00120 erase_log = 0; 00121 escmEventLog.reset(); 00122 escmEventLog.save(); 00123 update_needed = 1; 00124 active_selection = 0; 00125 current_index = 0; 00126 break; 00127 00128 case 1: 00129 // DISPLAY EXPANDED INFO 00130 lcd->cls(); 00131 lcd->locate(0,0); 00132 lcd->printf(" ID | Port | Unit | Time"); 00133 lcd->locate(0,33); 00134 lcd->printf("Addr=%02d",escmController.cur_address); 00135 00136 // update display 00137 for(int i=0; i<3; i++) { 00138 00139 int index = top + i; 00140 int line = (1+i); 00141 00142 int selected = current_index == index; 00143 00144 ESCM_Event *event = escmEventLog.index (index) ; 00145 00146 if (event != NULL && index < escmEventLog.size() ) { 00147 00148 if ( event->hours < 12 ) { 00149 00150 hr = event[i].hours; 00151 hr = (hr == 0) ? 12 : hr; 00152 sprintf(buf,"%02d | %02d | %02d | %02d:%02d:%02dam %02d/%02d/%04d", 00153 index + 1, 00154 event->port, 00155 event->address, 00156 hr, 00157 event->mins, 00158 event->secs, 00159 event->month, 00160 event->day, 00161 event->year 00162 ); 00163 00164 } 00165 else { 00166 hr = (event->hours - 12); 00167 hr = (hr == 0) ? 12 : hr; 00168 ; 00169 sprintf(buf,"%02d | %02d | %02d | %02d:%02d:%02dpm %02d/%02d/%04d", 00170 index + 1, 00171 event->port, 00172 event->address, 00173 hr, 00174 event->mins, 00175 event->secs, 00176 event->month, 00177 event->day, 00178 event->year 00179 ); 00180 00181 } 00182 00183 } else { 00184 sprintf(buf,"%-s | %-s | %-s | %-s", 00185 "--", 00186 "--", 00187 "--", 00188 "- N/A -"); 00189 } 00190 00191 if(selected) { 00192 lcd->locate(line,0); 00193 lcd->printf(">%-39s",buf); 00194 } else { 00195 lcd->locate(line,0); 00196 lcd->printf(" %-39s",buf); 00197 } 00198 00199 //lcd->locate(line,2); 00200 //lcd->printf(buf); 00201 00202 } 00203 update_page = 0; 00204 update_needed=0; 00205 break; 00206 break; 00207 default: 00208 00209 lcd->cls(); 00210 lcd->locate(0,0); 00211 #if 0 00212 lcd->printf(" ID | Port | Unit | Time"); 00213 #else 00214 lcd->printf(" ID | Description | Time"); 00215 #endif 00216 00217 lcd->locate(0,33); 00218 lcd->printf("Addr=%02d",escmController.cur_address); 00219 00220 // update display 00221 for(int i=0; i<3; i++) { 00222 00223 int index = top + i; 00224 int line = (1+i); 00225 00226 int selected = current_index == index; 00227 00228 00229 ESCM_Event *event = escmEventLog.index (index) ; 00230 00231 if (event != NULL && index < escmEventLog.size() ) { 00232 #if 0 00233 sprintf(buf,"%02d | %02d | %02d | %02d:%02d:%02d %02d/%02d/%04d", 00234 index + 1, 00235 event->port, 00236 event->address, 00237 event->hours, 00238 event->mins, 00239 event->secs, 00240 event->month, 00241 event->day, 00242 event->year 00243 ); 00244 #else 00245 char * ev_desc = addressMap.getDescription(event->address); 00246 00247 if ( event->hours < 12 ) { 00248 hr = (event[i].hours == 0) ? 12 : event[i].hours; 00249 hr = (hr == 0) ? 12 : hr; 00250 sprintf(buf,"%02d | %-12s | %02d:%02d:%02dam %02d/%02d/%02d", 00251 00252 event->address, 00253 ev_desc, 00254 hr, 00255 event->mins, 00256 event->secs, 00257 event->month, 00258 event->day, 00259 (event->year % 100) 00260 ); 00261 } else { 00262 00263 hr = (event->hours - 12); 00264 hr = (hr == 0) ? 12 : hr; 00265 00266 sprintf(buf,"%02d | %-12s | %02d:%02d:%02dpm %02d/%02d/%02d", 00267 00268 event->address, 00269 ev_desc, 00270 hr, 00271 event->mins, 00272 event->secs, 00273 event->month, 00274 event->day, 00275 (event->year % 100) 00276 ); 00277 } 00278 00279 #endif 00280 00281 } else { 00282 #if 0 00283 sprintf(buf,"%-s | %-s | %-s | %-s", 00284 "--", 00285 "--", 00286 "--", 00287 "- N/A -"); 00288 #else 00289 sprintf(buf,"%-s | %-s | %-s", 00290 "--", 00291 "Empty", 00292 "- N/A -"); 00293 #endif 00294 } 00295 00296 if(selected) { 00297 lcd->locate(line,0); 00298 lcd->printf(">%-39s",buf); 00299 } else { 00300 lcd->locate(line,0); 00301 lcd->printf(" %-39s",buf); 00302 } 00303 00304 //lcd->locate(line,2); 00305 //lcd->printf(buf); 00306 00307 } 00308 update_page = 0; 00309 update_needed=0; 00310 break; 00311 } 00312 00313 unlock(); 00314 } 00315 } 00316 00317 00318 /******************************************************************************/ 00319 void DisplayCodesMenu::pressSet() 00320 { 00321 switch(active_selection) { 00322 00323 case 0: 00324 case 1: 00325 { // normal 00326 00327 ESCM_Event *event = escmEventLog.index(current_index); 00328 if (event!=NULL) 00329 { 00330 escmController.say(event->address ); 00331 escmController.relayMessage(event->address ); 00332 } 00333 update_needed = 0; 00334 break; 00335 } 00336 case 2: // press yes 00337 active_selection = 3; 00338 update_needed = 1; 00339 break; 00340 case 3: // press yes 00341 default: 00342 active_selection = 0; 00343 break; 00344 } 00345 } 00346 00347 /******************************************************************************/ 00348 void DisplayCodesMenu::pressMode() 00349 { 00350 00351 switch(active_selection) { 00352 case 0: // normal 00353 active_selection = 1; 00354 update_needed = 1; 00355 break; 00356 case 1: // normal 00357 active_selection = 2; 00358 update_needed = 1; 00359 break; 00360 case 2: // normal 00361 case 3: // normal 00362 default: 00363 active_selection = 0; 00364 update_needed = 1; 00365 break; 00366 } 00367 } 00368 00369 /******************************************************************************/ 00370 void DisplayCodesMenu::pressDown() 00371 { 00372 00373 current_line++; 00374 current_index++; 00375 00376 if (current_index >= escmEventLog.size() ) 00377 current_index = 0; 00378 00379 00380 if (current_line > 3 ) 00381 current_line = 3; 00382 00383 update_needed=1; 00384 } 00385 00386 /******************************************************************************/ 00387 void DisplayCodesMenu::pressUp() 00388 { 00389 current_line--; 00390 current_index--; 00391 if (current_index < 0) 00392 current_index = escmEventLog.size()-1; 00393 00394 if (current_line < 1 ) 00395 current_line = 1; 00396 00397 update_needed =1; 00398 } 00399 /******************************************************************************/
Generated on Sun Jul 17 2022 01:55:32 by
1.7.2