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 "ColumnDHPSUDACPageHandler.h"
jmitc91516 1:a5258871b33d 2 #include "EasyGUITouchAreaIndices.h"
jmitc91516 1:a5258871b33d 3 #include "GetGCStatusLoop.h"
jmitc91516 1:a5258871b33d 4 #include "NumericKeypadPageHandler.h"
jmitc91516 1:a5258871b33d 5 #include "USBHostGCUtilities.h"
jmitc91516 1:a5258871b33d 6
jmitc91516 1:a5258871b33d 7 /*
jmitc91516 1:a5258871b33d 8 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 9 (we do not want multiple values for the same calibration parameters, etc, and nor will we show
jmitc91516 1:a5258871b33d 10 more than one easyGUI 'PSU_DAC_Page' to the user at the same time).
jmitc91516 1:a5258871b33d 11 */
jmitc91516 1:a5258871b33d 12 ColumnDHPSUDACPageHandler * ColumnDHPSUDACPageHandler::theColumnDHPSUDACPageHandlerInstance = NULL;
jmitc91516 1:a5258871b33d 13
jmitc91516 1:a5258871b33d 14
jmitc91516 1:a5258871b33d 15 /*
jmitc91516 1:a5258871b33d 16 Singleton class - return the one and only instance, first creating it if necessary.
jmitc91516 1:a5258871b33d 17 */
jmitc91516 1:a5258871b33d 18 ColumnDHPSUDACPageHandler * ColumnDHPSUDACPageHandler::GetInstance(USBDeviceConnected* newUsbDevice, USBHostGC* newUsbHostGC)
jmitc91516 1:a5258871b33d 19 {
jmitc91516 1:a5258871b33d 20 if (theColumnDHPSUDACPageHandlerInstance == NULL) {
jmitc91516 1:a5258871b33d 21 theColumnDHPSUDACPageHandlerInstance = new ColumnDHPSUDACPageHandler(newUsbDevice, newUsbHostGC);
jmitc91516 1:a5258871b33d 22 }
jmitc91516 1:a5258871b33d 23
jmitc91516 1:a5258871b33d 24 return theColumnDHPSUDACPageHandlerInstance;
jmitc91516 1:a5258871b33d 25 }
jmitc91516 1:a5258871b33d 26
jmitc91516 1:a5258871b33d 27 /*
jmitc91516 1:a5258871b33d 28 Overriden version of the above, that does not take any arguments and does not create the instance
jmitc91516 1:a5258871b33d 29 if it does not already exist.
jmitc91516 1:a5258871b33d 30
jmitc91516 1:a5258871b33d 31 Provided for callers that do not have the 'usbDevice' and 'usbHostGC' pointers, and just want access
jmitc91516 1:a5258871b33d 32 to the instance if it exists
jmitc91516 1:a5258871b33d 33 */
jmitc91516 1:a5258871b33d 34 ColumnDHPSUDACPageHandler * ColumnDHPSUDACPageHandler::GetInstance(void)
jmitc91516 1:a5258871b33d 35 {
jmitc91516 1:a5258871b33d 36 return theColumnDHPSUDACPageHandlerInstance;
jmitc91516 1:a5258871b33d 37 }
jmitc91516 1:a5258871b33d 38
jmitc91516 1:a5258871b33d 39
jmitc91516 1:a5258871b33d 40 // Singleton class - private constructor
jmitc91516 1:a5258871b33d 41 ColumnDHPSUDACPageHandler::ColumnDHPSUDACPageHandler(USBDeviceConnected* newUsbDevice, USBHostGC* newUsbHostGC)
jmitc91516 1:a5258871b33d 42 {
jmitc91516 1:a5258871b33d 43 usbDevice = newUsbDevice;
jmitc91516 1:a5258871b33d 44 usbHostGC = newUsbHostGC;
jmitc91516 1:a5258871b33d 45 }
jmitc91516 1:a5258871b33d 46
jmitc91516 1:a5258871b33d 47
jmitc91516 1:a5258871b33d 48 // Private destructor also
jmitc91516 1:a5258871b33d 49 ColumnDHPSUDACPageHandler::~ColumnDHPSUDACPageHandler()
jmitc91516 1:a5258871b33d 50 {
jmitc91516 1:a5258871b33d 51 }
jmitc91516 1:a5258871b33d 52
jmitc91516 1:a5258871b33d 53
jmitc91516 1:a5258871b33d 54 /*
jmitc91516 1:a5258871b33d 55 Tells the caller whether or not the specified touch index is on the easyGUI 'ColumnDHAutoCalibrationPage',
jmitc91516 1:a5258871b33d 56 and therefore needs to be handled by this class.
jmitc91516 1:a5258871b33d 57
jmitc91516 1:a5258871b33d 58 Args: the touch area index in question
jmitc91516 1:a5258871b33d 59
jmitc91516 1:a5258871b33d 60 Return code: true if the touch area is 'one of ours', false if not
jmitc91516 1:a5258871b33d 61 */
jmitc91516 1:a5258871b33d 62 bool ColumnDHPSUDACPageHandler::TouchAreaIsOnPSUDACPage(int touchAreaIndex)
jmitc91516 1:a5258871b33d 63 {
jmitc91516 1:a5258871b33d 64 if((touchAreaIndex >= MIN_COLUMN_DH_PSU_DAC_TOUCHINDEX) && (touchAreaIndex <= MAX_COLUMN_DH_PSU_DAC_TOUCHINDEX)) {
jmitc91516 1:a5258871b33d 65 return true;
jmitc91516 1:a5258871b33d 66 }
jmitc91516 1:a5258871b33d 67
jmitc91516 1:a5258871b33d 68 // 'else'
jmitc91516 1:a5258871b33d 69 return false;
jmitc91516 1:a5258871b33d 70 }
jmitc91516 1:a5258871b33d 71
jmitc91516 1:a5258871b33d 72
jmitc91516 1:a5258871b33d 73 /*
jmitc91516 1:a5258871b33d 74 If the specified touch area represents a key or field on the easyGUI 'ColumnDHSensorCalibrationPage',
jmitc91516 1:a5258871b33d 75 this function performs whatever action is appropriate for it. Provided so that the caller
jmitc91516 1:a5258871b33d 76 can (in effect) say "if this is one of yours, deal with it", without needing to know
jmitc91516 1:a5258871b33d 77 anything about what this class does, or how it handles the touch areas on that easyGUI page.
jmitc91516 1:a5258871b33d 78
jmitc91516 1:a5258871b33d 79 Args: the touch area index in question
jmitc91516 1:a5258871b33d 80
jmitc91516 1:a5258871b33d 81 Returns true if it dealt with the touch area (so the caller need not do anything else
jmitc91516 1:a5258871b33d 82 with the value), or false if it did not deal with the touch area (implying that it
jmitc91516 1:a5258871b33d 83 was not a touch area on the easyGUI 'Directly Heated Column Sensor Calibration Page', and so the caller
jmitc91516 1:a5258871b33d 84 must deal with it some other way).
jmitc91516 1:a5258871b33d 85 */
jmitc91516 1:a5258871b33d 86 bool ColumnDHPSUDACPageHandler::DealWithTouch(int touchAreaIndex)
jmitc91516 1:a5258871b33d 87 {
jmitc91516 1:a5258871b33d 88 bool dealtWithTouch = false; // so far...
jmitc91516 1:a5258871b33d 89
jmitc91516 1:a5258871b33d 90 switch(touchAreaIndex) {
jmitc91516 1:a5258871b33d 91 case COLUMN_DH_PSU_DAC_EDIT_DAC_VALUE: { // Restrict the scope of 'numericKeypadPageHandler' to this case -
jmitc91516 1:a5258871b33d 92 // avoid compiler warning "Transfer of control bypasses initialization"
jmitc91516 1:a5258871b33d 93 NumericKeypadPageHandler* numericKeypadPageHandler = NumericKeypadPageHandler::GetInstance(usbDevice, usbHostGC);
jmitc91516 1:a5258871b33d 94 if(numericKeypadPageHandler != NULL) {
jmitc91516 1:a5258871b33d 95 numericKeypadPageHandler->StartEditing(GuiVar_columnDHPSUDACSetValue);
jmitc91516 1:a5258871b33d 96 numericKeypadPageHandler->SetEasyGUIVariableToEdit(GuiVar_columnDHPSUDACSetValue);
jmitc91516 1:a5258871b33d 97 numericKeypadPageHandler->SetEasyGUICallingPage(GuiStruct_PSU_DAC_Page_Def);
jmitc91516 1:a5258871b33d 98 numericKeypadPageHandler->SetEditVariableRange(0, 4095);
jmitc91516 1:a5258871b33d 99 numericKeypadPageHandler->SetEditVariableName("PSU DAC Value");
jmitc91516 1:a5258871b33d 100 numericKeypadPageHandler->DisplayEasyGUIPage();
jmitc91516 1:a5258871b33d 101 }
jmitc91516 1:a5258871b33d 102 dealtWithTouch = true;
jmitc91516 1:a5258871b33d 103 break;
jmitc91516 1:a5258871b33d 104 } // See above
jmitc91516 1:a5258871b33d 105
jmitc91516 1:a5258871b33d 106 case COLUMN_DH_PSU_DAC_SET_DAC_VALUE:
jmitc91516 1:a5258871b33d 107 SetCurrentPSUDACValueInGC();
jmitc91516 1:a5258871b33d 108 GetCurrentPSUDACValueFromGC();
jmitc91516 1:a5258871b33d 109 UpdateEasyGUIPage();
jmitc91516 1:a5258871b33d 110 dealtWithTouch = true;
jmitc91516 1:a5258871b33d 111 break;
jmitc91516 1:a5258871b33d 112
jmitc91516 1:a5258871b33d 113 case COLUMN_DH_PSU_DAC_GET_DAC_VALUE:
jmitc91516 1:a5258871b33d 114 GetCurrentPSUDACValueFromGC();
jmitc91516 1:a5258871b33d 115 UpdateEasyGUIPage();
jmitc91516 1:a5258871b33d 116 dealtWithTouch = true;
jmitc91516 1:a5258871b33d 117 break;
jmitc91516 1:a5258871b33d 118
jmitc91516 1:a5258871b33d 119 default: // Not recognised - do nothing
jmitc91516 1:a5258871b33d 120 break;
jmitc91516 1:a5258871b33d 121 }
jmitc91516 1:a5258871b33d 122
jmitc91516 1:a5258871b33d 123 return dealtWithTouch;
jmitc91516 1:a5258871b33d 124 }
jmitc91516 1:a5258871b33d 125
jmitc91516 1:a5258871b33d 126
jmitc91516 1:a5258871b33d 127 /*
jmitc91516 1:a5258871b33d 128 Caller is telling us it is about to display the easyGUI 'ColumnDHSensorCalibrationPage',
jmitc91516 1:a5258871b33d 129 and that we should do whatever we have to do to get it ready,
jmitc91516 1:a5258871b33d 130 before the caller displays it.
jmitc91516 1:a5258871b33d 131
jmitc91516 1:a5258871b33d 132 No arguments, no return code
jmitc91516 1:a5258871b33d 133 */
jmitc91516 1:a5258871b33d 134 void ColumnDHPSUDACPageHandler::DisplayingEasyGUIPage(bool updateEasyGUIVariables)
jmitc91516 1:a5258871b33d 135 {
jmitc91516 1:a5258871b33d 136 if(updateEasyGUIVariables) {
jmitc91516 1:a5258871b33d 137 GetCurrentPSUDACValueFromGC();
jmitc91516 1:a5258871b33d 138 }
jmitc91516 1:a5258871b33d 139 }
jmitc91516 1:a5258871b33d 140
jmitc91516 1:a5258871b33d 141
jmitc91516 1:a5258871b33d 142 /*
jmitc91516 1:a5258871b33d 143 Gets the current PSU DAC value from the GC, and copies them
jmitc91516 1:a5258871b33d 144 into the relevant easyGUI variables for display to the user -
jmitc91516 1:a5258871b33d 145 these are the 'raw' DAC value, and the power expressed
jmitc91516 1:a5258871b33d 146 as a percentage of the maximum
jmitc91516 1:a5258871b33d 147
jmitc91516 1:a5258871b33d 148 No arguments, no return code
jmitc91516 1:a5258871b33d 149 */
jmitc91516 1:a5258871b33d 150 bool ColumnDHPSUDACPageHandler::GetCurrentPSUDACValueFromGC(void)
jmitc91516 1:a5258871b33d 151 {
jmitc91516 1:a5258871b33d 152 char response[50];
jmitc91516 1:a5258871b33d 153
jmitc91516 1:a5258871b33d 154 SendCommandToGCAndGetResponse("QDAC", response);
jmitc91516 1:a5258871b33d 155
jmitc91516 1:a5258871b33d 156 // We expect a response of the form "DDAnnnnn",
jmitc91516 1:a5258871b33d 157 // where "nnnnn" is the current DAC value.
jmitc91516 1:a5258871b33d 158 // Note that it is five digits, not four.
jmitc91516 1:a5258871b33d 159 if((response[0] == 'D') &&
jmitc91516 1:a5258871b33d 160 (response[1] == 'D') &&
jmitc91516 1:a5258871b33d 161 (response[2] == 'A')) {
jmitc91516 1:a5258871b33d 162
jmitc91516 1:a5258871b33d 163 // The response data is simply a value from 0 to 9999,
jmitc91516 1:a5258871b33d 164 // - but we don't want leading zeroes
jmitc91516 1:a5258871b33d 165 response[8]= '\0'; // This appears to be necessary
jmitc91516 1:a5258871b33d 166 int dacValue;
jmitc91516 1:a5258871b33d 167 sscanf(&response[3], "%d", &dacValue);
jmitc91516 1:a5258871b33d 168 sprintf(GuiVar_columnDHPSUDACGetValue, "%d", dacValue);
jmitc91516 1:a5258871b33d 169
jmitc91516 1:a5258871b33d 170 // Need to display power to 2 places of decimals (since that is what the VB6 app does)
jmitc91516 1:a5258871b33d 171 float temp = (float)dacValue;
jmitc91516 1:a5258871b33d 172 float dacPower = (temp * temp * 100.0f) / 16769025.0f; // 16769025 is 4095 squared
jmitc91516 1:a5258871b33d 173 sprintf(GuiVar_columnDHPSUDACPower, "%.2f", dacPower);
jmitc91516 1:a5258871b33d 174
jmitc91516 1:a5258871b33d 175 return true;
jmitc91516 1:a5258871b33d 176 }
jmitc91516 1:a5258871b33d 177
jmitc91516 1:a5258871b33d 178 // 'else'
jmitc91516 1:a5258871b33d 179 return false;
jmitc91516 1:a5258871b33d 180 }
jmitc91516 1:a5258871b33d 181
jmitc91516 1:a5258871b33d 182
jmitc91516 1:a5258871b33d 183 /*
jmitc91516 1:a5258871b33d 184 Sets the PSU DAC value in the GC, to match the value
jmitc91516 1:a5258871b33d 185 we are currently displaying to the user.
jmitc91516 1:a5258871b33d 186
jmitc91516 1:a5258871b33d 187 No arguments, no return code
jmitc91516 1:a5258871b33d 188 */
jmitc91516 1:a5258871b33d 189 bool ColumnDHPSUDACPageHandler::SetCurrentPSUDACValueInGC(void)
jmitc91516 1:a5258871b33d 190 {
jmitc91516 1:a5258871b33d 191 char buffer[50];
jmitc91516 1:a5258871b33d 192
jmitc91516 1:a5258871b33d 193 // In the command, the PSU DAC value must have 4 digits, padded if necessary with leading zeroes
jmitc91516 1:a5258871b33d 194 int calib;
jmitc91516 1:a5258871b33d 195 sscanf(GuiVar_columnDHPSUDACSetValue, "%d", &calib);
jmitc91516 1:a5258871b33d 196 sprintf(buffer, "SDAC%.4d", calib);
jmitc91516 1:a5258871b33d 197
jmitc91516 1:a5258871b33d 198 return SendCommandToGCWithDACKResponse(buffer);
jmitc91516 1:a5258871b33d 199 }
jmitc91516 1:a5258871b33d 200
jmitc91516 1:a5258871b33d 201
jmitc91516 1:a5258871b33d 202 /*
jmitc91516 1:a5258871b33d 203 As the name implies, sends a command to the GC and returns the response.
jmitc91516 1:a5258871b33d 204
jmitc91516 1:a5258871b33d 205 Args: pointer to a buffer containing the command, as a null-terminated string
jmitc91516 1:a5258871b33d 206 pointer to a buffer to contain the response, as a null-terminated string
jmitc91516 1:a5258871b33d 207
jmitc91516 1:a5258871b33d 208 No return code (it is up to the caller to examine the response to see whether
jmitc91516 1:a5258871b33d 209 the command succeeded or failed)
jmitc91516 1:a5258871b33d 210 */
jmitc91516 1:a5258871b33d 211 void ColumnDHPSUDACPageHandler::SendCommandToGCAndGetResponse(char* command, char* response)
jmitc91516 1:a5258871b33d 212 {
jmitc91516 1:a5258871b33d 213 //#define USE_GC_UTILS // Testing new class
jmitc91516 1:a5258871b33d 214 #ifdef USE_GC_UTILS
jmitc91516 1:a5258871b33d 215 USBHostGCUtilities::SendCommandToGCAndGetResponse(usbDevice, usbHostGC, command, response);
jmitc91516 1:a5258871b33d 216 #else
jmitc91516 1:a5258871b33d 217 while(usbHostGC->ExecutingSetDeviceReport()) {}
jmitc91516 1:a5258871b33d 218
jmitc91516 1:a5258871b33d 219 usbHostGC->SetDeviceReport(usbDevice, command, response);
jmitc91516 1:a5258871b33d 220 //#define DEBUG_PRINT_HERE
jmitc91516 1:a5258871b33d 221 #ifdef DEBUG_PRINT_HERE
jmitc91516 1:a5258871b33d 222 char dbg[100];
jmitc91516 1:a5258871b33d 223 sprintf(dbg, "SCTGC cmd \"%s\", response \"%s\"", command, response);
jmitc91516 1:a5258871b33d 224 SpecialDebugPrint(dbg, 10, 275);
jmitc91516 1:a5258871b33d 225 #endif // DEBUG_PRINT_HERE
jmitc91516 1:a5258871b33d 226 #endif // USE_GC_UTILS
jmitc91516 1:a5258871b33d 227 }
jmitc91516 1:a5258871b33d 228
jmitc91516 1:a5258871b33d 229
jmitc91516 1:a5258871b33d 230 /*
jmitc91516 1:a5258871b33d 231 Sends a command to the GC for which we expect a response of "DACK" if successful,
jmitc91516 1:a5258871b33d 232 "DNAK" or "EPKT" if failure.
jmitc91516 1:a5258871b33d 233
jmitc91516 1:a5258871b33d 234 Args: a pointer to the command in question, as a null terminated string
jmitc91516 1:a5258871b33d 235
jmitc91516 1:a5258871b33d 236 Returns true if the GC responded with "DACK", false for anything else
jmitc91516 1:a5258871b33d 237 */
jmitc91516 1:a5258871b33d 238 bool ColumnDHPSUDACPageHandler::SendCommandToGCWithDACKResponse(char *cmd)
jmitc91516 1:a5258871b33d 239 {
jmitc91516 1:a5258871b33d 240 //#define USE_GC_UTILS // Testing new class
jmitc91516 1:a5258871b33d 241 #ifdef USE_GC_UTILS
jmitc91516 1:a5258871b33d 242 return USBHostGCUtilities::SendCommandToGCWithDACKResponse(usbDevice, usbHostGC, cmd);
jmitc91516 1:a5258871b33d 243 #else
jmitc91516 1:a5258871b33d 244 char response[50];
jmitc91516 1:a5258871b33d 245 SendCommandToGCAndGetResponse(cmd, response);
jmitc91516 1:a5258871b33d 246 // We expect a response like this: "DACK" for success, "DNAK" for failure, "EPKT" for error
jmitc91516 1:a5258871b33d 247
jmitc91516 1:a5258871b33d 248 return (response[1] == 'A');
jmitc91516 1:a5258871b33d 249 #endif // USE_GC_UTILS
jmitc91516 1:a5258871b33d 250 }
jmitc91516 1:a5258871b33d 251
jmitc91516 1:a5258871b33d 252
jmitc91516 1:a5258871b33d 253 /*
jmitc91516 1:a5258871b33d 254 (Re)display the easyGUI 'ColumnDHManualCalibrationPage' -
jmitc91516 1:a5258871b33d 255 e.g. after the caller has updated one or more of the easyGUI variables
jmitc91516 1:a5258871b33d 256 included in the page, and wants to display the new value to the user.
jmitc91516 1:a5258871b33d 257
jmitc91516 1:a5258871b33d 258 No arguments, no return code
jmitc91516 1:a5258871b33d 259 */
jmitc91516 1:a5258871b33d 260 void ColumnDHPSUDACPageHandler::UpdateEasyGUIPage(void)
jmitc91516 1:a5258871b33d 261 {
jmitc91516 1:a5258871b33d 262 GetGCStatusLoop *getGCStatusLoop = GetGCStatusLoop::GetInstance();
jmitc91516 1:a5258871b33d 263
jmitc91516 1:a5258871b33d 264 if(getGCStatusLoop != NULL) {
jmitc91516 1:a5258871b33d 265 getGCStatusLoop->ForceUpdateOfColumnDHPSUDACPage();
jmitc91516 1:a5258871b33d 266 }
jmitc91516 1:a5258871b33d 267 }
jmitc91516 1:a5258871b33d 268
jmitc91516 1:a5258871b33d 269