Repository for import to local machine
Dependencies: DMBasicGUI DMSupport
EthernetKeypadPageHandler.cpp@8:26e49e6955bd, 2017-07-31 (annotated)
- Committer:
- jmitc91516
- Date:
- Mon Jul 31 15:37:57 2017 +0000
- Revision:
- 8:26e49e6955bd
- Parent:
- 1:a5258871b33d
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 "EthernetKeypadPageHandler.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 | For Display (LPC4088) Bug #11, draw a background bitmap without a grey bar at the bottom. |
jmitc91516 | 1:a5258871b33d | 18 | For now, fake this with a page full of one colour. |
jmitc91516 | 1:a5258871b33d | 19 | |
jmitc91516 | 1:a5258871b33d | 20 | We use the same (fake) background bitmap here, as in the 'ordinary' numeric keypad |
jmitc91516 | 1:a5258871b33d | 21 | |
jmitc91516 | 1:a5258871b33d | 22 | Defined in main.cpp |
jmitc91516 | 1:a5258871b33d | 23 | */ |
jmitc91516 | 1:a5258871b33d | 24 | void DrawFakeBackgroundBitmapForNumericKeypadPage(void); |
jmitc91516 | 1:a5258871b33d | 25 | |
jmitc91516 | 1:a5258871b33d | 26 | |
jmitc91516 | 1:a5258871b33d | 27 | |
jmitc91516 | 1:a5258871b33d | 28 | |
jmitc91516 | 1:a5258871b33d | 29 | /* |
jmitc91516 | 1:a5258871b33d | 30 | Displays the specified easyGUI 'structure' (or page, to use a more easily understood term). |
jmitc91516 | 1:a5258871b33d | 31 | Defined in main.cpp |
jmitc91516 | 1:a5258871b33d | 32 | */ |
jmitc91516 | 1:a5258871b33d | 33 | extern void DisplayEasyGuiStructure(int structureIndex, USBDeviceConnected* usbDevice, USBHostGC* usbHostGC, bool updateEasyGUIVariables = true); |
jmitc91516 | 1:a5258871b33d | 34 | |
jmitc91516 | 1:a5258871b33d | 35 | |
jmitc91516 | 1:a5258871b33d | 36 | |
jmitc91516 | 1:a5258871b33d | 37 | /* |
jmitc91516 | 1:a5258871b33d | 38 | 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 | 39 | (we will not show more than one "EthernetKeypadPage" to the user at the same time). |
jmitc91516 | 1:a5258871b33d | 40 | */ |
jmitc91516 | 1:a5258871b33d | 41 | EthernetKeypadPageHandler * EthernetKeypadPageHandler::theEthernetKeypadPageHandlerInstance = NULL; |
jmitc91516 | 1:a5258871b33d | 42 | |
jmitc91516 | 1:a5258871b33d | 43 | const int EthernetKeypadPageHandler::minimumOctetValue = 0; |
jmitc91516 | 1:a5258871b33d | 44 | const int EthernetKeypadPageHandler::maximumOctetValue = 255; |
jmitc91516 | 1:a5258871b33d | 45 | |
jmitc91516 | 1:a5258871b33d | 46 | #define TESTING_COLOURS |
jmitc91516 | 1:a5258871b33d | 47 | #ifdef TESTING_COLOURS |
jmitc91516 | 1:a5258871b33d | 48 | const GuiConst_INTCOLOR EthernetKeypadPageHandler::inactiveOctetBackgroundColour = 0xFFFF; // RGB565 value for white - same colour as background |
jmitc91516 | 1:a5258871b33d | 49 | const GuiConst_INTCOLOR EthernetKeypadPageHandler::activeOctetBackgroundColour = 0x07FF; // RGB565 value for yellow (255, 255, 0) |
jmitc91516 | 1:a5258871b33d | 50 | #else |
jmitc91516 | 1:a5258871b33d | 51 | const GuiConst_INTCOLOR EthernetKeypadPageHandler::inactiveOctetBackgroundColour = 0xE71C; // RGB565 value for light grey (224, 224, 224) |
jmitc91516 | 1:a5258871b33d | 52 | const GuiConst_INTCOLOR EthernetKeypadPageHandler::activeOctetBackgroundColour = 0xFFFF; // RGB565 value for white (255, 255, 255) |
jmitc91516 | 1:a5258871b33d | 53 | #endif // TESTING_COLOURS |
jmitc91516 | 1:a5258871b33d | 54 | //#define USE_BACKGROUND_COLOURS // else use box around active octet |
jmitc91516 | 1:a5258871b33d | 55 | |
jmitc91516 | 1:a5258871b33d | 56 | /* |
jmitc91516 | 1:a5258871b33d | 57 | Singleton class - return the one and only instance, first creating it if necessary. |
jmitc91516 | 1:a5258871b33d | 58 | */ |
jmitc91516 | 1:a5258871b33d | 59 | EthernetKeypadPageHandler * EthernetKeypadPageHandler::GetInstance(USBDeviceConnected* newUsbDevice, USBHostGC* newUsbHostGC) |
jmitc91516 | 1:a5258871b33d | 60 | { |
jmitc91516 | 1:a5258871b33d | 61 | if (theEthernetKeypadPageHandlerInstance == NULL) { |
jmitc91516 | 1:a5258871b33d | 62 | theEthernetKeypadPageHandlerInstance = new EthernetKeypadPageHandler(newUsbDevice, newUsbHostGC); |
jmitc91516 | 1:a5258871b33d | 63 | } |
jmitc91516 | 1:a5258871b33d | 64 | |
jmitc91516 | 1:a5258871b33d | 65 | return theEthernetKeypadPageHandlerInstance; |
jmitc91516 | 1:a5258871b33d | 66 | } |
jmitc91516 | 1:a5258871b33d | 67 | |
jmitc91516 | 1:a5258871b33d | 68 | // Singleton class - private constructor |
jmitc91516 | 1:a5258871b33d | 69 | EthernetKeypadPageHandler::EthernetKeypadPageHandler(USBDeviceConnected* newUsbDevice, USBHostGC* newUsbHostGC) |
jmitc91516 | 1:a5258871b33d | 70 | { |
jmitc91516 | 1:a5258871b33d | 71 | // Note that we do not use these values here - |
jmitc91516 | 1:a5258871b33d | 72 | // but we do need to pass them to the (main.cpp) function DisplayEasyGUIStructure |
jmitc91516 | 1:a5258871b33d | 73 | // when the user presses Apply or Cancel |
jmitc91516 | 1:a5258871b33d | 74 | usbDevice = newUsbDevice; |
jmitc91516 | 1:a5258871b33d | 75 | usbHostGC = newUsbHostGC; |
jmitc91516 | 1:a5258871b33d | 76 | |
jmitc91516 | 1:a5258871b33d | 77 | easyGUICallingPage = -1; // i.e. invalid, none |
jmitc91516 | 1:a5258871b33d | 78 | indexOfOctetBeingEdited = -1; // as above - invalid, none |
jmitc91516 | 1:a5258871b33d | 79 | |
jmitc91516 | 1:a5258871b33d | 80 | for (int index = 0; index < 4; ++index){ |
jmitc91516 | 1:a5258871b33d | 81 | callerEasyGUIOctetPtr[index] = NULL; |
jmitc91516 | 1:a5258871b33d | 82 | callerInternalOctetPtr[index] = NULL; |
jmitc91516 | 1:a5258871b33d | 83 | } |
jmitc91516 | 1:a5258871b33d | 84 | |
jmitc91516 | 1:a5258871b33d | 85 | easyGUIOctetValues[0] = GuiVar_ethernetOctet1; |
jmitc91516 | 1:a5258871b33d | 86 | easyGUIOctetValues[1] = GuiVar_ethernetOctet2; |
jmitc91516 | 1:a5258871b33d | 87 | easyGUIOctetValues[2] = GuiVar_ethernetOctet3; |
jmitc91516 | 1:a5258871b33d | 88 | easyGUIOctetValues[3] = GuiVar_ethernetOctet4; |
jmitc91516 | 1:a5258871b33d | 89 | |
jmitc91516 | 1:a5258871b33d | 90 | easyGUIOctetBackgroundColourVariables[0] = &GuiVar_ethernetOctet1BackgroundColour; |
jmitc91516 | 1:a5258871b33d | 91 | easyGUIOctetBackgroundColourVariables[1] = &GuiVar_ethernetOctet2BackgroundColour; |
jmitc91516 | 1:a5258871b33d | 92 | easyGUIOctetBackgroundColourVariables[2] = &GuiVar_ethernetOctet3BackgroundColour; |
jmitc91516 | 1:a5258871b33d | 93 | easyGUIOctetBackgroundColourVariables[3] = &GuiVar_ethernetOctet4BackgroundColour; |
jmitc91516 | 1:a5258871b33d | 94 | |
jmitc91516 | 1:a5258871b33d | 95 | activeOctetOutline[0].X1 = 270; activeOctetOutline[0].Y1 = 35, activeOctetOutline[0].X2 = 335, activeOctetOutline[0].Y2 = 80; |
jmitc91516 | 1:a5258871b33d | 96 | activeOctetOutline[1].X1 = 350; activeOctetOutline[1].Y1 = 35, activeOctetOutline[1].X2 = 415, activeOctetOutline[1].Y2 = 80; |
jmitc91516 | 1:a5258871b33d | 97 | activeOctetOutline[2].X1 = 430; activeOctetOutline[2].Y1 = 35, activeOctetOutline[2].X2 = 495, activeOctetOutline[2].Y2 = 80; |
jmitc91516 | 1:a5258871b33d | 98 | activeOctetOutline[3].X1 = 510; activeOctetOutline[3].Y1 = 35, activeOctetOutline[3].X2 = 575, activeOctetOutline[3].Y2 = 80; |
jmitc91516 | 1:a5258871b33d | 99 | } |
jmitc91516 | 1:a5258871b33d | 100 | |
jmitc91516 | 1:a5258871b33d | 101 | // Private destructor also |
jmitc91516 | 1:a5258871b33d | 102 | EthernetKeypadPageHandler::~EthernetKeypadPageHandler() |
jmitc91516 | 1:a5258871b33d | 103 | { |
jmitc91516 | 1:a5258871b33d | 104 | } |
jmitc91516 | 1:a5258871b33d | 105 | |
jmitc91516 | 1:a5258871b33d | 106 | |
jmitc91516 | 1:a5258871b33d | 107 | /* |
jmitc91516 | 1:a5258871b33d | 108 | Tells the caller whether or not the specified touch index is on the easyGUI 'NumericKeypadPage', |
jmitc91516 | 1:a5258871b33d | 109 | and therefore needs to be handled by this class. |
jmitc91516 | 1:a5258871b33d | 110 | |
jmitc91516 | 1:a5258871b33d | 111 | Args: the touch area index in question |
jmitc91516 | 1:a5258871b33d | 112 | |
jmitc91516 | 1:a5258871b33d | 113 | Return code: true if the touch area is 'one of ours', false if not |
jmitc91516 | 1:a5258871b33d | 114 | */ |
jmitc91516 | 1:a5258871b33d | 115 | bool EthernetKeypadPageHandler::TouchAreaIsOnEthernetKeypadPage(int touchAreaIndex) |
jmitc91516 | 1:a5258871b33d | 116 | { |
jmitc91516 | 1:a5258871b33d | 117 | if((touchAreaIndex >= MIN_ETHERNET_KEYPAD_TOUCHINDEX) && (touchAreaIndex <= MAX_ETHERNET_KEYPAD_TOUCHINDEX)) { |
jmitc91516 | 1:a5258871b33d | 118 | return true; |
jmitc91516 | 1:a5258871b33d | 119 | } |
jmitc91516 | 1:a5258871b33d | 120 | |
jmitc91516 | 1:a5258871b33d | 121 | // 'else' |
jmitc91516 | 1:a5258871b33d | 122 | return false; |
jmitc91516 | 1:a5258871b33d | 123 | } |
jmitc91516 | 1:a5258871b33d | 124 | |
jmitc91516 | 1:a5258871b33d | 125 | |
jmitc91516 | 1:a5258871b33d | 126 | /* |
jmitc91516 | 1:a5258871b33d | 127 | If the specified touch area represents a key or field on the easyGUI 'EtherneKeypadPage', |
jmitc91516 | 1:a5258871b33d | 128 | this function performs whatever action is appropriate for it. Provided so that the caller |
jmitc91516 | 1:a5258871b33d | 129 | can (in effect) say "if this is one of yours, deal with it", without needing to know |
jmitc91516 | 1:a5258871b33d | 130 | anything about what this class does, or how it handles the touch areas on that easyGUI page. |
jmitc91516 | 1:a5258871b33d | 131 | |
jmitc91516 | 1:a5258871b33d | 132 | Args: the touch area index in question |
jmitc91516 | 1:a5258871b33d | 133 | |
jmitc91516 | 1:a5258871b33d | 134 | Returns true if it dealt with the touch area (so the caller need not do anything else |
jmitc91516 | 1:a5258871b33d | 135 | with the value), or false if it did not deal with the touch area (implying that it |
jmitc91516 | 1:a5258871b33d | 136 | was not a touch area on the easyGUI 'EthernetKeypadPage', and so the caller |
jmitc91516 | 1:a5258871b33d | 137 | must deal with it some other way). |
jmitc91516 | 1:a5258871b33d | 138 | */ |
jmitc91516 | 1:a5258871b33d | 139 | bool EthernetKeypadPageHandler::DealWithTouch(int touchAreaIndex) |
jmitc91516 | 1:a5258871b33d | 140 | { |
jmitc91516 | 1:a5258871b33d | 141 | if((touchAreaIndex >= ETHERNET_KEYPAD_BUTTON_0) && (touchAreaIndex <= ETHERNET_KEYPAD_BUTTON_9)) { |
jmitc91516 | 1:a5258871b33d | 142 | |
jmitc91516 | 1:a5258871b33d | 143 | DealWithNumberKey(touchAreaIndex); |
jmitc91516 | 1:a5258871b33d | 144 | |
jmitc91516 | 1:a5258871b33d | 145 | return true; |
jmitc91516 | 1:a5258871b33d | 146 | } |
jmitc91516 | 1:a5258871b33d | 147 | |
jmitc91516 | 1:a5258871b33d | 148 | if(touchAreaIndex == ETHERNET_KEYPAD_DELETE_BUTTON) { |
jmitc91516 | 1:a5258871b33d | 149 | |
jmitc91516 | 1:a5258871b33d | 150 | DealWithDeleteKey(); |
jmitc91516 | 1:a5258871b33d | 151 | |
jmitc91516 | 1:a5258871b33d | 152 | return true; |
jmitc91516 | 1:a5258871b33d | 153 | } |
jmitc91516 | 1:a5258871b33d | 154 | |
jmitc91516 | 1:a5258871b33d | 155 | if(touchAreaIndex == ETHERNET_KEYPAD_APPLY_BUTTON) { |
jmitc91516 | 1:a5258871b33d | 156 | |
jmitc91516 | 1:a5258871b33d | 157 | DealWithApplyKey(); |
jmitc91516 | 1:a5258871b33d | 158 | |
jmitc91516 | 1:a5258871b33d | 159 | return true; |
jmitc91516 | 1:a5258871b33d | 160 | } |
jmitc91516 | 1:a5258871b33d | 161 | |
jmitc91516 | 1:a5258871b33d | 162 | if(touchAreaIndex == ETHERNET_KEYPAD_CANCEL_BUTTON) { |
jmitc91516 | 1:a5258871b33d | 163 | |
jmitc91516 | 1:a5258871b33d | 164 | DealWithCancelKey(); |
jmitc91516 | 1:a5258871b33d | 165 | |
jmitc91516 | 1:a5258871b33d | 166 | return true; |
jmitc91516 | 1:a5258871b33d | 167 | } |
jmitc91516 | 1:a5258871b33d | 168 | |
jmitc91516 | 1:a5258871b33d | 169 | if(touchAreaIndex == ETHERNET_KEYPAD_CLEAR_BUTTON) { |
jmitc91516 | 1:a5258871b33d | 170 | |
jmitc91516 | 1:a5258871b33d | 171 | DealWithClearKey(); |
jmitc91516 | 1:a5258871b33d | 172 | |
jmitc91516 | 1:a5258871b33d | 173 | return true; |
jmitc91516 | 1:a5258871b33d | 174 | } |
jmitc91516 | 1:a5258871b33d | 175 | |
jmitc91516 | 1:a5258871b33d | 176 | if(touchAreaIndex == ETHERNET_KEYPAD_DOT_BUTTON) { |
jmitc91516 | 1:a5258871b33d | 177 | |
jmitc91516 | 1:a5258871b33d | 178 | DealWithDotKey(); |
jmitc91516 | 1:a5258871b33d | 179 | |
jmitc91516 | 1:a5258871b33d | 180 | return true; |
jmitc91516 | 1:a5258871b33d | 181 | } |
jmitc91516 | 1:a5258871b33d | 182 | |
jmitc91516 | 1:a5258871b33d | 183 | // 'else' - none of the above |
jmitc91516 | 1:a5258871b33d | 184 | return false; |
jmitc91516 | 1:a5258871b33d | 185 | } |
jmitc91516 | 1:a5258871b33d | 186 | |
jmitc91516 | 1:a5258871b33d | 187 | |
jmitc91516 | 1:a5258871b33d | 188 | /* |
jmitc91516 | 1:a5258871b33d | 189 | This function allows the caller to tell us which of its easyGUI variables to update when the user presses the Apply button |
jmitc91516 | 1:a5258871b33d | 190 | |
jmitc91516 | 1:a5258871b33d | 191 | Args: pointers to the easyGUI variables for each of the four octets - we assume these are all easyGUI strings |
jmitc91516 | 1:a5258871b33d | 192 | |
jmitc91516 | 1:a5258871b33d | 193 | No return code |
jmitc91516 | 1:a5258871b33d | 194 | */ |
jmitc91516 | 1:a5258871b33d | 195 | void EthernetKeypadPageHandler::SetEasyGUIOctetVariablesToEdit(GuiConst_TEXT* easyGUIOctet1, GuiConst_TEXT* easyGUIOctet2, GuiConst_TEXT* easyGUIOctet3, GuiConst_TEXT* easyGUIOctet4) |
jmitc91516 | 1:a5258871b33d | 196 | { |
jmitc91516 | 1:a5258871b33d | 197 | callerEasyGUIOctetPtr[0] = easyGUIOctet1; |
jmitc91516 | 1:a5258871b33d | 198 | callerEasyGUIOctetPtr[1] = easyGUIOctet2; |
jmitc91516 | 1:a5258871b33d | 199 | callerEasyGUIOctetPtr[2] = easyGUIOctet3; |
jmitc91516 | 1:a5258871b33d | 200 | callerEasyGUIOctetPtr[3] = easyGUIOctet4; |
jmitc91516 | 1:a5258871b33d | 201 | } |
jmitc91516 | 1:a5258871b33d | 202 | |
jmitc91516 | 1:a5258871b33d | 203 | |
jmitc91516 | 1:a5258871b33d | 204 | /* |
jmitc91516 | 1:a5258871b33d | 205 | This function allows the caller to tell us which of its internal variables to update when the user presses the Apply button |
jmitc91516 | 1:a5258871b33d | 206 | |
jmitc91516 | 1:a5258871b33d | 207 | Args: pointers to the internal variables for each of the four octets - these must all be unsigned int's |
jmitc91516 | 1:a5258871b33d | 208 | |
jmitc91516 | 1:a5258871b33d | 209 | No return code |
jmitc91516 | 1:a5258871b33d | 210 | */ |
jmitc91516 | 1:a5258871b33d | 211 | void EthernetKeypadPageHandler::SetInternalOctetVariablesToEdit(unsigned int *internalOctet1, unsigned int *internalOctet2, unsigned int *internalOctet3, unsigned int *internalOctet4) |
jmitc91516 | 1:a5258871b33d | 212 | { |
jmitc91516 | 1:a5258871b33d | 213 | callerInternalOctetPtr[0] = internalOctet1; |
jmitc91516 | 1:a5258871b33d | 214 | callerInternalOctetPtr[1] = internalOctet2; |
jmitc91516 | 1:a5258871b33d | 215 | callerInternalOctetPtr[2] = internalOctet3; |
jmitc91516 | 1:a5258871b33d | 216 | callerInternalOctetPtr[3] = internalOctet4; |
jmitc91516 | 1:a5258871b33d | 217 | } |
jmitc91516 | 1:a5258871b33d | 218 | |
jmitc91516 | 1:a5258871b33d | 219 | /* |
jmitc91516 | 1:a5258871b33d | 220 | Actually start editing. |
jmitc91516 | 1:a5258871b33d | 221 | Caller *must* have called 'SetEasyGUIOctetVariablesToEdit' and 'SetInternalOctetVariablesToEdit' |
jmitc91516 | 1:a5258871b33d | 222 | before calling this function |
jmitc91516 | 1:a5258871b33d | 223 | **************************** |
jmitc91516 | 1:a5258871b33d | 224 | |
jmitc91516 | 1:a5258871b33d | 225 | Args: the name/title of the Ethernet parameter we are editing (e.g. "IP Address", etc) |
jmitc91516 | 1:a5258871b33d | 226 | |
jmitc91516 | 1:a5258871b33d | 227 | No return code |
jmitc91516 | 1:a5258871b33d | 228 | */ |
jmitc91516 | 1:a5258871b33d | 229 | void EthernetKeypadPageHandler::StartEditing(char *title) |
jmitc91516 | 1:a5258871b33d | 230 | { |
jmitc91516 | 1:a5258871b33d | 231 | strcpy(GuiVar_ethernetKeypadTitle, title); |
jmitc91516 | 1:a5258871b33d | 232 | |
jmitc91516 | 1:a5258871b33d | 233 | for (int index = 0; index < 4; ++index) { |
jmitc91516 | 1:a5258871b33d | 234 | currentOctetValues[index] = *callerInternalOctetPtr[index]; |
jmitc91516 | 1:a5258871b33d | 235 | } |
jmitc91516 | 1:a5258871b33d | 236 | |
jmitc91516 | 1:a5258871b33d | 237 | UpdateEasyGUIOctetValues(); |
jmitc91516 | 1:a5258871b33d | 238 | |
jmitc91516 | 1:a5258871b33d | 239 | indexOfOctetBeingEdited = 0; |
jmitc91516 | 1:a5258871b33d | 240 | |
jmitc91516 | 1:a5258871b33d | 241 | #ifdef USE_BACKGROUND_COLOURS |
jmitc91516 | 1:a5258871b33d | 242 | UpdateEasyGUIBackgroundsForCurrentOctetSelection(); |
jmitc91516 | 1:a5258871b33d | 243 | #endif // USE_BACKGROUND_COLOURS |
jmitc91516 | 1:a5258871b33d | 244 | |
jmitc91516 | 1:a5258871b33d | 245 | UpdateEasyGUIPage(); |
jmitc91516 | 1:a5258871b33d | 246 | } |
jmitc91516 | 1:a5258871b33d | 247 | |
jmitc91516 | 1:a5258871b33d | 248 | |
jmitc91516 | 1:a5258871b33d | 249 | /* |
jmitc91516 | 1:a5258871b33d | 250 | Update the easyGUI variables that display the octet values to the user, |
jmitc91516 | 1:a5258871b33d | 251 | from our internal values |
jmitc91516 | 1:a5258871b33d | 252 | |
jmitc91516 | 1:a5258871b33d | 253 | No arguments, no return code |
jmitc91516 | 1:a5258871b33d | 254 | */ |
jmitc91516 | 1:a5258871b33d | 255 | void EthernetKeypadPageHandler::UpdateEasyGUIOctetValues(void) |
jmitc91516 | 1:a5258871b33d | 256 | { |
jmitc91516 | 1:a5258871b33d | 257 | for (int index = 0; index < 4; ++index) { |
jmitc91516 | 1:a5258871b33d | 258 | sprintf(easyGUIOctetValues[index], "%d", currentOctetValues[index]); |
jmitc91516 | 1:a5258871b33d | 259 | } |
jmitc91516 | 1:a5258871b33d | 260 | } |
jmitc91516 | 1:a5258871b33d | 261 | |
jmitc91516 | 1:a5258871b33d | 262 | |
jmitc91516 | 1:a5258871b33d | 263 | /* |
jmitc91516 | 1:a5258871b33d | 264 | In response to the user pressing one of the number keys on the easyGUI 'EthernetKeypadPage', |
jmitc91516 | 1:a5258871b33d | 265 | edits the current octet appropriately. Note that we rely on the touch area indices being consecutive, |
jmitc91516 | 1:a5258871b33d | 266 | and in the same order as the numbers they represent. |
jmitc91516 | 1:a5258871b33d | 267 | |
jmitc91516 | 1:a5258871b33d | 268 | Argument: the index of the touch area for the key in question |
jmitc91516 | 1:a5258871b33d | 269 | (note that it is up to the caller to verify that it is a number key) |
jmitc91516 | 1:a5258871b33d | 270 | |
jmitc91516 | 1:a5258871b33d | 271 | No return value. |
jmitc91516 | 1:a5258871b33d | 272 | */ |
jmitc91516 | 1:a5258871b33d | 273 | void EthernetKeypadPageHandler::DealWithNumberKey(int touchAreaIndex) |
jmitc91516 | 1:a5258871b33d | 274 | { |
jmitc91516 | 1:a5258871b33d | 275 | if((indexOfOctetBeingEdited >= 0) && (indexOfOctetBeingEdited < 4)) { |
jmitc91516 | 1:a5258871b33d | 276 | int digitToInsert = touchAreaIndex - ETHERNET_KEYPAD_BUTTON_0; |
jmitc91516 | 1:a5258871b33d | 277 | if(digitToInsert > 9) digitToInsert = 9; |
jmitc91516 | 1:a5258871b33d | 278 | if(digitToInsert < 0) digitToInsert = 0; |
jmitc91516 | 1:a5258871b33d | 279 | |
jmitc91516 | 1:a5258871b33d | 280 | int temp = currentOctetValues[indexOfOctetBeingEdited]; |
jmitc91516 | 1:a5258871b33d | 281 | |
jmitc91516 | 1:a5258871b33d | 282 | if(temp < maximumOctetValue) { // else we can't increase it any further |
jmitc91516 | 1:a5258871b33d | 283 | |
jmitc91516 | 1:a5258871b33d | 284 | temp *= 10; |
jmitc91516 | 1:a5258871b33d | 285 | temp += digitToInsert; |
jmitc91516 | 1:a5258871b33d | 286 | |
jmitc91516 | 1:a5258871b33d | 287 | if(temp < maximumOctetValue) { |
jmitc91516 | 1:a5258871b33d | 288 | currentOctetValues[indexOfOctetBeingEdited] = temp; |
jmitc91516 | 1:a5258871b33d | 289 | } else { |
jmitc91516 | 1:a5258871b33d | 290 | currentOctetValues[indexOfOctetBeingEdited] = maximumOctetValue; |
jmitc91516 | 1:a5258871b33d | 291 | } |
jmitc91516 | 1:a5258871b33d | 292 | |
jmitc91516 | 1:a5258871b33d | 293 | UpdateEasyGUIOctetValues(); |
jmitc91516 | 1:a5258871b33d | 294 | |
jmitc91516 | 1:a5258871b33d | 295 | UpdateEasyGUIPage(); |
jmitc91516 | 1:a5258871b33d | 296 | } |
jmitc91516 | 1:a5258871b33d | 297 | } |
jmitc91516 | 1:a5258871b33d | 298 | } |
jmitc91516 | 1:a5258871b33d | 299 | |
jmitc91516 | 1:a5258871b33d | 300 | |
jmitc91516 | 1:a5258871b33d | 301 | /* |
jmitc91516 | 1:a5258871b33d | 302 | In response to the user pressing the dot key on the easyGUI 'EthernetKeypadPage', |
jmitc91516 | 1:a5258871b33d | 303 | moves editing to the next octet, or back to the first if we are currently at the fourth. |
jmitc91516 | 1:a5258871b33d | 304 | Note that it is up to the caller to verify that the user actually has pressed the dot key |
jmitc91516 | 1:a5258871b33d | 305 | |
jmitc91516 | 1:a5258871b33d | 306 | No arguments, no return value. |
jmitc91516 | 1:a5258871b33d | 307 | */ |
jmitc91516 | 1:a5258871b33d | 308 | void EthernetKeypadPageHandler::DealWithDotKey(void) |
jmitc91516 | 1:a5258871b33d | 309 | { |
jmitc91516 | 1:a5258871b33d | 310 | if((indexOfOctetBeingEdited >= 0) && (indexOfOctetBeingEdited < 3)) { |
jmitc91516 | 1:a5258871b33d | 311 | // Can move to next octet |
jmitc91516 | 1:a5258871b33d | 312 | ++indexOfOctetBeingEdited; |
jmitc91516 | 1:a5258871b33d | 313 | } else { |
jmitc91516 | 1:a5258871b33d | 314 | // Default to first octet |
jmitc91516 | 1:a5258871b33d | 315 | indexOfOctetBeingEdited = 0; |
jmitc91516 | 1:a5258871b33d | 316 | } |
jmitc91516 | 1:a5258871b33d | 317 | |
jmitc91516 | 1:a5258871b33d | 318 | #ifdef USE_BACKGROUND_COLOURS |
jmitc91516 | 1:a5258871b33d | 319 | UpdateEasyGUIBackgroundsForCurrentOctetSelection(); |
jmitc91516 | 1:a5258871b33d | 320 | #endif // USE_BACKGROUND_COLOURS |
jmitc91516 | 1:a5258871b33d | 321 | |
jmitc91516 | 1:a5258871b33d | 322 | UpdateEasyGUIPage(); |
jmitc91516 | 1:a5258871b33d | 323 | } |
jmitc91516 | 1:a5258871b33d | 324 | |
jmitc91516 | 1:a5258871b33d | 325 | |
jmitc91516 | 1:a5258871b33d | 326 | /* |
jmitc91516 | 1:a5258871b33d | 327 | (Re)display the easyGUI 'EthernetKeypadPage' - e.g. after we have updated |
jmitc91516 | 1:a5258871b33d | 328 | the octet being edited, and want to display the new value to the user. |
jmitc91516 | 1:a5258871b33d | 329 | |
jmitc91516 | 1:a5258871b33d | 330 | No arguments, no return code |
jmitc91516 | 1:a5258871b33d | 331 | */ |
jmitc91516 | 1:a5258871b33d | 332 | void EthernetKeypadPageHandler::UpdateEasyGUIPage(void) |
jmitc91516 | 1:a5258871b33d | 333 | { |
jmitc91516 | 1:a5258871b33d | 334 | #define WANT_GUILIB_CLEAR |
jmitc91516 | 1:a5258871b33d | 335 | #ifdef WANT_GUILIB_CLEAR |
jmitc91516 | 1:a5258871b33d | 336 | #ifdef USING_BACKGROUND_BITMAP |
jmitc91516 | 1:a5258871b33d | 337 | DrawFakeBackgroundBitmapForNumericKeypadPage(); |
jmitc91516 | 1:a5258871b33d | 338 | #else |
jmitc91516 | 1:a5258871b33d | 339 | GuiLib_Clear(); |
jmitc91516 | 1:a5258871b33d | 340 | #endif |
jmitc91516 | 1:a5258871b33d | 341 | #undef WANT_GUILIB_CLEAR |
jmitc91516 | 1:a5258871b33d | 342 | #endif |
jmitc91516 | 1:a5258871b33d | 343 | GuiLib_ShowScreen(GuiStruct_EthernetKeypadPage_Def, GuiLib_NO_CURSOR, GuiLib_RESET_AUTO_REDRAW); |
jmitc91516 | 1:a5258871b33d | 344 | |
jmitc91516 | 1:a5258871b33d | 345 | #ifndef USE_BACKGROUND_COLOURS |
jmitc91516 | 1:a5258871b33d | 346 | DrawOutlineAroundActiveOctet(); |
jmitc91516 | 1:a5258871b33d | 347 | #endif |
jmitc91516 | 1:a5258871b33d | 348 | |
jmitc91516 | 1:a5258871b33d | 349 | GuiLib_Refresh(); |
jmitc91516 | 1:a5258871b33d | 350 | } |
jmitc91516 | 1:a5258871b33d | 351 | |
jmitc91516 | 1:a5258871b33d | 352 | |
jmitc91516 | 1:a5258871b33d | 353 | /* |
jmitc91516 | 1:a5258871b33d | 354 | In response to the user pressing the Delete key on the easyGUI 'EthernetKeypadPage', |
jmitc91516 | 1:a5258871b33d | 355 | edits the current octet appropriately. Note that it is up to the caller to verify |
jmitc91516 | 1:a5258871b33d | 356 | that the user actually has pressed the Delete key |
jmitc91516 | 1:a5258871b33d | 357 | |
jmitc91516 | 1:a5258871b33d | 358 | No arguments, no return value. |
jmitc91516 | 1:a5258871b33d | 359 | */ |
jmitc91516 | 1:a5258871b33d | 360 | void EthernetKeypadPageHandler::DealWithDeleteKey(void) |
jmitc91516 | 1:a5258871b33d | 361 | { |
jmitc91516 | 1:a5258871b33d | 362 | if((indexOfOctetBeingEdited >= 0) && (indexOfOctetBeingEdited < 4)) { |
jmitc91516 | 1:a5258871b33d | 363 | |
jmitc91516 | 1:a5258871b33d | 364 | int temp = currentOctetValues[indexOfOctetBeingEdited]; |
jmitc91516 | 1:a5258871b33d | 365 | |
jmitc91516 | 1:a5258871b33d | 366 | if(temp > minimumOctetValue) { // else we can't reduce it any further |
jmitc91516 | 1:a5258871b33d | 367 | |
jmitc91516 | 1:a5258871b33d | 368 | temp /= 10; |
jmitc91516 | 1:a5258871b33d | 369 | |
jmitc91516 | 1:a5258871b33d | 370 | if(temp > minimumOctetValue) { |
jmitc91516 | 1:a5258871b33d | 371 | currentOctetValues[indexOfOctetBeingEdited] = temp; |
jmitc91516 | 1:a5258871b33d | 372 | } else { |
jmitc91516 | 1:a5258871b33d | 373 | currentOctetValues[indexOfOctetBeingEdited] = minimumOctetValue; |
jmitc91516 | 1:a5258871b33d | 374 | } |
jmitc91516 | 1:a5258871b33d | 375 | |
jmitc91516 | 1:a5258871b33d | 376 | UpdateEasyGUIOctetValues(); |
jmitc91516 | 1:a5258871b33d | 377 | |
jmitc91516 | 1:a5258871b33d | 378 | UpdateEasyGUIPage(); |
jmitc91516 | 1:a5258871b33d | 379 | } |
jmitc91516 | 1:a5258871b33d | 380 | } |
jmitc91516 | 1:a5258871b33d | 381 | } |
jmitc91516 | 1:a5258871b33d | 382 | |
jmitc91516 | 1:a5258871b33d | 383 | |
jmitc91516 | 1:a5258871b33d | 384 | /* |
jmitc91516 | 1:a5258871b33d | 385 | In response to the user pressing the Clear key on the easyGUI 'EthernetKeypadPage', |
jmitc91516 | 1:a5258871b33d | 386 | edits the current octet appropriately. Note that it is up to the caller to verify |
jmitc91516 | 1:a5258871b33d | 387 | that the user actually has pressed the Clear key |
jmitc91516 | 1:a5258871b33d | 388 | |
jmitc91516 | 1:a5258871b33d | 389 | No arguments, no return value. |
jmitc91516 | 1:a5258871b33d | 390 | */ |
jmitc91516 | 1:a5258871b33d | 391 | void EthernetKeypadPageHandler::DealWithClearKey(void) |
jmitc91516 | 1:a5258871b33d | 392 | { |
jmitc91516 | 1:a5258871b33d | 393 | if((indexOfOctetBeingEdited >= 0) && (indexOfOctetBeingEdited < 4)) { |
jmitc91516 | 1:a5258871b33d | 394 | |
jmitc91516 | 1:a5258871b33d | 395 | currentOctetValues[indexOfOctetBeingEdited] = minimumOctetValue; |
jmitc91516 | 1:a5258871b33d | 396 | |
jmitc91516 | 1:a5258871b33d | 397 | UpdateEasyGUIOctetValues(); |
jmitc91516 | 1:a5258871b33d | 398 | |
jmitc91516 | 1:a5258871b33d | 399 | UpdateEasyGUIPage(); |
jmitc91516 | 1:a5258871b33d | 400 | } |
jmitc91516 | 1:a5258871b33d | 401 | } |
jmitc91516 | 1:a5258871b33d | 402 | |
jmitc91516 | 1:a5258871b33d | 403 | |
jmitc91516 | 1:a5258871b33d | 404 | /* |
jmitc91516 | 1:a5258871b33d | 405 | In response to the user pressing the Apply key on the easyGUI 'EthernetKeypadPage', |
jmitc91516 | 1:a5258871b33d | 406 | updates the octet values on the calling page (which we currently assume |
jmitc91516 | 1:a5258871b33d | 407 | is always the Ethernet Parameters page), and redisplays the calling page. |
jmitc91516 | 1:a5258871b33d | 408 | |
jmitc91516 | 1:a5258871b33d | 409 | 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 | 410 | |
jmitc91516 | 1:a5258871b33d | 411 | No arguments, no return value. |
jmitc91516 | 1:a5258871b33d | 412 | */ |
jmitc91516 | 1:a5258871b33d | 413 | void EthernetKeypadPageHandler::DealWithApplyKey(void) |
jmitc91516 | 1:a5258871b33d | 414 | { |
jmitc91516 | 1:a5258871b33d | 415 | //Update the octet values in the Ethernet Parameters page |
jmitc91516 | 1:a5258871b33d | 416 | for (int index = 0; index < 4; ++index) { |
jmitc91516 | 1:a5258871b33d | 417 | if(callerEasyGUIOctetPtr[index] != NULL) { |
jmitc91516 | 1:a5258871b33d | 418 | sprintf(callerEasyGUIOctetPtr[index], "%d", currentOctetValues[index]); |
jmitc91516 | 1:a5258871b33d | 419 | } |
jmitc91516 | 1:a5258871b33d | 420 | |
jmitc91516 | 1:a5258871b33d | 421 | if(callerInternalOctetPtr[index] != NULL) { |
jmitc91516 | 1:a5258871b33d | 422 | *callerInternalOctetPtr[index] = currentOctetValues[index]; |
jmitc91516 | 1:a5258871b33d | 423 | } |
jmitc91516 | 1:a5258871b33d | 424 | } |
jmitc91516 | 1:a5258871b33d | 425 | |
jmitc91516 | 1:a5258871b33d | 426 | DisplayEasyGuiStructure(GuiStruct_EthernetParametersPage_50, usbDevice, usbHostGC, false); |
jmitc91516 | 1:a5258871b33d | 427 | } |
jmitc91516 | 1:a5258871b33d | 428 | |
jmitc91516 | 1:a5258871b33d | 429 | |
jmitc91516 | 1:a5258871b33d | 430 | /* |
jmitc91516 | 1:a5258871b33d | 431 | In response to the user pressing the Cancel key on the easyGUI 'EthernetKeypadPage', |
jmitc91516 | 1:a5258871b33d | 432 | (re)displays the calling page (which we currently assume is always the Ethernet Parameters page) |
jmitc91516 | 1:a5258871b33d | 433 | *without* updating its octet values. |
jmitc91516 | 1:a5258871b33d | 434 | |
jmitc91516 | 1:a5258871b33d | 435 | 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 | 436 | |
jmitc91516 | 1:a5258871b33d | 437 | No arguments, no return value. |
jmitc91516 | 1:a5258871b33d | 438 | */ |
jmitc91516 | 1:a5258871b33d | 439 | void EthernetKeypadPageHandler::DealWithCancelKey(void) |
jmitc91516 | 1:a5258871b33d | 440 | { |
jmitc91516 | 1:a5258871b33d | 441 | DisplayEasyGuiStructure(GuiStruct_EthernetParametersPage_50, usbDevice, usbHostGC); |
jmitc91516 | 1:a5258871b33d | 442 | } |
jmitc91516 | 1:a5258871b33d | 443 | |
jmitc91516 | 1:a5258871b33d | 444 | |
jmitc91516 | 1:a5258871b33d | 445 | /* |
jmitc91516 | 1:a5258871b33d | 446 | Update the easyGUI background colour variables to show which octet is 'active', |
jmitc91516 | 1:a5258871b33d | 447 | i.e. currently being edited. |
jmitc91516 | 1:a5258871b33d | 448 | |
jmitc91516 | 1:a5258871b33d | 449 | No arguments, no return value. |
jmitc91516 | 1:a5258871b33d | 450 | */ |
jmitc91516 | 1:a5258871b33d | 451 | void EthernetKeypadPageHandler::UpdateEasyGUIBackgroundsForCurrentOctetSelection(void) |
jmitc91516 | 1:a5258871b33d | 452 | { |
jmitc91516 | 1:a5258871b33d | 453 | for (int index = 0; index < 4; ++index) { |
jmitc91516 | 1:a5258871b33d | 454 | if(index == indexOfOctetBeingEdited) { |
jmitc91516 | 1:a5258871b33d | 455 | *easyGUIOctetBackgroundColourVariables[index] = activeOctetBackgroundColour; |
jmitc91516 | 1:a5258871b33d | 456 | } else { |
jmitc91516 | 1:a5258871b33d | 457 | *easyGUIOctetBackgroundColourVariables[index] = inactiveOctetBackgroundColour; |
jmitc91516 | 1:a5258871b33d | 458 | } |
jmitc91516 | 1:a5258871b33d | 459 | } |
jmitc91516 | 1:a5258871b33d | 460 | } |
jmitc91516 | 1:a5258871b33d | 461 | |
jmitc91516 | 1:a5258871b33d | 462 | |
jmitc91516 | 1:a5258871b33d | 463 | /* |
jmitc91516 | 1:a5258871b33d | 464 | Draw an outline box around the octet value the user is currently editing (if any), |
jmitc91516 | 1:a5258871b33d | 465 | to show which one it is. |
jmitc91516 | 1:a5258871b33d | 466 | |
jmitc91516 | 1:a5258871b33d | 467 | No arguments, no return value. |
jmitc91516 | 1:a5258871b33d | 468 | */ |
jmitc91516 | 1:a5258871b33d | 469 | void EthernetKeypadPageHandler::DrawOutlineAroundActiveOctet(void) |
jmitc91516 | 1:a5258871b33d | 470 | { |
jmitc91516 | 1:a5258871b33d | 471 | if((indexOfOctetBeingEdited >= 0) && (indexOfOctetBeingEdited < 4)) { |
jmitc91516 | 1:a5258871b33d | 472 | GuiLib_Box(activeOctetOutline[indexOfOctetBeingEdited].X1, |
jmitc91516 | 1:a5258871b33d | 473 | activeOctetOutline[indexOfOctetBeingEdited].Y1, |
jmitc91516 | 1:a5258871b33d | 474 | activeOctetOutline[indexOfOctetBeingEdited].X2, |
jmitc91516 | 1:a5258871b33d | 475 | activeOctetOutline[indexOfOctetBeingEdited].Y2, |
jmitc91516 | 1:a5258871b33d | 476 | 0 // Box colour - black |
jmitc91516 | 1:a5258871b33d | 477 | ); |
jmitc91516 | 1:a5258871b33d | 478 | } |
jmitc91516 | 1:a5258871b33d | 479 | } |
jmitc91516 | 1:a5258871b33d | 480 |