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.
EditAddressMenu.cpp
00001 /************************************************************************** 00002 * @file EditAddressMenu.cpp 00003 * @brief Base class for implementing the Edit Address 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 "EditAddressMenu.h" 00025 #include "TimeUtilities.h" 00026 #include "ESCMControlApp.h" 00027 00028 #define DEFAULT_DISPLAY 0 00029 #define SELECT_ADDRESS 1 00030 #define EDIT_ADDRESS 2 00031 00032 00033 string valid_characters = {"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_ " }; 00034 00035 /******************************************************************************/ 00036 EditAddressMenu::EditAddressMenu(char* id): Menu(id) 00037 { 00038 00039 active_selection = 0; 00040 active_address = 0; 00041 active_position = 0; 00042 00043 row=0; 00044 column=0; 00045 00046 00047 } 00048 00049 /******************************************************************************/ 00050 void EditAddressMenu::init() 00051 { 00052 active_selection = 0; 00053 active_address = 0; 00054 active_position = 0; 00055 update_needed = 1; 00056 00057 top = active_address; 00058 bottom = active_address +2; 00059 } 00060 00061 /******************************************************************************/ 00062 void EditAddressMenu::display(LCD * lcd) 00063 { 00064 // paging 00065 if (active_address < top ) 00066 { 00067 top = active_address ; 00068 bottom = active_address + 2; 00069 update_needed=1; 00070 } 00071 else if (active_address > bottom) 00072 { 00073 top = active_address - 2; 00074 bottom = active_address; 00075 update_needed=1; 00076 } 00077 else 00078 { 00079 00080 } 00081 00082 00083 if (update_needed) { 00084 00085 lcd->cls(); 00086 switch(active_selection) { 00087 // ----------------------------------------------------------------- 00088 //Select Address 00089 // ----------------------------------------------------------------- 00090 case SELECT_ADDRESS: 00091 { 00092 lcd->locate(0,0); 00093 lcd->printf("Select Address :"); 00094 lcd->locate(1,0); 00095 00096 Address *addr = &addressMap.addresses[active_address]; 00097 00098 lcd->printf(" %02d | %-20s", 00099 addr->address , 00100 addr->description ); 00101 } 00102 break; 00103 00104 // ----------------------------------------------------------------- 00105 // Select Char 00106 // ----------------------------------------------------------------- 00107 case EDIT_ADDRESS: 00108 00109 { 00110 Address *addr = &addressMap.addresses[active_address]; 00111 00112 lcd->locate(0,0); 00113 lcd->printf("Edit Text (%02d):" , addr->address ); 00114 lcd->locate(1,0); 00115 lcd->printf("Current Text : [%-20s]", addr->description ); 00116 lcd->locate(2,0); 00117 lcd->printf("Updated Text : [%-20s]", tmp_description ); 00118 lcd->locate(3,active_position+16); 00119 lcd->printf("^" ); 00120 } 00121 break; 00122 00123 // ----------------------------------------------------------------- 00124 // Display 00125 // ----------------------------------------------------------------- 00126 default: 00127 #if 1 00128 lcd->locate(0,0); 00129 lcd->printf("Address Map:"); 00130 #else 00131 lcd->locate(0,0); 00132 lcd->printf("index=%d, (%d %d)", active_address, top, bottom); 00133 #endif 00134 // update display 00135 for(int i=0; i<3; i++) { 00136 00137 int index = top + i; 00138 int line = (1+i); 00139 00140 int selected = active_address == index; 00141 00142 if(selected) { 00143 lcd->locate(line,0); 00144 lcd->printf(">"); 00145 } 00146 00147 00148 if (index < MAX_ADDRESSES) 00149 { 00150 Address *a = &addressMap.addresses[index]; 00151 lcd->locate(line,0); 00152 lcd->printf("%s%02d | %-20s", 00153 ((selected)?">":" "), 00154 a->address, 00155 a->description ); 00156 } 00157 } 00158 00159 break; 00160 }; 00161 00162 lcd->locate(2,20); 00163 //lcd->printf("%02d,%02d,%02d,%02d",active_address,active_position,top,bottom); 00164 update_needed=0; 00165 } 00166 00167 displayCurrentTime(lcd); 00168 } 00169 00170 /******************************************************************************/ 00171 void EditAddressMenu::pressMode() 00172 { 00173 // toggle active menu 00174 switch(active_selection) { 00175 case SELECT_ADDRESS: 00176 00177 // copy the current string to an editable copy 00178 strcpy( tmp_description , 00179 addressMap.addresses[active_address].description); 00180 00181 active_selection = EDIT_ADDRESS; 00182 active_position = 0; 00183 00184 break; 00185 case EDIT_ADDRESS: 00186 active_selection = DEFAULT_DISPLAY; 00187 00188 // ------------------------------------------------------- 00189 // save the editable copy back into address map 00190 strcpy( 00191 addressMap.addresses[active_address].description 00192 , tmp_description); 00193 addressMap.save(); 00194 // ------------------------------------------------------- 00195 active_position = 0; 00196 break; 00197 default: 00198 active_selection = SELECT_ADDRESS; 00199 break; 00200 }; 00201 00202 update_needed = 1; 00203 } 00204 00205 /******************************************************************************/ 00206 void EditAddressMenu::pressSet() 00207 { 00208 // set button advances to next character position OR 00209 // goes back to normal 00210 switch(active_selection) { 00211 00212 case DEFAULT_DISPLAY: 00213 case SELECT_ADDRESS: 00214 00215 00216 // copy the current string to an editable copy 00217 strcpy( tmp_description , 00218 addressMap.addresses[active_address].description); 00219 00220 active_selection = EDIT_ADDRESS; 00221 active_position = 0; 00222 00223 break; 00224 00225 case EDIT_ADDRESS: 00226 active_position++; 00227 00228 if ( active_position > MAX_ADDR_LENGTH ) 00229 { 00230 00231 // ------------------------------------------------------- 00232 // save the editable copy back into address map 00233 strcpy( 00234 addressMap.addresses[active_address].description 00235 , tmp_description); 00236 00237 addressMap.save(); 00238 // ------------------------------------------------------- 00239 active_position = 0; 00240 } 00241 00242 break; 00243 00244 default: 00245 break; 00246 }; 00247 00248 update_needed = 1; 00249 } 00250 00251 00252 /******************************************************************************/ 00253 void EditAddressMenu:: nextValidChar (char * value , int direction) 00254 { 00255 char c = *value; 00256 00257 int index = (int)valid_characters.find(c); 00258 00259 if ( index == string::npos ) 00260 { 00261 index = 0; ///invalid charcter 00262 } 00263 else 00264 { 00265 index += direction; 00266 00267 if (index< 0) 00268 index = valid_characters.size()-1; 00269 00270 if (index >= valid_characters.size()) 00271 index = 0; 00272 00273 } 00274 00275 *value = valid_characters[index]; 00276 } 00277 00278 00279 /******************************************************************************/ 00280 void EditAddressMenu::pressUp() 00281 { 00282 // either advances the pointer to current object in list OR 00283 // character in array 00284 switch(active_selection) { 00285 case SELECT_ADDRESS: 00286 active_address--; 00287 update_needed = 1; 00288 break; 00289 case EDIT_ADDRESS: 00290 nextValidChar (&tmp_description[active_position],1); 00291 update_needed = 1; 00292 break; 00293 00294 default: 00295 active_address--; 00296 update_needed = 1; 00297 break; 00298 00299 } 00300 00301 // --------------------------------------------- 00302 // wrap around 00303 if ( active_address < 0 ) 00304 { 00305 active_address = MAX_ADDRESSES-1; 00306 } 00307 00308 00309 } 00310 00311 /******************************************************************************/ 00312 void EditAddressMenu::pressDown() 00313 { 00314 // either advances the pointer to current object in list OR 00315 // character in array 00316 switch(active_selection) { 00317 00318 case SELECT_ADDRESS: 00319 active_address++; 00320 update_needed = 1; 00321 break; 00322 00323 case EDIT_ADDRESS: 00324 nextValidChar (&tmp_description[active_position],-1); 00325 update_needed = 1; 00326 break; 00327 00328 default: 00329 active_address++; 00330 update_needed = 1; 00331 break; 00332 00333 } 00334 00335 // --------------------------------------------- 00336 // wrap around 00337 if ( active_address >= MAX_ADDRESSES ) 00338 { 00339 active_address = 0; 00340 } 00341 } 00342 00343 /******************************************************************************/
Generated on Sun Jul 17 2022 01:55:32 by
 1.7.2
 1.7.2