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 "ColumnDHSensorCalibrationPageHandler.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 'ColumnDHSensorCalibrationPage' to the user at the same time).
jmitc91516 1:a5258871b33d 11 */
jmitc91516 1:a5258871b33d 12 ColumnDHSensorCalibrationPageHandler * ColumnDHSensorCalibrationPageHandler::theColumnDHSensorCalibrationPageHandlerInstance = 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 ColumnDHSensorCalibrationPageHandler * ColumnDHSensorCalibrationPageHandler::GetInstance(USBDeviceConnected* newUsbDevice, USBHostGC* newUsbHostGC)
jmitc91516 1:a5258871b33d 19 {
jmitc91516 1:a5258871b33d 20 if (theColumnDHSensorCalibrationPageHandlerInstance == NULL) {
jmitc91516 1:a5258871b33d 21 theColumnDHSensorCalibrationPageHandlerInstance = new ColumnDHSensorCalibrationPageHandler(newUsbDevice, newUsbHostGC);
jmitc91516 1:a5258871b33d 22 }
jmitc91516 1:a5258871b33d 23
jmitc91516 1:a5258871b33d 24 return theColumnDHSensorCalibrationPageHandlerInstance;
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 ColumnDHSensorCalibrationPageHandler * ColumnDHSensorCalibrationPageHandler::GetInstance(void)
jmitc91516 1:a5258871b33d 35 {
jmitc91516 1:a5258871b33d 36 return theColumnDHSensorCalibrationPageHandlerInstance;
jmitc91516 1:a5258871b33d 37 }
jmitc91516 1:a5258871b33d 38
jmitc91516 1:a5258871b33d 39
jmitc91516 1:a5258871b33d 40 // Singleton class - private constructor
jmitc91516 1:a5258871b33d 41 ColumnDHSensorCalibrationPageHandler::ColumnDHSensorCalibrationPageHandler(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 variablesForTouchArea[0].touchAreaIndex = COLUMN_DH_SENSOR_CALIB_EDIT_VOLTAGE_GAIN;
jmitc91516 1:a5258871b33d 47 variablesForTouchArea[0].easyGUIVariablePtr = GuiVar_columnDHSensorCalibVoltageGain;
jmitc91516 1:a5258871b33d 48 variablesForTouchArea[0].maxValue = 9999;
jmitc91516 1:a5258871b33d 49 variablesForTouchArea[0].minValue = 0;
jmitc91516 1:a5258871b33d 50 variablesForTouchArea[0].canBeNegative = false;
jmitc91516 1:a5258871b33d 51 strcpy(variablesForTouchArea[0].variableTitle, "Voltage Gain");
jmitc91516 1:a5258871b33d 52
jmitc91516 1:a5258871b33d 53 variablesForTouchArea[1].touchAreaIndex = COLUMN_DH_SENSOR_CALIB_EDIT_VOLTAGE_OFFSET;
jmitc91516 1:a5258871b33d 54 variablesForTouchArea[1].easyGUIVariablePtr = GuiVar_columnDHSensorCalibVoltageOffset;
jmitc91516 1:a5258871b33d 55 variablesForTouchArea[1].maxValue = 50;
jmitc91516 1:a5258871b33d 56 variablesForTouchArea[1].minValue = -50;
jmitc91516 1:a5258871b33d 57 variablesForTouchArea[1].canBeNegative = true;
jmitc91516 1:a5258871b33d 58 strcpy(variablesForTouchArea[1].variableTitle, "Voltage Offset");
jmitc91516 1:a5258871b33d 59
jmitc91516 1:a5258871b33d 60 variablesForTouchArea[2].touchAreaIndex = COLUMN_DH_SENSOR_CALIB_EDIT_CURRENT_GAIN;
jmitc91516 1:a5258871b33d 61 variablesForTouchArea[2].easyGUIVariablePtr = GuiVar_columnDHSensorCalibCurrentGain;
jmitc91516 1:a5258871b33d 62 variablesForTouchArea[2].maxValue = 9999;
jmitc91516 1:a5258871b33d 63 variablesForTouchArea[2].minValue = 0;
jmitc91516 1:a5258871b33d 64 variablesForTouchArea[2].canBeNegative = false;
jmitc91516 1:a5258871b33d 65 strcpy(variablesForTouchArea[2].variableTitle, "Current Gain");
jmitc91516 1:a5258871b33d 66
jmitc91516 1:a5258871b33d 67 variablesForTouchArea[3].touchAreaIndex = COLUMN_DH_SENSOR_CALIB_EDIT_CURRENT_OFFSET;
jmitc91516 1:a5258871b33d 68 variablesForTouchArea[3].easyGUIVariablePtr = GuiVar_columnDHSensorCalibCurrentOffset;
jmitc91516 1:a5258871b33d 69 variablesForTouchArea[3].maxValue = 50;
jmitc91516 1:a5258871b33d 70 variablesForTouchArea[3].minValue = -50;
jmitc91516 1:a5258871b33d 71 variablesForTouchArea[3].canBeNegative = true;
jmitc91516 1:a5258871b33d 72 strcpy(variablesForTouchArea[3].variableTitle, "Current Offset");
jmitc91516 1:a5258871b33d 73 }
jmitc91516 1:a5258871b33d 74
jmitc91516 1:a5258871b33d 75 // Private destructor also
jmitc91516 1:a5258871b33d 76 ColumnDHSensorCalibrationPageHandler::~ColumnDHSensorCalibrationPageHandler()
jmitc91516 1:a5258871b33d 77 {
jmitc91516 1:a5258871b33d 78 }
jmitc91516 1:a5258871b33d 79
jmitc91516 1:a5258871b33d 80
jmitc91516 1:a5258871b33d 81 /*
jmitc91516 1:a5258871b33d 82 Tells the caller whether or not the specified touch index is on the easyGUI 'ColumnDHAutoCalibrationPage',
jmitc91516 1:a5258871b33d 83 and therefore needs to be handled by this class.
jmitc91516 1:a5258871b33d 84
jmitc91516 1:a5258871b33d 85 Args: the touch area index in question
jmitc91516 1:a5258871b33d 86
jmitc91516 1:a5258871b33d 87 Return code: true if the touch area is 'one of ours', false if not
jmitc91516 1:a5258871b33d 88 */
jmitc91516 1:a5258871b33d 89 bool ColumnDHSensorCalibrationPageHandler::TouchAreaIsOnCalibrationPage(int touchAreaIndex)
jmitc91516 1:a5258871b33d 90 {
jmitc91516 1:a5258871b33d 91 if((touchAreaIndex >= MIN_COLUMN_DH_SENSOR_CALIB_TOUCHINDEX) && (touchAreaIndex <= MAX_COLUMN_DH_SENSOR_CALIB_TOUCHINDEX)) {
jmitc91516 1:a5258871b33d 92 return true;
jmitc91516 1:a5258871b33d 93 }
jmitc91516 1:a5258871b33d 94
jmitc91516 1:a5258871b33d 95 // 'else'
jmitc91516 1:a5258871b33d 96 return false;
jmitc91516 1:a5258871b33d 97 }
jmitc91516 1:a5258871b33d 98
jmitc91516 1:a5258871b33d 99
jmitc91516 1:a5258871b33d 100 /*
jmitc91516 1:a5258871b33d 101 If the specified touch area represents a key or field on the easyGUI 'ColumnDHSensorCalibrationPage',
jmitc91516 1:a5258871b33d 102 this function performs whatever action is appropriate for it. Provided so that the caller
jmitc91516 1:a5258871b33d 103 can (in effect) say "if this is one of yours, deal with it", without needing to know
jmitc91516 1:a5258871b33d 104 anything about what this class does, or how it handles the touch areas on that easyGUI page.
jmitc91516 1:a5258871b33d 105
jmitc91516 1:a5258871b33d 106 Args: the touch area index in question
jmitc91516 1:a5258871b33d 107
jmitc91516 1:a5258871b33d 108 Returns true if it dealt with the touch area (so the caller need not do anything else
jmitc91516 1:a5258871b33d 109 with the value), or false if it did not deal with the touch area (implying that it
jmitc91516 1:a5258871b33d 110 was not a touch area on the easyGUI 'Directly Heated Column Sensor Calibration Page', and so the caller
jmitc91516 1:a5258871b33d 111 must deal with it some other way).
jmitc91516 1:a5258871b33d 112 */
jmitc91516 1:a5258871b33d 113 bool ColumnDHSensorCalibrationPageHandler::DealWithTouch(int touchAreaIndex)
jmitc91516 1:a5258871b33d 114 {
jmitc91516 1:a5258871b33d 115 bool dealtWithTouch = false; // so far...
jmitc91516 1:a5258871b33d 116
jmitc91516 1:a5258871b33d 117 // Has the user selected a field to edit -
jmitc91516 1:a5258871b33d 118 // if so, we will have an entry in our 'variablesForTouchArea' array that corresponds with this touch area
jmitc91516 1:a5258871b33d 119 int indexOfValueToEdit = GetIndexOfValueToEditForTouchArea(touchAreaIndex);
jmitc91516 1:a5258871b33d 120 if(indexOfValueToEdit != -1) {
jmitc91516 1:a5258871b33d 121 // User has selected a field to edit
jmitc91516 1:a5258871b33d 122 NumericKeypadPageHandler* numericKeypadPageHandler = NumericKeypadPageHandler::GetInstance(usbDevice, usbHostGC);
jmitc91516 1:a5258871b33d 123 if(numericKeypadPageHandler != NULL) {
jmitc91516 1:a5258871b33d 124 numericKeypadPageHandler->StartEditing(variablesForTouchArea[indexOfValueToEdit].easyGUIVariablePtr, 0,
jmitc91516 1:a5258871b33d 125 variablesForTouchArea[indexOfValueToEdit].canBeNegative);
jmitc91516 1:a5258871b33d 126 numericKeypadPageHandler->SetEasyGUIVariableToEdit(variablesForTouchArea[indexOfValueToEdit].easyGUIVariablePtr);
jmitc91516 1:a5258871b33d 127 numericKeypadPageHandler->SetEasyGUICallingPage(GuiStruct_ColumnDHSensorCalibration_Def);
jmitc91516 1:a5258871b33d 128 numericKeypadPageHandler->SetEditVariableRange(variablesForTouchArea[indexOfValueToEdit].minValue, variablesForTouchArea[indexOfValueToEdit].maxValue);
jmitc91516 1:a5258871b33d 129 numericKeypadPageHandler->SetEditVariableName(variablesForTouchArea[indexOfValueToEdit].variableTitle);
jmitc91516 1:a5258871b33d 130 numericKeypadPageHandler->DisplayEasyGUIPage();
jmitc91516 1:a5258871b33d 131 }
jmitc91516 1:a5258871b33d 132
jmitc91516 1:a5258871b33d 133 dealtWithTouch = true;
jmitc91516 1:a5258871b33d 134 }
jmitc91516 1:a5258871b33d 135
jmitc91516 1:a5258871b33d 136 if(!dealtWithTouch) {
jmitc91516 1:a5258871b33d 137 switch(touchAreaIndex) {
jmitc91516 1:a5258871b33d 138 case COLUMN_DH_SENSOR_CALIB_SET:
jmitc91516 1:a5258871b33d 139 SetCurrentCalibrationInGC();
jmitc91516 1:a5258871b33d 140 dealtWithTouch = true;
jmitc91516 1:a5258871b33d 141 break;
jmitc91516 1:a5258871b33d 142
jmitc91516 1:a5258871b33d 143 case COLUMN_DH_SENSOR_CALIB_GET:
jmitc91516 1:a5258871b33d 144 GetCurrentCalibrationFromGC();
jmitc91516 1:a5258871b33d 145 dealtWithTouch = true;
jmitc91516 1:a5258871b33d 146 break;
jmitc91516 1:a5258871b33d 147
jmitc91516 1:a5258871b33d 148 default: // Not recognised - do nothing
jmitc91516 1:a5258871b33d 149 break;
jmitc91516 1:a5258871b33d 150 }
jmitc91516 1:a5258871b33d 151 }
jmitc91516 1:a5258871b33d 152
jmitc91516 1:a5258871b33d 153 return dealtWithTouch;
jmitc91516 1:a5258871b33d 154 }
jmitc91516 1:a5258871b33d 155
jmitc91516 1:a5258871b33d 156
jmitc91516 1:a5258871b33d 157 /*
jmitc91516 1:a5258871b33d 158 Caller is telling us it is about to display the easyGUI 'ColumnDHSensorCalibrationPage',
jmitc91516 1:a5258871b33d 159 and that we should do whatever we have to do to get it ready,
jmitc91516 1:a5258871b33d 160 before the caller displays it.
jmitc91516 1:a5258871b33d 161
jmitc91516 1:a5258871b33d 162 No arguments, no return code
jmitc91516 1:a5258871b33d 163 */
jmitc91516 1:a5258871b33d 164 void ColumnDHSensorCalibrationPageHandler::DisplayingEasyGUIPage(bool updateEasyGUIVariables)
jmitc91516 1:a5258871b33d 165 {
jmitc91516 1:a5258871b33d 166 if(updateEasyGUIVariables) {
jmitc91516 1:a5258871b33d 167 GetCurrentCalibrationFromGC();
jmitc91516 1:a5258871b33d 168 }
jmitc91516 1:a5258871b33d 169 }
jmitc91516 1:a5258871b33d 170
jmitc91516 1:a5258871b33d 171
jmitc91516 1:a5258871b33d 172 /*
jmitc91516 1:a5258871b33d 173 Gets the current calibration temperature and resistance values from the GC,
jmitc91516 1:a5258871b33d 174 and copies them into the relevant easyGUI variables for display to the user.
jmitc91516 1:a5258871b33d 175
jmitc91516 1:a5258871b33d 176 No arguments, no return code
jmitc91516 1:a5258871b33d 177 */
jmitc91516 1:a5258871b33d 178 void ColumnDHSensorCalibrationPageHandler::GetCurrentCalibrationFromGC(void)
jmitc91516 1:a5258871b33d 179 {
jmitc91516 1:a5258871b33d 180 GetGainCalibrationFromGC("GVSR", GuiVar_columnDHSensorCalibVoltageGain);
jmitc91516 1:a5258871b33d 181
jmitc91516 1:a5258871b33d 182 GetOffsetCalibrationFromGC("GVSO", GuiVar_columnDHSensorCalibVoltageOffset);
jmitc91516 1:a5258871b33d 183
jmitc91516 1:a5258871b33d 184 GetGainCalibrationFromGC("GCSR", GuiVar_columnDHSensorCalibCurrentGain);
jmitc91516 1:a5258871b33d 185
jmitc91516 1:a5258871b33d 186 GetOffsetCalibrationFromGC("GCSO", GuiVar_columnDHSensorCalibCurrentOffset);
jmitc91516 1:a5258871b33d 187 }
jmitc91516 1:a5258871b33d 188
jmitc91516 1:a5258871b33d 189
jmitc91516 1:a5258871b33d 190 /*
jmitc91516 1:a5258871b33d 191 Sets the calibration temperature and resistance values in the GC,
jmitc91516 1:a5258871b33d 192 to match the values we are currently displaying to the user.
jmitc91516 1:a5258871b33d 193
jmitc91516 1:a5258871b33d 194 No arguments, no return code
jmitc91516 1:a5258871b33d 195 */
jmitc91516 1:a5258871b33d 196 void ColumnDHSensorCalibrationPageHandler::SetCurrentCalibrationInGC(void)
jmitc91516 1:a5258871b33d 197 {
jmitc91516 1:a5258871b33d 198 SetGainCalibrationInGC("SVSR", GuiVar_columnDHSensorCalibVoltageGain);
jmitc91516 1:a5258871b33d 199 SetOffsetCalibrationInGC("SVSO", GuiVar_columnDHSensorCalibVoltageOffset);
jmitc91516 1:a5258871b33d 200 SetGainCalibrationInGC("SCSR", GuiVar_columnDHSensorCalibCurrentGain);
jmitc91516 1:a5258871b33d 201 SetOffsetCalibrationInGC("SCSO", GuiVar_columnDHSensorCalibCurrentOffset);
jmitc91516 1:a5258871b33d 202 }
jmitc91516 1:a5258871b33d 203
jmitc91516 1:a5258871b33d 204
jmitc91516 1:a5258871b33d 205 /*
jmitc91516 1:a5258871b33d 206 As the name implies, sends a command to the GC and returns the response.
jmitc91516 1:a5258871b33d 207
jmitc91516 1:a5258871b33d 208 Args: pointer to a buffer containing the command, as a null-terminated string
jmitc91516 1:a5258871b33d 209 pointer to a buffer to contain the response, as a null-terminated string
jmitc91516 1:a5258871b33d 210
jmitc91516 1:a5258871b33d 211 No return code (it is up to the caller to examine the response to see whether
jmitc91516 1:a5258871b33d 212 the command succeeded or failed)
jmitc91516 1:a5258871b33d 213 */
jmitc91516 1:a5258871b33d 214 void ColumnDHSensorCalibrationPageHandler::SendCommandToGCAndGetResponse(char* command, char* response)
jmitc91516 1:a5258871b33d 215 {
jmitc91516 1:a5258871b33d 216 #define USE_GC_UTILS // Testing new class
jmitc91516 1:a5258871b33d 217 #ifdef USE_GC_UTILS
jmitc91516 1:a5258871b33d 218 USBHostGCUtilities::SendCommandToGCAndGetResponse(usbDevice, usbHostGC, command, response);
jmitc91516 1:a5258871b33d 219 #else
jmitc91516 1:a5258871b33d 220 while(usbHostGC->ExecutingSetDeviceReport()) {}
jmitc91516 1:a5258871b33d 221
jmitc91516 1:a5258871b33d 222 usbHostGC->SetDeviceReport(usbDevice, command, response);
jmitc91516 1:a5258871b33d 223 //#define DEBUG_PRINT_HERE
jmitc91516 1:a5258871b33d 224 #ifdef DEBUG_PRINT_HERE
jmitc91516 1:a5258871b33d 225 char dbg[100];
jmitc91516 1:a5258871b33d 226 sprintf(dbg, "SCTGC cmd \"%s\", response \"%s\"", command, response);
jmitc91516 1:a5258871b33d 227 SpecialDebugPrint(dbg, 10, 275);
jmitc91516 1:a5258871b33d 228 #endif // DEBUG_PRINT_HERE
jmitc91516 1:a5258871b33d 229 #endif // USE_GC_UTILS
jmitc91516 1:a5258871b33d 230 }
jmitc91516 1:a5258871b33d 231
jmitc91516 1:a5258871b33d 232
jmitc91516 1:a5258871b33d 233 /*
jmitc91516 1:a5258871b33d 234 Sends a command to the GC for which we expect a response of "DACK" if successful,
jmitc91516 1:a5258871b33d 235 "DNAK" or "EPKT" if failure.
jmitc91516 1:a5258871b33d 236
jmitc91516 1:a5258871b33d 237 Args: a pointer to the command in question, as a null terminated string
jmitc91516 1:a5258871b33d 238
jmitc91516 1:a5258871b33d 239 Returns true if the GC responded with "DACK", false for anything else
jmitc91516 1:a5258871b33d 240 */
jmitc91516 1:a5258871b33d 241 bool ColumnDHSensorCalibrationPageHandler::SendCommandToGCWithDACKResponse(char *cmd)
jmitc91516 1:a5258871b33d 242 {
jmitc91516 1:a5258871b33d 243 #define USE_GC_UTILS // Testing new class
jmitc91516 1:a5258871b33d 244 #ifdef USE_GC_UTILS
jmitc91516 1:a5258871b33d 245 return USBHostGCUtilities::SendCommandToGCWithDACKResponse(usbDevice, usbHostGC, cmd);
jmitc91516 1:a5258871b33d 246 #else
jmitc91516 1:a5258871b33d 247 char response[50];
jmitc91516 1:a5258871b33d 248 SendCommandToGCAndGetResponse(cmd, response);
jmitc91516 1:a5258871b33d 249 // We expect a response like this: "DACK" for success, "DNAK" for failure, "EPKT" for error
jmitc91516 1:a5258871b33d 250
jmitc91516 1:a5258871b33d 251 return (response[1] == 'A');
jmitc91516 1:a5258871b33d 252 #endif // USE_GC_UTILS
jmitc91516 1:a5258871b33d 253 }
jmitc91516 1:a5258871b33d 254
jmitc91516 1:a5258871b33d 255
jmitc91516 1:a5258871b33d 256 /*
jmitc91516 1:a5258871b33d 257 The commands to get the Current and Voltage Sensor Gain Calibration values are very similar,
jmitc91516 1:a5258871b33d 258 including the format of their data values. This function gets the value using the specified command,
jmitc91516 1:a5258871b33d 259 and copies the value into the specified easyGUI variable.
jmitc91516 1:a5258871b33d 260
jmitc91516 1:a5258871b33d 261 It is up to the caller to display the updated easyGUI variable to the user.
jmitc91516 1:a5258871b33d 262
jmitc91516 1:a5258871b33d 263 Returns true if successful, false if not.
jmitc91516 1:a5258871b33d 264 */
jmitc91516 1:a5258871b33d 265 bool ColumnDHSensorCalibrationPageHandler::GetGainCalibrationFromGC(char *cmd, GuiConst_TEXT* easyGUIVariable)
jmitc91516 1:a5258871b33d 266 {
jmitc91516 1:a5258871b33d 267 char response[50];
jmitc91516 1:a5258871b33d 268
jmitc91516 1:a5258871b33d 269 SendCommandToGCAndGetResponse(cmd, response);
jmitc91516 1:a5258871b33d 270 if((response[0] == 'D') &&
jmitc91516 1:a5258871b33d 271 (response[1] == cmd[1]) &&
jmitc91516 1:a5258871b33d 272 (response[2] == cmd[2]) &&
jmitc91516 1:a5258871b33d 273 (response[3] == cmd[3])) {
jmitc91516 1:a5258871b33d 274
jmitc91516 1:a5258871b33d 275 // The response data is simply a value from 0 to 9999,
jmitc91516 1:a5258871b33d 276 // - but we don't want leading zeroes
jmitc91516 1:a5258871b33d 277 response[8]= '\0'; // This appears to be necessary
jmitc91516 1:a5258871b33d 278 int calib;
jmitc91516 1:a5258871b33d 279 sscanf(&response[4], "%d", &calib);
jmitc91516 1:a5258871b33d 280 sprintf(easyGUIVariable, "%d", calib);
jmitc91516 1:a5258871b33d 281
jmitc91516 1:a5258871b33d 282 return true;
jmitc91516 1:a5258871b33d 283 }
jmitc91516 1:a5258871b33d 284
jmitc91516 1:a5258871b33d 285 // 'else'
jmitc91516 1:a5258871b33d 286 return false;
jmitc91516 1:a5258871b33d 287 }
jmitc91516 1:a5258871b33d 288
jmitc91516 1:a5258871b33d 289
jmitc91516 1:a5258871b33d 290 /*
jmitc91516 1:a5258871b33d 291 The commands to get the Current and Voltage Sensor Offset Calibration values are very similar,
jmitc91516 1:a5258871b33d 292 including the format of their data values. This function gets the value using the specified command,
jmitc91516 1:a5258871b33d 293 and copies the value into the specified easyGUI variable.
jmitc91516 1:a5258871b33d 294
jmitc91516 1:a5258871b33d 295 It is up to the caller to display the updated easyGUI variable to the user.
jmitc91516 1:a5258871b33d 296
jmitc91516 1:a5258871b33d 297 Returns true if successful, false if not.
jmitc91516 1:a5258871b33d 298 */
jmitc91516 1:a5258871b33d 299 bool ColumnDHSensorCalibrationPageHandler::GetOffsetCalibrationFromGC(char *cmd, GuiConst_TEXT* easyGUIVariable)
jmitc91516 1:a5258871b33d 300 {
jmitc91516 1:a5258871b33d 301 char response[50];
jmitc91516 1:a5258871b33d 302
jmitc91516 1:a5258871b33d 303 SendCommandToGCAndGetResponse(cmd, response);
jmitc91516 1:a5258871b33d 304 if((response[0] == 'D') &&
jmitc91516 1:a5258871b33d 305 (response[1] == cmd[1]) &&
jmitc91516 1:a5258871b33d 306 (response[2] == cmd[2]) &&
jmitc91516 1:a5258871b33d 307 (response[3] == cmd[3])) {
jmitc91516 1:a5258871b33d 308
jmitc91516 1:a5258871b33d 309 // The response data is a value from 0 to 100,
jmitc91516 1:a5258871b33d 310 // which corresponds to user values from -50 to +50 -
jmitc91516 1:a5258871b33d 311 // so we subtract 50 before displaying the value to the user
jmitc91516 1:a5258871b33d 312
jmitc91516 1:a5258871b33d 313 int temp;
jmitc91516 1:a5258871b33d 314 sscanf(&response[4], "%d", &temp);
jmitc91516 1:a5258871b33d 315 temp -= 50;
jmitc91516 1:a5258871b33d 316 sprintf(easyGUIVariable, "%d", temp);
jmitc91516 1:a5258871b33d 317
jmitc91516 1:a5258871b33d 318 return true;
jmitc91516 1:a5258871b33d 319 }
jmitc91516 1:a5258871b33d 320
jmitc91516 1:a5258871b33d 321 // 'else'
jmitc91516 1:a5258871b33d 322 return false;
jmitc91516 1:a5258871b33d 323 }
jmitc91516 1:a5258871b33d 324
jmitc91516 1:a5258871b33d 325
jmitc91516 1:a5258871b33d 326
jmitc91516 1:a5258871b33d 327 /*
jmitc91516 1:a5258871b33d 328 The commands to set the Current and Voltage Sensor Gain Calibration values are very similar,
jmitc91516 1:a5258871b33d 329 including the format of their data values. This function sets the value in the GC
jmitc91516 1:a5258871b33d 330 using the specified command, and obtaining the value from the specified easyGUI variable.
jmitc91516 1:a5258871b33d 331
jmitc91516 1:a5258871b33d 332 Returns true if successful, false if not.
jmitc91516 1:a5258871b33d 333 */
jmitc91516 1:a5258871b33d 334 bool ColumnDHSensorCalibrationPageHandler::SetGainCalibrationInGC(char *cmd, GuiConst_TEXT* easyGUIVariable)
jmitc91516 1:a5258871b33d 335 {
jmitc91516 1:a5258871b33d 336 char buffer[50];
jmitc91516 1:a5258871b33d 337
jmitc91516 1:a5258871b33d 338 // In the command, the gain calibration value must have 4 digits, padded if necessary with leading zeroes
jmitc91516 1:a5258871b33d 339 int calib;
jmitc91516 1:a5258871b33d 340 sscanf(easyGUIVariable, "%d", &calib);
jmitc91516 1:a5258871b33d 341 sprintf(buffer, "%s%.4d", cmd, calib);
jmitc91516 1:a5258871b33d 342
jmitc91516 1:a5258871b33d 343 return SendCommandToGCWithDACKResponse(buffer);
jmitc91516 1:a5258871b33d 344 }
jmitc91516 1:a5258871b33d 345
jmitc91516 1:a5258871b33d 346
jmitc91516 1:a5258871b33d 347 /*
jmitc91516 1:a5258871b33d 348 The commands to set the Current and Voltage Sensor Offset Calibration values are very similar,
jmitc91516 1:a5258871b33d 349 including the format of their data values. This function sets the value in the GC
jmitc91516 1:a5258871b33d 350 using the specified command, and obtaining the value from the specified easyGUI variable.
jmitc91516 1:a5258871b33d 351
jmitc91516 1:a5258871b33d 352 Returns true if successful, false if not.
jmitc91516 1:a5258871b33d 353 */
jmitc91516 1:a5258871b33d 354 bool ColumnDHSensorCalibrationPageHandler::SetOffsetCalibrationInGC(char *cmd, GuiConst_TEXT* easyGUIVariable)
jmitc91516 1:a5258871b33d 355 {
jmitc91516 1:a5258871b33d 356 char buffer[50];
jmitc91516 1:a5258871b33d 357
jmitc91516 1:a5258871b33d 358 // The offset values we display to the user are in the range -50 to +50.
jmitc91516 1:a5258871b33d 359 // However, the range we send to the GC is 0 to 100 -
jmitc91516 1:a5258871b33d 360 // so we must add 50 before sending the value to the GC.
jmitc91516 1:a5258871b33d 361 // Also, the value we send must have 4 digits, padded if necessary with leading zeroes
jmitc91516 1:a5258871b33d 362 int temp;
jmitc91516 1:a5258871b33d 363 sscanf(easyGUIVariable, "%d", &temp);
jmitc91516 1:a5258871b33d 364 temp += 50;
jmitc91516 1:a5258871b33d 365 sprintf(buffer, "%s%.4d", cmd, temp);
jmitc91516 1:a5258871b33d 366
jmitc91516 1:a5258871b33d 367 return SendCommandToGCWithDACKResponse(buffer);
jmitc91516 1:a5258871b33d 368 }
jmitc91516 1:a5258871b33d 369
jmitc91516 1:a5258871b33d 370
jmitc91516 1:a5258871b33d 371 /*
jmitc91516 1:a5258871b33d 372 Tells the caller if the specified touch area corresponds to a value the user can edit
jmitc91516 1:a5258871b33d 373 on the easyGUI 'ColumnDHManualCalibrationPage', and if so, which one.
jmitc91516 1:a5258871b33d 374
jmitc91516 1:a5258871b33d 375 Args: the touch area index in question
jmitc91516 1:a5258871b33d 376
jmitc91516 1:a5258871b33d 377 Returns the index of the corresponding entry in our 'variablesForTouchArea' array,
jmitc91516 1:a5258871b33d 378 or -1 if there is no such entry. It is up to the caller to check for -1
jmitc91516 1:a5258871b33d 379 **************************************
jmitc91516 1:a5258871b33d 380 */
jmitc91516 1:a5258871b33d 381 int ColumnDHSensorCalibrationPageHandler::GetIndexOfValueToEditForTouchArea(int touchAreaIndex)
jmitc91516 1:a5258871b33d 382 {
jmitc91516 1:a5258871b33d 383 for (int index = 0; index < COUNT_OF_VARIABLES_FOR_TOUCH_AREAS; ++index) {
jmitc91516 1:a5258871b33d 384 if(variablesForTouchArea[index].touchAreaIndex == touchAreaIndex) {
jmitc91516 1:a5258871b33d 385 return index;
jmitc91516 1:a5258871b33d 386 }
jmitc91516 1:a5258871b33d 387 }
jmitc91516 1:a5258871b33d 388
jmitc91516 1:a5258871b33d 389 // 'else' no Column DH Sensor Calibration value corresponds to the specified touch area
jmitc91516 1:a5258871b33d 390 return -1;
jmitc91516 1:a5258871b33d 391 }