Repository for import to local machine

Dependencies:   DMBasicGUI DMSupport

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?

UserRevisionLine numberNew contents of line
jmitc91516 1:a5258871b33d 1 #include "DebugCommandsPageHandler.h"
jmitc91516 1:a5258871b33d 2 #include "EasyGUITouchAreaIndices.h"
jmitc91516 1:a5258871b33d 3 #include "GetGCStatusLoop.h"
jmitc91516 1:a5258871b33d 4 #include "DebugCommandsPageHandler.h"
jmitc91516 1:a5258871b33d 5 #include "USBHostGCUtilities.h"
jmitc91516 1:a5258871b33d 6
jmitc91516 1:a5258871b33d 7 // main.cpp
jmitc91516 1:a5258871b33d 8 void SpecialDebugPrint(char *stuffToPrint, GuiConst_INT16S X, GuiConst_INT16S Y);
jmitc91516 1:a5258871b33d 9
jmitc91516 1:a5258871b33d 10 /*
jmitc91516 1:a5258871b33d 11 Draws the default background bitmap, i.e. *without* the Ellutia logo.
jmitc91516 1:a5258871b33d 12 Defined in main.cpp
jmitc91516 1:a5258871b33d 13 */
jmitc91516 1:a5258871b33d 14 void DrawBackgroundBitmap(void);
jmitc91516 1:a5258871b33d 15
jmitc91516 1:a5258871b33d 16
jmitc91516 1:a5258871b33d 17 /*
jmitc91516 1:a5258871b33d 18 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 19 (we do not want multiple values for the same nudge and damp parameters, etc, nor will we show
jmitc91516 1:a5258871b33d 20 more than one easyGUI page to the user at the same time).
jmitc91516 1:a5258871b33d 21 */
jmitc91516 1:a5258871b33d 22 DebugCommandsPageHandler * DebugCommandsPageHandler::theDebugCommandsPageHandlerInstance = NULL;
jmitc91516 1:a5258871b33d 23
jmitc91516 1:a5258871b33d 24
jmitc91516 1:a5258871b33d 25 /*
jmitc91516 1:a5258871b33d 26 Singleton class - return the one and only instance, first creating it if necessary.
jmitc91516 1:a5258871b33d 27 */
jmitc91516 1:a5258871b33d 28 DebugCommandsPageHandler * DebugCommandsPageHandler::GetInstance(USBDeviceConnected* newUsbDevice, USBHostGC* newUsbHostGC)
jmitc91516 1:a5258871b33d 29 {
jmitc91516 1:a5258871b33d 30 if (theDebugCommandsPageHandlerInstance == NULL) {
jmitc91516 1:a5258871b33d 31 theDebugCommandsPageHandlerInstance = new DebugCommandsPageHandler(newUsbDevice, newUsbHostGC);
jmitc91516 1:a5258871b33d 32 }
jmitc91516 1:a5258871b33d 33
jmitc91516 1:a5258871b33d 34 return theDebugCommandsPageHandlerInstance;
jmitc91516 1:a5258871b33d 35 }
jmitc91516 1:a5258871b33d 36
jmitc91516 1:a5258871b33d 37 /*
jmitc91516 1:a5258871b33d 38 Overriden version of the above, that does not take any arguments and does not create the instance
jmitc91516 1:a5258871b33d 39 if it does not already exist. Caller *must* check for NULL.
jmitc91516 1:a5258871b33d 40
jmitc91516 1:a5258871b33d 41 Provided for callers that do not have the 'usbDevice' and 'usbHostGC' pointers, and just want access
jmitc91516 1:a5258871b33d 42 to the instance if it exists
jmitc91516 1:a5258871b33d 43 */
jmitc91516 1:a5258871b33d 44 DebugCommandsPageHandler * DebugCommandsPageHandler::GetInstance(void)
jmitc91516 1:a5258871b33d 45 {
jmitc91516 1:a5258871b33d 46 return theDebugCommandsPageHandlerInstance;
jmitc91516 1:a5258871b33d 47 }
jmitc91516 1:a5258871b33d 48
jmitc91516 1:a5258871b33d 49
jmitc91516 1:a5258871b33d 50 // Singleton class - private constructor
jmitc91516 1:a5258871b33d 51 DebugCommandsPageHandler::DebugCommandsPageHandler(USBDeviceConnected* newUsbDevice, USBHostGC* newUsbHostGC)
jmitc91516 1:a5258871b33d 52 {
jmitc91516 1:a5258871b33d 53 usbDevice = newUsbDevice;
jmitc91516 1:a5258871b33d 54 usbHostGC = newUsbHostGC;
jmitc91516 1:a5258871b33d 55
jmitc91516 1:a5258871b33d 56 // Set this true immediately after executing a GC command.
jmitc91516 1:a5258871b33d 57 // If the user types another char, clear the command first.
jmitc91516 1:a5258871b33d 58 commandJustExecuted = false;
jmitc91516 1:a5258871b33d 59 }
jmitc91516 1:a5258871b33d 60
jmitc91516 1:a5258871b33d 61
jmitc91516 1:a5258871b33d 62 // Private destructor also
jmitc91516 1:a5258871b33d 63 DebugCommandsPageHandler::~DebugCommandsPageHandler()
jmitc91516 1:a5258871b33d 64 {
jmitc91516 1:a5258871b33d 65 }
jmitc91516 1:a5258871b33d 66
jmitc91516 1:a5258871b33d 67 /*
jmitc91516 1:a5258871b33d 68 As the name implies, sends a command to the GC and displays the response.
jmitc91516 1:a5258871b33d 69 Expects the command to be in the easyGUI variable "GuiVar_debugCommandTx",
jmitc91516 1:a5258871b33d 70 and places the response in the easyGUI variable "GuiVar_debugCommandRx".
jmitc91516 1:a5258871b33d 71 It is up to the caller to (re)display the Debug Commands easyGUI page
jmitc91516 1:a5258871b33d 72 to show the updated values.
jmitc91516 1:a5258871b33d 73
jmitc91516 1:a5258871b33d 74 Args: pointer to a buffer containing the command, as a null-terminated string
jmitc91516 1:a5258871b33d 75 pointer to a buffer to contain the response, as a null-terminated string
jmitc91516 1:a5258871b33d 76
jmitc91516 1:a5258871b33d 77 No return code (it is up to the caller to examine the response to see whether
jmitc91516 1:a5258871b33d 78 the command succeeded or failed)
jmitc91516 1:a5258871b33d 79 */
jmitc91516 1:a5258871b33d 80 void DebugCommandsPageHandler::SendCommandToGCAndDisplayResponse(void)
jmitc91516 1:a5258871b33d 81 {
jmitc91516 1:a5258871b33d 82 char command[20];
jmitc91516 1:a5258871b33d 83 char response[20];
jmitc91516 1:a5258871b33d 84
jmitc91516 1:a5258871b33d 85 strcpy(command, GuiVar_debugCommandTx);
jmitc91516 1:a5258871b33d 86
jmitc91516 1:a5258871b33d 87 bool expect4Chars = ((command[0] == 'C') || (command[0] == 'S'));
jmitc91516 1:a5258871b33d 88 // Else expect 8 chars (or "EPKT")
jmitc91516 1:a5258871b33d 89
jmitc91516 1:a5258871b33d 90 #define USE_GC_UTILS // Testing new class
jmitc91516 1:a5258871b33d 91 #ifdef USE_GC_UTILS
jmitc91516 1:a5258871b33d 92 USBHostGCUtilities::SendCommandToGCAndGetResponse(usbDevice, usbHostGC, command, response);
jmitc91516 1:a5258871b33d 93 #else
jmitc91516 1:a5258871b33d 94 while(usbHostGC->ExecutingSetDeviceReport()) {}
jmitc91516 1:a5258871b33d 95
jmitc91516 1:a5258871b33d 96 usbHostGC->SetDeviceReport(usbDevice, command, response);
jmitc91516 1:a5258871b33d 97 #endif // USE_GC_UTILS
jmitc91516 1:a5258871b33d 98
jmitc91516 1:a5258871b33d 99 // There always seems to be garbage at the end of the response
jmitc91516 1:a5258871b33d 100 if(expect4Chars || (response[0] == 'E')) { // If 'E', assume "EPKT"
jmitc91516 1:a5258871b33d 101 response[4] = '\0';
jmitc91516 1:a5258871b33d 102 } else {
jmitc91516 1:a5258871b33d 103 response[8] = '\0';
jmitc91516 1:a5258871b33d 104 }
jmitc91516 1:a5258871b33d 105
jmitc91516 1:a5258871b33d 106 //#define DEBUG_PRINT_HERE
jmitc91516 1:a5258871b33d 107 #ifdef DEBUG_PRINT_HERE
jmitc91516 1:a5258871b33d 108 char dbg[100];
jmitc91516 1:a5258871b33d 109 sprintf(dbg, "DCPH cmd \"%s\", response \"%s\"", command, response);
jmitc91516 1:a5258871b33d 110 SpecialDebugPrint(dbg, 10, 275);
jmitc91516 1:a5258871b33d 111 #endif // DEBUG_PRINT_HERE
jmitc91516 1:a5258871b33d 112
jmitc91516 1:a5258871b33d 113 strcpy(GuiVar_debugCommandRx, response);
jmitc91516 1:a5258871b33d 114
jmitc91516 1:a5258871b33d 115 commandJustExecuted = true;
jmitc91516 1:a5258871b33d 116 }
jmitc91516 1:a5258871b33d 117
jmitc91516 1:a5258871b33d 118
jmitc91516 1:a5258871b33d 119 /*
jmitc91516 1:a5258871b33d 120 Tells the caller whether or not the specified touch index is on the Debug Commands page,
jmitc91516 1:a5258871b33d 121 and therefore needs to be handled by this class.
jmitc91516 1:a5258871b33d 122
jmitc91516 1:a5258871b33d 123 Args: the touch area index in question
jmitc91516 1:a5258871b33d 124
jmitc91516 1:a5258871b33d 125 Return code: true if the touch area is 'one of ours', false if not
jmitc91516 1:a5258871b33d 126 */
jmitc91516 1:a5258871b33d 127 bool DebugCommandsPageHandler::TouchAreaIsOnDebugCommandsPage(int touchAreaIndex)
jmitc91516 1:a5258871b33d 128 {
jmitc91516 1:a5258871b33d 129 if((touchAreaIndex >= MIN_DEBUG_COMMANDS_TOUCHINDEX) && (touchAreaIndex <= MAX_DEBUG_COMMANDS_TOUCHINDEX)) {
jmitc91516 1:a5258871b33d 130 return true;
jmitc91516 1:a5258871b33d 131 }
jmitc91516 1:a5258871b33d 132
jmitc91516 1:a5258871b33d 133 // 'else'
jmitc91516 1:a5258871b33d 134 return false;
jmitc91516 1:a5258871b33d 135 }
jmitc91516 1:a5258871b33d 136
jmitc91516 1:a5258871b33d 137
jmitc91516 1:a5258871b33d 138 /*
jmitc91516 1:a5258871b33d 139 Returns the character that matches the specified touch area index.
jmitc91516 1:a5258871b33d 140 This should be one of the character keys on the easyGUI DebugCommandsPage.
jmitc91516 1:a5258871b33d 141 If not, defaults to '0'.
jmitc91516 1:a5258871b33d 142
jmitc91516 1:a5258871b33d 143 Args: the touch area index
jmitc91516 1:a5258871b33d 144
jmitc91516 1:a5258871b33d 145 Returns the corresponding character if there is one, '0' if not
jmitc91516 1:a5258871b33d 146 */
jmitc91516 1:a5258871b33d 147 char DebugCommandsPageHandler::GetCharCodeForTouchAreaIndex(int touchAreaIndex)
jmitc91516 1:a5258871b33d 148 {
jmitc91516 1:a5258871b33d 149 if((touchAreaIndex >= DEBUG_COMMANDS_0) && (touchAreaIndex <= DEBUG_COMMANDS_9)) {
jmitc91516 1:a5258871b33d 150 return (touchAreaIndex - DEBUG_COMMANDS_0 + '0');
jmitc91516 1:a5258871b33d 151 }
jmitc91516 1:a5258871b33d 152
jmitc91516 1:a5258871b33d 153 // else...
jmitc91516 1:a5258871b33d 154 if((touchAreaIndex >= DEBUG_COMMANDS_A) && (touchAreaIndex <= DEBUG_COMMANDS_Z)) {
jmitc91516 1:a5258871b33d 155 return (touchAreaIndex - DEBUG_COMMANDS_A + 'A');
jmitc91516 1:a5258871b33d 156 }
jmitc91516 1:a5258871b33d 157
jmitc91516 1:a5258871b33d 158 // else...
jmitc91516 1:a5258871b33d 159 return '0';
jmitc91516 1:a5258871b33d 160 }
jmitc91516 1:a5258871b33d 161
jmitc91516 1:a5258871b33d 162
jmitc91516 1:a5258871b33d 163 /*
jmitc91516 1:a5258871b33d 164 If the specified touch area represents a key or field on the easyGUI Debug Commands page,
jmitc91516 1:a5258871b33d 165 this function performs whatever action is appropriate for it. Provided so that the caller
jmitc91516 1:a5258871b33d 166 can (in effect) say "if this is one of yours, deal with it", without needing to know
jmitc91516 1:a5258871b33d 167 anything about what this class does, or how it handles the touch areas on that easyGUI page.
jmitc91516 1:a5258871b33d 168
jmitc91516 1:a5258871b33d 169 Args: the touch area index in question
jmitc91516 1:a5258871b33d 170
jmitc91516 1:a5258871b33d 171 Returns true if it dealt with the touch area (so the caller need not do anything else
jmitc91516 1:a5258871b33d 172 with the value), or false if it did not deal with the touch area (implying that it
jmitc91516 1:a5258871b33d 173 was not a touch area on the easyGUI GC/Debug Commands page, and so the caller
jmitc91516 1:a5258871b33d 174 must deal with it some other way).
jmitc91516 1:a5258871b33d 175 */
jmitc91516 1:a5258871b33d 176 bool DebugCommandsPageHandler::DealWithTouch(int touchAreaIndex)
jmitc91516 1:a5258871b33d 177 {
jmitc91516 1:a5258871b33d 178 if(touchAreaIndex == DEBUG_COMMANDS_SEND) {
jmitc91516 1:a5258871b33d 179
jmitc91516 1:a5258871b33d 180 // Clear response first, so user sees something happen
jmitc91516 1:a5258871b33d 181 GuiVar_debugCommandRx[0] = '\0';
jmitc91516 1:a5258871b33d 182 DisplayEasyGUIPage();
jmitc91516 1:a5258871b33d 183
jmitc91516 1:a5258871b33d 184 SendCommandToGCAndDisplayResponse();
jmitc91516 1:a5258871b33d 185 DisplayEasyGUIPage();
jmitc91516 1:a5258871b33d 186
jmitc91516 1:a5258871b33d 187 return true;
jmitc91516 1:a5258871b33d 188 }
jmitc91516 1:a5258871b33d 189
jmitc91516 1:a5258871b33d 190 // If a character, append it to GuiVar_debugCommandTx, unless that is already at MAX_COMMAND_LENGTH
jmitc91516 1:a5258871b33d 191 if((touchAreaIndex >= MIN_DEBUG_COMMANDS_CHAR) && (touchAreaIndex <= MAX_DEBUG_COMMANDS_CHAR)) {
jmitc91516 1:a5258871b33d 192
jmitc91516 1:a5258871b33d 193 // If we have just executed a command, start a new one as soon as the user types another character,
jmitc91516 1:a5258871b33d 194 // but not if he types Delete or Clear (since he is in effect editing the previous command)
jmitc91516 1:a5258871b33d 195 if(commandJustExecuted) {
jmitc91516 1:a5258871b33d 196 GuiVar_debugCommandTx[0] = '\0'; // Clear the command we have just executed
jmitc91516 1:a5258871b33d 197
jmitc91516 1:a5258871b33d 198 commandJustExecuted = false; // So we know to append subsequent characters to this one
jmitc91516 1:a5258871b33d 199 }
jmitc91516 1:a5258871b33d 200
jmitc91516 1:a5258871b33d 201 int len = strlen(GuiVar_debugCommandTx);
jmitc91516 1:a5258871b33d 202 if(len < MAX_COMMAND_LENGTH) {
jmitc91516 1:a5258871b33d 203 // Append the new character to the command
jmitc91516 1:a5258871b33d 204 GuiVar_debugCommandTx[len] = GetCharCodeForTouchAreaIndex(touchAreaIndex);
jmitc91516 1:a5258871b33d 205 GuiVar_debugCommandTx[len + 1] = '\0';
jmitc91516 1:a5258871b33d 206
jmitc91516 1:a5258871b33d 207 DisplayEasyGUIPage();
jmitc91516 1:a5258871b33d 208 }
jmitc91516 1:a5258871b33d 209 return true;
jmitc91516 1:a5258871b33d 210 }
jmitc91516 1:a5258871b33d 211
jmitc91516 1:a5258871b33d 212 // If DEBUG_COMMANDS_DELETE, delete the last character in GuiVar_debugCommandTx, unless it already has zero characters
jmitc91516 1:a5258871b33d 213 if((touchAreaIndex == DEBUG_COMMANDS_DELETE)) {
jmitc91516 1:a5258871b33d 214 int len = strlen(GuiVar_debugCommandTx);
jmitc91516 1:a5258871b33d 215 if(len > 0) {
jmitc91516 1:a5258871b33d 216 // Delete the last character in the command
jmitc91516 1:a5258871b33d 217 GuiVar_debugCommandTx[len - 1] = '\0';
jmitc91516 1:a5258871b33d 218
jmitc91516 1:a5258871b33d 219 DisplayEasyGUIPage();
jmitc91516 1:a5258871b33d 220
jmitc91516 1:a5258871b33d 221 commandJustExecuted = false; // User has (in effect) edited this command - do not start a new one if he types another character
jmitc91516 1:a5258871b33d 222 }
jmitc91516 1:a5258871b33d 223 return true;
jmitc91516 1:a5258871b33d 224 }
jmitc91516 1:a5258871b33d 225
jmitc91516 1:a5258871b33d 226 // If DEBUG_COMMANDS_CLEAR, clear the command by setting GuiVar_debugCommandTx to an empty string
jmitc91516 1:a5258871b33d 227 if((touchAreaIndex == DEBUG_COMMANDS_CLEAR)) {
jmitc91516 1:a5258871b33d 228 GuiVar_debugCommandTx[0] = '\0';
jmitc91516 1:a5258871b33d 229 DisplayEasyGUIPage();
jmitc91516 1:a5258871b33d 230
jmitc91516 1:a5258871b33d 231 commandJustExecuted = false; // User has (in effect) edited this command - do not start a new one if he types another character
jmitc91516 1:a5258871b33d 232 return true;
jmitc91516 1:a5258871b33d 233 }
jmitc91516 1:a5258871b33d 234
jmitc91516 1:a5258871b33d 235 // 'else'...
jmitc91516 1:a5258871b33d 236
jmitc91516 1:a5258871b33d 237 return false;
jmitc91516 1:a5258871b33d 238 }
jmitc91516 1:a5258871b33d 239
jmitc91516 1:a5258871b33d 240
jmitc91516 1:a5258871b33d 241 /*
jmitc91516 1:a5258871b33d 242 (Re)display the easyGUI 'DebugCommandsPage' - e.g. after we have updated
jmitc91516 1:a5258871b33d 243 the command to be sent, and want to display the new value to the user.
jmitc91516 1:a5258871b33d 244
jmitc91516 1:a5258871b33d 245 No arguments, no return code
jmitc91516 1:a5258871b33d 246 */
jmitc91516 1:a5258871b33d 247 void DebugCommandsPageHandler::DisplayEasyGUIPage(void)
jmitc91516 1:a5258871b33d 248 {
jmitc91516 1:a5258871b33d 249 DrawBackgroundBitmap();
jmitc91516 1:a5258871b33d 250
jmitc91516 1:a5258871b33d 251 GuiLib_ShowScreen(GuiStruct_DebugCommandsPage_Def, GuiLib_NO_CURSOR, GuiLib_RESET_AUTO_REDRAW);
jmitc91516 1:a5258871b33d 252
jmitc91516 1:a5258871b33d 253 GuiLib_Refresh();
jmitc91516 1:a5258871b33d 254
jmitc91516 1:a5258871b33d 255 GetGCStatusLoop *getGCStatusLoop = GetGCStatusLoop::GetInstance();
jmitc91516 1:a5258871b33d 256 if(getGCStatusLoop != NULL) {
jmitc91516 1:a5258871b33d 257 getGCStatusLoop->SetCurrentPage(GuiStruct_DebugCommandsPage_Def);
jmitc91516 1:a5258871b33d 258 }
jmitc91516 1:a5258871b33d 259 }
jmitc91516 1:a5258871b33d 260