Release 1.01

Dependents:   mbed_escm2000

Committer:
foxbrianr
Date:
Tue Mar 17 17:23:15 2020 +0000
Revision:
8:9d4e684d8eb8
Parent:
5:9f4d4f8ffc00
fix up code for barry

Who changed what in which revision?

UserRevisionLine numberNew contents of line
foxbrianr 5:9f4d4f8ffc00 1 /**************************************************************************
foxbrianr 5:9f4d4f8ffc00 2 * @file EditAddressMenu.cpp
foxbrianr 5:9f4d4f8ffc00 3 * @brief Base class for implementing the Edit Address Menu display
foxbrianr 5:9f4d4f8ffc00 4 * @version: V1.0
foxbrianr 5:9f4d4f8ffc00 5 * @date: 9/17/2019
foxbrianr 5:9f4d4f8ffc00 6
foxbrianr 5:9f4d4f8ffc00 7 *
foxbrianr 5:9f4d4f8ffc00 8 * @note
foxbrianr 5:9f4d4f8ffc00 9 * Copyright (C) 2019 E3 Design. All rights reserved.
foxbrianr 5:9f4d4f8ffc00 10 *
foxbrianr 5:9f4d4f8ffc00 11 * @par
foxbrianr 5:9f4d4f8ffc00 12 * E3 Designers LLC is supplying this software for use with Cortex-M3 LPC1768
foxbrianr 5:9f4d4f8ffc00 13 * processor based microcontroller for the ESCM 2000 Monitor and Display.
foxbrianr 5:9f4d4f8ffc00 14 * *
foxbrianr 5:9f4d4f8ffc00 15 * @par
foxbrianr 5:9f4d4f8ffc00 16 * THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
foxbrianr 5:9f4d4f8ffc00 17 * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
foxbrianr 5:9f4d4f8ffc00 18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
foxbrianr 5:9f4d4f8ffc00 19 * ARM SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR
foxbrianr 5:9f4d4f8ffc00 20 * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
foxbrianr 5:9f4d4f8ffc00 21 *
foxbrianr 5:9f4d4f8ffc00 22 ******************************************************************************/
foxbrianr 4:7226c43320b5 23 #include "mbed.h"
foxbrianr 4:7226c43320b5 24 #include "EditAddressMenu.h"
foxbrianr 4:7226c43320b5 25 #include "TimeUtilities.h"
foxbrianr 4:7226c43320b5 26 #include "ESCMControlApp.h"
foxbrianr 4:7226c43320b5 27
foxbrianr 4:7226c43320b5 28 #define DEFAULT_DISPLAY 0
foxbrianr 4:7226c43320b5 29 #define SELECT_ADDRESS 1
foxbrianr 4:7226c43320b5 30 #define EDIT_ADDRESS 2
foxbrianr 4:7226c43320b5 31
foxbrianr 4:7226c43320b5 32
foxbrianr 5:9f4d4f8ffc00 33 string valid_characters = {"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_ " };
foxbrianr 4:7226c43320b5 34
foxbrianr 5:9f4d4f8ffc00 35 /******************************************************************************/
foxbrianr 4:7226c43320b5 36 EditAddressMenu::EditAddressMenu(char* id): Menu(id)
foxbrianr 4:7226c43320b5 37 {
foxbrianr 4:7226c43320b5 38
foxbrianr 4:7226c43320b5 39 active_selection = 0;
foxbrianr 4:7226c43320b5 40 active_address = 0;
foxbrianr 4:7226c43320b5 41 active_position = 0;
foxbrianr 4:7226c43320b5 42
foxbrianr 4:7226c43320b5 43 row=0;
foxbrianr 4:7226c43320b5 44 column=0;
foxbrianr 4:7226c43320b5 45
foxbrianr 4:7226c43320b5 46
foxbrianr 4:7226c43320b5 47 }
foxbrianr 4:7226c43320b5 48
foxbrianr 5:9f4d4f8ffc00 49 /******************************************************************************/
foxbrianr 4:7226c43320b5 50 void EditAddressMenu::init()
foxbrianr 4:7226c43320b5 51 {
foxbrianr 4:7226c43320b5 52 active_selection = 0;
foxbrianr 4:7226c43320b5 53 active_address = 0;
foxbrianr 4:7226c43320b5 54 active_position = 0;
foxbrianr 4:7226c43320b5 55 update_needed = 1;
foxbrianr 4:7226c43320b5 56
foxbrianr 4:7226c43320b5 57 top = active_address;
foxbrianr 4:7226c43320b5 58 bottom = active_address +2;
foxbrianr 4:7226c43320b5 59 }
foxbrianr 4:7226c43320b5 60
foxbrianr 5:9f4d4f8ffc00 61 /******************************************************************************/
foxbrianr 4:7226c43320b5 62 void EditAddressMenu::display(LCD * lcd)
foxbrianr 4:7226c43320b5 63 {
foxbrianr 4:7226c43320b5 64 // paging
foxbrianr 4:7226c43320b5 65 if (active_address < top )
foxbrianr 4:7226c43320b5 66 {
foxbrianr 4:7226c43320b5 67 top = active_address ;
foxbrianr 4:7226c43320b5 68 bottom = active_address + 2;
foxbrianr 4:7226c43320b5 69 update_needed=1;
foxbrianr 4:7226c43320b5 70 }
foxbrianr 4:7226c43320b5 71 else if (active_address > bottom)
foxbrianr 4:7226c43320b5 72 {
foxbrianr 4:7226c43320b5 73 top = active_address - 2;
foxbrianr 4:7226c43320b5 74 bottom = active_address;
foxbrianr 4:7226c43320b5 75 update_needed=1;
foxbrianr 4:7226c43320b5 76 }
foxbrianr 4:7226c43320b5 77 else
foxbrianr 4:7226c43320b5 78 {
foxbrianr 4:7226c43320b5 79
foxbrianr 4:7226c43320b5 80 }
foxbrianr 4:7226c43320b5 81
foxbrianr 4:7226c43320b5 82
foxbrianr 4:7226c43320b5 83 if (update_needed) {
foxbrianr 4:7226c43320b5 84
foxbrianr 4:7226c43320b5 85 lcd->cls();
foxbrianr 4:7226c43320b5 86 switch(active_selection) {
foxbrianr 4:7226c43320b5 87 // -----------------------------------------------------------------
foxbrianr 4:7226c43320b5 88 //Select Address
foxbrianr 4:7226c43320b5 89 // -----------------------------------------------------------------
foxbrianr 4:7226c43320b5 90 case SELECT_ADDRESS:
foxbrianr 4:7226c43320b5 91 {
foxbrianr 4:7226c43320b5 92 lcd->locate(0,0);
foxbrianr 4:7226c43320b5 93 lcd->printf("Select Address :");
foxbrianr 4:7226c43320b5 94 lcd->locate(1,0);
foxbrianr 4:7226c43320b5 95
foxbrianr 4:7226c43320b5 96 Address *addr = &addressMap.addresses[active_address];
foxbrianr 4:7226c43320b5 97
foxbrianr 4:7226c43320b5 98 lcd->printf(" %02d | %-20s",
foxbrianr 4:7226c43320b5 99 addr->address ,
foxbrianr 4:7226c43320b5 100 addr->description );
foxbrianr 4:7226c43320b5 101 }
foxbrianr 4:7226c43320b5 102 break;
foxbrianr 4:7226c43320b5 103
foxbrianr 4:7226c43320b5 104 // -----------------------------------------------------------------
foxbrianr 4:7226c43320b5 105 // Select Char
foxbrianr 4:7226c43320b5 106 // -----------------------------------------------------------------
foxbrianr 4:7226c43320b5 107 case EDIT_ADDRESS:
foxbrianr 4:7226c43320b5 108
foxbrianr 4:7226c43320b5 109 {
foxbrianr 4:7226c43320b5 110 Address *addr = &addressMap.addresses[active_address];
foxbrianr 4:7226c43320b5 111
foxbrianr 4:7226c43320b5 112 lcd->locate(0,0);
foxbrianr 4:7226c43320b5 113 lcd->printf("Edit Text (%02d):" , addr->address );
foxbrianr 4:7226c43320b5 114 lcd->locate(1,0);
foxbrianr 4:7226c43320b5 115 lcd->printf("Current Text : [%-20s]", addr->description );
foxbrianr 4:7226c43320b5 116 lcd->locate(2,0);
foxbrianr 4:7226c43320b5 117 lcd->printf("Updated Text : [%-20s]", tmp_description );
foxbrianr 4:7226c43320b5 118 lcd->locate(3,active_position+16);
foxbrianr 4:7226c43320b5 119 lcd->printf("^" );
foxbrianr 4:7226c43320b5 120 }
foxbrianr 4:7226c43320b5 121 break;
foxbrianr 4:7226c43320b5 122
foxbrianr 4:7226c43320b5 123 // -----------------------------------------------------------------
foxbrianr 4:7226c43320b5 124 // Display
foxbrianr 4:7226c43320b5 125 // -----------------------------------------------------------------
foxbrianr 4:7226c43320b5 126 default:
foxbrianr 4:7226c43320b5 127 #if 1
foxbrianr 4:7226c43320b5 128 lcd->locate(0,0);
foxbrianr 4:7226c43320b5 129 lcd->printf("Address Map:");
foxbrianr 4:7226c43320b5 130 #else
foxbrianr 4:7226c43320b5 131 lcd->locate(0,0);
foxbrianr 4:7226c43320b5 132 lcd->printf("index=%d, (%d %d)", active_address, top, bottom);
foxbrianr 4:7226c43320b5 133 #endif
foxbrianr 4:7226c43320b5 134 // update display
foxbrianr 4:7226c43320b5 135 for(int i=0; i<3; i++) {
foxbrianr 4:7226c43320b5 136
foxbrianr 4:7226c43320b5 137 int index = top + i;
foxbrianr 4:7226c43320b5 138 int line = (1+i);
foxbrianr 4:7226c43320b5 139
foxbrianr 4:7226c43320b5 140 int selected = active_address == index;
foxbrianr 4:7226c43320b5 141
foxbrianr 4:7226c43320b5 142 if(selected) {
foxbrianr 4:7226c43320b5 143 lcd->locate(line,0);
foxbrianr 4:7226c43320b5 144 lcd->printf(">");
foxbrianr 4:7226c43320b5 145 }
foxbrianr 4:7226c43320b5 146
foxbrianr 4:7226c43320b5 147
foxbrianr 4:7226c43320b5 148 if (index < MAX_ADDRESSES)
foxbrianr 4:7226c43320b5 149 {
foxbrianr 4:7226c43320b5 150 Address *a = &addressMap.addresses[index];
foxbrianr 4:7226c43320b5 151 lcd->locate(line,0);
foxbrianr 4:7226c43320b5 152 lcd->printf("%s%02d | %-20s",
foxbrianr 4:7226c43320b5 153 ((selected)?">":" "),
foxbrianr 4:7226c43320b5 154 a->address,
foxbrianr 4:7226c43320b5 155 a->description );
foxbrianr 4:7226c43320b5 156 }
foxbrianr 4:7226c43320b5 157 }
foxbrianr 4:7226c43320b5 158
foxbrianr 4:7226c43320b5 159 break;
foxbrianr 4:7226c43320b5 160 };
foxbrianr 5:9f4d4f8ffc00 161
foxbrianr 5:9f4d4f8ffc00 162 lcd->locate(2,20);
foxbrianr 5:9f4d4f8ffc00 163 //lcd->printf("%02d,%02d,%02d,%02d",active_address,active_position,top,bottom);
foxbrianr 4:7226c43320b5 164 update_needed=0;
foxbrianr 4:7226c43320b5 165 }
foxbrianr 5:9f4d4f8ffc00 166
foxbrianr 4:7226c43320b5 167 displayCurrentTime(lcd);
foxbrianr 4:7226c43320b5 168 }
foxbrianr 4:7226c43320b5 169
foxbrianr 5:9f4d4f8ffc00 170 /******************************************************************************/
foxbrianr 4:7226c43320b5 171 void EditAddressMenu::pressMode()
foxbrianr 4:7226c43320b5 172 {
foxbrianr 4:7226c43320b5 173 // toggle active menu
foxbrianr 4:7226c43320b5 174 switch(active_selection) {
foxbrianr 4:7226c43320b5 175 case SELECT_ADDRESS:
foxbrianr 4:7226c43320b5 176
foxbrianr 4:7226c43320b5 177 // copy the current string to an editable copy
foxbrianr 4:7226c43320b5 178 strcpy( tmp_description ,
foxbrianr 4:7226c43320b5 179 addressMap.addresses[active_address].description);
foxbrianr 4:7226c43320b5 180
foxbrianr 4:7226c43320b5 181 active_selection = EDIT_ADDRESS;
foxbrianr 4:7226c43320b5 182 active_position = 0;
foxbrianr 4:7226c43320b5 183
foxbrianr 4:7226c43320b5 184 break;
foxbrianr 4:7226c43320b5 185 case EDIT_ADDRESS:
foxbrianr 4:7226c43320b5 186 active_selection = DEFAULT_DISPLAY;
foxbrianr 4:7226c43320b5 187
foxbrianr 4:7226c43320b5 188 // -------------------------------------------------------
foxbrianr 4:7226c43320b5 189 // save the editable copy back into address map
foxbrianr 4:7226c43320b5 190 strcpy(
foxbrianr 4:7226c43320b5 191 addressMap.addresses[active_address].description
foxbrianr 4:7226c43320b5 192 , tmp_description);
foxbrianr 4:7226c43320b5 193 addressMap.save();
foxbrianr 4:7226c43320b5 194 // -------------------------------------------------------
foxbrianr 4:7226c43320b5 195 active_position = 0;
foxbrianr 4:7226c43320b5 196 break;
foxbrianr 4:7226c43320b5 197 default:
foxbrianr 4:7226c43320b5 198 active_selection = SELECT_ADDRESS;
foxbrianr 4:7226c43320b5 199 break;
foxbrianr 4:7226c43320b5 200 };
foxbrianr 4:7226c43320b5 201
foxbrianr 4:7226c43320b5 202 update_needed = 1;
foxbrianr 4:7226c43320b5 203 }
foxbrianr 4:7226c43320b5 204
foxbrianr 5:9f4d4f8ffc00 205 /******************************************************************************/
foxbrianr 4:7226c43320b5 206 void EditAddressMenu::pressSet()
foxbrianr 4:7226c43320b5 207 {
foxbrianr 4:7226c43320b5 208 // set button advances to next character position OR
foxbrianr 4:7226c43320b5 209 // goes back to normal
foxbrianr 4:7226c43320b5 210 switch(active_selection) {
foxbrianr 4:7226c43320b5 211
foxbrianr 4:7226c43320b5 212 case DEFAULT_DISPLAY:
foxbrianr 4:7226c43320b5 213 case SELECT_ADDRESS:
foxbrianr 4:7226c43320b5 214
foxbrianr 4:7226c43320b5 215
foxbrianr 4:7226c43320b5 216 // copy the current string to an editable copy
foxbrianr 4:7226c43320b5 217 strcpy( tmp_description ,
foxbrianr 4:7226c43320b5 218 addressMap.addresses[active_address].description);
foxbrianr 4:7226c43320b5 219
foxbrianr 4:7226c43320b5 220 active_selection = EDIT_ADDRESS;
foxbrianr 4:7226c43320b5 221 active_position = 0;
foxbrianr 4:7226c43320b5 222
foxbrianr 4:7226c43320b5 223 break;
foxbrianr 4:7226c43320b5 224
foxbrianr 4:7226c43320b5 225 case EDIT_ADDRESS:
foxbrianr 4:7226c43320b5 226 active_position++;
foxbrianr 4:7226c43320b5 227
foxbrianr 4:7226c43320b5 228 if ( active_position > MAX_ADDR_LENGTH )
foxbrianr 4:7226c43320b5 229 {
foxbrianr 4:7226c43320b5 230
foxbrianr 4:7226c43320b5 231 // -------------------------------------------------------
foxbrianr 4:7226c43320b5 232 // save the editable copy back into address map
foxbrianr 4:7226c43320b5 233 strcpy(
foxbrianr 4:7226c43320b5 234 addressMap.addresses[active_address].description
foxbrianr 4:7226c43320b5 235 , tmp_description);
foxbrianr 4:7226c43320b5 236
foxbrianr 4:7226c43320b5 237 addressMap.save();
foxbrianr 4:7226c43320b5 238 // -------------------------------------------------------
foxbrianr 4:7226c43320b5 239 active_position = 0;
foxbrianr 4:7226c43320b5 240 }
foxbrianr 4:7226c43320b5 241
foxbrianr 4:7226c43320b5 242 break;
foxbrianr 4:7226c43320b5 243
foxbrianr 4:7226c43320b5 244 default:
foxbrianr 4:7226c43320b5 245 break;
foxbrianr 4:7226c43320b5 246 };
foxbrianr 4:7226c43320b5 247
foxbrianr 4:7226c43320b5 248 update_needed = 1;
foxbrianr 4:7226c43320b5 249 }
foxbrianr 4:7226c43320b5 250
foxbrianr 4:7226c43320b5 251
foxbrianr 5:9f4d4f8ffc00 252 /******************************************************************************/
foxbrianr 4:7226c43320b5 253 void EditAddressMenu:: nextValidChar (char * value , int direction)
foxbrianr 4:7226c43320b5 254 {
foxbrianr 4:7226c43320b5 255 char c = *value;
foxbrianr 4:7226c43320b5 256
foxbrianr 5:9f4d4f8ffc00 257 int index = (int)valid_characters.find(c);
foxbrianr 4:7226c43320b5 258
foxbrianr 4:7226c43320b5 259 if ( index == string::npos )
foxbrianr 4:7226c43320b5 260 {
foxbrianr 5:9f4d4f8ffc00 261 index = 0; ///invalid charcter
foxbrianr 4:7226c43320b5 262 }
foxbrianr 4:7226c43320b5 263 else
foxbrianr 4:7226c43320b5 264 {
foxbrianr 4:7226c43320b5 265 index += direction;
foxbrianr 4:7226c43320b5 266
foxbrianr 5:9f4d4f8ffc00 267 if (index< 0)
foxbrianr 4:7226c43320b5 268 index = valid_characters.size()-1;
foxbrianr 5:9f4d4f8ffc00 269
foxbrianr 4:7226c43320b5 270 if (index >= valid_characters.size())
foxbrianr 4:7226c43320b5 271 index = 0;
foxbrianr 4:7226c43320b5 272
foxbrianr 4:7226c43320b5 273 }
foxbrianr 4:7226c43320b5 274
foxbrianr 4:7226c43320b5 275 *value = valid_characters[index];
foxbrianr 4:7226c43320b5 276 }
foxbrianr 4:7226c43320b5 277
foxbrianr 4:7226c43320b5 278
foxbrianr 5:9f4d4f8ffc00 279 /******************************************************************************/
foxbrianr 4:7226c43320b5 280 void EditAddressMenu::pressUp()
foxbrianr 4:7226c43320b5 281 {
foxbrianr 4:7226c43320b5 282 // either advances the pointer to current object in list OR
foxbrianr 4:7226c43320b5 283 // character in array
foxbrianr 4:7226c43320b5 284 switch(active_selection) {
foxbrianr 4:7226c43320b5 285 case SELECT_ADDRESS:
foxbrianr 4:7226c43320b5 286 active_address--;
foxbrianr 4:7226c43320b5 287 update_needed = 1;
foxbrianr 4:7226c43320b5 288 break;
foxbrianr 4:7226c43320b5 289 case EDIT_ADDRESS:
foxbrianr 4:7226c43320b5 290 nextValidChar (&tmp_description[active_position],1);
foxbrianr 4:7226c43320b5 291 update_needed = 1;
foxbrianr 4:7226c43320b5 292 break;
foxbrianr 4:7226c43320b5 293
foxbrianr 4:7226c43320b5 294 default:
foxbrianr 4:7226c43320b5 295 active_address--;
foxbrianr 4:7226c43320b5 296 update_needed = 1;
foxbrianr 4:7226c43320b5 297 break;
foxbrianr 4:7226c43320b5 298
foxbrianr 4:7226c43320b5 299 }
foxbrianr 4:7226c43320b5 300
foxbrianr 5:9f4d4f8ffc00 301 // ---------------------------------------------
foxbrianr 5:9f4d4f8ffc00 302 // wrap around
foxbrianr 5:9f4d4f8ffc00 303 if ( active_address < 0 )
foxbrianr 5:9f4d4f8ffc00 304 {
foxbrianr 5:9f4d4f8ffc00 305 active_address = MAX_ADDRESSES-1;
foxbrianr 5:9f4d4f8ffc00 306 }
foxbrianr 5:9f4d4f8ffc00 307
foxbrianr 5:9f4d4f8ffc00 308
foxbrianr 4:7226c43320b5 309 }
foxbrianr 4:7226c43320b5 310
foxbrianr 5:9f4d4f8ffc00 311 /******************************************************************************/
foxbrianr 4:7226c43320b5 312 void EditAddressMenu::pressDown()
foxbrianr 4:7226c43320b5 313 {
foxbrianr 4:7226c43320b5 314 // either advances the pointer to current object in list OR
foxbrianr 4:7226c43320b5 315 // character in array
foxbrianr 4:7226c43320b5 316 switch(active_selection) {
foxbrianr 4:7226c43320b5 317
foxbrianr 4:7226c43320b5 318 case SELECT_ADDRESS:
foxbrianr 4:7226c43320b5 319 active_address++;
foxbrianr 4:7226c43320b5 320 update_needed = 1;
foxbrianr 4:7226c43320b5 321 break;
foxbrianr 4:7226c43320b5 322
foxbrianr 4:7226c43320b5 323 case EDIT_ADDRESS:
foxbrianr 4:7226c43320b5 324 nextValidChar (&tmp_description[active_position],-1);
foxbrianr 4:7226c43320b5 325 update_needed = 1;
foxbrianr 4:7226c43320b5 326 break;
foxbrianr 4:7226c43320b5 327
foxbrianr 4:7226c43320b5 328 default:
foxbrianr 4:7226c43320b5 329 active_address++;
foxbrianr 4:7226c43320b5 330 update_needed = 1;
foxbrianr 4:7226c43320b5 331 break;
foxbrianr 4:7226c43320b5 332
foxbrianr 4:7226c43320b5 333 }
foxbrianr 4:7226c43320b5 334
foxbrianr 5:9f4d4f8ffc00 335 // ---------------------------------------------
foxbrianr 5:9f4d4f8ffc00 336 // wrap around
foxbrianr 5:9f4d4f8ffc00 337 if ( active_address >= MAX_ADDRESSES )
foxbrianr 5:9f4d4f8ffc00 338 {
foxbrianr 5:9f4d4f8ffc00 339 active_address = 0;
foxbrianr 5:9f4d4f8ffc00 340 }
foxbrianr 5:9f4d4f8ffc00 341 }
foxbrianr 4:7226c43320b5 342
foxbrianr 5:9f4d4f8ffc00 343 /******************************************************************************/