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.
Dependencies: DMBasicGUI DMSupport
NumericKeypadPageHandler.cpp
00001 #include "NumericKeypadPageHandler.h" 00002 #include "EasyGUITouchAreaIndices.h" 00003 #include "GetGCStatusLoop.h" 00004 00005 #include <stdio.h> 00006 #include <stdlib.h> 00007 00008 00009 /* 00010 Draws the background bitmap. It fills the screen, so you do not need to call GuiLib_Clear. 00011 Defined in main.cpp 00012 */ 00013 extern void DrawBackgroundBitmap(void); 00014 #define USING_BACKGROUND_BITMAP 00015 00016 00017 /* 00018 For Display (LPC4088) Bug #11, draw a background bitmap without a grey bar at the bottom. 00019 For now, fake this with a page full of one colour. 00020 00021 Defined in main.cpp 00022 */ 00023 void DrawFakeBackgroundBitmapForNumericKeypadPage(void); 00024 00025 00026 /* 00027 Displays the specified easyGUI 'structure' (or page, to use a more easily understood term). 00028 Defined in main.cpp 00029 */ 00030 extern void DisplayEasyGuiStructure(int structureIndex, USBDeviceConnected* usbDevice, USBHostGC* usbHostGC, bool updateEasyGUIVariables = true); 00031 00032 00033 /* 00034 Converts three eight-bit colour values to the corresponding 16-bit RGB565 value. 00035 Defined in main.cpp 00036 */ 00037 extern GuiConst_INTCOLOR SixteenBitColorValue(GuiConst_INT8U red, GuiConst_INT8U green, GuiConst_INT8U blue); 00038 00039 00040 /* 00041 Displays the specified text string at the specified location in the currently-displayed easyGUI page. 00042 00043 Defined in main.cpp - and omits the 'ALLOW_DEBUG_PRINTS' #define 00044 */ 00045 extern void SpecialDebugPrint(char *stuffToPrint, GuiConst_INT16S X, GuiConst_INT16S Y); 00046 00047 00048 /* 00049 Note that this class is a singleton - we do not need or want there to be more than one instance of it 00050 (we will not show more than one "NumericKeypadPage" to the user at the same time). 00051 */ 00052 NumericKeypadPageHandler * NumericKeypadPageHandler::theNumericKeypadPageHandlerInstance = NULL; 00053 00054 00055 /* 00056 Singleton class - return the one and only instance, first creating it if necessary. 00057 */ 00058 NumericKeypadPageHandler * NumericKeypadPageHandler::GetInstance(USBDeviceConnected* newUsbDevice, USBHostGC* newUsbHostGC) 00059 { 00060 if (theNumericKeypadPageHandlerInstance == NULL) { 00061 theNumericKeypadPageHandlerInstance = new NumericKeypadPageHandler(newUsbDevice, newUsbHostGC); 00062 } 00063 00064 return theNumericKeypadPageHandlerInstance; 00065 } 00066 00067 // Singleton class - private constructor 00068 NumericKeypadPageHandler::NumericKeypadPageHandler(USBDeviceConnected* newUsbDevice, USBHostGC* newUsbHostGC) 00069 { 00070 // Note that we do not use these values here - 00071 // but we do need to pass them to the (main.cpp) function DisplayEasyGUIStructure 00072 // when the user presses Apply or Cancel 00073 usbDevice = newUsbDevice; 00074 usbHostGC = newUsbHostGC; 00075 00076 easyGUIVariableToEdit = NULL; 00077 internalVariableToEdit = NULL; 00078 editVariableUnits[0]= '\0'; 00079 00080 easyGUICallingPage = -1; 00081 00082 applyFunctionPtr = NULL; 00083 00084 minimumValue = 0; 00085 maximumValue = 999; 00086 00087 allowedDecimalPlaces = 0; 00088 editingFractionalPart= 0; 00089 00090 allowNegativeNumbers = false; 00091 00092 inLockMode = false; 00093 validLockCode = 0; 00094 easyGUIVariableForInvalidLockCodeMessage = NULL; 00095 invalidLockCodeMessage[0] = '\0'; 00096 pageToDisplayIfLockCodeValid = -1; 00097 00098 GuiVar_numericKeypadValueBackgroundColour = SixteenBitColorValue(255, 255, 255); // White (no need for 'active' colour - 00099 // there is only one active field, and it is always active) 00100 } 00101 00102 // Private destructor also 00103 NumericKeypadPageHandler::~NumericKeypadPageHandler() 00104 { 00105 } 00106 00107 00108 /* 00109 Tells the caller whether or not the specified touch index is on the easyGUI 'NumericKeypadPage', 00110 and therefore needs to be handled by this class. 00111 00112 Args: the touch area index in question 00113 00114 Return code: true if the touch area is 'one of ours', false if not 00115 */ 00116 bool NumericKeypadPageHandler::TouchAreaIsOnNumericKeypadPage(int touchAreaIndex) 00117 { 00118 if((touchAreaIndex >= MIN_NUMERIC_KEYPAD_TOUCHINDEX) && (touchAreaIndex <= MAX_NUMERIC_KEYPAD_TOUCHINDEX)) { 00119 return true; 00120 } 00121 00122 // 'else' 00123 return false; 00124 } 00125 00126 00127 /* 00128 If the specified touch area represents a key or field on the easyGUI 'NumericKeypadPage', 00129 this function performs whatever action is appropriate for it. Provided so that the caller 00130 can (in effect) say "if this is one of yours, deal with it", without needing to know 00131 anything about what this class does, or how it handles the touch areas on that easyGUI page. 00132 00133 Args: the touch area index in question 00134 00135 Returns true if it dealt with the touch area (so the caller need not do anything else 00136 with the value), or false if it did not deal with the touch area (implying that it 00137 was not a touch area on the easyGUI 'NumericKeypadPage', and so the caller 00138 must deal with it some other way). 00139 */ 00140 bool NumericKeypadPageHandler::DealWithTouch(int touchAreaIndex) 00141 { 00142 if((touchAreaIndex >= NUMERIC_KEYPAD_BUTTON_0) && (touchAreaIndex <= NUMERIC_KEYPAD_BUTTON_9)) { 00143 00144 DealWithNumberKey(touchAreaIndex); 00145 00146 return true; 00147 } 00148 00149 if(touchAreaIndex == NUMERIC_KEYPAD_DELETE_BUTTON) { 00150 00151 DealWithDeleteKey(); 00152 00153 return true; 00154 } 00155 00156 if(touchAreaIndex == NUMERIC_KEYPAD_DOT_BUTTON) { 00157 00158 DealWithDotKey(); 00159 00160 return true; 00161 } 00162 00163 if(touchAreaIndex == NUMERIC_KEYPAD_PLUS_MINUS_BUTTON) { 00164 00165 DealWithPlusMinusKey(); 00166 00167 return true; 00168 } 00169 00170 if(touchAreaIndex == NUMERIC_KEYPAD_APPLY_BUTTON) { 00171 00172 DealWithApplyKey(); 00173 00174 return true; 00175 } 00176 00177 if(touchAreaIndex == NUMERIC_KEYPAD_CANCEL_BUTTON) { 00178 00179 DealWithCancelKey(); 00180 00181 return true; 00182 } 00183 00184 if(touchAreaIndex == NUMERIC_KEYPAD_CLEAR_BUTTON) { 00185 00186 DealWithClearKey(); 00187 00188 return true; 00189 } 00190 00191 // 'else' - none of the above 00192 return false; 00193 } 00194 00195 00196 /* 00197 Get ready to edit - initialise our pointers to the variables the calling page wants us to edit 00198 00199 Argument: the initial value of the variable we are editing, as an integer 00200 00201 No return code 00202 */ 00203 void NumericKeypadPageHandler::StartEditing(int initialValue, unsigned int placesOfDecimals, bool wantNegative) 00204 { 00205 easyGUIVariableToEdit = NULL; 00206 internalVariableToEdit = NULL; 00207 editVariableUnits[0]= '\0'; 00208 00209 applyFunctionPtr = NULL; 00210 00211 inLockMode = false; 00212 validLockCode = 0; 00213 easyGUIVariableForInvalidLockCodeMessage = NULL; 00214 invalidLockCodeMessage[0] = '\0'; 00215 pageToDisplayIfLockCodeValid = -1; 00216 00217 allowedDecimalPlaces = placesOfDecimals; 00218 00219 // We always edit at the right hand end (like e.g. a calculator) 00220 editingFractionalPart = (placesOfDecimals > 0); 00221 00222 allowNegativeNumbers = wantNegative; 00223 00224 sprintf(GuiVar_numericKeypadValue, "%d", initialValue); 00225 } 00226 00227 /* 00228 Get ready to edit - initialise our pointers to the variables the calling page wants us to edit 00229 00230 Argument: the initial value of the variable we are editing, as a string (which we assume represents an integer value) 00231 00232 No return code 00233 */ 00234 void NumericKeypadPageHandler::StartEditing(char* initialValue, unsigned int placesOfDecimals, bool wantNegative) 00235 { 00236 easyGUIVariableToEdit = NULL; 00237 internalVariableToEdit = NULL; 00238 editVariableUnits[0]= '\0'; 00239 00240 applyFunctionPtr = NULL; 00241 00242 inLockMode = false; 00243 validLockCode = 0; 00244 easyGUIVariableForInvalidLockCodeMessage = NULL; 00245 invalidLockCodeMessage[0] = '\0'; 00246 pageToDisplayIfLockCodeValid = -1; 00247 00248 allowedDecimalPlaces = placesOfDecimals; 00249 00250 allowNegativeNumbers = wantNegative; 00251 00252 // We always edit at the right hand end (like e.g. a calculator) 00253 editingFractionalPart = (placesOfDecimals > 0); 00254 00255 strcpy(GuiVar_numericKeypadValue, initialValue); 00256 } 00257 00258 00259 /* 00260 In lock mode, when the user presses the Apply button, we are not going to update a variable provided by the caller, 00261 but instead we will compare the value the user "typed in" against a "lock code" specified by the caller. If they match, 00262 we display a page specified by the caller - if they don't, we write a message to an easyGui variable (also specified by the caller), 00263 and display the calling page (which we assume has that easyGUI variable on it). 00264 00265 Arguments: the valid lock code 00266 the ID of the page to display if the lock code the user provides is valid (1) 00267 the easy GUI (string) variable to receive the invalid lock code message (2) 00268 the text of the invalid lock code message (2) 00269 00270 (1) is only used if the user provides a valid lock code 00271 (2) are only used if the user provides an invalid lock code 00272 00273 *** Note that it is up to the caller to specify valid values for all the above *** 00274 00275 No return code 00276 */ 00277 void NumericKeypadPageHandler::StartEditingInLockMode(unsigned int newValidLockCode, int newPageToDisplayIfLockCodeValid, 00278 GuiConst_TEXT* newEasyGUIVariableForInvalidLockCodeMessage, char *newInvalidLockCodeMessage) 00279 { 00280 easyGUIVariableToEdit = NULL; 00281 internalVariableToEdit = NULL; 00282 editVariableUnits[0]= '\0'; 00283 00284 applyFunctionPtr = NULL; 00285 00286 inLockMode = true; 00287 validLockCode = newValidLockCode; 00288 pageToDisplayIfLockCodeValid = newPageToDisplayIfLockCodeValid; 00289 easyGUIVariableForInvalidLockCodeMessage = newEasyGUIVariableForInvalidLockCodeMessage; 00290 strcpy(invalidLockCodeMessage, newInvalidLockCodeMessage); 00291 00292 allowedDecimalPlaces = 0; 00293 editingFractionalPart = false; 00294 00295 allowNegativeNumbers = false; 00296 00297 strcpy(GuiVar_numericKeypadValue, "0"); 00298 } 00299 00300 00301 /* 00302 Allows the caller to tell us which easyGUI variable to edit 00303 00304 Args: pointer to the variable in question. 00305 Note that it must of type GuiConst_TEXT - i.e. a string - 00306 even though the variable we edit and display while in this page 00307 is actually an integer 00308 00309 No return value 00310 */ 00311 void NumericKeypadPageHandler::SetEasyGUIVariableToEdit(GuiConst_TEXT* easyGUIVariable) 00312 { 00313 easyGUIVariableToEdit = easyGUIVariable; 00314 editVariableUnits[0]= '\0'; // No units so far 00315 } 00316 00317 00318 /* 00319 Allows the caller to tell us which internal (non-easyGUI integer) variable to edit 00320 00321 Args: pointer to the variable in question. 00322 Note that it must of type int 00323 00324 No return value 00325 */ 00326 void NumericKeypadPageHandler::SetInternalVariableToEdit(unsigned int* internalVariable) 00327 { 00328 internalVariableToEdit = internalVariable; 00329 } 00330 00331 00332 /* 00333 Allows the caller to tell us which easyGUI page (structure) it is, 00334 and therefore which page/structure to display when the user presses Apply or Cancel 00335 00336 Args: index of the calling page 00337 00338 No return value 00339 */ 00340 void NumericKeypadPageHandler::SetEasyGUICallingPage(int newCallingPage) 00341 { 00342 easyGUICallingPage = newCallingPage; 00343 } 00344 00345 00346 /* 00347 Allows the caller to tell us the minimum and maximum values 00348 for the easyGUI variable we are editing 00349 00350 Args: minimum value 00351 maximum value 00352 */ 00353 void NumericKeypadPageHandler::SetEditVariableRange(int min, int max) 00354 { 00355 minimumValue = min; 00356 maximumValue = max; 00357 00358 // Guard against contradictory parameters 00359 if(minimumValue >= 0) { 00360 allowNegativeNumbers = false; 00361 } 00362 } 00363 00364 00365 /* 00366 In response to the user pressing the Delete key on the easyGUI 'NumericKeypadPage', 00367 edits the value appropriately. Note that it is up to the caller to verify 00368 that the user actually has pressed the Delete key 00369 00370 No arguments, no return value. 00371 */ 00372 void NumericKeypadPageHandler::DealWithDeleteKey(void) 00373 { 00374 if(editingFractionalPart) { 00375 // Just delete the last character 00376 int len = strlen(GuiVar_numericKeypadValue); 00377 char charToDelete = GuiVar_numericKeypadValue[len - 1]; 00378 00379 GuiVar_numericKeypadValue[len - 1] = '\0'; 00380 if(charToDelete == '.') { 00381 // Deleted the dot character 00382 editingFractionalPart = false; 00383 } 00384 00385 DisplayEasyGUIPage(); 00386 00387 } else { 00388 int keypadValue; 00389 sscanf(GuiVar_numericKeypadValue, "%d", &keypadValue); 00390 00391 bool valueIsNegative; 00392 int tempMin; 00393 if(keypadValue < 0) { 00394 valueIsNegative = true; 00395 keypadValue = -keypadValue; 00396 tempMin = 0; 00397 } else { 00398 valueIsNegative = false; 00399 tempMin = minimumValue;// May be greater than zero 00400 } 00401 00402 if(keypadValue > tempMin) { // else we can't reduce it any further 00403 00404 GuiConst_INT32S temp = keypadValue; 00405 00406 temp /= 10; 00407 00408 if(temp > tempMin) { 00409 sprintf(GuiVar_numericKeypadValue, "%d", valueIsNegative ? -temp : temp); 00410 } else { 00411 sprintf(GuiVar_numericKeypadValue, "%d", tempMin); 00412 } 00413 00414 DisplayEasyGUIPage(); 00415 } 00416 } 00417 } 00418 00419 00420 /* 00421 In response to the user pressing the Clear key on the easyGUI 'NumericKeypadPage', 00422 edits the value appropriately. Note that it is up to the caller to verify 00423 that the user actually has pressed the Clear key 00424 00425 No arguments, no return value. 00426 */ 00427 void NumericKeypadPageHandler::DealWithClearKey(void) 00428 { 00429 //sprintf(GuiVar_numericKeypadValue, "%d", minimumValue); 00430 // No - always zero 00431 GuiVar_numericKeypadValue[0] = '0'; 00432 GuiVar_numericKeypadValue[1] = '\0'; 00433 00434 editingFractionalPart = false; 00435 00436 DisplayEasyGUIPage(); 00437 } 00438 00439 00440 /* 00441 (Re)display the easyGUI 'NumericKeypadPage' - e.g. after we have updated 00442 the value being edited, and want to display the new value to the user. 00443 00444 No arguments, no return code 00445 */ 00446 void NumericKeypadPageHandler::DisplayEasyGUIPage(void) 00447 { 00448 #define WANT_GUILIB_CLEAR 00449 #ifdef WANT_GUILIB_CLEAR 00450 #ifdef USING_BACKGROUND_BITMAP 00451 DrawFakeBackgroundBitmapForNumericKeypadPage(); 00452 #else 00453 GuiLib_Clear(); 00454 #endif 00455 #undef WANT_GUILIB_CLEAR 00456 #endif 00457 GuiLib_ShowScreen(GuiStruct_NumericKeypadPage_Def, GuiLib_NO_CURSOR, GuiLib_RESET_AUTO_REDRAW); 00458 00459 // But hide the dot key if we're not using it 00460 if(allowedDecimalPlaces == 0) { 00461 GuiLib_FillBox(435, 260, 505, 330, 0xFFFF); // Hard coded coords copied from easyGUI. White colour (16 bit, 565 RGB) 00462 } 00463 00464 // And hide the +/- key if we're not using it 00465 if(!allowNegativeNumbers) { 00466 GuiLib_FillBox(295, 260, 365, 330, 0xFFFF); // Hard coded coords copied from easyGUI. White colour (16 bit, 565 RGB) 00467 } 00468 00469 GuiLib_Refresh(); 00470 00471 00472 GetGCStatusLoop *getGCStatusLoop = GetGCStatusLoop::GetInstance(); 00473 00474 if(getGCStatusLoop != NULL) { 00475 getGCStatusLoop->SetCurrentPage(GuiStruct_NumericKeypadPage_Def); 00476 } 00477 } 00478 00479 00480 /* 00481 Tells the caller how many digits are currently in the fractional part 00482 (i.e. to the right of the decimal point). Does not count the decimal point. 00483 Returns zero if there is no decimal point. 00484 */ 00485 unsigned int NumericKeypadPageHandler::LengthOfFractionalPart(void) 00486 { 00487 int len = strlen(GuiVar_numericKeypadValue); 00488 00489 int fracCount = 0; 00490 bool foundDot = false; 00491 for (int index = 0; index < len; ++index) { 00492 if(GuiVar_numericKeypadValue[index] == '.') { 00493 foundDot = true; 00494 continue; // Go straight to next char (i.e. don't count the dot) 00495 } 00496 00497 if(foundDot) ++fracCount; 00498 } 00499 00500 return fracCount; 00501 } 00502 00503 00504 /* 00505 Make sure our keypad value has the correct number of decimal places - 00506 pad with zeroes if necessary (e.g. "100.0", not "100.", etc) 00507 */ 00508 void NumericKeypadPageHandler::PadFractionalPartWithZeroesIfNecessary(void) 00509 { 00510 int lengthOfFractionalPart = LengthOfFractionalPart(); 00511 00512 int shortfall = allowedDecimalPlaces - lengthOfFractionalPart; 00513 00514 if(shortfall > 0) { 00515 int index = strlen(GuiVar_numericKeypadValue); 00516 00517 // First make sure there is a decimal point - 00518 // if not, append one 00519 if(lengthOfFractionalPart == 0) { 00520 if(GuiVar_numericKeypadValue[index - 1] != '.') { 00521 GuiVar_numericKeypadValue[index++]= '.'; 00522 } 00523 } 00524 // else there must be a decimal point 00525 00526 while(shortfall > 0) { 00527 GuiVar_numericKeypadValue[index++] = '0'; 00528 --shortfall; 00529 } 00530 00531 GuiVar_numericKeypadValue[index] = '\0'; 00532 } 00533 } 00534 00535 00536 /* 00537 In response to the user pressing one of the number keys on the easyGUI 'NumericKeypadPage', 00538 edits the variable appropriately. Note that we rely on the touch area indices being consecutive, 00539 and in the same order as the numbers they represent. 00540 00541 Argument: the index of the touch area for the key in question 00542 (note that it is up to the caller to verify that it is a number key) 00543 00544 No return value. 00545 */ 00546 void NumericKeypadPageHandler::DealWithNumberKey(int touchAreaIndex) 00547 { 00548 int digitToInsert = touchAreaIndex - NUMERIC_KEYPAD_BUTTON_0; 00549 if(digitToInsert > 9) digitToInsert = 9; 00550 if(digitToInsert < 0) digitToInsert = 0; 00551 00552 if(editingFractionalPart) { 00553 if(LengthOfFractionalPart() < allowedDecimalPlaces) { 00554 00555 // Just append the digit to the fractional part - 00556 // don't check the min and max values (these apply to the integer part) 00557 int len = strlen(GuiVar_numericKeypadValue); 00558 00559 GuiVar_numericKeypadValue[len] = '0' + digitToInsert; // Convert to char 00560 GuiVar_numericKeypadValue[len + 1] = '\0'; 00561 00562 DisplayEasyGUIPage(); 00563 } 00564 // else we cannot add more digits anyway 00565 00566 } else { 00567 GuiConst_INT32S temp; 00568 sscanf(GuiVar_numericKeypadValue, "%d", &temp); 00569 00570 int tempMax; 00571 bool valueIsNegative; 00572 if(temp < 0) { 00573 valueIsNegative = true; 00574 temp = -temp; 00575 tempMax = -minimumValue; // Assume this must be < 0 00576 } else { 00577 valueIsNegative = false; 00578 tempMax = maximumValue; 00579 } 00580 00581 if(temp < tempMax) { // else we can't increase it any further 00582 00583 temp *= 10; 00584 temp += digitToInsert; 00585 00586 if(temp < tempMax) { 00587 sprintf(GuiVar_numericKeypadValue, "%d", valueIsNegative ? -temp : temp); 00588 } else { 00589 sprintf(GuiVar_numericKeypadValue, "%d", valueIsNegative ? -tempMax : tempMax); 00590 } 00591 00592 DisplayEasyGUIPage(); 00593 } 00594 } 00595 } 00596 00597 00598 /* 00599 Handles the user pressing the dot key on the easyGUI 'NumericKeypadPage'. 00600 If we are (1) editing a value with a fractional part, and (2) we are not already 00601 editing the fractional part, starts editing the fractional part. 00602 If either (1) or (2) is false, does nothing (note that although we hide the dot key 00603 if the value does not have a fractional part, the touch area is still there). 00604 00605 Note that it is up to the caller (of this function) to verify that the user actually has pressed the dot key. 00606 00607 No arguments, no return value. 00608 */ 00609 void NumericKeypadPageHandler::DealWithDotKey(void) 00610 { 00611 if((allowedDecimalPlaces > 0) && (!editingFractionalPart)) { 00612 strcat(GuiVar_numericKeypadValue, "."); 00613 00614 editingFractionalPart = true; 00615 00616 DisplayEasyGUIPage(); 00617 } 00618 // else '.' is illegal at this point - ignore 00619 } 00620 00621 00622 /* 00623 Handles the user pressing the plus/minus key on the easyGUI 'NumericKeypadPage'. 00624 This is legal only if we are editing a value that can be negative - 00625 we ignore it otherwise (note that although we hide the plus/minus key 00626 if the value is not allowed to be negative, the touch area is still there). 00627 If the key is legal, we first check that the value is not zero - if it is zero, 00628 we do nothing, otherwise we look at the first character of the displayed string. 00629 If it is *not* '-', we insert a '-' character at the start, while if it *is* '-', 00630 we remove it. Note that we do *not* display a '+' character. 00631 00632 Note that it is up to the caller (of this function) to verify that the user 00633 actually has pressed the plus/minus key. 00634 00635 No arguments, no return value. 00636 */ 00637 void NumericKeypadPageHandler::DealWithPlusMinusKey(void) 00638 { 00639 if(allowNegativeNumbers) { 00640 int temp; 00641 sscanf(GuiVar_numericKeypadValue, "%d", &temp); 00642 if(temp != 0) { 00643 char buffer[60]; // Longer than 'GuiVar_numericKeypadValue' 00644 if(GuiVar_numericKeypadValue[0] == '-') { 00645 strcpy(buffer, &GuiVar_numericKeypadValue[1]); 00646 } else { 00647 buffer[0] = '-'; 00648 strcpy(&buffer[1], GuiVar_numericKeypadValue); 00649 } 00650 strcpy(GuiVar_numericKeypadValue, buffer); 00651 00652 DisplayEasyGUIPage(); 00653 } 00654 // else value is zero - pointless putting a minus sign on it 00655 } 00656 // else '+/-' is illegal at this point - ignore 00657 } 00658 00659 /* 00660 In response to the user pressing the Apply key on the easyGUI 'NumericKeypadPage', 00661 sets the easyGUI variable the calling page told us to edit, and (re)displays 00662 the calling page. 00663 00664 Note that it is up to the caller (of this function) to verify that the user actually has pressed the Apply key. 00665 00666 No arguments, no return value. 00667 */ 00668 void NumericKeypadPageHandler::DealWithApplyKey(void) 00669 { 00670 if(easyGUIVariableToEdit != NULL) { 00671 if(allowedDecimalPlaces > 0) { 00672 PadFractionalPartWithZeroesIfNecessary(); 00673 } 00674 00675 strcpy(easyGUIVariableToEdit, GuiVar_numericKeypadValue); 00676 00677 if(strlen(editVariableUnits) > 0) { 00678 strcat(easyGUIVariableToEdit, " "); 00679 strcat(easyGUIVariableToEdit, editVariableUnits); 00680 } 00681 } 00682 00683 if(internalVariableToEdit != NULL) { 00684 // Note that internalVariableToEdit is (currently) always an int, 00685 // regardless of how many places of decimals we have been told to use 00686 sscanf(GuiVar_numericKeypadValue, "%d", internalVariableToEdit); 00687 } 00688 00689 if(applyFunctionPtr != NULL) { 00690 (*applyFunctionPtr)(usbDevice, usbHostGC); 00691 } 00692 00693 if(inLockMode) { 00694 int temp; 00695 sscanf(GuiVar_numericKeypadValue,"%d", &temp); 00696 if(temp == validLockCode) { 00697 DisplayEasyGuiStructure(pageToDisplayIfLockCodeValid, usbDevice, usbHostGC, false); 00698 } else { 00699 strcpy(easyGUIVariableForInvalidLockCodeMessage, invalidLockCodeMessage); 00700 DisplayEasyGuiStructure(easyGUICallingPage, usbDevice, usbHostGC, false); 00701 } 00702 } else { 00703 if(easyGUICallingPage != -1) { 00704 DisplayEasyGuiStructure(easyGUICallingPage, usbDevice, usbHostGC, false); 00705 } 00706 } 00707 } 00708 00709 00710 /* 00711 In response to the user pressing the Cancel key on the easyGUI 'NumericKeypadPage', 00712 (re)displays the calling page *without* updating the easyGUI variable 00713 the calling page told us to edit. 00714 00715 Note that it is up to the caller (of this function) to verify that the user actually has pressed the Cancel key. 00716 00717 No arguments, no return value. 00718 */ 00719 void NumericKeypadPageHandler::DealWithCancelKey(void) 00720 { 00721 if(easyGUICallingPage != -1) { 00722 DisplayEasyGuiStructure(easyGUICallingPage, usbDevice, usbHostGC); 00723 } 00724 } 00725 00726 00727 /* 00728 Sets the name of the variable being edited. This is displayed on our easyGUI page, 00729 to the left of the keypad, above the variable itself. 00730 00731 Args: a pointer to null-terminated string containing the name 00732 00733 No return value 00734 */ 00735 void NumericKeypadPageHandler::SetEditVariableName(char *name) 00736 { 00737 strcpy(GuiVar_numericKeypadName, name); 00738 } 00739 00740 00741 /* 00742 Sets the units that apply to the easyGUI variable being edited. 00743 We do not display these while editing - they are simply concatenated 00744 to the variable's value when the user presses Apply. 00745 Note that we also concatenate a space separator before the units - 00746 so the units specified here should be (e.g.) "deg C", not " deg C". 00747 00748 The default - if this function is not called after 'StartEditing' - 00749 is that there are no units. 00750 00751 Args: a pointer to null-terminated string containing the units. 00752 00753 No return value 00754 */ 00755 void NumericKeypadPageHandler::SetEditVariableUnits(const char *units) 00756 { 00757 strcpy(editVariableUnits, units); 00758 } 00759 00760 00761 /* 00762 Sets our pointer to a function, provided by the caller, that we are to call 00763 if/when the user presses our Apply button. This must have the form: 00764 00765 void FunctionName(USBDeviceConnected* usbDevice, USBHostGC* usbHostGC) 00766 00767 Args: a pointer to the function to call 00768 00769 No return value 00770 */ 00771 void NumericKeypadPageHandler::SetApplyFunctionPtr(ApplyFunctionPtr newApplyFunctionPtr) 00772 { 00773 applyFunctionPtr = newApplyFunctionPtr; 00774 } 00775 00776 00777
Generated on Tue Jul 19 2022 00:31:07 by
1.7.2