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 "ColumnDHAutoCalibrationPageHandler.h"
jmitc91516 1:a5258871b33d 2 #include "EasyGUITouchAreaIndices.h"
jmitc91516 1:a5258871b33d 3 #include "GetGCStatusLoop.h"
jmitc91516 1:a5258871b33d 4 #include "USBHostGCUtilities.h"
jmitc91516 1:a5258871b33d 5
jmitc91516 1:a5258871b33d 6 #include <stdio.h>
jmitc91516 1:a5258871b33d 7 #include <stdlib.h>
jmitc91516 1:a5258871b33d 8 #include <math.h>
jmitc91516 1:a5258871b33d 9 #include <time.h>
jmitc91516 1:a5258871b33d 10
jmitc91516 1:a5258871b33d 11
jmitc91516 1:a5258871b33d 12 /*
jmitc91516 1:a5258871b33d 13 Passed three 8-bit colour components - red, green and blue.
jmitc91516 1:a5258871b33d 14 Returns the corresponding 16-bit colour value (5 bits for red, 6 bits for green, 5 bits for blue).
jmitc91516 1:a5258871b33d 15
jmitc91516 1:a5258871b33d 16 Defined in main.cpp
jmitc91516 1:a5258871b33d 17 */
jmitc91516 1:a5258871b33d 18 extern GuiConst_INTCOLOR SixteenBitColorValue(GuiConst_INT8U red, GuiConst_INT8U green, GuiConst_INT8U blue);
jmitc91516 1:a5258871b33d 19
jmitc91516 1:a5258871b33d 20 /*
jmitc91516 1:a5258871b33d 21 Allows us to tell the world not to unlock the door actuators while we are calibrating.
jmitc91516 1:a5258871b33d 22
jmitc91516 1:a5258871b33d 23 Defined in main.cpp
jmitc91516 1:a5258871b33d 24 */
jmitc91516 1:a5258871b33d 25 extern void CanUnlockDoorActuators(bool value);
jmitc91516 1:a5258871b33d 26
jmitc91516 1:a5258871b33d 27 /*
jmitc91516 1:a5258871b33d 28 Displays the specified text string at the specified location in the currently-displayed easyGUI page.
jmitc91516 1:a5258871b33d 29
jmitc91516 1:a5258871b33d 30 Defined in main.cpp - and omits the 'ALLOW_DEBUG_PRINTS' #define
jmitc91516 1:a5258871b33d 31 */
jmitc91516 1:a5258871b33d 32 extern void SpecialDebugPrint(char *stuffToPrint, GuiConst_INT16S X, GuiConst_INT16S Y);
jmitc91516 1:a5258871b33d 33
jmitc91516 1:a5258871b33d 34
jmitc91516 1:a5258871b33d 35 /*
jmitc91516 1:a5258871b33d 36 Draws the background bitmap - without the Ellutia logo. It fills the screen, so you do not need to call GuiLib_Clear.
jmitc91516 1:a5258871b33d 37 Defined in main.cpp
jmitc91516 1:a5258871b33d 38 */
jmitc91516 1:a5258871b33d 39 extern void DrawBackgroundBitmap(void);
jmitc91516 1:a5258871b33d 40 #define USING_BACKGROUND_BITMAP
jmitc91516 1:a5258871b33d 41
jmitc91516 1:a5258871b33d 42
jmitc91516 1:a5258871b33d 43 /*
jmitc91516 1:a5258871b33d 44 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 45 (we do not want multiple values for the calibration point selection, etc, and nor will we show
jmitc91516 1:a5258871b33d 46 more than one easyGUI 'ColumnDHAutoCalibrationPage' to the user at the same time).
jmitc91516 1:a5258871b33d 47 */
jmitc91516 1:a5258871b33d 48 ColumnDHAutoCalibrationPageHandler * ColumnDHAutoCalibrationPageHandler::theColumnDHAutoCalibrationPageHandlerInstance = NULL;
jmitc91516 1:a5258871b33d 49
jmitc91516 1:a5258871b33d 50
jmitc91516 1:a5258871b33d 51 /*
jmitc91516 1:a5258871b33d 52 String saying "we do not yet know this value"
jmitc91516 1:a5258871b33d 53 */
jmitc91516 1:a5258871b33d 54 const char* ColumnDHAutoCalibrationPageHandler::notAvailable = "-";
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 ColumnDHAutoCalibrationPageHandler * ColumnDHAutoCalibrationPageHandler::GetInstance(USBDeviceConnected* newUsbDevice, USBHostGC* newUsbHostGC)
jmitc91516 1:a5258871b33d 60 {
jmitc91516 1:a5258871b33d 61 if (theColumnDHAutoCalibrationPageHandlerInstance == NULL) {
jmitc91516 1:a5258871b33d 62 theColumnDHAutoCalibrationPageHandlerInstance = new ColumnDHAutoCalibrationPageHandler(newUsbDevice, newUsbHostGC);
jmitc91516 1:a5258871b33d 63 }
jmitc91516 1:a5258871b33d 64
jmitc91516 1:a5258871b33d 65 return theColumnDHAutoCalibrationPageHandlerInstance;
jmitc91516 1:a5258871b33d 66 }
jmitc91516 1:a5258871b33d 67
jmitc91516 1:a5258871b33d 68 /*
jmitc91516 1:a5258871b33d 69 Overriden version of the above, that does not take any arguments and does not create the instance
jmitc91516 1:a5258871b33d 70 if it does not already exist.
jmitc91516 1:a5258871b33d 71
jmitc91516 1:a5258871b33d 72 Provided for callers that do not have the 'usbDevice' and'usbHostGC' pointers, and just want access
jmitc91516 1:a5258871b33d 73 to the instance if it exists
jmitc91516 1:a5258871b33d 74 */
jmitc91516 1:a5258871b33d 75 ColumnDHAutoCalibrationPageHandler * ColumnDHAutoCalibrationPageHandler::GetInstance(void)
jmitc91516 1:a5258871b33d 76 {
jmitc91516 1:a5258871b33d 77 return theColumnDHAutoCalibrationPageHandlerInstance;
jmitc91516 1:a5258871b33d 78 }
jmitc91516 1:a5258871b33d 79
jmitc91516 1:a5258871b33d 80
jmitc91516 1:a5258871b33d 81 // Singleton class - private constructor
jmitc91516 1:a5258871b33d 82 ColumnDHAutoCalibrationPageHandler::ColumnDHAutoCalibrationPageHandler(USBDeviceConnected* newUsbDevice, USBHostGC* newUsbHostGC)
jmitc91516 1:a5258871b33d 83 {
jmitc91516 1:a5258871b33d 84 usbDevice = newUsbDevice;
jmitc91516 1:a5258871b33d 85 usbHostGC = newUsbHostGC;
jmitc91516 1:a5258871b33d 86
jmitc91516 1:a5258871b33d 87 strcpy(GuiVar_columnDHAutoCalibCalibrateButtonText, "Calibrate");
jmitc91516 1:a5258871b33d 88
jmitc91516 1:a5258871b33d 89 for (int index = 0; index < 3; ++index) {
jmitc91516 1:a5258871b33d 90 calibTemperature[index] = GetColumnTemperaturePointFromGC(index + 1);
jmitc91516 1:a5258871b33d 91 calibResistance[index] = GetColumnResistancePointFromGC(index + 1);
jmitc91516 1:a5258871b33d 92 }
jmitc91516 1:a5258871b33d 93
jmitc91516 1:a5258871b33d 94 currentCalibrationState = GetCalibrationState();
jmitc91516 1:a5258871b33d 95 previousCalibrationState = INVALID;
jmitc91516 1:a5258871b33d 96 SetEasyGUICalibrationState();
jmitc91516 1:a5258871b33d 97 ShowSetCalibrationButtonEnabledState();
jmitc91516 1:a5258871b33d 98
jmitc91516 1:a5258871b33d 99 SetEasyGUIHeatState();
jmitc91516 1:a5258871b33d 100 SetEasyGUIOvenTemperature();
jmitc91516 1:a5258871b33d 101
jmitc91516 1:a5258871b33d 102 stabilisationTime = GetStabilisationTimeFromGC();
jmitc91516 1:a5258871b33d 103
jmitc91516 1:a5258871b33d 104 actualColumnResistance = -1.0f;
jmitc91516 1:a5258871b33d 105
jmitc91516 1:a5258871b33d 106 needToGetColumnResistance = false;
jmitc91516 1:a5258871b33d 107
jmitc91516 1:a5258871b33d 108 #ifndef USE_STABILISATION_TIMER
jmitc91516 1:a5258871b33d 109 gcTimeStabilisationStarted = -1.0f;
jmitc91516 1:a5258871b33d 110 #endif
jmitc91516 1:a5258871b33d 111
jmitc91516 1:a5258871b33d 112 #ifdef USE_ENABLE_SET_BUTTON_FLAG
jmitc91516 1:a5258871b33d 113 enableSetButton = false;
jmitc91516 1:a5258871b33d 114 #endif
jmitc91516 1:a5258871b33d 115 }
jmitc91516 1:a5258871b33d 116
jmitc91516 1:a5258871b33d 117 // Private destructor also
jmitc91516 1:a5258871b33d 118 ColumnDHAutoCalibrationPageHandler::~ColumnDHAutoCalibrationPageHandler()
jmitc91516 1:a5258871b33d 119 {
jmitc91516 1:a5258871b33d 120 }
jmitc91516 1:a5258871b33d 121
jmitc91516 1:a5258871b33d 122 /*
jmitc91516 1:a5258871b33d 123 Tells the caller whether or not the specified touch index is on the easyGUI 'ColumnDHAutoCalibrationPage',
jmitc91516 1:a5258871b33d 124 and therefore needs to be handled by this class.
jmitc91516 1:a5258871b33d 125
jmitc91516 1:a5258871b33d 126 Args: the touch area index in question
jmitc91516 1:a5258871b33d 127
jmitc91516 1:a5258871b33d 128 Return code: true if the touch area is 'one of ours', false if not
jmitc91516 1:a5258871b33d 129 */
jmitc91516 1:a5258871b33d 130 bool ColumnDHAutoCalibrationPageHandler::TouchAreaIsOnCalibrationPage(int touchAreaIndex)
jmitc91516 1:a5258871b33d 131 {
jmitc91516 1:a5258871b33d 132 if((touchAreaIndex >= MIN_COLUMN_DH_AUTO_CALIB_TOUCHINDEX) && (touchAreaIndex <= MAX_COLUMN_DH_AUTO_CALIB_TOUCHINDEX)) {
jmitc91516 1:a5258871b33d 133 return true;
jmitc91516 1:a5258871b33d 134 }
jmitc91516 1:a5258871b33d 135
jmitc91516 1:a5258871b33d 136 // 'else'
jmitc91516 1:a5258871b33d 137 return false;
jmitc91516 1:a5258871b33d 138 }
jmitc91516 1:a5258871b33d 139
jmitc91516 1:a5258871b33d 140
jmitc91516 1:a5258871b33d 141 /*
jmitc91516 1:a5258871b33d 142 If the specified touch area represents a key or field on the easyGUI 'ColumnDHCalibrationPage',
jmitc91516 1:a5258871b33d 143 this function performs whatever action is appropriate for it. Provided so that the caller
jmitc91516 1:a5258871b33d 144 can (in effect) say "if this is one of yours, deal with it", without needing to know
jmitc91516 1:a5258871b33d 145 anything about what this class does, or how it handles the touch areas on that easyGUI page.
jmitc91516 1:a5258871b33d 146
jmitc91516 1:a5258871b33d 147 Args: the touch area index in question
jmitc91516 1:a5258871b33d 148
jmitc91516 1:a5258871b33d 149 Returns true if it dealt with the touch area (so the caller need not do anything else
jmitc91516 1:a5258871b33d 150 with the value), or false if it did not deal with the touch area (implying that it
jmitc91516 1:a5258871b33d 151 was not a touch area on the easyGUI 'Directly Heated Column Auto CalibrationPage', and so the caller
jmitc91516 1:a5258871b33d 152 must deal with it some other way).
jmitc91516 1:a5258871b33d 153 */
jmitc91516 1:a5258871b33d 154 bool ColumnDHAutoCalibrationPageHandler::DealWithTouch(int touchAreaIndex)
jmitc91516 1:a5258871b33d 155 {
jmitc91516 1:a5258871b33d 156 bool dealtWithTouch = false;
jmitc91516 1:a5258871b33d 157
jmitc91516 1:a5258871b33d 158 // Don't allow the user to select a different calibration point,
jmitc91516 1:a5258871b33d 159 // or change any calibration parameters, while we are calibrating the current point
jmitc91516 1:a5258871b33d 160 switch(touchAreaIndex) {
jmitc91516 1:a5258871b33d 161 case COLUMN_DH_AUTO_CALIB_SELECT_POINT_1:
jmitc91516 1:a5258871b33d 162 if(!CalibratingNow()) {
jmitc91516 1:a5258871b33d 163 if(GuiVar_columnDHAutoCalibPointSelection != 0) {
jmitc91516 1:a5258871b33d 164 GuiVar_columnDHAutoCalibPointSelection = 0;
jmitc91516 1:a5258871b33d 165
jmitc91516 1:a5258871b33d 166 calibTemperature[GuiVar_columnDHAutoCalibPointSelection] = GetColumnTemperaturePointFromGC(GuiVar_columnDHAutoCalibPointSelection + 1);
jmitc91516 1:a5258871b33d 167 SetEasyGUICalibrationPointTemperatureFromInternalValue(true);
jmitc91516 1:a5258871b33d 168
jmitc91516 1:a5258871b33d 169 calibResistance[GuiVar_columnDHAutoCalibPointSelection] = GetColumnResistancePointFromGC(GuiVar_columnDHAutoCalibPointSelection + 1);
jmitc91516 1:a5258871b33d 170 SetEasyGUICalibrationPointResistanceFromInternalValue();
jmitc91516 1:a5258871b33d 171
jmitc91516 1:a5258871b33d 172 #ifdef USE_ENABLE_SET_BUTTON_FLAG
jmitc91516 1:a5258871b33d 173 enableSetButton = false;
jmitc91516 1:a5258871b33d 174 #endif
jmitc91516 1:a5258871b33d 175 UpdateEasyGUIPage();
jmitc91516 1:a5258871b33d 176 }
jmitc91516 1:a5258871b33d 177 }
jmitc91516 1:a5258871b33d 178 dealtWithTouch = true;
jmitc91516 1:a5258871b33d 179 break;
jmitc91516 1:a5258871b33d 180
jmitc91516 1:a5258871b33d 181 case COLUMN_DH_AUTO_CALIB_SELECT_POINT_2:
jmitc91516 1:a5258871b33d 182 if(!CalibratingNow()) {
jmitc91516 1:a5258871b33d 183 if(GuiVar_columnDHAutoCalibPointSelection != 1) {
jmitc91516 1:a5258871b33d 184 GuiVar_columnDHAutoCalibPointSelection = 1;
jmitc91516 1:a5258871b33d 185
jmitc91516 1:a5258871b33d 186 calibTemperature[GuiVar_columnDHAutoCalibPointSelection] = GetColumnTemperaturePointFromGC(GuiVar_columnDHAutoCalibPointSelection + 1);
jmitc91516 1:a5258871b33d 187 SetEasyGUICalibrationPointTemperatureFromInternalValue(true);
jmitc91516 1:a5258871b33d 188
jmitc91516 1:a5258871b33d 189 calibResistance[GuiVar_columnDHAutoCalibPointSelection] = GetColumnResistancePointFromGC(GuiVar_columnDHAutoCalibPointSelection + 1);
jmitc91516 1:a5258871b33d 190 SetEasyGUICalibrationPointResistanceFromInternalValue();
jmitc91516 1:a5258871b33d 191
jmitc91516 1:a5258871b33d 192 #ifdef USE_ENABLE_SET_BUTTON_FLAG
jmitc91516 1:a5258871b33d 193 enableSetButton = false;
jmitc91516 1:a5258871b33d 194 #endif
jmitc91516 1:a5258871b33d 195 UpdateEasyGUIPage();
jmitc91516 1:a5258871b33d 196 }
jmitc91516 1:a5258871b33d 197 }
jmitc91516 1:a5258871b33d 198 dealtWithTouch = true;
jmitc91516 1:a5258871b33d 199 break;
jmitc91516 1:a5258871b33d 200
jmitc91516 1:a5258871b33d 201 case COLUMN_DH_AUTO_CALIB_SELECT_POINT_3:
jmitc91516 1:a5258871b33d 202 if(!CalibratingNow()) {
jmitc91516 1:a5258871b33d 203 if(GuiVar_columnDHAutoCalibPointSelection != 2) {
jmitc91516 1:a5258871b33d 204 GuiVar_columnDHAutoCalibPointSelection = 2;
jmitc91516 1:a5258871b33d 205
jmitc91516 1:a5258871b33d 206 calibTemperature[GuiVar_columnDHAutoCalibPointSelection] = GetColumnTemperaturePointFromGC(GuiVar_columnDHAutoCalibPointSelection + 1);
jmitc91516 1:a5258871b33d 207 SetEasyGUICalibrationPointTemperatureFromInternalValue(true);
jmitc91516 1:a5258871b33d 208
jmitc91516 1:a5258871b33d 209 calibResistance[GuiVar_columnDHAutoCalibPointSelection] = GetColumnResistancePointFromGC(GuiVar_columnDHAutoCalibPointSelection + 1);
jmitc91516 1:a5258871b33d 210 SetEasyGUICalibrationPointResistanceFromInternalValue();
jmitc91516 1:a5258871b33d 211
jmitc91516 1:a5258871b33d 212 #ifdef USE_ENABLE_SET_BUTTON_FLAG
jmitc91516 1:a5258871b33d 213 enableSetButton = false;
jmitc91516 1:a5258871b33d 214 #endif
jmitc91516 1:a5258871b33d 215 UpdateEasyGUIPage();
jmitc91516 1:a5258871b33d 216 }
jmitc91516 1:a5258871b33d 217 }
jmitc91516 1:a5258871b33d 218 dealtWithTouch = true;
jmitc91516 1:a5258871b33d 219 break;
jmitc91516 1:a5258871b33d 220
jmitc91516 1:a5258871b33d 221 case COLUMN_DH_AUTO_CALIB_INC_STABILISATION_TIME:
jmitc91516 1:a5258871b33d 222 if(!CalibratingNow()) {
jmitc91516 1:a5258871b33d 223 ++stabilisationTime;
jmitc91516 1:a5258871b33d 224 SetEasyGUIStabilisationTimeFromInternalValue();
jmitc91516 1:a5258871b33d 225 UpdateEasyGUIPage();
jmitc91516 1:a5258871b33d 226 }
jmitc91516 1:a5258871b33d 227 dealtWithTouch = true;
jmitc91516 1:a5258871b33d 228 break;
jmitc91516 1:a5258871b33d 229
jmitc91516 1:a5258871b33d 230 case COLUMN_DH_AUTO_CALIB_DEC_STABILISATION_TIME:
jmitc91516 1:a5258871b33d 231 if(!CalibratingNow()) {
jmitc91516 1:a5258871b33d 232 if(stabilisationTime > 0) {
jmitc91516 1:a5258871b33d 233 --stabilisationTime;
jmitc91516 1:a5258871b33d 234 SetEasyGUIStabilisationTimeFromInternalValue();
jmitc91516 1:a5258871b33d 235 UpdateEasyGUIPage();
jmitc91516 1:a5258871b33d 236 }
jmitc91516 1:a5258871b33d 237 }
jmitc91516 1:a5258871b33d 238 dealtWithTouch = true;
jmitc91516 1:a5258871b33d 239 break;
jmitc91516 1:a5258871b33d 240
jmitc91516 1:a5258871b33d 241 case COLUMN_DH_AUTO_CALIB_GET_STABILISATION_TIME:
jmitc91516 1:a5258871b33d 242 if(!CalibratingNow()) {
jmitc91516 1:a5258871b33d 243 stabilisationTime = GetStabilisationTimeFromGC();
jmitc91516 1:a5258871b33d 244 SetEasyGUIStabilisationTimeFromInternalValue();
jmitc91516 1:a5258871b33d 245 UpdateEasyGUIPage();
jmitc91516 1:a5258871b33d 246 }
jmitc91516 1:a5258871b33d 247 dealtWithTouch = true;
jmitc91516 1:a5258871b33d 248 break;
jmitc91516 1:a5258871b33d 249
jmitc91516 1:a5258871b33d 250 case COLUMN_DH_AUTO_CALIB_SET_STABILISATION_TIME:
jmitc91516 1:a5258871b33d 251 if(!CalibratingNow()) {
jmitc91516 1:a5258871b33d 252 SetStabilisationTimeInGC(stabilisationTime);
jmitc91516 1:a5258871b33d 253 }
jmitc91516 1:a5258871b33d 254 dealtWithTouch = true;
jmitc91516 1:a5258871b33d 255 break;
jmitc91516 1:a5258871b33d 256
jmitc91516 1:a5258871b33d 257 case COLUMN_DH_AUTO_CALIB_INC_CALIB_TEMP:
jmitc91516 1:a5258871b33d 258 if(!CalibratingNow()) {
jmitc91516 1:a5258871b33d 259 calibTemperature[GuiVar_columnDHAutoCalibPointSelection] += 1.0f;
jmitc91516 1:a5258871b33d 260 SetEasyGUICalibrationPointTemperatureFromInternalValue(false);
jmitc91516 1:a5258871b33d 261 UpdateEasyGUIPage();
jmitc91516 1:a5258871b33d 262 }
jmitc91516 1:a5258871b33d 263 dealtWithTouch = true;
jmitc91516 1:a5258871b33d 264 break;
jmitc91516 1:a5258871b33d 265
jmitc91516 1:a5258871b33d 266 case COLUMN_DH_AUTO_CALIB_DEC_CALIB_TEMP:
jmitc91516 1:a5258871b33d 267 if(!CalibratingNow()) {
jmitc91516 1:a5258871b33d 268 if(calibTemperature[GuiVar_columnDHAutoCalibPointSelection] >= 1.0f) {
jmitc91516 1:a5258871b33d 269 calibTemperature[GuiVar_columnDHAutoCalibPointSelection] -= 1.0f;
jmitc91516 1:a5258871b33d 270 SetEasyGUICalibrationPointTemperatureFromInternalValue(false);
jmitc91516 1:a5258871b33d 271 UpdateEasyGUIPage();
jmitc91516 1:a5258871b33d 272 }
jmitc91516 1:a5258871b33d 273 }
jmitc91516 1:a5258871b33d 274 dealtWithTouch = true;
jmitc91516 1:a5258871b33d 275 break;
jmitc91516 1:a5258871b33d 276
jmitc91516 1:a5258871b33d 277 case COLUMN_DH_AUTO_CALIB_START_CALIBRATION:
jmitc91516 1:a5258871b33d 278 if(CalibratingNow()) {
jmitc91516 1:a5258871b33d 279 // Need to stop calibrating
jmitc91516 1:a5258871b33d 280 char commandBuffer[30];
jmitc91516 1:a5258871b33d 281 ConstructStopCalibrationCommand(commandBuffer);
jmitc91516 1:a5258871b33d 282 if(SendCommandToGCWithDACKResponse(commandBuffer)) {
jmitc91516 1:a5258871b33d 283 // Stop calibration succeeded
jmitc91516 1:a5258871b33d 284
jmitc91516 1:a5258871b33d 285 currentCalibrationState = IDLE;
jmitc91516 1:a5258871b33d 286
jmitc91516 1:a5258871b33d 287 needToGetColumnResistance = false;
jmitc91516 1:a5258871b33d 288
jmitc91516 1:a5258871b33d 289 strcpy(GuiVar_columnDHAutoCalibCalibrateButtonText, "Calibrate");
jmitc91516 1:a5258871b33d 290
jmitc91516 1:a5258871b33d 291 #ifdef USE_ENABLE_SET_BUTTON_FLAG
jmitc91516 1:a5258871b33d 292 enableSetButton = false;
jmitc91516 1:a5258871b33d 293 #endif
jmitc91516 1:a5258871b33d 294 // Let user change pages again
jmitc91516 1:a5258871b33d 295 TouchPanelPageSelector::SetPageChangeEnabled(true);
jmitc91516 1:a5258871b33d 296 }
jmitc91516 1:a5258871b33d 297 } else {
jmitc91516 1:a5258871b33d 298 // Need to start calibrating
jmitc91516 1:a5258871b33d 299 char commandBuffer[30];
jmitc91516 1:a5258871b33d 300 ConstructStartCalibrationCommand(commandBuffer);
jmitc91516 1:a5258871b33d 301 if(SendCommandToGCWithDACKResponse(commandBuffer)) {
jmitc91516 1:a5258871b33d 302 // Start calibration succeeded
jmitc91516 1:a5258871b33d 303 currentCalibrationState = GetCalibrationState();
jmitc91516 1:a5258871b33d 304 previousCalibrationState = INVALID; // Make explicit - we have started a new calibration operation
jmitc91516 1:a5258871b33d 305 // (do not leave STAGE_3 as the previous calibration state)
jmitc91516 1:a5258871b33d 306
jmitc91516 1:a5258871b33d 307 // Make sure the stabilisation time is the same as in the GC -
jmitc91516 1:a5258871b33d 308 // i.e. that it matches the value the GC is actually using
jmitc91516 1:a5258871b33d 309 stabilisationTime = GetStabilisationTimeFromGC();
jmitc91516 1:a5258871b33d 310 SetEasyGUIStabilisationTimeFromInternalValue();
jmitc91516 1:a5258871b33d 311
jmitc91516 1:a5258871b33d 312 // Make sure we have a valid stabilisation start time,
jmitc91516 1:a5258871b33d 313 // in case we somehow skip stage 1 and go straight to stage 1A
jmitc91516 1:a5258871b33d 314 // (see function SetEasyGUICalibrationTimeRemaining())
jmitc91516 1:a5258871b33d 315 gcTimeStabilisationStarted = GetTimeFromGC();
jmitc91516 1:a5258871b33d 316
jmitc91516 1:a5258871b33d 317 strcpy(GuiVar_columnDHAutoCalibCalibrateButtonText, "Stop");
jmitc91516 1:a5258871b33d 318
jmitc91516 1:a5258871b33d 319 needToGetColumnResistance = true;
jmitc91516 1:a5258871b33d 320
jmitc91516 1:a5258871b33d 321 #ifdef USE_ENABLE_SET_BUTTON_FLAG
jmitc91516 1:a5258871b33d 322 enableSetButton = false;
jmitc91516 1:a5258871b33d 323 #endif
jmitc91516 1:a5258871b33d 324 // Do not allow user to change pages while we are calibrating
jmitc91516 1:a5258871b33d 325 TouchPanelPageSelector::SetPageChangeEnabled(false);
jmitc91516 1:a5258871b33d 326 }
jmitc91516 1:a5258871b33d 327 }
jmitc91516 1:a5258871b33d 328 UpdateEasyGUIPage();
jmitc91516 1:a5258871b33d 329 dealtWithTouch = true;
jmitc91516 1:a5258871b33d 330 break;
jmitc91516 1:a5258871b33d 331
jmitc91516 1:a5258871b33d 332 case COLUMN_DH_AUTO_CALIB_SET_CURRENT_CALIBRATION:
jmitc91516 1:a5258871b33d 333 #ifdef USE_ENABLE_SET_BUTTON_FLAG
jmitc91516 1:a5258871b33d 334 if(enableSetButton) {
jmitc91516 1:a5258871b33d 335 #else
jmitc91516 1:a5258871b33d 336 // 'Set' is valid during *** and after *** stage 3
jmitc91516 1:a5258871b33d 337 if((currentCalibrationState == STAGE_3) || (previousCalibrationState == STAGE_3)) {
jmitc91516 1:a5258871b33d 338 #endif
jmitc91516 1:a5258871b33d 339 // TODO: Use the 'new' values shown to the user on the easyGUI page,
jmitc91516 1:a5258871b33d 340 // which we got from the GC at the end of calibration stage 3.
jmitc91516 1:a5258871b33d 341 // These are in:
jmitc91516 1:a5258871b33d 342 // GuiVar_columnDHAutoCalibTemperatureToSet for temperature
jmitc91516 1:a5258871b33d 343 // GuiVar_columnDHAutoCalibResistance for resistance
jmitc91516 1:a5258871b33d 344 // DON'T get the current values from the GC - they will have changed since
jmitc91516 1:a5258871b33d 345 // the calibration process ended
jmitc91516 1:a5258871b33d 346 float temp;
jmitc91516 1:a5258871b33d 347 sscanf(GuiVar_columnDHAutoCalibTemperatureToSet, "%f", &temp);
jmitc91516 1:a5258871b33d 348 SetColumnTemperaturePointInGC(GuiVar_columnDHAutoCalibPointSelection + 1, temp);
jmitc91516 1:a5258871b33d 349
jmitc91516 1:a5258871b33d 350 sscanf(GuiVar_columnDHAutoCalibResistance, "%f", &temp);
jmitc91516 1:a5258871b33d 351 SetColumnResistancePointInGC(GuiVar_columnDHAutoCalibPointSelection + 1, temp);
jmitc91516 1:a5258871b33d 352
jmitc91516 1:a5258871b33d 353 // Update the user interface to show the new resistance value for the current calibration point
jmitc91516 1:a5258871b33d 354 calibResistance[GuiVar_columnDHAutoCalibPointSelection] = GetColumnResistancePointFromGC(GuiVar_columnDHAutoCalibPointSelection + 1);
jmitc91516 1:a5258871b33d 355 SetEasyGUICalibrationPointResistanceFromInternalValue();
jmitc91516 1:a5258871b33d 356
jmitc91516 1:a5258871b33d 357 // ...and to show the new temperature value
jmitc91516 1:a5258871b33d 358 calibTemperature[GuiVar_columnDHAutoCalibPointSelection] = GetColumnTemperaturePointFromGC(GuiVar_columnDHAutoCalibPointSelection + 1);
jmitc91516 1:a5258871b33d 359 SetEasyGUICalibrationPointTemperatureFromInternalValue(true);
jmitc91516 1:a5258871b33d 360
jmitc91516 1:a5258871b33d 361 #ifdef USE_ENABLE_SET_BUTTON_FLAG
jmitc91516 1:a5258871b33d 362 enableSetButton = false;
jmitc91516 1:a5258871b33d 363 #endif
jmitc91516 1:a5258871b33d 364 UpdateEasyGUIPage();
jmitc91516 1:a5258871b33d 365 }
jmitc91516 1:a5258871b33d 366 // 'else'- ignore
jmitc91516 1:a5258871b33d 367 break;
jmitc91516 1:a5258871b33d 368
jmitc91516 1:a5258871b33d 369 default: // Not recognised - do nothing
jmitc91516 1:a5258871b33d 370 break;
jmitc91516 1:a5258871b33d 371 }
jmitc91516 1:a5258871b33d 372
jmitc91516 1:a5258871b33d 373 return dealtWithTouch;
jmitc91516 1:a5258871b33d 374 }
jmitc91516 1:a5258871b33d 375
jmitc91516 1:a5258871b33d 376
jmitc91516 1:a5258871b33d 377 bool ColumnDHAutoCalibrationPageHandler::CalibratingNow(void)
jmitc91516 1:a5258871b33d 378 {
jmitc91516 1:a5258871b33d 379 if((currentCalibrationState == INVALID) || (currentCalibrationState == IDLE)) {
jmitc91516 1:a5258871b33d 380 return false;
jmitc91516 1:a5258871b33d 381 }
jmitc91516 1:a5258871b33d 382
jmitc91516 1:a5258871b33d 383 // 'else'
jmitc91516 1:a5258871b33d 384 return true;
jmitc91516 1:a5258871b33d 385 }
jmitc91516 1:a5258871b33d 386
jmitc91516 1:a5258871b33d 387
jmitc91516 1:a5258871b33d 388 /*
jmitc91516 1:a5258871b33d 389 Caller is telling us it is about to display the easyGUI 'ColumnDHAutoCalibrationPage',
jmitc91516 1:a5258871b33d 390 and that we should do whatever we have to do to get it ready,
jmitc91516 1:a5258871b33d 391 before the caller displays it.
jmitc91516 1:a5258871b33d 392
jmitc91516 1:a5258871b33d 393 No arguments, no return code
jmitc91516 1:a5258871b33d 394 */
jmitc91516 1:a5258871b33d 395 void ColumnDHAutoCalibrationPageHandler::DisplayingEasyGUIPage(void)
jmitc91516 1:a5258871b33d 396 {
jmitc91516 1:a5258871b33d 397 strcpy(GuiVar_columnDHAutoCalibStabilisationTimeRemaining, notAvailable);
jmitc91516 1:a5258871b33d 398
jmitc91516 1:a5258871b33d 399 SetEasyGUICalibrationPointTemperatureFromInternalValue(false);
jmitc91516 1:a5258871b33d 400 SetEasyGUIStabilisationTimeFromInternalValue();
jmitc91516 1:a5258871b33d 401
jmitc91516 1:a5258871b33d 402 UpdateVolatileEasyGUIVariables();
jmitc91516 1:a5258871b33d 403 }
jmitc91516 1:a5258871b33d 404
jmitc91516 1:a5258871b33d 405
jmitc91516 1:a5258871b33d 406 /*
jmitc91516 1:a5258871b33d 407 (Re)display the easyGUI 'ColumnDHAutoCalibrationPage' -
jmitc91516 1:a5258871b33d 408 e.g. after the caller has updated one or more of the easyGUI variables
jmitc91516 1:a5258871b33d 409 included in the page, and wants to display the new value to the user.
jmitc91516 1:a5258871b33d 410
jmitc91516 1:a5258871b33d 411 No arguments, no return code
jmitc91516 1:a5258871b33d 412 */
jmitc91516 1:a5258871b33d 413 void ColumnDHAutoCalibrationPageHandler::UpdateEasyGUIPage(void)
jmitc91516 1:a5258871b33d 414 {
jmitc91516 1:a5258871b33d 415 GetGCStatusLoop *getGCStatusLoop = GetGCStatusLoop::GetInstance();
jmitc91516 1:a5258871b33d 416
jmitc91516 1:a5258871b33d 417 if(getGCStatusLoop != NULL) {
jmitc91516 1:a5258871b33d 418 // The Gas Calibration page has a status rectangle for the gas -
jmitc91516 1:a5258871b33d 419 // GetGCStatusLoop can display this, we cannot
jmitc91516 1:a5258871b33d 420 getGCStatusLoop->ForceUpdateOfColumnDHAutoCalibrationPage();
jmitc91516 1:a5258871b33d 421 }
jmitc91516 1:a5258871b33d 422 }
jmitc91516 1:a5258871b33d 423
jmitc91516 1:a5258871b33d 424 /*
jmitc91516 1:a5258871b33d 425 Update the easyGUI variable that displays the calibration temperature
jmitc91516 1:a5258871b33d 426 to match the current value stored in our own internal variable.
jmitc91516 1:a5258871b33d 427 Note that there are two - one always displays the value stored in the GC,
jmitc91516 1:a5258871b33d 428 the other displays the value the user wants to set.
jmitc91516 1:a5258871b33d 429
jmitc91516 1:a5258871b33d 430 Provided so that we do this consistently everywhere.
jmitc91516 1:a5258871b33d 431 */
jmitc91516 1:a5258871b33d 432 void ColumnDHAutoCalibrationPageHandler::SetEasyGUICalibrationPointTemperatureFromInternalValue(bool updateBoth)
jmitc91516 1:a5258871b33d 433 {
jmitc91516 1:a5258871b33d 434 // We display only the integer part of the temperature - pointless displaying the fractional part
jmitc91516 1:a5258871b33d 435 // if we only allow the user to change the value in increments of 1.0 (i.e. we give them
jmitc91516 1:a5258871b33d 436 // no way to change the fractional part)
jmitc91516 1:a5258871b33d 437 float temp = floor(calibTemperature[GuiVar_columnDHAutoCalibPointSelection] + 0.5f);
jmitc91516 1:a5258871b33d 438 sprintf(GuiVar_columnDHAutoCalibTemperatureToSet, "%1.0f", temp);
jmitc91516 1:a5258871b33d 439
jmitc91516 1:a5258871b33d 440 if(updateBoth) {
jmitc91516 1:a5258871b33d 441 // But we do display the temperature obtained from the GC, to one decimal place
jmitc91516 1:a5258871b33d 442 // (since the GC returns it in that format)
jmitc91516 1:a5258871b33d 443 sprintf(GuiVar_columnDHAutoCalibCurrentTemp, "%1.1f", calibTemperature[GuiVar_columnDHAutoCalibPointSelection]);
jmitc91516 1:a5258871b33d 444 }
jmitc91516 1:a5258871b33d 445 }
jmitc91516 1:a5258871b33d 446
jmitc91516 1:a5258871b33d 447
jmitc91516 1:a5258871b33d 448 /*
jmitc91516 1:a5258871b33d 449 Update the easyGUI variable that displays the calibration point resistance
jmitc91516 1:a5258871b33d 450 to match the current value stored in our own internal variable. Also update
jmitc91516 1:a5258871b33d 451 the 'actual' resistance to show 'not available', since we have not calibrated yet.
jmitc91516 1:a5258871b33d 452
jmitc91516 1:a5258871b33d 453 Intended to be called when the user selects a different calibration point.
jmitc91516 1:a5258871b33d 454
jmitc91516 1:a5258871b33d 455 Provided so that we do this consistently everywhere.
jmitc91516 1:a5258871b33d 456 */
jmitc91516 1:a5258871b33d 457 void ColumnDHAutoCalibrationPageHandler::SetEasyGUICalibrationPointResistanceFromInternalValue(void)
jmitc91516 1:a5258871b33d 458 {
jmitc91516 1:a5258871b33d 459 if(calibResistance[GuiVar_columnDHAutoCalibPointSelection] >= 0.0f) {
jmitc91516 1:a5258871b33d 460 sprintf(GuiVar_columnDHAutoCalibCurrentRes, "%1.2f", calibResistance[GuiVar_columnDHAutoCalibPointSelection]);
jmitc91516 1:a5258871b33d 461 } else {
jmitc91516 1:a5258871b33d 462 strcpy(GuiVar_columnDHAutoCalibCurrentRes, notAvailable);
jmitc91516 1:a5258871b33d 463 }
jmitc91516 1:a5258871b33d 464
jmitc91516 1:a5258871b33d 465 strcpy(GuiVar_columnDHAutoCalibResistance, notAvailable);
jmitc91516 1:a5258871b33d 466 }
jmitc91516 1:a5258871b33d 467
jmitc91516 1:a5258871b33d 468
jmitc91516 1:a5258871b33d 469 /*
jmitc91516 1:a5258871b33d 470 Update the easyGUI variable that displays the calibration stabilisation time
jmitc91516 1:a5258871b33d 471 to match the current value stored in our own internal variable.
jmitc91516 1:a5258871b33d 472
jmitc91516 1:a5258871b33d 473 Provided so that we do this consistently everywhere
jmitc91516 1:a5258871b33d 474 */
jmitc91516 1:a5258871b33d 475 void ColumnDHAutoCalibrationPageHandler::SetEasyGUIStabilisationTimeFromInternalValue(void)
jmitc91516 1:a5258871b33d 476 {
jmitc91516 1:a5258871b33d 477 sprintf(GuiVar_columnDHAutoCalibStabilisationTimeToSet, "%1d", stabilisationTime);
jmitc91516 1:a5258871b33d 478 }
jmitc91516 1:a5258871b33d 479
jmitc91516 1:a5258871b33d 480
jmitc91516 1:a5258871b33d 481 /*
jmitc91516 1:a5258871b33d 482 Construct the GC command to start the calibration process,
jmitc91516 1:a5258871b33d 483 using the current parameter values.
jmitc91516 1:a5258871b33d 484
jmitc91516 1:a5258871b33d 485 Args: pointer to a buffer in which to store the command, as a null-terminated string
jmitc91516 1:a5258871b33d 486
jmitc91516 1:a5258871b33d 487 No return code
jmitc91516 1:a5258871b33d 488 */
jmitc91516 1:a5258871b33d 489 void ColumnDHAutoCalibrationPageHandler::ConstructStartCalibrationCommand(char* commandBuffer)
jmitc91516 1:a5258871b33d 490 {
jmitc91516 1:a5258871b33d 491 // Command is "CCONnttt", where 'n' is the calibration point (1, 2 or 3),
jmitc91516 1:a5258871b33d 492 // and "ttt" is the temperature
jmitc91516 1:a5258871b33d 493
jmitc91516 1:a5258871b33d 494 commandBuffer[0] = 'C';
jmitc91516 1:a5258871b33d 495 commandBuffer[1] = 'C';
jmitc91516 1:a5258871b33d 496 commandBuffer[2] = 'O';
jmitc91516 1:a5258871b33d 497 commandBuffer[3] = 'N';
jmitc91516 1:a5258871b33d 498
jmitc91516 1:a5258871b33d 499 switch (GuiVar_columnDHAutoCalibPointSelection) {
jmitc91516 1:a5258871b33d 500 case 0:
jmitc91516 1:a5258871b33d 501 commandBuffer[4] = '1';
jmitc91516 1:a5258871b33d 502 break;
jmitc91516 1:a5258871b33d 503
jmitc91516 1:a5258871b33d 504 case 1:
jmitc91516 1:a5258871b33d 505 commandBuffer[4] = '2';
jmitc91516 1:a5258871b33d 506 break;
jmitc91516 1:a5258871b33d 507
jmitc91516 1:a5258871b33d 508 default: // Assume the index is 2
jmitc91516 1:a5258871b33d 509 commandBuffer[4] = '3';
jmitc91516 1:a5258871b33d 510 break;
jmitc91516 1:a5258871b33d 511 }
jmitc91516 1:a5258871b33d 512
jmitc91516 1:a5258871b33d 513 sprintf(&commandBuffer[5], "%03.0f", calibTemperature[GuiVar_columnDHAutoCalibPointSelection]);
jmitc91516 1:a5258871b33d 514 }
jmitc91516 1:a5258871b33d 515
jmitc91516 1:a5258871b33d 516
jmitc91516 1:a5258871b33d 517 /*
jmitc91516 1:a5258871b33d 518 Construct the GC command to stop the calibration process.
jmitc91516 1:a5258871b33d 519 (Provided to match the 'ConstructStartCalibrationCommand' function.)
jmitc91516 1:a5258871b33d 520
jmitc91516 1:a5258871b33d 521 Args: pointer to a buffer in which to store the command, as a null-terminated string
jmitc91516 1:a5258871b33d 522
jmitc91516 1:a5258871b33d 523 No return code
jmitc91516 1:a5258871b33d 524 */
jmitc91516 1:a5258871b33d 525 void ColumnDHAutoCalibrationPageHandler::ConstructStopCalibrationCommand(char* commandBuffer)
jmitc91516 1:a5258871b33d 526 {
jmitc91516 1:a5258871b33d 527 // Command is "CCOF"
jmitc91516 1:a5258871b33d 528
jmitc91516 1:a5258871b33d 529 commandBuffer[0] = 'C';
jmitc91516 1:a5258871b33d 530 commandBuffer[1] = 'C';
jmitc91516 1:a5258871b33d 531 commandBuffer[2] = 'O';
jmitc91516 1:a5258871b33d 532 commandBuffer[3] = 'F';
jmitc91516 1:a5258871b33d 533 commandBuffer[4] = '\0';
jmitc91516 1:a5258871b33d 534 }
jmitc91516 1:a5258871b33d 535
jmitc91516 1:a5258871b33d 536
jmitc91516 1:a5258871b33d 537 /*
jmitc91516 1:a5258871b33d 538 As the name implies, sends a command to the GC and returns the response.
jmitc91516 1:a5258871b33d 539
jmitc91516 1:a5258871b33d 540 Args: pointer to a buffer containing the command, as a null-terminated string
jmitc91516 1:a5258871b33d 541 pointer to a buffer to contain the response, as a null-terminated string
jmitc91516 1:a5258871b33d 542
jmitc91516 1:a5258871b33d 543 No return code (it is up to the caller to examine the response to see whether
jmitc91516 1:a5258871b33d 544 the command succeeded or failed)
jmitc91516 1:a5258871b33d 545 */
jmitc91516 1:a5258871b33d 546 void ColumnDHAutoCalibrationPageHandler::SendCommandToGCAndGetResponse(char* command, char* response)
jmitc91516 1:a5258871b33d 547 {
jmitc91516 1:a5258871b33d 548 #define USE_GC_UTILS // Testing new class
jmitc91516 1:a5258871b33d 549 #ifdef USE_GC_UTILS
jmitc91516 1:a5258871b33d 550 USBHostGCUtilities::SendCommandToGCAndGetResponse(usbDevice, usbHostGC, command, response);
jmitc91516 1:a5258871b33d 551 #else
jmitc91516 1:a5258871b33d 552 while(usbHostGC->ExecutingSetDeviceReport()) {}
jmitc91516 1:a5258871b33d 553
jmitc91516 1:a5258871b33d 554 usbHostGC->SetDeviceReport(usbDevice, command, response);
jmitc91516 1:a5258871b33d 555 //#define DEBUG_PRINT_HERE
jmitc91516 1:a5258871b33d 556 #ifdef DEBUG_PRINT_HERE
jmitc91516 1:a5258871b33d 557 char dbg[100];
jmitc91516 1:a5258871b33d 558 sprintf(dbg, "SCTGC cmd \"%s\", response \"%s\"", command, response);
jmitc91516 1:a5258871b33d 559 SpecialDebugPrint(dbg, 10, 275);
jmitc91516 1:a5258871b33d 560 #endif // DEBUG_PRINT_HERE
jmitc91516 1:a5258871b33d 561 #endif // USE_GC_UTILS
jmitc91516 1:a5258871b33d 562 }
jmitc91516 1:a5258871b33d 563
jmitc91516 1:a5258871b33d 564
jmitc91516 1:a5258871b33d 565 /*
jmitc91516 1:a5258871b33d 566 Sends a command to the GC for which we expect a response of "DACK" if successful,
jmitc91516 1:a5258871b33d 567 "DNAK" or "EPKT" if failure.
jmitc91516 1:a5258871b33d 568
jmitc91516 1:a5258871b33d 569 Args: a pointer to the command in question, as a null terminated string
jmitc91516 1:a5258871b33d 570
jmitc91516 1:a5258871b33d 571 Returns true if the GC responded with "DACK", false for anything else
jmitc91516 1:a5258871b33d 572 */
jmitc91516 1:a5258871b33d 573 bool ColumnDHAutoCalibrationPageHandler::SendCommandToGCWithDACKResponse(char *cmd)
jmitc91516 1:a5258871b33d 574 {
jmitc91516 1:a5258871b33d 575 #define USE_GC_UTILS // Testing new class
jmitc91516 1:a5258871b33d 576 #ifdef USE_GC_UTILS
jmitc91516 1:a5258871b33d 577 return USBHostGCUtilities::SendCommandToGCWithDACKResponse(usbDevice, usbHostGC, cmd);
jmitc91516 1:a5258871b33d 578 #else
jmitc91516 1:a5258871b33d 579 char response[50];
jmitc91516 1:a5258871b33d 580 SendCommandToGCAndGetResponse(cmd, response);
jmitc91516 1:a5258871b33d 581 // We expect a response like this: "DACK" for success, "DNAK" for failure, "EPKT" for error
jmitc91516 1:a5258871b33d 582
jmitc91516 1:a5258871b33d 583 return (response[1] == 'A');
jmitc91516 1:a5258871b33d 584 #endif // USE_GC_UTILS
jmitc91516 1:a5258871b33d 585 }
jmitc91516 1:a5258871b33d 586
jmitc91516 1:a5258871b33d 587
jmitc91516 1:a5258871b33d 588 /*
jmitc91516 1:a5258871b33d 589 Obtains the current calibration from the GC, and returns it as a value
jmitc91516 1:a5258871b33d 590 in the 'CalibrationState' enumeration.
jmitc91516 1:a5258871b33d 591 */
jmitc91516 1:a5258871b33d 592 CalibrationState ColumnDHAutoCalibrationPageHandler::GetCalibrationState(void)
jmitc91516 1:a5258871b33d 593 {
jmitc91516 1:a5258871b33d 594 char response[30];
jmitc91516 1:a5258871b33d 595
jmitc91516 1:a5258871b33d 596 SendCommandToGCAndGetResponse("QDCS", response);
jmitc91516 1:a5258871b33d 597
jmitc91516 1:a5258871b33d 598 // We expect a response of the form "DDCSnnnn", where "nnnn" is the calibration state:
jmitc91516 1:a5258871b33d 599 // 0000 = idle
jmitc91516 1:a5258871b33d 600 // 0001 = stage 1
jmitc91516 1:a5258871b33d 601 // 0002 = stage 1A
jmitc91516 1:a5258871b33d 602 // 0003 = stage 2
jmitc91516 1:a5258871b33d 603 // 0004 = stage 3
jmitc91516 1:a5258871b33d 604
jmitc91516 1:a5258871b33d 605 if(response[0] != 'D') {
jmitc91516 1:a5258871b33d 606 return INVALID;
jmitc91516 1:a5258871b33d 607 }
jmitc91516 1:a5258871b33d 608
jmitc91516 1:a5258871b33d 609 if(response[1] != 'D') {
jmitc91516 1:a5258871b33d 610 return INVALID;
jmitc91516 1:a5258871b33d 611 }
jmitc91516 1:a5258871b33d 612
jmitc91516 1:a5258871b33d 613 if(response[2] != 'C') {
jmitc91516 1:a5258871b33d 614 return INVALID;
jmitc91516 1:a5258871b33d 615 }
jmitc91516 1:a5258871b33d 616
jmitc91516 1:a5258871b33d 617 if(response[3] != 'S') {
jmitc91516 1:a5258871b33d 618 return INVALID;
jmitc91516 1:a5258871b33d 619 }
jmitc91516 1:a5258871b33d 620
jmitc91516 1:a5258871b33d 621 if(response[4] != '0') {
jmitc91516 1:a5258871b33d 622 return INVALID;
jmitc91516 1:a5258871b33d 623 }
jmitc91516 1:a5258871b33d 624
jmitc91516 1:a5258871b33d 625 if(response[5] != '0') {
jmitc91516 1:a5258871b33d 626 return INVALID;
jmitc91516 1:a5258871b33d 627 }
jmitc91516 1:a5258871b33d 628
jmitc91516 1:a5258871b33d 629 if(response[6] != '0') {
jmitc91516 1:a5258871b33d 630 return INVALID;
jmitc91516 1:a5258871b33d 631 }
jmitc91516 1:a5258871b33d 632
jmitc91516 1:a5258871b33d 633 switch (response[7]) {
jmitc91516 1:a5258871b33d 634 case '0':
jmitc91516 1:a5258871b33d 635 return IDLE;
jmitc91516 1:a5258871b33d 636
jmitc91516 1:a5258871b33d 637 case '1':
jmitc91516 1:a5258871b33d 638 return STAGE_1;
jmitc91516 1:a5258871b33d 639
jmitc91516 1:a5258871b33d 640 case '2':
jmitc91516 1:a5258871b33d 641 return STAGE_1A;
jmitc91516 1:a5258871b33d 642
jmitc91516 1:a5258871b33d 643 case '3':
jmitc91516 1:a5258871b33d 644 return STAGE_2;
jmitc91516 1:a5258871b33d 645
jmitc91516 1:a5258871b33d 646 case '4':
jmitc91516 1:a5258871b33d 647 return STAGE_3;
jmitc91516 1:a5258871b33d 648
jmitc91516 1:a5258871b33d 649 default:
jmitc91516 1:a5258871b33d 650 return INVALID;
jmitc91516 1:a5258871b33d 651 }
jmitc91516 1:a5258871b33d 652 }
jmitc91516 1:a5258871b33d 653
jmitc91516 1:a5258871b33d 654
jmitc91516 1:a5258871b33d 655 /*
jmitc91516 1:a5258871b33d 656 Set the easyGUI variable that displays the calibration state,
jmitc91516 1:a5258871b33d 657 to correspond with the current mode.
jmitc91516 1:a5258871b33d 658
jmitc91516 1:a5258871b33d 659 No arguments, no return value
jmitc91516 1:a5258871b33d 660 */
jmitc91516 1:a5258871b33d 661 void ColumnDHAutoCalibrationPageHandler::SetEasyGUICalibrationState(void)
jmitc91516 1:a5258871b33d 662 {
jmitc91516 1:a5258871b33d 663 switch (currentCalibrationState) {
jmitc91516 1:a5258871b33d 664 case IDLE:
jmitc91516 1:a5258871b33d 665 strcpy(GuiVar_columnDHAutoCalibCalibrationState, "Idle");
jmitc91516 1:a5258871b33d 666 break;
jmitc91516 1:a5258871b33d 667
jmitc91516 1:a5258871b33d 668 case STAGE_1:
jmitc91516 1:a5258871b33d 669 strcpy(GuiVar_columnDHAutoCalibCalibrationState, "Heat to Calib + 10");
jmitc91516 1:a5258871b33d 670 break;
jmitc91516 1:a5258871b33d 671
jmitc91516 1:a5258871b33d 672 case STAGE_1A:
jmitc91516 1:a5258871b33d 673 strcpy(GuiVar_columnDHAutoCalibCalibrationState, "Stabilising");
jmitc91516 1:a5258871b33d 674 break;
jmitc91516 1:a5258871b33d 675
jmitc91516 1:a5258871b33d 676 case STAGE_2:
jmitc91516 1:a5258871b33d 677 strcpy(GuiVar_columnDHAutoCalibCalibrationState, "Cool to Calib");
jmitc91516 1:a5258871b33d 678 break;
jmitc91516 1:a5258871b33d 679
jmitc91516 1:a5258871b33d 680 case STAGE_3:
jmitc91516 1:a5258871b33d 681 strcpy(GuiVar_columnDHAutoCalibCalibrationState, "Measuring");
jmitc91516 1:a5258871b33d 682 break;
jmitc91516 1:a5258871b33d 683
jmitc91516 1:a5258871b33d 684 default:
jmitc91516 1:a5258871b33d 685 strcpy(GuiVar_columnDHAutoCalibCalibrationState, "Invalid");
jmitc91516 1:a5258871b33d 686 break;
jmitc91516 1:a5258871b33d 687 }
jmitc91516 1:a5258871b33d 688 }
jmitc91516 1:a5258871b33d 689
jmitc91516 1:a5258871b33d 690 /*
jmitc91516 1:a5258871b33d 691 The Set Calibration button should be enabled during stage 3 and afterwards - but not before.
jmitc91516 1:a5258871b33d 692 This function sets the colour of the "Set" text on the button appropriately.
jmitc91516 1:a5258871b33d 693
jmitc91516 1:a5258871b33d 694 No arguments, no return code
jmitc91516 1:a5258871b33d 695 */
jmitc91516 1:a5258871b33d 696 void ColumnDHAutoCalibrationPageHandler::ShowSetCalibrationButtonEnabledState(void)
jmitc91516 1:a5258871b33d 697 {
jmitc91516 1:a5258871b33d 698 #ifdef USE_ENABLE_SET_BUTTON_FLAG
jmitc91516 1:a5258871b33d 699 if(enableSetButton) {
jmitc91516 1:a5258871b33d 700 #else
jmitc91516 1:a5258871b33d 701 if((currentCalibrationState == STAGE_3) || (previousCalibrationState == STAGE_3)) {
jmitc91516 1:a5258871b33d 702 #endif
jmitc91516 1:a5258871b33d 703 GuiVar_columnDHAutoCalibSetColour = 0; // Black - enabled
jmitc91516 1:a5258871b33d 704 } else {
jmitc91516 1:a5258871b33d 705 GuiVar_columnDHAutoCalibSetColour = SixteenBitColorValue(192, 192, 192); // Light grey - disabled
jmitc91516 1:a5258871b33d 706 }
jmitc91516 1:a5258871b33d 707 }
jmitc91516 1:a5258871b33d 708
jmitc91516 1:a5258871b33d 709
jmitc91516 1:a5258871b33d 710 /*
jmitc91516 1:a5258871b33d 711 Set the easyGUI variable that displays the heat state (i.e. on/off),
jmitc91516 1:a5258871b33d 712 to correspond with the current state.
jmitc91516 1:a5258871b33d 713
jmitc91516 1:a5258871b33d 714 No arguments, no return value
jmitc91516 1:a5258871b33d 715 */
jmitc91516 1:a5258871b33d 716 void ColumnDHAutoCalibrationPageHandler::SetEasyGUIHeatState(void)
jmitc91516 1:a5258871b33d 717 {
jmitc91516 1:a5258871b33d 718 char response[30];
jmitc91516 1:a5258871b33d 719
jmitc91516 1:a5258871b33d 720 SendCommandToGCAndGetResponse("QHTS", response);
jmitc91516 1:a5258871b33d 721
jmitc91516 1:a5258871b33d 722 bool heatIsOn = false;
jmitc91516 1:a5258871b33d 723
jmitc91516 1:a5258871b33d 724 // We expect a response like "DHTS000n", where 'n' is '1' for heat on,
jmitc91516 1:a5258871b33d 725 // '0' for heat off. Guard against "EPKT" as well
jmitc91516 1:a5258871b33d 726 if((response[0] == 'D') && (strlen(response) >= 8) && (response[7] == '1')) {
jmitc91516 1:a5258871b33d 727 heatIsOn = true;
jmitc91516 1:a5258871b33d 728 }
jmitc91516 1:a5258871b33d 729
jmitc91516 1:a5258871b33d 730 strcpy(GuiVar_columnDHAutoCalibHeatState, heatIsOn ? "On" : "Off");
jmitc91516 1:a5258871b33d 731 }
jmitc91516 1:a5258871b33d 732
jmitc91516 1:a5258871b33d 733
jmitc91516 1:a5258871b33d 734 /*
jmitc91516 1:a5258871b33d 735 Set the easyGUI variable that displays the oven temperature
jmitc91516 1:a5258871b33d 736 to correspond with the current oven temperature
jmitc91516 1:a5258871b33d 737 (i.e. not a calibration point value, but the actual temperature).
jmitc91516 1:a5258871b33d 738
jmitc91516 1:a5258871b33d 739 No arguments, no return value
jmitc91516 1:a5258871b33d 740 */
jmitc91516 1:a5258871b33d 741 void ColumnDHAutoCalibrationPageHandler::SetEasyGUIOvenTemperature(void)
jmitc91516 1:a5258871b33d 742 {
jmitc91516 1:a5258871b33d 743 char response[30];
jmitc91516 1:a5258871b33d 744
jmitc91516 1:a5258871b33d 745 SendCommandToGCAndGetResponse("QCOL", response);
jmitc91516 1:a5258871b33d 746
jmitc91516 1:a5258871b33d 747 // We expect a response like "DCOLnnnn", where "nnnn"
jmitc91516 1:a5258871b33d 748 // is the current oven temperaure in units of 0.1 deg C
jmitc91516 1:a5258871b33d 749 // Guard against "EPKT" as well
jmitc91516 1:a5258871b33d 750
jmitc91516 1:a5258871b33d 751 strcpy(GuiVar_columnDHAutoCalibActualOvenTemp, notAvailable); // default
jmitc91516 1:a5258871b33d 752
jmitc91516 1:a5258871b33d 753 if(response[0] != 'D') {
jmitc91516 1:a5258871b33d 754 return;
jmitc91516 1:a5258871b33d 755 }
jmitc91516 1:a5258871b33d 756 if(response[1] != 'C') {
jmitc91516 1:a5258871b33d 757 return;
jmitc91516 1:a5258871b33d 758 }
jmitc91516 1:a5258871b33d 759 if(response[2] != 'O') {
jmitc91516 1:a5258871b33d 760 return;
jmitc91516 1:a5258871b33d 761 }
jmitc91516 1:a5258871b33d 762 if(response[3] != 'L') {
jmitc91516 1:a5258871b33d 763 return;
jmitc91516 1:a5258871b33d 764 }
jmitc91516 1:a5258871b33d 765
jmitc91516 1:a5258871b33d 766 GuiVar_columnDHAutoCalibActualOvenTemp[0] = response[4];
jmitc91516 1:a5258871b33d 767 GuiVar_columnDHAutoCalibActualOvenTemp[1] = response[5];
jmitc91516 1:a5258871b33d 768 GuiVar_columnDHAutoCalibActualOvenTemp[2] = response[6];
jmitc91516 1:a5258871b33d 769 GuiVar_columnDHAutoCalibActualOvenTemp[3] = '.';
jmitc91516 1:a5258871b33d 770 GuiVar_columnDHAutoCalibActualOvenTemp[4] = response[7];
jmitc91516 1:a5258871b33d 771 GuiVar_columnDHAutoCalibActualOvenTemp[5] = '\0';
jmitc91516 1:a5258871b33d 772 }
jmitc91516 1:a5258871b33d 773
jmitc91516 1:a5258871b33d 774
jmitc91516 1:a5258871b33d 775 /*
jmitc91516 1:a5258871b33d 776 Gets the current oven temperature, returns it as a floating point value
jmitc91516 1:a5258871b33d 777
jmitc91516 1:a5258871b33d 778 No arguments
jmitc91516 1:a5258871b33d 779
jmitc91516 1:a5258871b33d 780 Return value: the current oven temperature, as a value of type float
jmitc91516 1:a5258871b33d 781 */
jmitc91516 1:a5258871b33d 782 float ColumnDHAutoCalibrationPageHandler::GetCurrentOvenTemperature(void)
jmitc91516 1:a5258871b33d 783 {
jmitc91516 1:a5258871b33d 784 char response[30];
jmitc91516 1:a5258871b33d 785
jmitc91516 1:a5258871b33d 786 SendCommandToGCAndGetResponse("QCOL", response);
jmitc91516 1:a5258871b33d 787
jmitc91516 1:a5258871b33d 788 // We expect a response like "DCOLnnnn", where "nnnn"
jmitc91516 1:a5258871b33d 789 // is the current oven temperaure in units of 0.1 deg C
jmitc91516 1:a5258871b33d 790 // Guard against "EPKT" as well
jmitc91516 1:a5258871b33d 791
jmitc91516 1:a5258871b33d 792 if(response[0] != 'D') {
jmitc91516 1:a5258871b33d 793 return -1.0f;
jmitc91516 1:a5258871b33d 794 }
jmitc91516 1:a5258871b33d 795 if(response[1] != 'C') {
jmitc91516 1:a5258871b33d 796 return -1.0f;
jmitc91516 1:a5258871b33d 797 }
jmitc91516 1:a5258871b33d 798 if(response[2] != 'O') {
jmitc91516 1:a5258871b33d 799 return -1.0f;
jmitc91516 1:a5258871b33d 800 }
jmitc91516 1:a5258871b33d 801 if(response[3] != 'L') {
jmitc91516 1:a5258871b33d 802 return -1.0f;
jmitc91516 1:a5258871b33d 803 }
jmitc91516 1:a5258871b33d 804
jmitc91516 1:a5258871b33d 805 float temp;
jmitc91516 1:a5258871b33d 806 sscanf(&response[4], "%f", &temp);
jmitc91516 1:a5258871b33d 807
jmitc91516 1:a5258871b33d 808 return (temp / 10.0f);
jmitc91516 1:a5258871b33d 809 }
jmitc91516 1:a5258871b33d 810
jmitc91516 1:a5258871b33d 811
jmitc91516 1:a5258871b33d 812 /*
jmitc91516 1:a5258871b33d 813 Set the easyGUI variable that displays the calibration time remaining
jmitc91516 1:a5258871b33d 814 to the correct value - according to whether we are actually calibrating now
jmitc91516 1:a5258871b33d 815 or not.
jmitc91516 1:a5258871b33d 816
jmitc91516 1:a5258871b33d 817 No arguments, no return code.
jmitc91516 1:a5258871b33d 818 */
jmitc91516 1:a5258871b33d 819 void ColumnDHAutoCalibrationPageHandler::SetEasyGUICalibrationTimeRemaining(void)
jmitc91516 1:a5258871b33d 820 {
jmitc91516 1:a5258871b33d 821 if(CalibratingNow()) {
jmitc91516 1:a5258871b33d 822 // "Time remaining" is stabilisation time remaining - applies only in calibration stage 1A
jmitc91516 1:a5258871b33d 823 if(currentCalibrationState == STAGE_1A) {
jmitc91516 1:a5258871b33d 824 if(previousCalibrationState == STAGE_1) {
jmitc91516 1:a5258871b33d 825 #ifdef USE_STABILISATION_TIMER
jmitc91516 1:a5258871b33d 826 stabilisationTimer.reset();
jmitc91516 1:a5258871b33d 827 stabilisationTimer.start();
jmitc91516 1:a5258871b33d 828 #else
jmitc91516 1:a5258871b33d 829 gcTimeStabilisationStarted = GetTimeFromGC();
jmitc91516 1:a5258871b33d 830 #endif
jmitc91516 1:a5258871b33d 831 }
jmitc91516 1:a5258871b33d 832 #ifdef USE_STABILISATION_TIMER
jmitc91516 1:a5258871b33d 833 double timeTakenSoFarInSeconds = ((double)stabilisationTimer.read_ms()) / 1000.0; // Note that we zeroed the timer when we entered stage 1A
jmitc91516 1:a5258871b33d 834 int timeTakenSoFarInMinutes = (int) floor((timeTakenSoFarInSeconds / 60.0) + 0.5);
jmitc91516 1:a5258871b33d 835 #else
jmitc91516 1:a5258871b33d 836 float gcTimeNow = GetTimeFromGC();
jmitc91516 1:a5258871b33d 837 float timeTakenSoFarInMinutes = gcTimeNow - gcTimeStabilisationStarted;
jmitc91516 1:a5258871b33d 838 #endif
jmitc91516 1:a5258871b33d 839 sprintf(GuiVar_columnDHAutoCalibStabilisationTimeRemaining, "%1.1f", ((float)stabilisationTime - timeTakenSoFarInMinutes));
jmitc91516 1:a5258871b33d 840 } else {
jmitc91516 1:a5258871b33d 841 if (previousCalibrationState == STAGE_1A) {
jmitc91516 1:a5258871b33d 842 #ifdef USE_STABILISATION_TIMER
jmitc91516 1:a5258871b33d 843 stabilisationTimer.stop();
jmitc91516 1:a5258871b33d 844 #endif
jmitc91516 1:a5258871b33d 845 strcpy(GuiVar_columnDHAutoCalibStabilisationTimeRemaining, notAvailable);
jmitc91516 1:a5258871b33d 846 }
jmitc91516 1:a5258871b33d 847 }
jmitc91516 1:a5258871b33d 848 } else {
jmitc91516 1:a5258871b33d 849 strcpy(GuiVar_columnDHAutoCalibStabilisationTimeRemaining, notAvailable);
jmitc91516 1:a5258871b33d 850 }
jmitc91516 1:a5258871b33d 851 }
jmitc91516 1:a5258871b33d 852
jmitc91516 1:a5258871b33d 853
jmitc91516 1:a5258871b33d 854 /*
jmitc91516 1:a5258871b33d 855 This updates all the easyGUI variables that display something that may change
jmitc91516 1:a5258871b33d 856 while this page is displayed, without this page's knowledge. It is intended
jmitc91516 1:a5258871b33d 857 that will (e.g.) be called as part of GetGCStatusLoop's regular polling of the GC's state.
jmitc91516 1:a5258871b33d 858
jmitc91516 1:a5258871b33d 859 An important consideration, which affects the way we treat each of the easyGUI variables,
jmitc91516 1:a5258871b33d 860 is the current calibration state of the GC.
jmitc91516 1:a5258871b33d 861
jmitc91516 1:a5258871b33d 862 No arguments, no return code
jmitc91516 1:a5258871b33d 863 */
jmitc91516 1:a5258871b33d 864 void ColumnDHAutoCalibrationPageHandler::UpdateVolatileEasyGUIVariables(void)
jmitc91516 1:a5258871b33d 865 {
jmitc91516 1:a5258871b33d 866 previousCalibrationState = currentCalibrationState;
jmitc91516 1:a5258871b33d 867
jmitc91516 1:a5258871b33d 868 currentCalibrationState = GetCalibrationState();
jmitc91516 1:a5258871b33d 869
jmitc91516 1:a5258871b33d 870 SetEasyGUICalibrationState();
jmitc91516 1:a5258871b33d 871 ShowSetCalibrationButtonEnabledState();
jmitc91516 1:a5258871b33d 872 SetEasyGUIHeatState();
jmitc91516 1:a5258871b33d 873 SetEasyGUIOvenTemperature();
jmitc91516 1:a5258871b33d 874
jmitc91516 1:a5258871b33d 875 SetEasyGUICalibrationTimeRemaining();
jmitc91516 1:a5258871b33d 876
jmitc91516 1:a5258871b33d 877 if(CalibratingNow()) {
jmitc91516 1:a5258871b33d 878 strcpy(GuiVar_columnDHAutoCalibCalibrateButtonText, "Stop");
jmitc91516 1:a5258871b33d 879
jmitc91516 1:a5258871b33d 880 CanUnlockDoorActuators(false); // Not while we are calibrating
jmitc91516 1:a5258871b33d 881 } else {
jmitc91516 1:a5258871b33d 882 strcpy(GuiVar_columnDHAutoCalibCalibrateButtonText, "Calibrate");
jmitc91516 1:a5258871b33d 883
jmitc91516 1:a5258871b33d 884 CanUnlockDoorActuators(true); // We are not calibrating
jmitc91516 1:a5258871b33d 885 }
jmitc91516 1:a5258871b33d 886
jmitc91516 1:a5258871b33d 887 // if((currentCalibrationState == STAGE_3) || (previousCalibrationState == STAGE_3)) {
jmitc91516 1:a5258871b33d 888 // No - only *in* stage 3, not after - buffer length (for resistance measurement) in embedded code may have changed
jmitc91516 1:a5258871b33d 889 if(currentCalibrationState == STAGE_3) {
jmitc91516 1:a5258871b33d 890 // Can now get directly heated column resistance
jmitc91516 1:a5258871b33d 891
jmitc91516 1:a5258871b33d 892 if(needToGetColumnResistance) { // But do not get it twice
jmitc91516 1:a5258871b33d 893 // Do we need to get the column resistance ourselves, and give the user the option to update the current calibration point afterwards,
jmitc91516 1:a5258871b33d 894 // or does the embedded code measure the resistance, then update the current point, automatically by itself in stage 3?
jmitc91516 1:a5258871b33d 895 // If we don't do "CCSM", does it ever come out of calibration stage 3?
jmitc91516 1:a5258871b33d 896 //#define GET_COLUMN_RESISTANCE_OURSELVES
jmitc91516 1:a5258871b33d 897 #ifdef GET_COLUMN_RESISTANCE_OURSELVES
jmitc91516 1:a5258871b33d 898 DisplayGettingColumnResistancePage(); // Tell user what we are doing
jmitc91516 1:a5258871b33d 899 // Send CCSM command
jmitc91516 1:a5258871b33d 900 TellGCToMeasureColumnResistance();
jmitc91516 1:a5258871b33d 901 // Wait 2 seconds + a margin
jmitc91516 1:a5258871b33d 902 Thread::wait(2100);
jmitc91516 1:a5258871b33d 903 actualColumnResistance = GetActualColumnResistanceFromGC();
jmitc91516 1:a5258871b33d 904 sprintf(GuiVar_columnDHAutoCalibResistance, "%.2f", actualColumnResistance);
jmitc91516 1:a5258871b33d 905 #ifdef USE_ENABLE_SET_BUTTON_FLAG
jmitc91516 1:a5258871b33d 906 enableSetButton = true;
jmitc91516 1:a5258871b33d 907 #endif
jmitc91516 1:a5258871b33d 908 // TODO: Update 'New' temperature and resistance - user can then decide
jmitc91516 1:a5258871b33d 909 // whether or not to press "Set" to copy those values to the current point
jmitc91516 1:a5258871b33d 910 // GuiVar_columnDHAutoCalibTemperatureToSet for temperature
jmitc91516 1:a5258871b33d 911 // GuiVar_columnDHAutoCalibResistance for resistance
jmitc91516 1:a5258871b33d 912 sprintf(GuiVar_columnDHAutoCalibTemperatureToSet, "%.0f", GetCurrentOvenTemperature());
jmitc91516 1:a5258871b33d 913 sprintf(GuiVar_columnDHAutoCalibResistance, "%.2f", actualColumnResistance);
jmitc91516 1:a5258871b33d 914
jmitc91516 1:a5258871b33d 915 RedisplayColumnCalibrationPage(); // Normal service is resumed
jmitc91516 1:a5258871b33d 916 #endif // GET_COLUMN_RESISTANCE_OURSELVES
jmitc91516 1:a5258871b33d 917 needToGetColumnResistance = false;
jmitc91516 1:a5258871b33d 918 }
jmitc91516 1:a5258871b33d 919 }
jmitc91516 1:a5258871b33d 920
jmitc91516 1:a5258871b33d 921 #ifndef GET_COLUMN_RESISTANCE_OURSELVES
jmitc91516 1:a5258871b33d 922 if(previousCalibrationState == STAGE_3){
jmitc91516 1:a5258871b33d 923 // Update the displayed temperature and resistance for the currently selected point
jmitc91516 1:a5258871b33d 924 calibTemperature[GuiVar_columnDHAutoCalibPointSelection] = GetColumnTemperaturePointFromGC(GuiVar_columnDHAutoCalibPointSelection + 1);
jmitc91516 1:a5258871b33d 925 SetEasyGUICalibrationPointTemperatureFromInternalValue(true);
jmitc91516 1:a5258871b33d 926
jmitc91516 1:a5258871b33d 927 calibResistance[GuiVar_columnDHAutoCalibPointSelection] = GetColumnResistancePointFromGC(GuiVar_columnDHAutoCalibPointSelection + 1);
jmitc91516 1:a5258871b33d 928 SetEasyGUICalibrationPointResistanceFromInternalValue();
jmitc91516 1:a5258871b33d 929 }
jmitc91516 1:a5258871b33d 930 #endif
jmitc91516 1:a5258871b33d 931
jmitc91516 1:a5258871b33d 932 // Bodge to fix problem where the calibrated resistance is initially displayed as "99.99" -
jmitc91516 1:a5258871b33d 933 // this is the initial value that easyGUI assigns to that variable
jmitc91516 1:a5258871b33d 934 if(strcmp(GuiVar_columnDHAutoCalibCurrentRes, "99.99") == 0) {
jmitc91516 1:a5258871b33d 935 SetEasyGUICalibrationPointResistanceFromInternalValue();
jmitc91516 1:a5258871b33d 936 }
jmitc91516 1:a5258871b33d 937 }
jmitc91516 1:a5258871b33d 938
jmitc91516 1:a5258871b33d 939
jmitc91516 1:a5258871b33d 940 /*
jmitc91516 1:a5258871b33d 941 Gets the current stabilisation time from the GC, returns it as an integer
jmitc91516 1:a5258871b33d 942
jmitc91516 1:a5258871b33d 943 No arguments
jmitc91516 1:a5258871b33d 944
jmitc91516 1:a5258871b33d 945 Return value: the stabilisation time obtained from the GC, or -1 if this failed
jmitc91516 1:a5258871b33d 946 */
jmitc91516 1:a5258871b33d 947 int ColumnDHAutoCalibrationPageHandler::GetStabilisationTimeFromGC(void)
jmitc91516 1:a5258871b33d 948 {
jmitc91516 1:a5258871b33d 949 char response[30];
jmitc91516 1:a5258871b33d 950
jmitc91516 1:a5258871b33d 951 SendCommandToGCAndGetResponse("GCST", response);
jmitc91516 1:a5258871b33d 952
jmitc91516 1:a5258871b33d 953 // We expect a response like "DCST00nn", where "nn" is the stabilisation time
jmitc91516 1:a5258871b33d 954 // in minutes, 0 to 99
jmitc91516 1:a5258871b33d 955 if(response[0] != 'D') {
jmitc91516 1:a5258871b33d 956 return -1;
jmitc91516 1:a5258871b33d 957 }
jmitc91516 1:a5258871b33d 958
jmitc91516 1:a5258871b33d 959 if(response[1] != 'C') {
jmitc91516 1:a5258871b33d 960 return -1;
jmitc91516 1:a5258871b33d 961 }
jmitc91516 1:a5258871b33d 962
jmitc91516 1:a5258871b33d 963 if(response[2] != 'S') {
jmitc91516 1:a5258871b33d 964 return -1;
jmitc91516 1:a5258871b33d 965 }
jmitc91516 1:a5258871b33d 966
jmitc91516 1:a5258871b33d 967 if(response[3] != 'T') {
jmitc91516 1:a5258871b33d 968 return -1;
jmitc91516 1:a5258871b33d 969 }
jmitc91516 1:a5258871b33d 970
jmitc91516 1:a5258871b33d 971 if(response[4] != '0') {
jmitc91516 1:a5258871b33d 972 return -1;
jmitc91516 1:a5258871b33d 973 }
jmitc91516 1:a5258871b33d 974
jmitc91516 1:a5258871b33d 975 if(response[5] != '0') {
jmitc91516 1:a5258871b33d 976 return -1;
jmitc91516 1:a5258871b33d 977 }
jmitc91516 1:a5258871b33d 978
jmitc91516 1:a5258871b33d 979 int retVal;
jmitc91516 1:a5258871b33d 980 sscanf(&response[6], "%d", &retVal);
jmitc91516 1:a5258871b33d 981 return retVal;
jmitc91516 1:a5258871b33d 982 }
jmitc91516 1:a5258871b33d 983
jmitc91516 1:a5258871b33d 984
jmitc91516 1:a5258871b33d 985 /*
jmitc91516 1:a5258871b33d 986 Sets the current stabilisation time in the GC from the integer value passed to it
jmitc91516 1:a5258871b33d 987
jmitc91516 1:a5258871b33d 988 Argument: the new value for the stabilisation time, in (whole) minutes
jmitc91516 1:a5258871b33d 989
jmitc91516 1:a5258871b33d 990 Returns true if the GC responded with "DACK", false if anything else
jmitc91516 1:a5258871b33d 991 */
jmitc91516 1:a5258871b33d 992 bool ColumnDHAutoCalibrationPageHandler::SetStabilisationTimeInGC(int value)
jmitc91516 1:a5258871b33d 993 {
jmitc91516 1:a5258871b33d 994 char commandBuffer[30];
jmitc91516 1:a5258871b33d 995
jmitc91516 1:a5258871b33d 996 sprintf(commandBuffer, "SCST%04d", value);
jmitc91516 1:a5258871b33d 997
jmitc91516 1:a5258871b33d 998 return SendCommandToGCWithDACKResponse(commandBuffer);
jmitc91516 1:a5258871b33d 999 }
jmitc91516 1:a5258871b33d 1000
jmitc91516 1:a5258871b33d 1001
jmitc91516 1:a5258871b33d 1002 /*
jmitc91516 1:a5258871b33d 1003 Gets and returns the temperature value for the specified calibration point.
jmitc91516 1:a5258871b33d 1004
jmitc91516 1:a5258871b33d 1005 Argument: the index of the required calibration point (1, 2 or 3)
jmitc91516 1:a5258871b33d 1006
jmitc91516 1:a5258871b33d 1007 Return code: the corresponding temperature value, as a floating point value
jmitc91516 1:a5258871b33d 1008 (the temperature is returned in units of 1/10 ohm)
jmitc91516 1:a5258871b33d 1009 */
jmitc91516 1:a5258871b33d 1010 float ColumnDHAutoCalibrationPageHandler::GetColumnTemperaturePointFromGC(int pointIndex)
jmitc91516 1:a5258871b33d 1011 {
jmitc91516 1:a5258871b33d 1012 char commandBuffer[30];
jmitc91516 1:a5258871b33d 1013
jmitc91516 1:a5258871b33d 1014 commandBuffer[0] = 'G';
jmitc91516 1:a5258871b33d 1015 commandBuffer[1] = 'C';
jmitc91516 1:a5258871b33d 1016 commandBuffer[2] = 'T';
jmitc91516 1:a5258871b33d 1017
jmitc91516 1:a5258871b33d 1018 switch(pointIndex) {
jmitc91516 1:a5258871b33d 1019 case 2:
jmitc91516 1:a5258871b33d 1020 commandBuffer[3] = '2';
jmitc91516 1:a5258871b33d 1021 break;
jmitc91516 1:a5258871b33d 1022 case 3:
jmitc91516 1:a5258871b33d 1023 commandBuffer[3] = '3';
jmitc91516 1:a5258871b33d 1024 break;
jmitc91516 1:a5258871b33d 1025 default: // Assume 1
jmitc91516 1:a5258871b33d 1026 commandBuffer[3] = '1';
jmitc91516 1:a5258871b33d 1027 break;
jmitc91516 1:a5258871b33d 1028
jmitc91516 1:a5258871b33d 1029 }
jmitc91516 1:a5258871b33d 1030 commandBuffer[4] = '\0';
jmitc91516 1:a5258871b33d 1031
jmitc91516 1:a5258871b33d 1032 char response[30];
jmitc91516 1:a5258871b33d 1033 SendCommandToGCAndGetResponse(commandBuffer, response);
jmitc91516 1:a5258871b33d 1034
jmitc91516 1:a5258871b33d 1035 // We expect a response like "DCRnrrrr", where 'n' is the point index
jmitc91516 1:a5258871b33d 1036 // and "rrrr" is the resistance in ohms multiplied by 100
jmitc91516 1:a5258871b33d 1037 if(response[0] != 'D') {
jmitc91516 1:a5258871b33d 1038 return -1.0f;
jmitc91516 1:a5258871b33d 1039 }
jmitc91516 1:a5258871b33d 1040
jmitc91516 1:a5258871b33d 1041 if(response[1] != 'C') {
jmitc91516 1:a5258871b33d 1042 return -1.0f;
jmitc91516 1:a5258871b33d 1043 }
jmitc91516 1:a5258871b33d 1044
jmitc91516 1:a5258871b33d 1045 if(response[2] != 'T') {
jmitc91516 1:a5258871b33d 1046 return -1.0f;
jmitc91516 1:a5258871b33d 1047 }
jmitc91516 1:a5258871b33d 1048
jmitc91516 1:a5258871b33d 1049 if(response[3] != commandBuffer[3]) {
jmitc91516 1:a5258871b33d 1050 return -1.0f;
jmitc91516 1:a5258871b33d 1051 }
jmitc91516 1:a5258871b33d 1052
jmitc91516 1:a5258871b33d 1053 int temp;
jmitc91516 1:a5258871b33d 1054 sscanf(&response[4], "%d", &temp);
jmitc91516 1:a5258871b33d 1055
jmitc91516 1:a5258871b33d 1056 float retVal = (float) temp;
jmitc91516 1:a5258871b33d 1057 retVal /= 10.0f;
jmitc91516 1:a5258871b33d 1058 return retVal;
jmitc91516 1:a5258871b33d 1059 }
jmitc91516 1:a5258871b33d 1060
jmitc91516 1:a5258871b33d 1061 /*
jmitc91516 1:a5258871b33d 1062 Sets the temperature value for the specified calibration point.
jmitc91516 1:a5258871b33d 1063
jmitc91516 1:a5258871b33d 1064 Arguments: the index of the required calibration point (1, 2 or 3)
jmitc91516 1:a5258871b33d 1065 the temperature value to set (deg C)
jmitc91516 1:a5258871b33d 1066
jmitc91516 1:a5258871b33d 1067 No return code
jmitc91516 1:a5258871b33d 1068 */
jmitc91516 1:a5258871b33d 1069 void ColumnDHAutoCalibrationPageHandler::SetColumnTemperaturePointInGC(int pointIndex, float temperatureToSet)
jmitc91516 1:a5258871b33d 1070 {
jmitc91516 1:a5258871b33d 1071 char commandBuffer[30];
jmitc91516 1:a5258871b33d 1072
jmitc91516 1:a5258871b33d 1073 commandBuffer[0] = 'S';
jmitc91516 1:a5258871b33d 1074 commandBuffer[1] = 'C';
jmitc91516 1:a5258871b33d 1075 commandBuffer[2] = 'T';
jmitc91516 1:a5258871b33d 1076
jmitc91516 1:a5258871b33d 1077 switch(pointIndex) {
jmitc91516 1:a5258871b33d 1078 case 2:
jmitc91516 1:a5258871b33d 1079 commandBuffer[3] = '2';
jmitc91516 1:a5258871b33d 1080 break;
jmitc91516 1:a5258871b33d 1081 case 3:
jmitc91516 1:a5258871b33d 1082 commandBuffer[3] = '3';
jmitc91516 1:a5258871b33d 1083 break;
jmitc91516 1:a5258871b33d 1084 default: // Assume 1
jmitc91516 1:a5258871b33d 1085 commandBuffer[3] = '1';
jmitc91516 1:a5258871b33d 1086 break;
jmitc91516 1:a5258871b33d 1087
jmitc91516 1:a5258871b33d 1088 }
jmitc91516 1:a5258871b33d 1089
jmitc91516 1:a5258871b33d 1090 // Value is sent in units of 1/10 deg C
jmitc91516 1:a5258871b33d 1091 double dTemp = (double) temperatureToSet * 10.0;
jmitc91516 1:a5258871b33d 1092 int valueToSend = (int) floor(dTemp + 0.5);
jmitc91516 1:a5258871b33d 1093 sprintf(&commandBuffer[4], "%04d", valueToSend);
jmitc91516 1:a5258871b33d 1094
jmitc91516 1:a5258871b33d 1095 commandBuffer[8] = '\0';
jmitc91516 1:a5258871b33d 1096
jmitc91516 1:a5258871b33d 1097 char response[30];
jmitc91516 1:a5258871b33d 1098 SendCommandToGCAndGetResponse(commandBuffer, response);
jmitc91516 1:a5258871b33d 1099 }
jmitc91516 1:a5258871b33d 1100
jmitc91516 1:a5258871b33d 1101
jmitc91516 1:a5258871b33d 1102 /*
jmitc91516 1:a5258871b33d 1103 Gets and returns the resistance value for the specified calibration point.
jmitc91516 1:a5258871b33d 1104
jmitc91516 1:a5258871b33d 1105 Argument: the index of the required calibration point (1, 2 or 3)
jmitc91516 1:a5258871b33d 1106
jmitc91516 1:a5258871b33d 1107 Return code: the corresponding resistance value, as a floating point value
jmitc91516 1:a5258871b33d 1108 (the resistance is returned in units of 1/100 ohm)
jmitc91516 1:a5258871b33d 1109 */
jmitc91516 1:a5258871b33d 1110 float ColumnDHAutoCalibrationPageHandler::GetColumnResistancePointFromGC(int pointIndex)
jmitc91516 1:a5258871b33d 1111 {
jmitc91516 1:a5258871b33d 1112 char commandBuffer[30];
jmitc91516 1:a5258871b33d 1113
jmitc91516 1:a5258871b33d 1114 commandBuffer[0] = 'G';
jmitc91516 1:a5258871b33d 1115 commandBuffer[1] = 'C';
jmitc91516 1:a5258871b33d 1116 commandBuffer[2] = 'R';
jmitc91516 1:a5258871b33d 1117
jmitc91516 1:a5258871b33d 1118 switch(pointIndex) {
jmitc91516 1:a5258871b33d 1119 case 2:
jmitc91516 1:a5258871b33d 1120 commandBuffer[3] = '2';
jmitc91516 1:a5258871b33d 1121 break;
jmitc91516 1:a5258871b33d 1122 case 3:
jmitc91516 1:a5258871b33d 1123 commandBuffer[3] = '3';
jmitc91516 1:a5258871b33d 1124 break;
jmitc91516 1:a5258871b33d 1125 default: // Assume 1
jmitc91516 1:a5258871b33d 1126 commandBuffer[3] = '1';
jmitc91516 1:a5258871b33d 1127 break;
jmitc91516 1:a5258871b33d 1128
jmitc91516 1:a5258871b33d 1129 }
jmitc91516 1:a5258871b33d 1130 commandBuffer[4] = '\0';
jmitc91516 1:a5258871b33d 1131
jmitc91516 1:a5258871b33d 1132 char response[30];
jmitc91516 1:a5258871b33d 1133 SendCommandToGCAndGetResponse(commandBuffer, response);
jmitc91516 1:a5258871b33d 1134
jmitc91516 1:a5258871b33d 1135 // We expect a response like "DCRnrrrr", where 'n' is the point index
jmitc91516 1:a5258871b33d 1136 // and "rrrr" is the resistance in ohms multiplied by 100
jmitc91516 1:a5258871b33d 1137 if(response[0] != 'D') {
jmitc91516 1:a5258871b33d 1138 return -1.0f;
jmitc91516 1:a5258871b33d 1139 }
jmitc91516 1:a5258871b33d 1140
jmitc91516 1:a5258871b33d 1141 if(response[1] != 'C') {
jmitc91516 1:a5258871b33d 1142 return -1.0f;
jmitc91516 1:a5258871b33d 1143 }
jmitc91516 1:a5258871b33d 1144
jmitc91516 1:a5258871b33d 1145 if(response[2] != 'R') {
jmitc91516 1:a5258871b33d 1146 return -1.0f;
jmitc91516 1:a5258871b33d 1147 }
jmitc91516 1:a5258871b33d 1148
jmitc91516 1:a5258871b33d 1149 if(response[3] != commandBuffer[3]) {
jmitc91516 1:a5258871b33d 1150 return -1.0f;
jmitc91516 1:a5258871b33d 1151 }
jmitc91516 1:a5258871b33d 1152
jmitc91516 1:a5258871b33d 1153 int temp;
jmitc91516 1:a5258871b33d 1154 sscanf(&response[4], "%d", &temp);
jmitc91516 1:a5258871b33d 1155
jmitc91516 1:a5258871b33d 1156 float retVal = (float) temp;
jmitc91516 1:a5258871b33d 1157 retVal /= 100.0f;
jmitc91516 1:a5258871b33d 1158 return retVal;
jmitc91516 1:a5258871b33d 1159 }
jmitc91516 1:a5258871b33d 1160
jmitc91516 1:a5258871b33d 1161 /*
jmitc91516 1:a5258871b33d 1162 Sets the resistance value for the specified calibration point.
jmitc91516 1:a5258871b33d 1163
jmitc91516 1:a5258871b33d 1164 Arguments: the index of the required calibration point (1, 2 or 3)
jmitc91516 1:a5258871b33d 1165 the corresponding resistance value (in ohms)
jmitc91516 1:a5258871b33d 1166
jmitc91516 1:a5258871b33d 1167 No return code
jmitc91516 1:a5258871b33d 1168 */
jmitc91516 1:a5258871b33d 1169 void ColumnDHAutoCalibrationPageHandler::SetColumnResistancePointInGC(int pointIndex, float resistanceToSet)
jmitc91516 1:a5258871b33d 1170 {
jmitc91516 1:a5258871b33d 1171 char commandBuffer[30];
jmitc91516 1:a5258871b33d 1172
jmitc91516 1:a5258871b33d 1173 commandBuffer[0] = 'S';
jmitc91516 1:a5258871b33d 1174 commandBuffer[1] = 'C';
jmitc91516 1:a5258871b33d 1175 commandBuffer[2] = 'R';
jmitc91516 1:a5258871b33d 1176
jmitc91516 1:a5258871b33d 1177 switch(pointIndex) {
jmitc91516 1:a5258871b33d 1178 case 2:
jmitc91516 1:a5258871b33d 1179 commandBuffer[3] = '2';
jmitc91516 1:a5258871b33d 1180 break;
jmitc91516 1:a5258871b33d 1181 case 3:
jmitc91516 1:a5258871b33d 1182 commandBuffer[3] = '3';
jmitc91516 1:a5258871b33d 1183 break;
jmitc91516 1:a5258871b33d 1184 default: // Assume 1
jmitc91516 1:a5258871b33d 1185 commandBuffer[3] = '1';
jmitc91516 1:a5258871b33d 1186 break;
jmitc91516 1:a5258871b33d 1187
jmitc91516 1:a5258871b33d 1188 }
jmitc91516 1:a5258871b33d 1189
jmitc91516 1:a5258871b33d 1190 // Value is sent in units of 1/100 deg C
jmitc91516 1:a5258871b33d 1191 double dTemp = (double) resistanceToSet * 100.0;
jmitc91516 1:a5258871b33d 1192 int valueToSend = (int) floor(dTemp + 0.5);
jmitc91516 1:a5258871b33d 1193 sprintf(&commandBuffer[4], "%04d", valueToSend);
jmitc91516 1:a5258871b33d 1194
jmitc91516 1:a5258871b33d 1195 commandBuffer[8] = '\0';
jmitc91516 1:a5258871b33d 1196
jmitc91516 1:a5258871b33d 1197
jmitc91516 1:a5258871b33d 1198 char response[30];
jmitc91516 1:a5258871b33d 1199 SendCommandToGCAndGetResponse(commandBuffer, response);
jmitc91516 1:a5258871b33d 1200 }
jmitc91516 1:a5258871b33d 1201
jmitc91516 1:a5258871b33d 1202
jmitc91516 1:a5258871b33d 1203 /*
jmitc91516 1:a5258871b33d 1204 Gets and returns the actual resistance of the directly heated column.
jmitc91516 1:a5258871b33d 1205 Note that this will only be valid during and after calibration stage 3.
jmitc91516 1:a5258871b33d 1206
jmitc91516 1:a5258871b33d 1207 No arguments
jmitc91516 1:a5258871b33d 1208
jmitc91516 1:a5258871b33d 1209 Return code: the column resistance, as a floating point value
jmitc91516 1:a5258871b33d 1210 (the resistance is returned in units of 1/100 ohm)
jmitc91516 1:a5258871b33d 1211 */
jmitc91516 1:a5258871b33d 1212 float ColumnDHAutoCalibrationPageHandler::GetActualColumnResistanceFromGC(void)
jmitc91516 1:a5258871b33d 1213 {
jmitc91516 1:a5258871b33d 1214 char commandBuffer[30];
jmitc91516 1:a5258871b33d 1215
jmitc91516 1:a5258871b33d 1216 commandBuffer[0] = 'Q';
jmitc91516 1:a5258871b33d 1217 commandBuffer[1] = 'D';
jmitc91516 1:a5258871b33d 1218 commandBuffer[2] = 'C';
jmitc91516 1:a5258871b33d 1219 commandBuffer[3] = 'R';
jmitc91516 1:a5258871b33d 1220
jmitc91516 1:a5258871b33d 1221 commandBuffer[4] = '\0';
jmitc91516 1:a5258871b33d 1222
jmitc91516 1:a5258871b33d 1223
jmitc91516 1:a5258871b33d 1224 char response[30];
jmitc91516 1:a5258871b33d 1225 SendCommandToGCAndGetResponse(commandBuffer, response);
jmitc91516 1:a5258871b33d 1226
jmitc91516 1:a5258871b33d 1227 // We expect a response like "DDCrrrrr", where "rrrrr" (note 5 digits, not 4)
jmitc91516 1:a5258871b33d 1228 // is the resistance in ohms multiplied by 100
jmitc91516 1:a5258871b33d 1229 if(response[0] != 'D') {
jmitc91516 1:a5258871b33d 1230 return -1.0f;
jmitc91516 1:a5258871b33d 1231 }
jmitc91516 1:a5258871b33d 1232
jmitc91516 1:a5258871b33d 1233 if(response[1] != 'D') {
jmitc91516 1:a5258871b33d 1234 return -1.0f;
jmitc91516 1:a5258871b33d 1235 }
jmitc91516 1:a5258871b33d 1236
jmitc91516 1:a5258871b33d 1237 if(response[2] != 'C') {
jmitc91516 1:a5258871b33d 1238 return -1.0f;
jmitc91516 1:a5258871b33d 1239 }
jmitc91516 1:a5258871b33d 1240
jmitc91516 1:a5258871b33d 1241 int temp;
jmitc91516 1:a5258871b33d 1242 sscanf(&response[3], "%d", &temp);
jmitc91516 1:a5258871b33d 1243
jmitc91516 1:a5258871b33d 1244 float retVal = (float) temp;
jmitc91516 1:a5258871b33d 1245 retVal /= 100.0f;
jmitc91516 1:a5258871b33d 1246 return retVal;
jmitc91516 1:a5258871b33d 1247 }
jmitc91516 1:a5258871b33d 1248
jmitc91516 1:a5258871b33d 1249
jmitc91516 1:a5258871b33d 1250 /*
jmitc91516 1:a5258871b33d 1251 Sends a "CCSM" command to the GC, to tell it to start the process of measuring the column resistance.
jmitc91516 1:a5258871b33d 1252 *** We cannot request the resistance value until at least two seconds after this. ***
jmitc91516 1:a5258871b33d 1253
jmitc91516 1:a5258871b33d 1254 No arguments.
jmitc91516 1:a5258871b33d 1255
jmitc91516 1:a5258871b33d 1256 Returns true if the command succeeded ("DACK" response), false if not.
jmitc91516 1:a5258871b33d 1257 */
jmitc91516 1:a5258871b33d 1258 bool ColumnDHAutoCalibrationPageHandler::TellGCToMeasureColumnResistance(void)
jmitc91516 1:a5258871b33d 1259 {
jmitc91516 1:a5258871b33d 1260 char commandBuffer[20];
jmitc91516 1:a5258871b33d 1261
jmitc91516 1:a5258871b33d 1262 commandBuffer[0] = 'C';
jmitc91516 1:a5258871b33d 1263 commandBuffer[1] = 'C';
jmitc91516 1:a5258871b33d 1264 commandBuffer[2] = 'S';
jmitc91516 1:a5258871b33d 1265 commandBuffer[3] = 'M';
jmitc91516 1:a5258871b33d 1266 commandBuffer[4] = '\0';
jmitc91516 1:a5258871b33d 1267
jmitc91516 1:a5258871b33d 1268 return SendCommandToGCWithDACKResponse(commandBuffer);
jmitc91516 1:a5258871b33d 1269 }
jmitc91516 1:a5258871b33d 1270
jmitc91516 1:a5258871b33d 1271
jmitc91516 1:a5258871b33d 1272 #ifndef USE_STABILISATION_TIMER
jmitc91516 1:a5258871b33d 1273 /*
jmitc91516 1:a5258871b33d 1274 Gets the GC run time, and returns it as a floating point value.
jmitc91516 1:a5258871b33d 1275 Note that the GC returns the run time as a four digit value,
jmitc91516 1:a5258871b33d 1276 scaled in units of 0.1 min. This function applies that scaling
jmitc91516 1:a5258871b33d 1277 to the value it returns - i.e. if the GC returns "1234",
jmitc91516 1:a5258871b33d 1278 this function returns 123.4 as the float value.
jmitc91516 1:a5258871b33d 1279
jmitc91516 1:a5258871b33d 1280 Returns the time obtained from the GC, or -1 if this failed
jmitc91516 1:a5258871b33d 1281 */
jmitc91516 1:a5258871b33d 1282 float ColumnDHAutoCalibrationPageHandler::GetTimeFromGC(void)
jmitc91516 1:a5258871b33d 1283 {
jmitc91516 1:a5258871b33d 1284 char response[50];
jmitc91516 1:a5258871b33d 1285 SendCommandToGCAndGetResponse("QTIM", response);
jmitc91516 1:a5258871b33d 1286
jmitc91516 1:a5258871b33d 1287 if(response[0] == 'E') {
jmitc91516 1:a5258871b33d 1288 // Got "EPKT" response
jmitc91516 1:a5258871b33d 1289 return -1.0f;
jmitc91516 1:a5258871b33d 1290 }
jmitc91516 1:a5258871b33d 1291
jmitc91516 1:a5258871b33d 1292 // Assume we have received a valid response from the GC. We expect a response like this:
jmitc91516 1:a5258871b33d 1293 // "DTIM1234", with run time in units of 0.1 min
jmitc91516 1:a5258871b33d 1294 char buff[10];
jmitc91516 1:a5258871b33d 1295 buff[0] = response[4];
jmitc91516 1:a5258871b33d 1296 buff[1] = response[5];
jmitc91516 1:a5258871b33d 1297 buff[2] = response[6];
jmitc91516 1:a5258871b33d 1298 buff[3] = '.';
jmitc91516 1:a5258871b33d 1299 buff[4] = response[7];
jmitc91516 1:a5258871b33d 1300 buff[5] = '\0';
jmitc91516 1:a5258871b33d 1301
jmitc91516 1:a5258871b33d 1302 float gcTime;
jmitc91516 1:a5258871b33d 1303 sscanf(buff, "%f", &gcTime);
jmitc91516 1:a5258871b33d 1304
jmitc91516 1:a5258871b33d 1305 return gcTime;
jmitc91516 1:a5258871b33d 1306 }
jmitc91516 1:a5258871b33d 1307 #endif
jmitc91516 1:a5258871b33d 1308
jmitc91516 1:a5258871b33d 1309
jmitc91516 1:a5258871b33d 1310 /*
jmitc91516 1:a5258871b33d 1311 Displays the 'getting column resistance' page.
jmitc91516 1:a5258871b33d 1312
jmitc91516 1:a5258871b33d 1313 At this point, we have issued the "CCSM" command to the GC, to start the process
jmitc91516 1:a5258871b33d 1314 of getting the column resistance. We have to wait two seconds before we can get
jmitc91516 1:a5258871b33d 1315 the resistance value. We display this page during those two seconds, to make it clear
jmitc91516 1:a5258871b33d 1316 to the user that we cannot do anything else during that time.
jmitc91516 1:a5258871b33d 1317
jmitc91516 1:a5258871b33d 1318 After getting the resistance, call 'RedisplayColumnCalibrationPage'.
jmitc91516 1:a5258871b33d 1319
jmitc91516 1:a5258871b33d 1320 No args, no return code.
jmitc91516 1:a5258871b33d 1321 */
jmitc91516 1:a5258871b33d 1322 void ColumnDHAutoCalibrationPageHandler::DisplayGettingColumnResistancePage(void)
jmitc91516 1:a5258871b33d 1323 {
jmitc91516 1:a5258871b33d 1324 #ifdef USING_BACKGROUND_BITMAP
jmitc91516 1:a5258871b33d 1325 DrawBackgroundBitmap();
jmitc91516 1:a5258871b33d 1326 #else
jmitc91516 1:a5258871b33d 1327 GuiLib_Clear();
jmitc91516 1:a5258871b33d 1328 #endif
jmitc91516 1:a5258871b33d 1329
jmitc91516 1:a5258871b33d 1330 GuiLib_ShowScreen(GuiStruct_GettingColumnResistancePage_Def, GuiLib_NO_CURSOR, GuiLib_RESET_AUTO_REDRAW);
jmitc91516 1:a5258871b33d 1331
jmitc91516 1:a5258871b33d 1332 GuiLib_Refresh();
jmitc91516 1:a5258871b33d 1333 }
jmitc91516 1:a5258871b33d 1334
jmitc91516 1:a5258871b33d 1335
jmitc91516 1:a5258871b33d 1336 /*
jmitc91516 1:a5258871b33d 1337 After issuing the "CCSM" command, we display the 'getting column resistance' page,
jmitc91516 1:a5258871b33d 1338 wait two seconds, then get the column resistance. During this period, we display the
jmitc91516 1:a5258871b33d 1339 "Getting Column Resistance" page. After this, we redisplay our normal page,
jmitc91516 1:a5258871b33d 1340 by calling this function.
jmitc91516 1:a5258871b33d 1341
jmitc91516 1:a5258871b33d 1342 This function currently contains only a single function call. It is implemented
jmitc91516 1:a5258871b33d 1343 for clarity in the code - and in case we decide something more complicated
jmitc91516 1:a5258871b33d 1344 is required in future.
jmitc91516 1:a5258871b33d 1345
jmitc91516 1:a5258871b33d 1346 No args, no return code.
jmitc91516 1:a5258871b33d 1347 */
jmitc91516 1:a5258871b33d 1348 void ColumnDHAutoCalibrationPageHandler::RedisplayColumnCalibrationPage(void)
jmitc91516 1:a5258871b33d 1349 {
jmitc91516 1:a5258871b33d 1350 UpdateVolatileEasyGUIVariables();
jmitc91516 1:a5258871b33d 1351
jmitc91516 1:a5258871b33d 1352 UpdateEasyGUIPage();
jmitc91516 1:a5258871b33d 1353 }
jmitc91516 1:a5258871b33d 1354