Release 1.01

Dependents:   mbed_escm2000

Committer:
foxbrianr
Date:
Thu Sep 12 11:27:50 2019 +0000
Revision:
4:7226c43320b5
Child:
5:9f4d4f8ffc00
beta1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
foxbrianr 4:7226c43320b5 1 #include "mbed.h"
foxbrianr 4:7226c43320b5 2 #include "EditAddressMenu.h"
foxbrianr 4:7226c43320b5 3 #include "TimeUtilities.h"
foxbrianr 4:7226c43320b5 4 #include "ESCMControlApp.h"
foxbrianr 4:7226c43320b5 5
foxbrianr 4:7226c43320b5 6 #define DEFAULT_DISPLAY 0
foxbrianr 4:7226c43320b5 7 #define SELECT_ADDRESS 1
foxbrianr 4:7226c43320b5 8 #define EDIT_ADDRESS 2
foxbrianr 4:7226c43320b5 9
foxbrianr 4:7226c43320b5 10
foxbrianr 4:7226c43320b5 11 string valid_characters = {"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890 " };
foxbrianr 4:7226c43320b5 12
foxbrianr 4:7226c43320b5 13 EditAddressMenu::EditAddressMenu(char* id): Menu(id)
foxbrianr 4:7226c43320b5 14 {
foxbrianr 4:7226c43320b5 15
foxbrianr 4:7226c43320b5 16 active_selection = 0;
foxbrianr 4:7226c43320b5 17 active_address = 0;
foxbrianr 4:7226c43320b5 18 active_position = 0;
foxbrianr 4:7226c43320b5 19
foxbrianr 4:7226c43320b5 20 row=0;
foxbrianr 4:7226c43320b5 21 column=0;
foxbrianr 4:7226c43320b5 22
foxbrianr 4:7226c43320b5 23
foxbrianr 4:7226c43320b5 24 }
foxbrianr 4:7226c43320b5 25
foxbrianr 4:7226c43320b5 26
foxbrianr 4:7226c43320b5 27
foxbrianr 4:7226c43320b5 28 void EditAddressMenu::init()
foxbrianr 4:7226c43320b5 29 {
foxbrianr 4:7226c43320b5 30 active_selection = 0;
foxbrianr 4:7226c43320b5 31 active_address = 0;
foxbrianr 4:7226c43320b5 32 active_position = 0;
foxbrianr 4:7226c43320b5 33 update_needed = 1;
foxbrianr 4:7226c43320b5 34
foxbrianr 4:7226c43320b5 35 top = active_address;
foxbrianr 4:7226c43320b5 36 bottom = active_address +2;
foxbrianr 4:7226c43320b5 37 }
foxbrianr 4:7226c43320b5 38
foxbrianr 4:7226c43320b5 39 void EditAddressMenu::display(LCD * lcd)
foxbrianr 4:7226c43320b5 40 {
foxbrianr 4:7226c43320b5 41 // paging
foxbrianr 4:7226c43320b5 42 if (active_address < top )
foxbrianr 4:7226c43320b5 43 {
foxbrianr 4:7226c43320b5 44 top = active_address ;
foxbrianr 4:7226c43320b5 45 bottom = active_address + 2;
foxbrianr 4:7226c43320b5 46 update_needed=1;
foxbrianr 4:7226c43320b5 47 }
foxbrianr 4:7226c43320b5 48 else if (active_address > bottom)
foxbrianr 4:7226c43320b5 49 {
foxbrianr 4:7226c43320b5 50 top = active_address - 2;
foxbrianr 4:7226c43320b5 51 bottom = active_address;
foxbrianr 4:7226c43320b5 52 update_needed=1;
foxbrianr 4:7226c43320b5 53 }
foxbrianr 4:7226c43320b5 54 else
foxbrianr 4:7226c43320b5 55 {
foxbrianr 4:7226c43320b5 56
foxbrianr 4:7226c43320b5 57 }
foxbrianr 4:7226c43320b5 58
foxbrianr 4:7226c43320b5 59
foxbrianr 4:7226c43320b5 60 if (update_needed) {
foxbrianr 4:7226c43320b5 61
foxbrianr 4:7226c43320b5 62 lcd->cls();
foxbrianr 4:7226c43320b5 63 switch(active_selection) {
foxbrianr 4:7226c43320b5 64 // -----------------------------------------------------------------
foxbrianr 4:7226c43320b5 65 //Select Address
foxbrianr 4:7226c43320b5 66 // -----------------------------------------------------------------
foxbrianr 4:7226c43320b5 67 case SELECT_ADDRESS:
foxbrianr 4:7226c43320b5 68 {
foxbrianr 4:7226c43320b5 69 lcd->locate(0,0);
foxbrianr 4:7226c43320b5 70 lcd->printf("Select Address :");
foxbrianr 4:7226c43320b5 71 lcd->locate(1,0);
foxbrianr 4:7226c43320b5 72
foxbrianr 4:7226c43320b5 73 Address *addr = &addressMap.addresses[active_address];
foxbrianr 4:7226c43320b5 74
foxbrianr 4:7226c43320b5 75 lcd->printf(" %02d | %-20s",
foxbrianr 4:7226c43320b5 76 addr->address ,
foxbrianr 4:7226c43320b5 77 addr->description );
foxbrianr 4:7226c43320b5 78 }
foxbrianr 4:7226c43320b5 79 break;
foxbrianr 4:7226c43320b5 80
foxbrianr 4:7226c43320b5 81 // -----------------------------------------------------------------
foxbrianr 4:7226c43320b5 82 // Select Char
foxbrianr 4:7226c43320b5 83 // -----------------------------------------------------------------
foxbrianr 4:7226c43320b5 84 case EDIT_ADDRESS:
foxbrianr 4:7226c43320b5 85
foxbrianr 4:7226c43320b5 86 {
foxbrianr 4:7226c43320b5 87 Address *addr = &addressMap.addresses[active_address];
foxbrianr 4:7226c43320b5 88
foxbrianr 4:7226c43320b5 89 lcd->locate(0,0);
foxbrianr 4:7226c43320b5 90 lcd->printf("Edit Text (%02d):" , addr->address );
foxbrianr 4:7226c43320b5 91 lcd->locate(1,0);
foxbrianr 4:7226c43320b5 92 lcd->printf("Current Text : [%-20s]", addr->description );
foxbrianr 4:7226c43320b5 93 lcd->locate(2,0);
foxbrianr 4:7226c43320b5 94 lcd->printf("Updated Text : [%-20s]", tmp_description );
foxbrianr 4:7226c43320b5 95 lcd->locate(3,active_position+16);
foxbrianr 4:7226c43320b5 96 lcd->printf("^" );
foxbrianr 4:7226c43320b5 97 }
foxbrianr 4:7226c43320b5 98 break;
foxbrianr 4:7226c43320b5 99
foxbrianr 4:7226c43320b5 100 // -----------------------------------------------------------------
foxbrianr 4:7226c43320b5 101 // Display
foxbrianr 4:7226c43320b5 102 // -----------------------------------------------------------------
foxbrianr 4:7226c43320b5 103 default:
foxbrianr 4:7226c43320b5 104 #if 1
foxbrianr 4:7226c43320b5 105 lcd->locate(0,0);
foxbrianr 4:7226c43320b5 106 lcd->printf("Address Map:");
foxbrianr 4:7226c43320b5 107 #else
foxbrianr 4:7226c43320b5 108 lcd->locate(0,0);
foxbrianr 4:7226c43320b5 109 lcd->printf("index=%d, (%d %d)", active_address, top, bottom);
foxbrianr 4:7226c43320b5 110 #endif
foxbrianr 4:7226c43320b5 111 // update display
foxbrianr 4:7226c43320b5 112 for(int i=0; i<3; i++) {
foxbrianr 4:7226c43320b5 113
foxbrianr 4:7226c43320b5 114 int index = top + i;
foxbrianr 4:7226c43320b5 115 int line = (1+i);
foxbrianr 4:7226c43320b5 116
foxbrianr 4:7226c43320b5 117 int selected = active_address == index;
foxbrianr 4:7226c43320b5 118
foxbrianr 4:7226c43320b5 119 if(selected) {
foxbrianr 4:7226c43320b5 120 lcd->locate(line,0);
foxbrianr 4:7226c43320b5 121 lcd->printf(">");
foxbrianr 4:7226c43320b5 122 }
foxbrianr 4:7226c43320b5 123
foxbrianr 4:7226c43320b5 124
foxbrianr 4:7226c43320b5 125 if (index < MAX_ADDRESSES)
foxbrianr 4:7226c43320b5 126 {
foxbrianr 4:7226c43320b5 127 Address *a = &addressMap.addresses[index];
foxbrianr 4:7226c43320b5 128 lcd->locate(line,0);
foxbrianr 4:7226c43320b5 129 lcd->printf("%s%02d | %-20s",
foxbrianr 4:7226c43320b5 130 ((selected)?">":" "),
foxbrianr 4:7226c43320b5 131 a->address,
foxbrianr 4:7226c43320b5 132 a->description );
foxbrianr 4:7226c43320b5 133 }
foxbrianr 4:7226c43320b5 134 }
foxbrianr 4:7226c43320b5 135
foxbrianr 4:7226c43320b5 136 if (strlen(addressMap.addresses[active_address].description) > 0)
foxbrianr 4:7226c43320b5 137 {
foxbrianr 4:7226c43320b5 138 escmController.say("%s is open" ,
foxbrianr 4:7226c43320b5 139 addressMap.addresses[active_address].description );
foxbrianr 4:7226c43320b5 140 }
foxbrianr 4:7226c43320b5 141 else
foxbrianr 4:7226c43320b5 142 {
foxbrianr 4:7226c43320b5 143 escmController.say("Unit %d is open" ,
foxbrianr 4:7226c43320b5 144 addressMap.addresses[active_address].address );
foxbrianr 4:7226c43320b5 145 }
foxbrianr 4:7226c43320b5 146
foxbrianr 4:7226c43320b5 147 break;
foxbrianr 4:7226c43320b5 148 };
foxbrianr 4:7226c43320b5 149 update_needed=0;
foxbrianr 4:7226c43320b5 150 }
foxbrianr 4:7226c43320b5 151 displayCurrentTime(lcd);
foxbrianr 4:7226c43320b5 152 }
foxbrianr 4:7226c43320b5 153
foxbrianr 4:7226c43320b5 154 void EditAddressMenu::pressMode()
foxbrianr 4:7226c43320b5 155 {
foxbrianr 4:7226c43320b5 156 // toggle active menu
foxbrianr 4:7226c43320b5 157 switch(active_selection) {
foxbrianr 4:7226c43320b5 158 case SELECT_ADDRESS:
foxbrianr 4:7226c43320b5 159
foxbrianr 4:7226c43320b5 160 // copy the current string to an editable copy
foxbrianr 4:7226c43320b5 161 strcpy( tmp_description ,
foxbrianr 4:7226c43320b5 162 addressMap.addresses[active_address].description);
foxbrianr 4:7226c43320b5 163
foxbrianr 4:7226c43320b5 164 active_selection = EDIT_ADDRESS;
foxbrianr 4:7226c43320b5 165 active_position = 0;
foxbrianr 4:7226c43320b5 166
foxbrianr 4:7226c43320b5 167 break;
foxbrianr 4:7226c43320b5 168 case EDIT_ADDRESS:
foxbrianr 4:7226c43320b5 169 active_selection = DEFAULT_DISPLAY;
foxbrianr 4:7226c43320b5 170
foxbrianr 4:7226c43320b5 171 // -------------------------------------------------------
foxbrianr 4:7226c43320b5 172 // save the editable copy back into address map
foxbrianr 4:7226c43320b5 173 strcpy(
foxbrianr 4:7226c43320b5 174 addressMap.addresses[active_address].description
foxbrianr 4:7226c43320b5 175 , tmp_description);
foxbrianr 4:7226c43320b5 176 addressMap.save();
foxbrianr 4:7226c43320b5 177 // -------------------------------------------------------
foxbrianr 4:7226c43320b5 178 active_position = 0;
foxbrianr 4:7226c43320b5 179 break;
foxbrianr 4:7226c43320b5 180 default:
foxbrianr 4:7226c43320b5 181 active_selection = SELECT_ADDRESS;
foxbrianr 4:7226c43320b5 182 break;
foxbrianr 4:7226c43320b5 183 };
foxbrianr 4:7226c43320b5 184
foxbrianr 4:7226c43320b5 185 update_needed = 1;
foxbrianr 4:7226c43320b5 186 }
foxbrianr 4:7226c43320b5 187
foxbrianr 4:7226c43320b5 188 void EditAddressMenu::pressSet()
foxbrianr 4:7226c43320b5 189 {
foxbrianr 4:7226c43320b5 190 // set button advances to next character position OR
foxbrianr 4:7226c43320b5 191 // goes back to normal
foxbrianr 4:7226c43320b5 192 switch(active_selection) {
foxbrianr 4:7226c43320b5 193
foxbrianr 4:7226c43320b5 194 case DEFAULT_DISPLAY:
foxbrianr 4:7226c43320b5 195 case SELECT_ADDRESS:
foxbrianr 4:7226c43320b5 196
foxbrianr 4:7226c43320b5 197
foxbrianr 4:7226c43320b5 198 // copy the current string to an editable copy
foxbrianr 4:7226c43320b5 199 strcpy( tmp_description ,
foxbrianr 4:7226c43320b5 200 addressMap.addresses[active_address].description);
foxbrianr 4:7226c43320b5 201
foxbrianr 4:7226c43320b5 202 active_selection = EDIT_ADDRESS;
foxbrianr 4:7226c43320b5 203 active_position = 0;
foxbrianr 4:7226c43320b5 204
foxbrianr 4:7226c43320b5 205 break;
foxbrianr 4:7226c43320b5 206
foxbrianr 4:7226c43320b5 207 case EDIT_ADDRESS:
foxbrianr 4:7226c43320b5 208 active_position++;
foxbrianr 4:7226c43320b5 209
foxbrianr 4:7226c43320b5 210 if ( active_position > MAX_ADDR_LENGTH )
foxbrianr 4:7226c43320b5 211 {
foxbrianr 4:7226c43320b5 212
foxbrianr 4:7226c43320b5 213 // -------------------------------------------------------
foxbrianr 4:7226c43320b5 214 // save the editable copy back into address map
foxbrianr 4:7226c43320b5 215 strcpy(
foxbrianr 4:7226c43320b5 216 addressMap.addresses[active_address].description
foxbrianr 4:7226c43320b5 217 , tmp_description);
foxbrianr 4:7226c43320b5 218
foxbrianr 4:7226c43320b5 219 addressMap.save();
foxbrianr 4:7226c43320b5 220 // -------------------------------------------------------
foxbrianr 4:7226c43320b5 221 active_position = 0;
foxbrianr 4:7226c43320b5 222 }
foxbrianr 4:7226c43320b5 223
foxbrianr 4:7226c43320b5 224 break;
foxbrianr 4:7226c43320b5 225
foxbrianr 4:7226c43320b5 226 default:
foxbrianr 4:7226c43320b5 227 break;
foxbrianr 4:7226c43320b5 228 };
foxbrianr 4:7226c43320b5 229
foxbrianr 4:7226c43320b5 230 update_needed = 1;
foxbrianr 4:7226c43320b5 231 }
foxbrianr 4:7226c43320b5 232
foxbrianr 4:7226c43320b5 233
foxbrianr 4:7226c43320b5 234 void EditAddressMenu:: nextValidChar (char * value , int direction)
foxbrianr 4:7226c43320b5 235 {
foxbrianr 4:7226c43320b5 236 char c = *value;
foxbrianr 4:7226c43320b5 237
foxbrianr 4:7226c43320b5 238 size_t index = valid_characters.find(c);
foxbrianr 4:7226c43320b5 239
foxbrianr 4:7226c43320b5 240 if ( index == string::npos )
foxbrianr 4:7226c43320b5 241 {
foxbrianr 4:7226c43320b5 242 index = 0;
foxbrianr 4:7226c43320b5 243 }
foxbrianr 4:7226c43320b5 244 else
foxbrianr 4:7226c43320b5 245 {
foxbrianr 4:7226c43320b5 246 index += direction;
foxbrianr 4:7226c43320b5 247
foxbrianr 4:7226c43320b5 248 if (index<0)
foxbrianr 4:7226c43320b5 249 index = valid_characters.size()-1;
foxbrianr 4:7226c43320b5 250 if (index >= valid_characters.size())
foxbrianr 4:7226c43320b5 251 index = 0;
foxbrianr 4:7226c43320b5 252
foxbrianr 4:7226c43320b5 253 }
foxbrianr 4:7226c43320b5 254
foxbrianr 4:7226c43320b5 255 *value = valid_characters[index];
foxbrianr 4:7226c43320b5 256 }
foxbrianr 4:7226c43320b5 257
foxbrianr 4:7226c43320b5 258
foxbrianr 4:7226c43320b5 259 void EditAddressMenu::pressUp()
foxbrianr 4:7226c43320b5 260 {
foxbrianr 4:7226c43320b5 261 // either advances the pointer to current object in list OR
foxbrianr 4:7226c43320b5 262 // character in array
foxbrianr 4:7226c43320b5 263 switch(active_selection) {
foxbrianr 4:7226c43320b5 264 case SELECT_ADDRESS:
foxbrianr 4:7226c43320b5 265 active_address--;
foxbrianr 4:7226c43320b5 266 update_needed = 1;
foxbrianr 4:7226c43320b5 267 break;
foxbrianr 4:7226c43320b5 268 case EDIT_ADDRESS:
foxbrianr 4:7226c43320b5 269 nextValidChar (&tmp_description[active_position],1);
foxbrianr 4:7226c43320b5 270 update_needed = 1;
foxbrianr 4:7226c43320b5 271 break;
foxbrianr 4:7226c43320b5 272
foxbrianr 4:7226c43320b5 273 default:
foxbrianr 4:7226c43320b5 274 active_address--;
foxbrianr 4:7226c43320b5 275 update_needed = 1;
foxbrianr 4:7226c43320b5 276 break;
foxbrianr 4:7226c43320b5 277
foxbrianr 4:7226c43320b5 278 }
foxbrianr 4:7226c43320b5 279
foxbrianr 4:7226c43320b5 280 LIMIT(active_address , 0, MAX_ADDRESSES - 1);
foxbrianr 4:7226c43320b5 281 LIMIT(active_position , 0, MAX_ADDR_LENGTH -1);
foxbrianr 4:7226c43320b5 282
foxbrianr 4:7226c43320b5 283 }
foxbrianr 4:7226c43320b5 284
foxbrianr 4:7226c43320b5 285 void EditAddressMenu::pressDown()
foxbrianr 4:7226c43320b5 286 {
foxbrianr 4:7226c43320b5 287 // either advances the pointer to current object in list OR
foxbrianr 4:7226c43320b5 288 // character in array
foxbrianr 4:7226c43320b5 289 switch(active_selection) {
foxbrianr 4:7226c43320b5 290
foxbrianr 4:7226c43320b5 291 case SELECT_ADDRESS:
foxbrianr 4:7226c43320b5 292 active_address++;
foxbrianr 4:7226c43320b5 293 update_needed = 1;
foxbrianr 4:7226c43320b5 294 break;
foxbrianr 4:7226c43320b5 295
foxbrianr 4:7226c43320b5 296 case EDIT_ADDRESS:
foxbrianr 4:7226c43320b5 297 nextValidChar (&tmp_description[active_position],-1);
foxbrianr 4:7226c43320b5 298 //active_position--;
foxbrianr 4:7226c43320b5 299 update_needed = 1;
foxbrianr 4:7226c43320b5 300 break;
foxbrianr 4:7226c43320b5 301
foxbrianr 4:7226c43320b5 302 default:
foxbrianr 4:7226c43320b5 303 active_address++;
foxbrianr 4:7226c43320b5 304 update_needed = 1;
foxbrianr 4:7226c43320b5 305 break;
foxbrianr 4:7226c43320b5 306
foxbrianr 4:7226c43320b5 307 }
foxbrianr 4:7226c43320b5 308
foxbrianr 4:7226c43320b5 309
foxbrianr 4:7226c43320b5 310
foxbrianr 4:7226c43320b5 311 LIMIT(active_address , 0, MAX_ADDRESSES - 1);
foxbrianr 4:7226c43320b5 312 LIMIT(active_position , 0, MAX_ADDR_LENGTH -1);
foxbrianr 4:7226c43320b5 313
foxbrianr 4:7226c43320b5 314 }