Repository for import to local machine
Dependencies: DMBasicGUI DMSupport
NumericKeypadPageHandler.cpp@8:26e49e6955bd, 2017-07-31 (annotated)
- Committer:
- jmitc91516
- Date:
- Mon Jul 31 15:37:57 2017 +0000
- Revision:
- 8:26e49e6955bd
- Parent:
- 6:dba3fbdfd5da
Method ramp scrolling improved, and more bitmaps moved to QSPI memory
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jmitc91516 | 1:a5258871b33d | 1 | #include "NumericKeypadPageHandler.h" |
jmitc91516 | 1:a5258871b33d | 2 | #include "EasyGUITouchAreaIndices.h" |
jmitc91516 | 1:a5258871b33d | 3 | #include "GetGCStatusLoop.h" |
jmitc91516 | 1:a5258871b33d | 4 | |
jmitc91516 | 1:a5258871b33d | 5 | #include <stdio.h> |
jmitc91516 | 1:a5258871b33d | 6 | #include <stdlib.h> |
jmitc91516 | 1:a5258871b33d | 7 | |
jmitc91516 | 1:a5258871b33d | 8 | |
jmitc91516 | 1:a5258871b33d | 9 | /* |
jmitc91516 | 1:a5258871b33d | 10 | Draws the background bitmap. It fills the screen, so you do not need to call GuiLib_Clear. |
jmitc91516 | 1:a5258871b33d | 11 | Defined in main.cpp |
jmitc91516 | 1:a5258871b33d | 12 | */ |
jmitc91516 | 1:a5258871b33d | 13 | extern void DrawBackgroundBitmap(void); |
jmitc91516 | 1:a5258871b33d | 14 | #define USING_BACKGROUND_BITMAP |
jmitc91516 | 1:a5258871b33d | 15 | |
jmitc91516 | 1:a5258871b33d | 16 | |
jmitc91516 | 1:a5258871b33d | 17 | /* |
jmitc91516 | 1:a5258871b33d | 18 | For Display (LPC4088) Bug #11, draw a background bitmap without a grey bar at the bottom. |
jmitc91516 | 1:a5258871b33d | 19 | For now, fake this with a page full of one colour. |
jmitc91516 | 1:a5258871b33d | 20 | |
jmitc91516 | 1:a5258871b33d | 21 | Defined in main.cpp |
jmitc91516 | 1:a5258871b33d | 22 | */ |
jmitc91516 | 1:a5258871b33d | 23 | void DrawFakeBackgroundBitmapForNumericKeypadPage(void); |
jmitc91516 | 1:a5258871b33d | 24 | |
jmitc91516 | 1:a5258871b33d | 25 | |
jmitc91516 | 1:a5258871b33d | 26 | /* |
jmitc91516 | 1:a5258871b33d | 27 | Displays the specified easyGUI 'structure' (or page, to use a more easily understood term). |
jmitc91516 | 1:a5258871b33d | 28 | Defined in main.cpp |
jmitc91516 | 1:a5258871b33d | 29 | */ |
jmitc91516 | 1:a5258871b33d | 30 | extern void DisplayEasyGuiStructure(int structureIndex, USBDeviceConnected* usbDevice, USBHostGC* usbHostGC, bool updateEasyGUIVariables = true); |
jmitc91516 | 1:a5258871b33d | 31 | |
jmitc91516 | 1:a5258871b33d | 32 | |
jmitc91516 | 1:a5258871b33d | 33 | /* |
jmitc91516 | 1:a5258871b33d | 34 | Converts three eight-bit colour values to the corresponding 16-bit RGB565 value. |
jmitc91516 | 1:a5258871b33d | 35 | Defined in main.cpp |
jmitc91516 | 1:a5258871b33d | 36 | */ |
jmitc91516 | 1:a5258871b33d | 37 | extern GuiConst_INTCOLOR SixteenBitColorValue(GuiConst_INT8U red, GuiConst_INT8U green, GuiConst_INT8U blue); |
jmitc91516 | 1:a5258871b33d | 38 | |
jmitc91516 | 1:a5258871b33d | 39 | |
jmitc91516 | 1:a5258871b33d | 40 | /* |
jmitc91516 | 1:a5258871b33d | 41 | Displays the specified text string at the specified location in the currently-displayed easyGUI page. |
jmitc91516 | 1:a5258871b33d | 42 | |
jmitc91516 | 1:a5258871b33d | 43 | Defined in main.cpp - and omits the 'ALLOW_DEBUG_PRINTS' #define |
jmitc91516 | 1:a5258871b33d | 44 | */ |
jmitc91516 | 1:a5258871b33d | 45 | extern void SpecialDebugPrint(char *stuffToPrint, GuiConst_INT16S X, GuiConst_INT16S Y); |
jmitc91516 | 1:a5258871b33d | 46 | |
jmitc91516 | 1:a5258871b33d | 47 | |
jmitc91516 | 1:a5258871b33d | 48 | /* |
jmitc91516 | 1:a5258871b33d | 49 | Note that this class is a singleton - we do not need or want there to be more than one instance of it |
jmitc91516 | 1:a5258871b33d | 50 | (we will not show more than one "NumericKeypadPage" to the user at the same time). |
jmitc91516 | 1:a5258871b33d | 51 | */ |
jmitc91516 | 1:a5258871b33d | 52 | NumericKeypadPageHandler * NumericKeypadPageHandler::theNumericKeypadPageHandlerInstance = NULL; |
jmitc91516 | 1:a5258871b33d | 53 | |
jmitc91516 | 1:a5258871b33d | 54 | |
jmitc91516 | 1:a5258871b33d | 55 | /* |
jmitc91516 | 1:a5258871b33d | 56 | Singleton class - return the one and only instance, first creating it if necessary. |
jmitc91516 | 1:a5258871b33d | 57 | */ |
jmitc91516 | 1:a5258871b33d | 58 | NumericKeypadPageHandler * NumericKeypadPageHandler::GetInstance(USBDeviceConnected* newUsbDevice, USBHostGC* newUsbHostGC) |
jmitc91516 | 1:a5258871b33d | 59 | { |
jmitc91516 | 1:a5258871b33d | 60 | if (theNumericKeypadPageHandlerInstance == NULL) { |
jmitc91516 | 1:a5258871b33d | 61 | theNumericKeypadPageHandlerInstance = new NumericKeypadPageHandler(newUsbDevice, newUsbHostGC); |
jmitc91516 | 1:a5258871b33d | 62 | } |
jmitc91516 | 1:a5258871b33d | 63 | |
jmitc91516 | 1:a5258871b33d | 64 | return theNumericKeypadPageHandlerInstance; |
jmitc91516 | 1:a5258871b33d | 65 | } |
jmitc91516 | 1:a5258871b33d | 66 | |
jmitc91516 | 1:a5258871b33d | 67 | // Singleton class - private constructor |
jmitc91516 | 1:a5258871b33d | 68 | NumericKeypadPageHandler::NumericKeypadPageHandler(USBDeviceConnected* newUsbDevice, USBHostGC* newUsbHostGC) |
jmitc91516 | 1:a5258871b33d | 69 | { |
jmitc91516 | 1:a5258871b33d | 70 | // Note that we do not use these values here - |
jmitc91516 | 1:a5258871b33d | 71 | // but we do need to pass them to the (main.cpp) function DisplayEasyGUIStructure |
jmitc91516 | 1:a5258871b33d | 72 | // when the user presses Apply or Cancel |
jmitc91516 | 1:a5258871b33d | 73 | usbDevice = newUsbDevice; |
jmitc91516 | 1:a5258871b33d | 74 | usbHostGC = newUsbHostGC; |
jmitc91516 | 1:a5258871b33d | 75 | |
jmitc91516 | 1:a5258871b33d | 76 | easyGUIVariableToEdit = NULL; |
jmitc91516 | 1:a5258871b33d | 77 | internalVariableToEdit = NULL; |
jmitc91516 | 1:a5258871b33d | 78 | editVariableUnits[0]= '\0'; |
jmitc91516 | 1:a5258871b33d | 79 | |
jmitc91516 | 1:a5258871b33d | 80 | easyGUICallingPage = -1; |
jmitc91516 | 1:a5258871b33d | 81 | |
jmitc91516 | 1:a5258871b33d | 82 | applyFunctionPtr = NULL; |
jmitc91516 | 1:a5258871b33d | 83 | |
jmitc91516 | 1:a5258871b33d | 84 | minimumValue = 0; |
jmitc91516 | 1:a5258871b33d | 85 | maximumValue = 999; |
jmitc91516 | 1:a5258871b33d | 86 | |
jmitc91516 | 1:a5258871b33d | 87 | allowedDecimalPlaces = 0; |
jmitc91516 | 1:a5258871b33d | 88 | editingFractionalPart= 0; |
jmitc91516 | 1:a5258871b33d | 89 | |
jmitc91516 | 1:a5258871b33d | 90 | allowNegativeNumbers = false; |
jmitc91516 | 1:a5258871b33d | 91 | |
jmitc91516 | 1:a5258871b33d | 92 | inLockMode = false; |
jmitc91516 | 1:a5258871b33d | 93 | validLockCode = 0; |
jmitc91516 | 1:a5258871b33d | 94 | easyGUIVariableForInvalidLockCodeMessage = NULL; |
jmitc91516 | 1:a5258871b33d | 95 | invalidLockCodeMessage[0] = '\0'; |
jmitc91516 | 1:a5258871b33d | 96 | pageToDisplayIfLockCodeValid = -1; |
jmitc91516 | 1:a5258871b33d | 97 | |
jmitc91516 | 1:a5258871b33d | 98 | GuiVar_numericKeypadValueBackgroundColour = SixteenBitColorValue(255, 255, 255); // White (no need for 'active' colour - |
jmitc91516 | 1:a5258871b33d | 99 | // there is only one active field, and it is always active) |
jmitc91516 | 1:a5258871b33d | 100 | } |
jmitc91516 | 1:a5258871b33d | 101 | |
jmitc91516 | 1:a5258871b33d | 102 | // Private destructor also |
jmitc91516 | 1:a5258871b33d | 103 | NumericKeypadPageHandler::~NumericKeypadPageHandler() |
jmitc91516 | 1:a5258871b33d | 104 | { |
jmitc91516 | 1:a5258871b33d | 105 | } |
jmitc91516 | 1:a5258871b33d | 106 | |
jmitc91516 | 1:a5258871b33d | 107 | |
jmitc91516 | 1:a5258871b33d | 108 | /* |
jmitc91516 | 1:a5258871b33d | 109 | Tells the caller whether or not the specified touch index is on the easyGUI 'NumericKeypadPage', |
jmitc91516 | 1:a5258871b33d | 110 | and therefore needs to be handled by this class. |
jmitc91516 | 1:a5258871b33d | 111 | |
jmitc91516 | 1:a5258871b33d | 112 | Args: the touch area index in question |
jmitc91516 | 1:a5258871b33d | 113 | |
jmitc91516 | 1:a5258871b33d | 114 | Return code: true if the touch area is 'one of ours', false if not |
jmitc91516 | 1:a5258871b33d | 115 | */ |
jmitc91516 | 1:a5258871b33d | 116 | bool NumericKeypadPageHandler::TouchAreaIsOnNumericKeypadPage(int touchAreaIndex) |
jmitc91516 | 1:a5258871b33d | 117 | { |
jmitc91516 | 1:a5258871b33d | 118 | if((touchAreaIndex >= MIN_NUMERIC_KEYPAD_TOUCHINDEX) && (touchAreaIndex <= MAX_NUMERIC_KEYPAD_TOUCHINDEX)) { |
jmitc91516 | 1:a5258871b33d | 119 | return true; |
jmitc91516 | 1:a5258871b33d | 120 | } |
jmitc91516 | 1:a5258871b33d | 121 | |
jmitc91516 | 1:a5258871b33d | 122 | // 'else' |
jmitc91516 | 1:a5258871b33d | 123 | return false; |
jmitc91516 | 1:a5258871b33d | 124 | } |
jmitc91516 | 1:a5258871b33d | 125 | |
jmitc91516 | 1:a5258871b33d | 126 | |
jmitc91516 | 1:a5258871b33d | 127 | /* |
jmitc91516 | 1:a5258871b33d | 128 | If the specified touch area represents a key or field on the easyGUI 'NumericKeypadPage', |
jmitc91516 | 1:a5258871b33d | 129 | this function performs whatever action is appropriate for it. Provided so that the caller |
jmitc91516 | 1:a5258871b33d | 130 | can (in effect) say "if this is one of yours, deal with it", without needing to know |
jmitc91516 | 1:a5258871b33d | 131 | anything about what this class does, or how it handles the touch areas on that easyGUI page. |
jmitc91516 | 1:a5258871b33d | 132 | |
jmitc91516 | 1:a5258871b33d | 133 | Args: the touch area index in question |
jmitc91516 | 1:a5258871b33d | 134 | |
jmitc91516 | 1:a5258871b33d | 135 | Returns true if it dealt with the touch area (so the caller need not do anything else |
jmitc91516 | 1:a5258871b33d | 136 | with the value), or false if it did not deal with the touch area (implying that it |
jmitc91516 | 1:a5258871b33d | 137 | was not a touch area on the easyGUI 'NumericKeypadPage', and so the caller |
jmitc91516 | 1:a5258871b33d | 138 | must deal with it some other way). |
jmitc91516 | 1:a5258871b33d | 139 | */ |
jmitc91516 | 1:a5258871b33d | 140 | bool NumericKeypadPageHandler::DealWithTouch(int touchAreaIndex) |
jmitc91516 | 1:a5258871b33d | 141 | { |
jmitc91516 | 1:a5258871b33d | 142 | if((touchAreaIndex >= NUMERIC_KEYPAD_BUTTON_0) && (touchAreaIndex <= NUMERIC_KEYPAD_BUTTON_9)) { |
jmitc91516 | 1:a5258871b33d | 143 | |
jmitc91516 | 1:a5258871b33d | 144 | DealWithNumberKey(touchAreaIndex); |
jmitc91516 | 1:a5258871b33d | 145 | |
jmitc91516 | 1:a5258871b33d | 146 | return true; |
jmitc91516 | 1:a5258871b33d | 147 | } |
jmitc91516 | 1:a5258871b33d | 148 | |
jmitc91516 | 1:a5258871b33d | 149 | if(touchAreaIndex == NUMERIC_KEYPAD_DELETE_BUTTON) { |
jmitc91516 | 1:a5258871b33d | 150 | |
jmitc91516 | 1:a5258871b33d | 151 | DealWithDeleteKey(); |
jmitc91516 | 1:a5258871b33d | 152 | |
jmitc91516 | 1:a5258871b33d | 153 | return true; |
jmitc91516 | 1:a5258871b33d | 154 | } |
jmitc91516 | 1:a5258871b33d | 155 | |
jmitc91516 | 1:a5258871b33d | 156 | if(touchAreaIndex == NUMERIC_KEYPAD_DOT_BUTTON) { |
jmitc91516 | 1:a5258871b33d | 157 | |
jmitc91516 | 1:a5258871b33d | 158 | DealWithDotKey(); |
jmitc91516 | 1:a5258871b33d | 159 | |
jmitc91516 | 1:a5258871b33d | 160 | return true; |
jmitc91516 | 1:a5258871b33d | 161 | } |
jmitc91516 | 1:a5258871b33d | 162 | |
jmitc91516 | 1:a5258871b33d | 163 | if(touchAreaIndex == NUMERIC_KEYPAD_PLUS_MINUS_BUTTON) { |
jmitc91516 | 1:a5258871b33d | 164 | |
jmitc91516 | 1:a5258871b33d | 165 | DealWithPlusMinusKey(); |
jmitc91516 | 1:a5258871b33d | 166 | |
jmitc91516 | 1:a5258871b33d | 167 | return true; |
jmitc91516 | 1:a5258871b33d | 168 | } |
jmitc91516 | 1:a5258871b33d | 169 | |
jmitc91516 | 1:a5258871b33d | 170 | if(touchAreaIndex == NUMERIC_KEYPAD_APPLY_BUTTON) { |
jmitc91516 | 1:a5258871b33d | 171 | |
jmitc91516 | 1:a5258871b33d | 172 | DealWithApplyKey(); |
jmitc91516 | 1:a5258871b33d | 173 | |
jmitc91516 | 1:a5258871b33d | 174 | return true; |
jmitc91516 | 1:a5258871b33d | 175 | } |
jmitc91516 | 1:a5258871b33d | 176 | |
jmitc91516 | 1:a5258871b33d | 177 | if(touchAreaIndex == NUMERIC_KEYPAD_CANCEL_BUTTON) { |
jmitc91516 | 1:a5258871b33d | 178 | |
jmitc91516 | 1:a5258871b33d | 179 | DealWithCancelKey(); |
jmitc91516 | 1:a5258871b33d | 180 | |
jmitc91516 | 1:a5258871b33d | 181 | return true; |
jmitc91516 | 1:a5258871b33d | 182 | } |
jmitc91516 | 1:a5258871b33d | 183 | |
jmitc91516 | 1:a5258871b33d | 184 | if(touchAreaIndex == NUMERIC_KEYPAD_CLEAR_BUTTON) { |
jmitc91516 | 1:a5258871b33d | 185 | |
jmitc91516 | 1:a5258871b33d | 186 | DealWithClearKey(); |
jmitc91516 | 1:a5258871b33d | 187 | |
jmitc91516 | 1:a5258871b33d | 188 | return true; |
jmitc91516 | 1:a5258871b33d | 189 | } |
jmitc91516 | 1:a5258871b33d | 190 | |
jmitc91516 | 1:a5258871b33d | 191 | // 'else' - none of the above |
jmitc91516 | 1:a5258871b33d | 192 | return false; |
jmitc91516 | 1:a5258871b33d | 193 | } |
jmitc91516 | 1:a5258871b33d | 194 | |
jmitc91516 | 1:a5258871b33d | 195 | |
jmitc91516 | 1:a5258871b33d | 196 | /* |
jmitc91516 | 1:a5258871b33d | 197 | Get ready to edit - initialise our pointers to the variables the calling page wants us to edit |
jmitc91516 | 1:a5258871b33d | 198 | |
jmitc91516 | 1:a5258871b33d | 199 | Argument: the initial value of the variable we are editing, as an integer |
jmitc91516 | 1:a5258871b33d | 200 | |
jmitc91516 | 1:a5258871b33d | 201 | No return code |
jmitc91516 | 1:a5258871b33d | 202 | */ |
jmitc91516 | 1:a5258871b33d | 203 | void NumericKeypadPageHandler::StartEditing(int initialValue, unsigned int placesOfDecimals, bool wantNegative) |
jmitc91516 | 1:a5258871b33d | 204 | { |
jmitc91516 | 1:a5258871b33d | 205 | easyGUIVariableToEdit = NULL; |
jmitc91516 | 1:a5258871b33d | 206 | internalVariableToEdit = NULL; |
jmitc91516 | 1:a5258871b33d | 207 | editVariableUnits[0]= '\0'; |
jmitc91516 | 1:a5258871b33d | 208 | |
jmitc91516 | 1:a5258871b33d | 209 | applyFunctionPtr = NULL; |
jmitc91516 | 1:a5258871b33d | 210 | |
jmitc91516 | 1:a5258871b33d | 211 | inLockMode = false; |
jmitc91516 | 1:a5258871b33d | 212 | validLockCode = 0; |
jmitc91516 | 1:a5258871b33d | 213 | easyGUIVariableForInvalidLockCodeMessage = NULL; |
jmitc91516 | 1:a5258871b33d | 214 | invalidLockCodeMessage[0] = '\0'; |
jmitc91516 | 1:a5258871b33d | 215 | pageToDisplayIfLockCodeValid = -1; |
jmitc91516 | 1:a5258871b33d | 216 | |
jmitc91516 | 1:a5258871b33d | 217 | allowedDecimalPlaces = placesOfDecimals; |
jmitc91516 | 1:a5258871b33d | 218 | |
jmitc91516 | 1:a5258871b33d | 219 | // We always edit at the right hand end (like e.g. a calculator) |
jmitc91516 | 1:a5258871b33d | 220 | editingFractionalPart = (placesOfDecimals > 0); |
jmitc91516 | 1:a5258871b33d | 221 | |
jmitc91516 | 1:a5258871b33d | 222 | allowNegativeNumbers = wantNegative; |
jmitc91516 | 1:a5258871b33d | 223 | |
jmitc91516 | 1:a5258871b33d | 224 | sprintf(GuiVar_numericKeypadValue, "%d", initialValue); |
jmitc91516 | 1:a5258871b33d | 225 | } |
jmitc91516 | 1:a5258871b33d | 226 | |
jmitc91516 | 1:a5258871b33d | 227 | /* |
jmitc91516 | 1:a5258871b33d | 228 | Get ready to edit - initialise our pointers to the variables the calling page wants us to edit |
jmitc91516 | 1:a5258871b33d | 229 | |
jmitc91516 | 1:a5258871b33d | 230 | Argument: the initial value of the variable we are editing, as a string (which we assume represents an integer value) |
jmitc91516 | 1:a5258871b33d | 231 | |
jmitc91516 | 1:a5258871b33d | 232 | No return code |
jmitc91516 | 1:a5258871b33d | 233 | */ |
jmitc91516 | 1:a5258871b33d | 234 | void NumericKeypadPageHandler::StartEditing(char* initialValue, unsigned int placesOfDecimals, bool wantNegative) |
jmitc91516 | 1:a5258871b33d | 235 | { |
jmitc91516 | 1:a5258871b33d | 236 | easyGUIVariableToEdit = NULL; |
jmitc91516 | 1:a5258871b33d | 237 | internalVariableToEdit = NULL; |
jmitc91516 | 1:a5258871b33d | 238 | editVariableUnits[0]= '\0'; |
jmitc91516 | 1:a5258871b33d | 239 | |
jmitc91516 | 1:a5258871b33d | 240 | applyFunctionPtr = NULL; |
jmitc91516 | 1:a5258871b33d | 241 | |
jmitc91516 | 1:a5258871b33d | 242 | inLockMode = false; |
jmitc91516 | 1:a5258871b33d | 243 | validLockCode = 0; |
jmitc91516 | 1:a5258871b33d | 244 | easyGUIVariableForInvalidLockCodeMessage = NULL; |
jmitc91516 | 1:a5258871b33d | 245 | invalidLockCodeMessage[0] = '\0'; |
jmitc91516 | 1:a5258871b33d | 246 | pageToDisplayIfLockCodeValid = -1; |
jmitc91516 | 1:a5258871b33d | 247 | |
jmitc91516 | 1:a5258871b33d | 248 | allowedDecimalPlaces = placesOfDecimals; |
jmitc91516 | 1:a5258871b33d | 249 | |
jmitc91516 | 1:a5258871b33d | 250 | allowNegativeNumbers = wantNegative; |
jmitc91516 | 1:a5258871b33d | 251 | |
jmitc91516 | 1:a5258871b33d | 252 | // We always edit at the right hand end (like e.g. a calculator) |
jmitc91516 | 1:a5258871b33d | 253 | editingFractionalPart = (placesOfDecimals > 0); |
jmitc91516 | 1:a5258871b33d | 254 | |
jmitc91516 | 1:a5258871b33d | 255 | strcpy(GuiVar_numericKeypadValue, initialValue); |
jmitc91516 | 1:a5258871b33d | 256 | } |
jmitc91516 | 1:a5258871b33d | 257 | |
jmitc91516 | 1:a5258871b33d | 258 | |
jmitc91516 | 1:a5258871b33d | 259 | /* |
jmitc91516 | 1:a5258871b33d | 260 | In lock mode, when the user presses the Apply button, we are not going to update a variable provided by the caller, |
jmitc91516 | 1:a5258871b33d | 261 | but instead we will compare the value the user "typed in" against a "lock code" specified by the caller. If they match, |
jmitc91516 | 1:a5258871b33d | 262 | 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), |
jmitc91516 | 1:a5258871b33d | 263 | and display the calling page (which we assume has that easyGUI variable on it). |
jmitc91516 | 1:a5258871b33d | 264 | |
jmitc91516 | 1:a5258871b33d | 265 | Arguments: the valid lock code |
jmitc91516 | 1:a5258871b33d | 266 | the ID of the page to display if the lock code the user provides is valid (1) |
jmitc91516 | 1:a5258871b33d | 267 | the easy GUI (string) variable to receive the invalid lock code message (2) |
jmitc91516 | 1:a5258871b33d | 268 | the text of the invalid lock code message (2) |
jmitc91516 | 1:a5258871b33d | 269 | |
jmitc91516 | 1:a5258871b33d | 270 | (1) is only used if the user provides a valid lock code |
jmitc91516 | 1:a5258871b33d | 271 | (2) are only used if the user provides an invalid lock code |
jmitc91516 | 1:a5258871b33d | 272 | |
jmitc91516 | 1:a5258871b33d | 273 | *** Note that it is up to the caller to specify valid values for all the above *** |
jmitc91516 | 1:a5258871b33d | 274 | |
jmitc91516 | 1:a5258871b33d | 275 | No return code |
jmitc91516 | 1:a5258871b33d | 276 | */ |
jmitc91516 | 1:a5258871b33d | 277 | void NumericKeypadPageHandler::StartEditingInLockMode(unsigned int newValidLockCode, int newPageToDisplayIfLockCodeValid, |
jmitc91516 | 1:a5258871b33d | 278 | GuiConst_TEXT* newEasyGUIVariableForInvalidLockCodeMessage, char *newInvalidLockCodeMessage) |
jmitc91516 | 1:a5258871b33d | 279 | { |
jmitc91516 | 1:a5258871b33d | 280 | easyGUIVariableToEdit = NULL; |
jmitc91516 | 1:a5258871b33d | 281 | internalVariableToEdit = NULL; |
jmitc91516 | 1:a5258871b33d | 282 | editVariableUnits[0]= '\0'; |
jmitc91516 | 1:a5258871b33d | 283 | |
jmitc91516 | 1:a5258871b33d | 284 | applyFunctionPtr = NULL; |
jmitc91516 | 1:a5258871b33d | 285 | |
jmitc91516 | 1:a5258871b33d | 286 | inLockMode = true; |
jmitc91516 | 1:a5258871b33d | 287 | validLockCode = newValidLockCode; |
jmitc91516 | 1:a5258871b33d | 288 | pageToDisplayIfLockCodeValid = newPageToDisplayIfLockCodeValid; |
jmitc91516 | 1:a5258871b33d | 289 | easyGUIVariableForInvalidLockCodeMessage = newEasyGUIVariableForInvalidLockCodeMessage; |
jmitc91516 | 1:a5258871b33d | 290 | strcpy(invalidLockCodeMessage, newInvalidLockCodeMessage); |
jmitc91516 | 1:a5258871b33d | 291 | |
jmitc91516 | 1:a5258871b33d | 292 | allowedDecimalPlaces = 0; |
jmitc91516 | 1:a5258871b33d | 293 | editingFractionalPart = false; |
jmitc91516 | 1:a5258871b33d | 294 | |
jmitc91516 | 1:a5258871b33d | 295 | allowNegativeNumbers = false; |
jmitc91516 | 1:a5258871b33d | 296 | |
jmitc91516 | 1:a5258871b33d | 297 | strcpy(GuiVar_numericKeypadValue, "0"); |
jmitc91516 | 1:a5258871b33d | 298 | } |
jmitc91516 | 1:a5258871b33d | 299 | |
jmitc91516 | 1:a5258871b33d | 300 | |
jmitc91516 | 1:a5258871b33d | 301 | /* |
jmitc91516 | 1:a5258871b33d | 302 | Allows the caller to tell us which easyGUI variable to edit |
jmitc91516 | 1:a5258871b33d | 303 | |
jmitc91516 | 1:a5258871b33d | 304 | Args: pointer to the variable in question. |
jmitc91516 | 1:a5258871b33d | 305 | Note that it must of type GuiConst_TEXT - i.e. a string - |
jmitc91516 | 1:a5258871b33d | 306 | even though the variable we edit and display while in this page |
jmitc91516 | 1:a5258871b33d | 307 | is actually an integer |
jmitc91516 | 1:a5258871b33d | 308 | |
jmitc91516 | 1:a5258871b33d | 309 | No return value |
jmitc91516 | 1:a5258871b33d | 310 | */ |
jmitc91516 | 1:a5258871b33d | 311 | void NumericKeypadPageHandler::SetEasyGUIVariableToEdit(GuiConst_TEXT* easyGUIVariable) |
jmitc91516 | 1:a5258871b33d | 312 | { |
jmitc91516 | 1:a5258871b33d | 313 | easyGUIVariableToEdit = easyGUIVariable; |
jmitc91516 | 1:a5258871b33d | 314 | editVariableUnits[0]= '\0'; // No units so far |
jmitc91516 | 1:a5258871b33d | 315 | } |
jmitc91516 | 1:a5258871b33d | 316 | |
jmitc91516 | 1:a5258871b33d | 317 | |
jmitc91516 | 1:a5258871b33d | 318 | /* |
jmitc91516 | 1:a5258871b33d | 319 | Allows the caller to tell us which internal (non-easyGUI integer) variable to edit |
jmitc91516 | 1:a5258871b33d | 320 | |
jmitc91516 | 1:a5258871b33d | 321 | Args: pointer to the variable in question. |
jmitc91516 | 1:a5258871b33d | 322 | Note that it must of type int |
jmitc91516 | 1:a5258871b33d | 323 | |
jmitc91516 | 1:a5258871b33d | 324 | No return value |
jmitc91516 | 1:a5258871b33d | 325 | */ |
jmitc91516 | 1:a5258871b33d | 326 | void NumericKeypadPageHandler::SetInternalVariableToEdit(unsigned int* internalVariable) |
jmitc91516 | 1:a5258871b33d | 327 | { |
jmitc91516 | 1:a5258871b33d | 328 | internalVariableToEdit = internalVariable; |
jmitc91516 | 1:a5258871b33d | 329 | } |
jmitc91516 | 1:a5258871b33d | 330 | |
jmitc91516 | 1:a5258871b33d | 331 | |
jmitc91516 | 1:a5258871b33d | 332 | /* |
jmitc91516 | 1:a5258871b33d | 333 | Allows the caller to tell us which easyGUI page (structure) it is, |
jmitc91516 | 1:a5258871b33d | 334 | and therefore which page/structure to display when the user presses Apply or Cancel |
jmitc91516 | 1:a5258871b33d | 335 | |
jmitc91516 | 1:a5258871b33d | 336 | Args: index of the calling page |
jmitc91516 | 1:a5258871b33d | 337 | |
jmitc91516 | 1:a5258871b33d | 338 | No return value |
jmitc91516 | 1:a5258871b33d | 339 | */ |
jmitc91516 | 1:a5258871b33d | 340 | void NumericKeypadPageHandler::SetEasyGUICallingPage(int newCallingPage) |
jmitc91516 | 1:a5258871b33d | 341 | { |
jmitc91516 | 1:a5258871b33d | 342 | easyGUICallingPage = newCallingPage; |
jmitc91516 | 1:a5258871b33d | 343 | } |
jmitc91516 | 1:a5258871b33d | 344 | |
jmitc91516 | 1:a5258871b33d | 345 | |
jmitc91516 | 1:a5258871b33d | 346 | /* |
jmitc91516 | 1:a5258871b33d | 347 | Allows the caller to tell us the minimum and maximum values |
jmitc91516 | 1:a5258871b33d | 348 | for the easyGUI variable we are editing |
jmitc91516 | 1:a5258871b33d | 349 | |
jmitc91516 | 1:a5258871b33d | 350 | Args: minimum value |
jmitc91516 | 1:a5258871b33d | 351 | maximum value |
jmitc91516 | 1:a5258871b33d | 352 | */ |
jmitc91516 | 1:a5258871b33d | 353 | void NumericKeypadPageHandler::SetEditVariableRange(int min, int max) |
jmitc91516 | 1:a5258871b33d | 354 | { |
jmitc91516 | 1:a5258871b33d | 355 | minimumValue = min; |
jmitc91516 | 1:a5258871b33d | 356 | maximumValue = max; |
jmitc91516 | 1:a5258871b33d | 357 | |
jmitc91516 | 1:a5258871b33d | 358 | // Guard against contradictory parameters |
jmitc91516 | 1:a5258871b33d | 359 | if(minimumValue >= 0) { |
jmitc91516 | 1:a5258871b33d | 360 | allowNegativeNumbers = false; |
jmitc91516 | 1:a5258871b33d | 361 | } |
jmitc91516 | 1:a5258871b33d | 362 | } |
jmitc91516 | 1:a5258871b33d | 363 | |
jmitc91516 | 1:a5258871b33d | 364 | |
jmitc91516 | 1:a5258871b33d | 365 | /* |
jmitc91516 | 1:a5258871b33d | 366 | In response to the user pressing the Delete key on the easyGUI 'NumericKeypadPage', |
jmitc91516 | 1:a5258871b33d | 367 | edits the value appropriately. Note that it is up to the caller to verify |
jmitc91516 | 1:a5258871b33d | 368 | that the user actually has pressed the Delete key |
jmitc91516 | 1:a5258871b33d | 369 | |
jmitc91516 | 1:a5258871b33d | 370 | No arguments, no return value. |
jmitc91516 | 1:a5258871b33d | 371 | */ |
jmitc91516 | 1:a5258871b33d | 372 | void NumericKeypadPageHandler::DealWithDeleteKey(void) |
jmitc91516 | 1:a5258871b33d | 373 | { |
jmitc91516 | 1:a5258871b33d | 374 | if(editingFractionalPart) { |
jmitc91516 | 1:a5258871b33d | 375 | // Just delete the last character |
jmitc91516 | 1:a5258871b33d | 376 | int len = strlen(GuiVar_numericKeypadValue); |
jmitc91516 | 1:a5258871b33d | 377 | char charToDelete = GuiVar_numericKeypadValue[len - 1]; |
jmitc91516 | 1:a5258871b33d | 378 | |
jmitc91516 | 1:a5258871b33d | 379 | GuiVar_numericKeypadValue[len - 1] = '\0'; |
jmitc91516 | 1:a5258871b33d | 380 | if(charToDelete == '.') { |
jmitc91516 | 1:a5258871b33d | 381 | // Deleted the dot character |
jmitc91516 | 1:a5258871b33d | 382 | editingFractionalPart = false; |
jmitc91516 | 1:a5258871b33d | 383 | } |
jmitc91516 | 1:a5258871b33d | 384 | |
jmitc91516 | 1:a5258871b33d | 385 | DisplayEasyGUIPage(); |
jmitc91516 | 1:a5258871b33d | 386 | |
jmitc91516 | 1:a5258871b33d | 387 | } else { |
jmitc91516 | 1:a5258871b33d | 388 | int keypadValue; |
jmitc91516 | 1:a5258871b33d | 389 | sscanf(GuiVar_numericKeypadValue, "%d", &keypadValue); |
jmitc91516 | 1:a5258871b33d | 390 | |
jmitc91516 | 1:a5258871b33d | 391 | bool valueIsNegative; |
jmitc91516 | 1:a5258871b33d | 392 | int tempMin; |
jmitc91516 | 1:a5258871b33d | 393 | if(keypadValue < 0) { |
jmitc91516 | 1:a5258871b33d | 394 | valueIsNegative = true; |
jmitc91516 | 1:a5258871b33d | 395 | keypadValue = -keypadValue; |
jmitc91516 | 1:a5258871b33d | 396 | tempMin = 0; |
jmitc91516 | 1:a5258871b33d | 397 | } else { |
jmitc91516 | 1:a5258871b33d | 398 | valueIsNegative = false; |
jmitc91516 | 1:a5258871b33d | 399 | tempMin = minimumValue;// May be greater than zero |
jmitc91516 | 1:a5258871b33d | 400 | } |
jmitc91516 | 1:a5258871b33d | 401 | |
jmitc91516 | 1:a5258871b33d | 402 | if(keypadValue > tempMin) { // else we can't reduce it any further |
jmitc91516 | 1:a5258871b33d | 403 | |
jmitc91516 | 1:a5258871b33d | 404 | GuiConst_INT32S temp = keypadValue; |
jmitc91516 | 1:a5258871b33d | 405 | |
jmitc91516 | 1:a5258871b33d | 406 | temp /= 10; |
jmitc91516 | 1:a5258871b33d | 407 | |
jmitc91516 | 1:a5258871b33d | 408 | if(temp > tempMin) { |
jmitc91516 | 1:a5258871b33d | 409 | sprintf(GuiVar_numericKeypadValue, "%d", valueIsNegative ? -temp : temp); |
jmitc91516 | 1:a5258871b33d | 410 | } else { |
jmitc91516 | 1:a5258871b33d | 411 | sprintf(GuiVar_numericKeypadValue, "%d", tempMin); |
jmitc91516 | 1:a5258871b33d | 412 | } |
jmitc91516 | 1:a5258871b33d | 413 | |
jmitc91516 | 1:a5258871b33d | 414 | DisplayEasyGUIPage(); |
jmitc91516 | 1:a5258871b33d | 415 | } |
jmitc91516 | 1:a5258871b33d | 416 | } |
jmitc91516 | 1:a5258871b33d | 417 | } |
jmitc91516 | 1:a5258871b33d | 418 | |
jmitc91516 | 1:a5258871b33d | 419 | |
jmitc91516 | 1:a5258871b33d | 420 | /* |
jmitc91516 | 1:a5258871b33d | 421 | In response to the user pressing the Clear key on the easyGUI 'NumericKeypadPage', |
jmitc91516 | 1:a5258871b33d | 422 | edits the value appropriately. Note that it is up to the caller to verify |
jmitc91516 | 1:a5258871b33d | 423 | that the user actually has pressed the Clear key |
jmitc91516 | 1:a5258871b33d | 424 | |
jmitc91516 | 1:a5258871b33d | 425 | No arguments, no return value. |
jmitc91516 | 1:a5258871b33d | 426 | */ |
jmitc91516 | 1:a5258871b33d | 427 | void NumericKeypadPageHandler::DealWithClearKey(void) |
jmitc91516 | 1:a5258871b33d | 428 | { |
jmitc91516 | 1:a5258871b33d | 429 | //sprintf(GuiVar_numericKeypadValue, "%d", minimumValue); |
jmitc91516 | 1:a5258871b33d | 430 | // No - always zero |
jmitc91516 | 1:a5258871b33d | 431 | GuiVar_numericKeypadValue[0] = '0'; |
jmitc91516 | 1:a5258871b33d | 432 | GuiVar_numericKeypadValue[1] = '\0'; |
jmitc91516 | 1:a5258871b33d | 433 | |
jmitc91516 | 1:a5258871b33d | 434 | editingFractionalPart = false; |
jmitc91516 | 1:a5258871b33d | 435 | |
jmitc91516 | 1:a5258871b33d | 436 | DisplayEasyGUIPage(); |
jmitc91516 | 1:a5258871b33d | 437 | } |
jmitc91516 | 1:a5258871b33d | 438 | |
jmitc91516 | 1:a5258871b33d | 439 | |
jmitc91516 | 1:a5258871b33d | 440 | /* |
jmitc91516 | 1:a5258871b33d | 441 | (Re)display the easyGUI 'NumericKeypadPage' - e.g. after we have updated |
jmitc91516 | 1:a5258871b33d | 442 | the value being edited, and want to display the new value to the user. |
jmitc91516 | 1:a5258871b33d | 443 | |
jmitc91516 | 1:a5258871b33d | 444 | No arguments, no return code |
jmitc91516 | 1:a5258871b33d | 445 | */ |
jmitc91516 | 1:a5258871b33d | 446 | void NumericKeypadPageHandler::DisplayEasyGUIPage(void) |
jmitc91516 | 1:a5258871b33d | 447 | { |
jmitc91516 | 1:a5258871b33d | 448 | #define WANT_GUILIB_CLEAR |
jmitc91516 | 1:a5258871b33d | 449 | #ifdef WANT_GUILIB_CLEAR |
jmitc91516 | 1:a5258871b33d | 450 | #ifdef USING_BACKGROUND_BITMAP |
jmitc91516 | 1:a5258871b33d | 451 | DrawFakeBackgroundBitmapForNumericKeypadPage(); |
jmitc91516 | 1:a5258871b33d | 452 | #else |
jmitc91516 | 1:a5258871b33d | 453 | GuiLib_Clear(); |
jmitc91516 | 1:a5258871b33d | 454 | #endif |
jmitc91516 | 1:a5258871b33d | 455 | #undef WANT_GUILIB_CLEAR |
jmitc91516 | 1:a5258871b33d | 456 | #endif |
jmitc91516 | 1:a5258871b33d | 457 | GuiLib_ShowScreen(GuiStruct_NumericKeypadPage_Def, GuiLib_NO_CURSOR, GuiLib_RESET_AUTO_REDRAW); |
jmitc91516 | 1:a5258871b33d | 458 | |
jmitc91516 | 1:a5258871b33d | 459 | // But hide the dot key if we're not using it |
jmitc91516 | 1:a5258871b33d | 460 | if(allowedDecimalPlaces == 0) { |
jmitc91516 | 1:a5258871b33d | 461 | GuiLib_FillBox(435, 260, 505, 330, 0xFFFF); // Hard coded coords copied from easyGUI. White colour (16 bit, 565 RGB) |
jmitc91516 | 1:a5258871b33d | 462 | } |
jmitc91516 | 1:a5258871b33d | 463 | |
jmitc91516 | 1:a5258871b33d | 464 | // And hide the +/- key if we're not using it |
jmitc91516 | 1:a5258871b33d | 465 | if(!allowNegativeNumbers) { |
jmitc91516 | 1:a5258871b33d | 466 | GuiLib_FillBox(295, 260, 365, 330, 0xFFFF); // Hard coded coords copied from easyGUI. White colour (16 bit, 565 RGB) |
jmitc91516 | 1:a5258871b33d | 467 | } |
jmitc91516 | 1:a5258871b33d | 468 | |
jmitc91516 | 1:a5258871b33d | 469 | GuiLib_Refresh(); |
jmitc91516 | 1:a5258871b33d | 470 | |
jmitc91516 | 1:a5258871b33d | 471 | |
jmitc91516 | 1:a5258871b33d | 472 | GetGCStatusLoop *getGCStatusLoop = GetGCStatusLoop::GetInstance(); |
jmitc91516 | 1:a5258871b33d | 473 | |
jmitc91516 | 1:a5258871b33d | 474 | if(getGCStatusLoop != NULL) { |
jmitc91516 | 1:a5258871b33d | 475 | getGCStatusLoop->SetCurrentPage(GuiStruct_NumericKeypadPage_Def); |
jmitc91516 | 1:a5258871b33d | 476 | } |
jmitc91516 | 1:a5258871b33d | 477 | } |
jmitc91516 | 1:a5258871b33d | 478 | |
jmitc91516 | 1:a5258871b33d | 479 | |
jmitc91516 | 1:a5258871b33d | 480 | /* |
jmitc91516 | 1:a5258871b33d | 481 | Tells the caller how many digits are currently in the fractional part |
jmitc91516 | 1:a5258871b33d | 482 | (i.e. to the right of the decimal point). Does not count the decimal point. |
jmitc91516 | 1:a5258871b33d | 483 | Returns zero if there is no decimal point. |
jmitc91516 | 1:a5258871b33d | 484 | */ |
jmitc91516 | 1:a5258871b33d | 485 | unsigned int NumericKeypadPageHandler::LengthOfFractionalPart(void) |
jmitc91516 | 1:a5258871b33d | 486 | { |
jmitc91516 | 1:a5258871b33d | 487 | int len = strlen(GuiVar_numericKeypadValue); |
jmitc91516 | 1:a5258871b33d | 488 | |
jmitc91516 | 1:a5258871b33d | 489 | int fracCount = 0; |
jmitc91516 | 1:a5258871b33d | 490 | bool foundDot = false; |
jmitc91516 | 1:a5258871b33d | 491 | for (int index = 0; index < len; ++index) { |
jmitc91516 | 1:a5258871b33d | 492 | if(GuiVar_numericKeypadValue[index] == '.') { |
jmitc91516 | 1:a5258871b33d | 493 | foundDot = true; |
jmitc91516 | 1:a5258871b33d | 494 | continue; // Go straight to next char (i.e. don't count the dot) |
jmitc91516 | 1:a5258871b33d | 495 | } |
jmitc91516 | 1:a5258871b33d | 496 | |
jmitc91516 | 1:a5258871b33d | 497 | if(foundDot) ++fracCount; |
jmitc91516 | 1:a5258871b33d | 498 | } |
jmitc91516 | 1:a5258871b33d | 499 | |
jmitc91516 | 1:a5258871b33d | 500 | return fracCount; |
jmitc91516 | 1:a5258871b33d | 501 | } |
jmitc91516 | 1:a5258871b33d | 502 | |
jmitc91516 | 1:a5258871b33d | 503 | |
jmitc91516 | 1:a5258871b33d | 504 | /* |
jmitc91516 | 1:a5258871b33d | 505 | Make sure our keypad value has the correct number of decimal places - |
jmitc91516 | 1:a5258871b33d | 506 | pad with zeroes if necessary (e.g. "100.0", not "100.", etc) |
jmitc91516 | 1:a5258871b33d | 507 | */ |
jmitc91516 | 1:a5258871b33d | 508 | void NumericKeypadPageHandler::PadFractionalPartWithZeroesIfNecessary(void) |
jmitc91516 | 1:a5258871b33d | 509 | { |
jmitc91516 | 1:a5258871b33d | 510 | int lengthOfFractionalPart = LengthOfFractionalPart(); |
jmitc91516 | 1:a5258871b33d | 511 | |
jmitc91516 | 1:a5258871b33d | 512 | int shortfall = allowedDecimalPlaces - lengthOfFractionalPart; |
jmitc91516 | 1:a5258871b33d | 513 | |
jmitc91516 | 1:a5258871b33d | 514 | if(shortfall > 0) { |
jmitc91516 | 1:a5258871b33d | 515 | int index = strlen(GuiVar_numericKeypadValue); |
jmitc91516 | 1:a5258871b33d | 516 | |
jmitc91516 | 1:a5258871b33d | 517 | // First make sure there is a decimal point - |
jmitc91516 | 1:a5258871b33d | 518 | // if not, append one |
jmitc91516 | 1:a5258871b33d | 519 | if(lengthOfFractionalPart == 0) { |
jmitc91516 | 1:a5258871b33d | 520 | if(GuiVar_numericKeypadValue[index - 1] != '.') { |
jmitc91516 | 1:a5258871b33d | 521 | GuiVar_numericKeypadValue[index++]= '.'; |
jmitc91516 | 1:a5258871b33d | 522 | } |
jmitc91516 | 1:a5258871b33d | 523 | } |
jmitc91516 | 1:a5258871b33d | 524 | // else there must be a decimal point |
jmitc91516 | 1:a5258871b33d | 525 | |
jmitc91516 | 1:a5258871b33d | 526 | while(shortfall > 0) { |
jmitc91516 | 1:a5258871b33d | 527 | GuiVar_numericKeypadValue[index++] = '0'; |
jmitc91516 | 1:a5258871b33d | 528 | --shortfall; |
jmitc91516 | 1:a5258871b33d | 529 | } |
jmitc91516 | 1:a5258871b33d | 530 | |
jmitc91516 | 1:a5258871b33d | 531 | GuiVar_numericKeypadValue[index] = '\0'; |
jmitc91516 | 1:a5258871b33d | 532 | } |
jmitc91516 | 1:a5258871b33d | 533 | } |
jmitc91516 | 1:a5258871b33d | 534 | |
jmitc91516 | 1:a5258871b33d | 535 | |
jmitc91516 | 1:a5258871b33d | 536 | /* |
jmitc91516 | 1:a5258871b33d | 537 | In response to the user pressing one of the number keys on the easyGUI 'NumericKeypadPage', |
jmitc91516 | 1:a5258871b33d | 538 | edits the variable appropriately. Note that we rely on the touch area indices being consecutive, |
jmitc91516 | 1:a5258871b33d | 539 | and in the same order as the numbers they represent. |
jmitc91516 | 1:a5258871b33d | 540 | |
jmitc91516 | 1:a5258871b33d | 541 | Argument: the index of the touch area for the key in question |
jmitc91516 | 1:a5258871b33d | 542 | (note that it is up to the caller to verify that it is a number key) |
jmitc91516 | 1:a5258871b33d | 543 | |
jmitc91516 | 1:a5258871b33d | 544 | No return value. |
jmitc91516 | 1:a5258871b33d | 545 | */ |
jmitc91516 | 1:a5258871b33d | 546 | void NumericKeypadPageHandler::DealWithNumberKey(int touchAreaIndex) |
jmitc91516 | 1:a5258871b33d | 547 | { |
jmitc91516 | 1:a5258871b33d | 548 | int digitToInsert = touchAreaIndex - NUMERIC_KEYPAD_BUTTON_0; |
jmitc91516 | 1:a5258871b33d | 549 | if(digitToInsert > 9) digitToInsert = 9; |
jmitc91516 | 1:a5258871b33d | 550 | if(digitToInsert < 0) digitToInsert = 0; |
jmitc91516 | 1:a5258871b33d | 551 | |
jmitc91516 | 1:a5258871b33d | 552 | if(editingFractionalPart) { |
jmitc91516 | 1:a5258871b33d | 553 | if(LengthOfFractionalPart() < allowedDecimalPlaces) { |
jmitc91516 | 1:a5258871b33d | 554 | |
jmitc91516 | 1:a5258871b33d | 555 | // Just append the digit to the fractional part - |
jmitc91516 | 1:a5258871b33d | 556 | // don't check the min and max values (these apply to the integer part) |
jmitc91516 | 1:a5258871b33d | 557 | int len = strlen(GuiVar_numericKeypadValue); |
jmitc91516 | 1:a5258871b33d | 558 | |
jmitc91516 | 1:a5258871b33d | 559 | GuiVar_numericKeypadValue[len] = '0' + digitToInsert; // Convert to char |
jmitc91516 | 1:a5258871b33d | 560 | GuiVar_numericKeypadValue[len + 1] = '\0'; |
jmitc91516 | 1:a5258871b33d | 561 | |
jmitc91516 | 1:a5258871b33d | 562 | DisplayEasyGUIPage(); |
jmitc91516 | 1:a5258871b33d | 563 | } |
jmitc91516 | 1:a5258871b33d | 564 | // else we cannot add more digits anyway |
jmitc91516 | 1:a5258871b33d | 565 | |
jmitc91516 | 1:a5258871b33d | 566 | } else { |
jmitc91516 | 1:a5258871b33d | 567 | GuiConst_INT32S temp; |
jmitc91516 | 1:a5258871b33d | 568 | sscanf(GuiVar_numericKeypadValue, "%d", &temp); |
jmitc91516 | 1:a5258871b33d | 569 | |
jmitc91516 | 1:a5258871b33d | 570 | int tempMax; |
jmitc91516 | 1:a5258871b33d | 571 | bool valueIsNegative; |
jmitc91516 | 1:a5258871b33d | 572 | if(temp < 0) { |
jmitc91516 | 1:a5258871b33d | 573 | valueIsNegative = true; |
jmitc91516 | 1:a5258871b33d | 574 | temp = -temp; |
jmitc91516 | 1:a5258871b33d | 575 | tempMax = -minimumValue; // Assume this must be < 0 |
jmitc91516 | 1:a5258871b33d | 576 | } else { |
jmitc91516 | 1:a5258871b33d | 577 | valueIsNegative = false; |
jmitc91516 | 1:a5258871b33d | 578 | tempMax = maximumValue; |
jmitc91516 | 1:a5258871b33d | 579 | } |
jmitc91516 | 1:a5258871b33d | 580 | |
jmitc91516 | 1:a5258871b33d | 581 | if(temp < tempMax) { // else we can't increase it any further |
jmitc91516 | 1:a5258871b33d | 582 | |
jmitc91516 | 1:a5258871b33d | 583 | temp *= 10; |
jmitc91516 | 1:a5258871b33d | 584 | temp += digitToInsert; |
jmitc91516 | 1:a5258871b33d | 585 | |
jmitc91516 | 1:a5258871b33d | 586 | if(temp < tempMax) { |
jmitc91516 | 1:a5258871b33d | 587 | sprintf(GuiVar_numericKeypadValue, "%d", valueIsNegative ? -temp : temp); |
jmitc91516 | 1:a5258871b33d | 588 | } else { |
jmitc91516 | 1:a5258871b33d | 589 | sprintf(GuiVar_numericKeypadValue, "%d", valueIsNegative ? -tempMax : tempMax); |
jmitc91516 | 1:a5258871b33d | 590 | } |
jmitc91516 | 1:a5258871b33d | 591 | |
jmitc91516 | 1:a5258871b33d | 592 | DisplayEasyGUIPage(); |
jmitc91516 | 1:a5258871b33d | 593 | } |
jmitc91516 | 1:a5258871b33d | 594 | } |
jmitc91516 | 1:a5258871b33d | 595 | } |
jmitc91516 | 1:a5258871b33d | 596 | |
jmitc91516 | 1:a5258871b33d | 597 | |
jmitc91516 | 1:a5258871b33d | 598 | /* |
jmitc91516 | 1:a5258871b33d | 599 | Handles the user pressing the dot key on the easyGUI 'NumericKeypadPage'. |
jmitc91516 | 1:a5258871b33d | 600 | If we are (1) editing a value with a fractional part, and (2) we are not already |
jmitc91516 | 1:a5258871b33d | 601 | editing the fractional part, starts editing the fractional part. |
jmitc91516 | 1:a5258871b33d | 602 | If either (1) or (2) is false, does nothing (note that although we hide the dot key |
jmitc91516 | 1:a5258871b33d | 603 | if the value does not have a fractional part, the touch area is still there). |
jmitc91516 | 1:a5258871b33d | 604 | |
jmitc91516 | 1:a5258871b33d | 605 | Note that it is up to the caller (of this function) to verify that the user actually has pressed the dot key. |
jmitc91516 | 1:a5258871b33d | 606 | |
jmitc91516 | 1:a5258871b33d | 607 | No arguments, no return value. |
jmitc91516 | 1:a5258871b33d | 608 | */ |
jmitc91516 | 1:a5258871b33d | 609 | void NumericKeypadPageHandler::DealWithDotKey(void) |
jmitc91516 | 1:a5258871b33d | 610 | { |
jmitc91516 | 1:a5258871b33d | 611 | if((allowedDecimalPlaces > 0) && (!editingFractionalPart)) { |
jmitc91516 | 1:a5258871b33d | 612 | strcat(GuiVar_numericKeypadValue, "."); |
jmitc91516 | 1:a5258871b33d | 613 | |
jmitc91516 | 1:a5258871b33d | 614 | editingFractionalPart = true; |
jmitc91516 | 1:a5258871b33d | 615 | |
jmitc91516 | 1:a5258871b33d | 616 | DisplayEasyGUIPage(); |
jmitc91516 | 1:a5258871b33d | 617 | } |
jmitc91516 | 1:a5258871b33d | 618 | // else '.' is illegal at this point - ignore |
jmitc91516 | 1:a5258871b33d | 619 | } |
jmitc91516 | 1:a5258871b33d | 620 | |
jmitc91516 | 1:a5258871b33d | 621 | |
jmitc91516 | 1:a5258871b33d | 622 | /* |
jmitc91516 | 1:a5258871b33d | 623 | Handles the user pressing the plus/minus key on the easyGUI 'NumericKeypadPage'. |
jmitc91516 | 1:a5258871b33d | 624 | This is legal only if we are editing a value that can be negative - |
jmitc91516 | 1:a5258871b33d | 625 | we ignore it otherwise (note that although we hide the plus/minus key |
jmitc91516 | 1:a5258871b33d | 626 | if the value is not allowed to be negative, the touch area is still there). |
jmitc91516 | 1:a5258871b33d | 627 | If the key is legal, we first check that the value is not zero - if it is zero, |
jmitc91516 | 1:a5258871b33d | 628 | we do nothing, otherwise we look at the first character of the displayed string. |
jmitc91516 | 1:a5258871b33d | 629 | If it is *not* '-', we insert a '-' character at the start, while if it *is* '-', |
jmitc91516 | 1:a5258871b33d | 630 | we remove it. Note that we do *not* display a '+' character. |
jmitc91516 | 1:a5258871b33d | 631 | |
jmitc91516 | 1:a5258871b33d | 632 | Note that it is up to the caller (of this function) to verify that the user |
jmitc91516 | 1:a5258871b33d | 633 | actually has pressed the plus/minus key. |
jmitc91516 | 1:a5258871b33d | 634 | |
jmitc91516 | 1:a5258871b33d | 635 | No arguments, no return value. |
jmitc91516 | 1:a5258871b33d | 636 | */ |
jmitc91516 | 1:a5258871b33d | 637 | void NumericKeypadPageHandler::DealWithPlusMinusKey(void) |
jmitc91516 | 1:a5258871b33d | 638 | { |
jmitc91516 | 1:a5258871b33d | 639 | if(allowNegativeNumbers) { |
jmitc91516 | 1:a5258871b33d | 640 | int temp; |
jmitc91516 | 1:a5258871b33d | 641 | sscanf(GuiVar_numericKeypadValue, "%d", &temp); |
jmitc91516 | 1:a5258871b33d | 642 | if(temp != 0) { |
jmitc91516 | 1:a5258871b33d | 643 | char buffer[60]; // Longer than 'GuiVar_numericKeypadValue' |
jmitc91516 | 1:a5258871b33d | 644 | if(GuiVar_numericKeypadValue[0] == '-') { |
jmitc91516 | 1:a5258871b33d | 645 | strcpy(buffer, &GuiVar_numericKeypadValue[1]); |
jmitc91516 | 1:a5258871b33d | 646 | } else { |
jmitc91516 | 1:a5258871b33d | 647 | buffer[0] = '-'; |
jmitc91516 | 1:a5258871b33d | 648 | strcpy(&buffer[1], GuiVar_numericKeypadValue); |
jmitc91516 | 1:a5258871b33d | 649 | } |
jmitc91516 | 1:a5258871b33d | 650 | strcpy(GuiVar_numericKeypadValue, buffer); |
jmitc91516 | 1:a5258871b33d | 651 | |
jmitc91516 | 1:a5258871b33d | 652 | DisplayEasyGUIPage(); |
jmitc91516 | 1:a5258871b33d | 653 | } |
jmitc91516 | 1:a5258871b33d | 654 | // else value is zero - pointless putting a minus sign on it |
jmitc91516 | 1:a5258871b33d | 655 | } |
jmitc91516 | 1:a5258871b33d | 656 | // else '+/-' is illegal at this point - ignore |
jmitc91516 | 1:a5258871b33d | 657 | } |
jmitc91516 | 1:a5258871b33d | 658 | |
jmitc91516 | 1:a5258871b33d | 659 | /* |
jmitc91516 | 1:a5258871b33d | 660 | In response to the user pressing the Apply key on the easyGUI 'NumericKeypadPage', |
jmitc91516 | 1:a5258871b33d | 661 | sets the easyGUI variable the calling page told us to edit, and (re)displays |
jmitc91516 | 1:a5258871b33d | 662 | the calling page. |
jmitc91516 | 1:a5258871b33d | 663 | |
jmitc91516 | 1:a5258871b33d | 664 | Note that it is up to the caller (of this function) to verify that the user actually has pressed the Apply key. |
jmitc91516 | 1:a5258871b33d | 665 | |
jmitc91516 | 1:a5258871b33d | 666 | No arguments, no return value. |
jmitc91516 | 1:a5258871b33d | 667 | */ |
jmitc91516 | 1:a5258871b33d | 668 | void NumericKeypadPageHandler::DealWithApplyKey(void) |
jmitc91516 | 1:a5258871b33d | 669 | { |
jmitc91516 | 1:a5258871b33d | 670 | if(easyGUIVariableToEdit != NULL) { |
jmitc91516 | 1:a5258871b33d | 671 | if(allowedDecimalPlaces > 0) { |
jmitc91516 | 1:a5258871b33d | 672 | PadFractionalPartWithZeroesIfNecessary(); |
jmitc91516 | 1:a5258871b33d | 673 | } |
jmitc91516 | 1:a5258871b33d | 674 | |
jmitc91516 | 1:a5258871b33d | 675 | strcpy(easyGUIVariableToEdit, GuiVar_numericKeypadValue); |
jmitc91516 | 1:a5258871b33d | 676 | |
jmitc91516 | 1:a5258871b33d | 677 | if(strlen(editVariableUnits) > 0) { |
jmitc91516 | 1:a5258871b33d | 678 | strcat(easyGUIVariableToEdit, " "); |
jmitc91516 | 1:a5258871b33d | 679 | strcat(easyGUIVariableToEdit, editVariableUnits); |
jmitc91516 | 1:a5258871b33d | 680 | } |
jmitc91516 | 1:a5258871b33d | 681 | } |
jmitc91516 | 1:a5258871b33d | 682 | |
jmitc91516 | 1:a5258871b33d | 683 | if(internalVariableToEdit != NULL) { |
jmitc91516 | 1:a5258871b33d | 684 | // Note that internalVariableToEdit is (currently) always an int, |
jmitc91516 | 1:a5258871b33d | 685 | // regardless of how many places of decimals we have been told to use |
jmitc91516 | 1:a5258871b33d | 686 | sscanf(GuiVar_numericKeypadValue, "%d", internalVariableToEdit); |
jmitc91516 | 1:a5258871b33d | 687 | } |
jmitc91516 | 1:a5258871b33d | 688 | |
jmitc91516 | 1:a5258871b33d | 689 | if(applyFunctionPtr != NULL) { |
jmitc91516 | 1:a5258871b33d | 690 | (*applyFunctionPtr)(usbDevice, usbHostGC); |
jmitc91516 | 1:a5258871b33d | 691 | } |
jmitc91516 | 1:a5258871b33d | 692 | |
jmitc91516 | 1:a5258871b33d | 693 | if(inLockMode) { |
jmitc91516 | 1:a5258871b33d | 694 | int temp; |
jmitc91516 | 1:a5258871b33d | 695 | sscanf(GuiVar_numericKeypadValue,"%d", &temp); |
jmitc91516 | 1:a5258871b33d | 696 | if(temp == validLockCode) { |
jmitc91516 | 1:a5258871b33d | 697 | DisplayEasyGuiStructure(pageToDisplayIfLockCodeValid, usbDevice, usbHostGC, false); |
jmitc91516 | 1:a5258871b33d | 698 | } else { |
jmitc91516 | 1:a5258871b33d | 699 | strcpy(easyGUIVariableForInvalidLockCodeMessage, invalidLockCodeMessage); |
jmitc91516 | 1:a5258871b33d | 700 | DisplayEasyGuiStructure(easyGUICallingPage, usbDevice, usbHostGC, false); |
jmitc91516 | 1:a5258871b33d | 701 | } |
jmitc91516 | 1:a5258871b33d | 702 | } else { |
jmitc91516 | 1:a5258871b33d | 703 | if(easyGUICallingPage != -1) { |
jmitc91516 | 1:a5258871b33d | 704 | DisplayEasyGuiStructure(easyGUICallingPage, usbDevice, usbHostGC, false); |
jmitc91516 | 1:a5258871b33d | 705 | } |
jmitc91516 | 1:a5258871b33d | 706 | } |
jmitc91516 | 1:a5258871b33d | 707 | } |
jmitc91516 | 1:a5258871b33d | 708 | |
jmitc91516 | 1:a5258871b33d | 709 | |
jmitc91516 | 1:a5258871b33d | 710 | /* |
jmitc91516 | 1:a5258871b33d | 711 | In response to the user pressing the Cancel key on the easyGUI 'NumericKeypadPage', |
jmitc91516 | 1:a5258871b33d | 712 | (re)displays the calling page *without* updating the easyGUI variable |
jmitc91516 | 1:a5258871b33d | 713 | the calling page told us to edit. |
jmitc91516 | 1:a5258871b33d | 714 | |
jmitc91516 | 1:a5258871b33d | 715 | Note that it is up to the caller (of this function) to verify that the user actually has pressed the Cancel key. |
jmitc91516 | 1:a5258871b33d | 716 | |
jmitc91516 | 1:a5258871b33d | 717 | No arguments, no return value. |
jmitc91516 | 1:a5258871b33d | 718 | */ |
jmitc91516 | 1:a5258871b33d | 719 | void NumericKeypadPageHandler::DealWithCancelKey(void) |
jmitc91516 | 1:a5258871b33d | 720 | { |
jmitc91516 | 1:a5258871b33d | 721 | if(easyGUICallingPage != -1) { |
jmitc91516 | 1:a5258871b33d | 722 | DisplayEasyGuiStructure(easyGUICallingPage, usbDevice, usbHostGC); |
jmitc91516 | 1:a5258871b33d | 723 | } |
jmitc91516 | 1:a5258871b33d | 724 | } |
jmitc91516 | 1:a5258871b33d | 725 | |
jmitc91516 | 1:a5258871b33d | 726 | |
jmitc91516 | 1:a5258871b33d | 727 | /* |
jmitc91516 | 1:a5258871b33d | 728 | Sets the name of the variable being edited. This is displayed on our easyGUI page, |
jmitc91516 | 1:a5258871b33d | 729 | to the left of the keypad, above the variable itself. |
jmitc91516 | 1:a5258871b33d | 730 | |
jmitc91516 | 1:a5258871b33d | 731 | Args: a pointer to null-terminated string containing the name |
jmitc91516 | 1:a5258871b33d | 732 | |
jmitc91516 | 1:a5258871b33d | 733 | No return value |
jmitc91516 | 1:a5258871b33d | 734 | */ |
jmitc91516 | 1:a5258871b33d | 735 | void NumericKeypadPageHandler::SetEditVariableName(char *name) |
jmitc91516 | 1:a5258871b33d | 736 | { |
jmitc91516 | 1:a5258871b33d | 737 | strcpy(GuiVar_numericKeypadName, name); |
jmitc91516 | 1:a5258871b33d | 738 | } |
jmitc91516 | 1:a5258871b33d | 739 | |
jmitc91516 | 1:a5258871b33d | 740 | |
jmitc91516 | 1:a5258871b33d | 741 | /* |
jmitc91516 | 1:a5258871b33d | 742 | Sets the units that apply to the easyGUI variable being edited. |
jmitc91516 | 1:a5258871b33d | 743 | We do not display these while editing - they are simply concatenated |
jmitc91516 | 1:a5258871b33d | 744 | to the variable's value when the user presses Apply. |
jmitc91516 | 1:a5258871b33d | 745 | Note that we also concatenate a space separator before the units - |
jmitc91516 | 1:a5258871b33d | 746 | so the units specified here should be (e.g.) "deg C", not " deg C". |
jmitc91516 | 1:a5258871b33d | 747 | |
jmitc91516 | 1:a5258871b33d | 748 | The default - if this function is not called after 'StartEditing' - |
jmitc91516 | 1:a5258871b33d | 749 | is that there are no units. |
jmitc91516 | 1:a5258871b33d | 750 | |
jmitc91516 | 1:a5258871b33d | 751 | Args: a pointer to null-terminated string containing the units. |
jmitc91516 | 1:a5258871b33d | 752 | |
jmitc91516 | 1:a5258871b33d | 753 | No return value |
jmitc91516 | 1:a5258871b33d | 754 | */ |
jmitc91516 | 6:dba3fbdfd5da | 755 | void NumericKeypadPageHandler::SetEditVariableUnits(const char *units) |
jmitc91516 | 1:a5258871b33d | 756 | { |
jmitc91516 | 1:a5258871b33d | 757 | strcpy(editVariableUnits, units); |
jmitc91516 | 1:a5258871b33d | 758 | } |
jmitc91516 | 1:a5258871b33d | 759 | |
jmitc91516 | 1:a5258871b33d | 760 | |
jmitc91516 | 1:a5258871b33d | 761 | /* |
jmitc91516 | 1:a5258871b33d | 762 | Sets our pointer to a function, provided by the caller, that we are to call |
jmitc91516 | 1:a5258871b33d | 763 | if/when the user presses our Apply button. This must have the form: |
jmitc91516 | 1:a5258871b33d | 764 | |
jmitc91516 | 1:a5258871b33d | 765 | void FunctionName(USBDeviceConnected* usbDevice, USBHostGC* usbHostGC) |
jmitc91516 | 1:a5258871b33d | 766 | |
jmitc91516 | 1:a5258871b33d | 767 | Args: a pointer to the function to call |
jmitc91516 | 1:a5258871b33d | 768 | |
jmitc91516 | 1:a5258871b33d | 769 | No return value |
jmitc91516 | 1:a5258871b33d | 770 | */ |
jmitc91516 | 1:a5258871b33d | 771 | void NumericKeypadPageHandler::SetApplyFunctionPtr(ApplyFunctionPtr newApplyFunctionPtr) |
jmitc91516 | 1:a5258871b33d | 772 | { |
jmitc91516 | 1:a5258871b33d | 773 | applyFunctionPtr = newApplyFunctionPtr; |
jmitc91516 | 1:a5258871b33d | 774 | } |
jmitc91516 | 1:a5258871b33d | 775 | |
jmitc91516 | 1:a5258871b33d | 776 | |
jmitc91516 | 1:a5258871b33d | 777 |