Repository for import to local machine
Dependencies: DMBasicGUI DMSupport
GasCalibrationPageHandler.cpp@1:a5258871b33d, 2017-07-20 (annotated)
- Committer:
- jmitc91516
- Date:
- Thu Jul 20 08:42:29 2017 +0000
- Revision:
- 1:a5258871b33d
Version before re-layout (July 2017). Also for mbed CLI import to local machine.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jmitc91516 | 1:a5258871b33d | 1 | #include "GasCalibrationPageHandler.h" |
jmitc91516 | 1:a5258871b33d | 2 | #include "EasyGUITouchAreaIndices.h" |
jmitc91516 | 1:a5258871b33d | 3 | #include "SettingsHandler.h" |
jmitc91516 | 1:a5258871b33d | 4 | #include "GetGCStatusLoop.h" |
jmitc91516 | 1:a5258871b33d | 5 | #include "NumericKeypadPageHandler.h" |
jmitc91516 | 1:a5258871b33d | 6 | |
jmitc91516 | 1:a5258871b33d | 7 | #include <stdio.h> |
jmitc91516 | 1:a5258871b33d | 8 | #include <stdlib.h> |
jmitc91516 | 1:a5258871b33d | 9 | |
jmitc91516 | 1:a5258871b33d | 10 | |
jmitc91516 | 1:a5258871b33d | 11 | |
jmitc91516 | 1:a5258871b33d | 12 | /* |
jmitc91516 | 1:a5258871b33d | 13 | Displays the specified easyGUI 'structure' (or page, to use a more easily understood term). |
jmitc91516 | 1:a5258871b33d | 14 | Defined in main.cpp |
jmitc91516 | 1:a5258871b33d | 15 | */ |
jmitc91516 | 1:a5258871b33d | 16 | extern void DisplayEasyGuiStructure(int structureIndex, USBDeviceConnected* usbDevice, USBHostGC* usbHostGC, bool updateEasyGUIVariables = true); |
jmitc91516 | 1:a5258871b33d | 17 | |
jmitc91516 | 1:a5258871b33d | 18 | |
jmitc91516 | 1:a5258871b33d | 19 | /* |
jmitc91516 | 1:a5258871b33d | 20 | Converts three eight-bit colour values to the corresponding 16-bit RGB565 value. |
jmitc91516 | 1:a5258871b33d | 21 | Defined in main.cpp |
jmitc91516 | 1:a5258871b33d | 22 | */ |
jmitc91516 | 1:a5258871b33d | 23 | GuiConst_INTCOLOR SixteenBitColorValue(GuiConst_INT8U red, GuiConst_INT8U green, GuiConst_INT8U blue); |
jmitc91516 | 1:a5258871b33d | 24 | |
jmitc91516 | 1:a5258871b33d | 25 | /* |
jmitc91516 | 1:a5258871b33d | 26 | We distinguish the 'active' field - i.e. the one being edited by the user - |
jmitc91516 | 1:a5258871b33d | 27 | from the inactive fields, by its background colour |
jmitc91516 | 1:a5258871b33d | 28 | */ |
jmitc91516 | 1:a5258871b33d | 29 | #define EXPERIMENTING_WITH_COLORS |
jmitc91516 | 1:a5258871b33d | 30 | const GuiConst_INTCOLOR GasCalibrationPageHandler::inactiveFieldBackgroundColour = SixteenBitColorValue(192, 192, 192); // Grey |
jmitc91516 | 1:a5258871b33d | 31 | #ifdef EXPERIMENTING_WITH_COLORS |
jmitc91516 | 1:a5258871b33d | 32 | const GuiConst_INTCOLOR GasCalibrationPageHandler::activeFieldBackgroundColour = SixteenBitColorValue(255, 255, 0); // Yellow |
jmitc91516 | 1:a5258871b33d | 33 | #else |
jmitc91516 | 1:a5258871b33d | 34 | const GuiConst_INTCOLOR GasCalibrationPageHandler::activeFieldBackgroundColour = SixteenBitColorValue(255, 255, 255); // White |
jmitc91516 | 1:a5258871b33d | 35 | #endif // EXPERIMENTING_WITH_COLORS |
jmitc91516 | 1:a5258871b33d | 36 | |
jmitc91516 | 1:a5258871b33d | 37 | |
jmitc91516 | 1:a5258871b33d | 38 | /* |
jmitc91516 | 1:a5258871b33d | 39 | 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 | 40 | (we do not want multiple values for the carrier gas selection, etc, and nor will we show |
jmitc91516 | 1:a5258871b33d | 41 | more than one easyGUI 'GasCalibrationPage' to the user at the same time). |
jmitc91516 | 1:a5258871b33d | 42 | */ |
jmitc91516 | 1:a5258871b33d | 43 | GasCalibrationPageHandler * GasCalibrationPageHandler::theGasCalibrationPageHandlerInstance = NULL; |
jmitc91516 | 1:a5258871b33d | 44 | |
jmitc91516 | 1:a5258871b33d | 45 | |
jmitc91516 | 1:a5258871b33d | 46 | /* |
jmitc91516 | 1:a5258871b33d | 47 | Singleton class - return the one and only instance, first creating it if necessary. |
jmitc91516 | 1:a5258871b33d | 48 | */ |
jmitc91516 | 1:a5258871b33d | 49 | GasCalibrationPageHandler * GasCalibrationPageHandler::GetInstance(USBDeviceConnected* newUsbDevice, USBHostGC* newUsbHostGC) |
jmitc91516 | 1:a5258871b33d | 50 | { |
jmitc91516 | 1:a5258871b33d | 51 | if (theGasCalibrationPageHandlerInstance == NULL) { |
jmitc91516 | 1:a5258871b33d | 52 | theGasCalibrationPageHandlerInstance = new GasCalibrationPageHandler(newUsbDevice, newUsbHostGC); |
jmitc91516 | 1:a5258871b33d | 53 | } |
jmitc91516 | 1:a5258871b33d | 54 | |
jmitc91516 | 1:a5258871b33d | 55 | return theGasCalibrationPageHandlerInstance; |
jmitc91516 | 1:a5258871b33d | 56 | } |
jmitc91516 | 1:a5258871b33d | 57 | |
jmitc91516 | 1:a5258871b33d | 58 | // Singleton class - private constructor |
jmitc91516 | 1:a5258871b33d | 59 | GasCalibrationPageHandler::GasCalibrationPageHandler(USBDeviceConnected* newUsbDevice, USBHostGC* newUsbHostGC) |
jmitc91516 | 1:a5258871b33d | 60 | { |
jmitc91516 | 1:a5258871b33d | 61 | usbDevice = newUsbDevice; |
jmitc91516 | 1:a5258871b33d | 62 | usbHostGC = newUsbHostGC; |
jmitc91516 | 1:a5258871b33d | 63 | |
jmitc91516 | 1:a5258871b33d | 64 | |
jmitc91516 | 1:a5258871b33d | 65 | variablesForTouchArea[0].touchAreaIndex = GAS_CALIB_DAC_1_VALUE_EDIT; |
jmitc91516 | 1:a5258871b33d | 66 | variablesForTouchArea[0].easyGUIVariablePtr = GuiVar_gasCalibDAC1; |
jmitc91516 | 1:a5258871b33d | 67 | variablesForTouchArea[0].maxValue = 4095; |
jmitc91516 | 1:a5258871b33d | 68 | variablesForTouchArea[0].easyGUIBackgroundColorVariablePtr = &GuiVar_gasCalibDAC1BackgroundColour; |
jmitc91516 | 1:a5258871b33d | 69 | strcpy(variablesForTouchArea[0].variableName, "DAC value 1"); |
jmitc91516 | 1:a5258871b33d | 70 | |
jmitc91516 | 1:a5258871b33d | 71 | variablesForTouchArea[1].touchAreaIndex = GAS_CALIB_FLOW_1_VALUE_EDIT; |
jmitc91516 | 1:a5258871b33d | 72 | variablesForTouchArea[1].easyGUIVariablePtr = GuiVar_gasCalibFlow1; |
jmitc91516 | 1:a5258871b33d | 73 | variablesForTouchArea[1].maxValue = 500; |
jmitc91516 | 1:a5258871b33d | 74 | variablesForTouchArea[1].easyGUIBackgroundColorVariablePtr = &GuiVar_gasCalibFlow1BackgroundColour; |
jmitc91516 | 1:a5258871b33d | 75 | strcpy(variablesForTouchArea[1].variableName, "Flow value 1"); |
jmitc91516 | 1:a5258871b33d | 76 | |
jmitc91516 | 1:a5258871b33d | 77 | variablesForTouchArea[2].touchAreaIndex = GAS_CALIB_DAC_2_VALUE_EDIT; |
jmitc91516 | 1:a5258871b33d | 78 | variablesForTouchArea[2].easyGUIVariablePtr = GuiVar_gasCalibDAC2; |
jmitc91516 | 1:a5258871b33d | 79 | variablesForTouchArea[2].maxValue = 4095; |
jmitc91516 | 1:a5258871b33d | 80 | variablesForTouchArea[2].easyGUIBackgroundColorVariablePtr = &GuiVar_gasCalibDAC2BackgroundColour; |
jmitc91516 | 1:a5258871b33d | 81 | strcpy(variablesForTouchArea[2].variableName, "DAC value 2"); |
jmitc91516 | 1:a5258871b33d | 82 | |
jmitc91516 | 1:a5258871b33d | 83 | variablesForTouchArea[3].touchAreaIndex = GAS_CALIB_FLOW_2_VALUE_EDIT; |
jmitc91516 | 1:a5258871b33d | 84 | variablesForTouchArea[3].easyGUIVariablePtr = GuiVar_gasCalibFlow2; |
jmitc91516 | 1:a5258871b33d | 85 | variablesForTouchArea[3].maxValue = 500; |
jmitc91516 | 1:a5258871b33d | 86 | variablesForTouchArea[3].easyGUIBackgroundColorVariablePtr = &GuiVar_gasCalibFlow2BackgroundColour; |
jmitc91516 | 1:a5258871b33d | 87 | strcpy(variablesForTouchArea[3].variableName, "Flow value 2"); |
jmitc91516 | 1:a5258871b33d | 88 | |
jmitc91516 | 1:a5258871b33d | 89 | variablesForTouchArea[4].touchAreaIndex = GAS_CALIB_DAC_3_VALUE_EDIT; |
jmitc91516 | 1:a5258871b33d | 90 | variablesForTouchArea[4].easyGUIVariablePtr = GuiVar_gasCalibDAC3; |
jmitc91516 | 1:a5258871b33d | 91 | variablesForTouchArea[4].maxValue = 4095; |
jmitc91516 | 1:a5258871b33d | 92 | variablesForTouchArea[4].easyGUIBackgroundColorVariablePtr = &GuiVar_gasCalibDAC3BackgroundColour; |
jmitc91516 | 1:a5258871b33d | 93 | strcpy(variablesForTouchArea[4].variableName, "DAC value 3"); |
jmitc91516 | 1:a5258871b33d | 94 | |
jmitc91516 | 1:a5258871b33d | 95 | variablesForTouchArea[5].touchAreaIndex = GAS_CALIB_FLOW_3_VALUE_EDIT; |
jmitc91516 | 1:a5258871b33d | 96 | variablesForTouchArea[5].easyGUIVariablePtr = GuiVar_gasCalibFlow3; |
jmitc91516 | 1:a5258871b33d | 97 | variablesForTouchArea[5].maxValue = 500; |
jmitc91516 | 1:a5258871b33d | 98 | variablesForTouchArea[5].easyGUIBackgroundColorVariablePtr = &GuiVar_gasCalibFlow3BackgroundColour; |
jmitc91516 | 1:a5258871b33d | 99 | strcpy(variablesForTouchArea[5].variableName, "Flow value 3"); |
jmitc91516 | 1:a5258871b33d | 100 | |
jmitc91516 | 1:a5258871b33d | 101 | variablesForTouchArea[6].touchAreaIndex = GAS_CALIB_DAC_4_VALUE_EDIT; |
jmitc91516 | 1:a5258871b33d | 102 | variablesForTouchArea[6].easyGUIVariablePtr = GuiVar_gasCalibDAC4; |
jmitc91516 | 1:a5258871b33d | 103 | variablesForTouchArea[6].maxValue = 4095; |
jmitc91516 | 1:a5258871b33d | 104 | variablesForTouchArea[6].easyGUIBackgroundColorVariablePtr = &GuiVar_gasCalibDAC4BackgroundColour; |
jmitc91516 | 1:a5258871b33d | 105 | strcpy(variablesForTouchArea[6].variableName, "DAC value 4"); |
jmitc91516 | 1:a5258871b33d | 106 | |
jmitc91516 | 1:a5258871b33d | 107 | variablesForTouchArea[7].touchAreaIndex = GAS_CALIB_FLOW_4_VALUE_EDIT; |
jmitc91516 | 1:a5258871b33d | 108 | variablesForTouchArea[7].easyGUIVariablePtr = GuiVar_gasCalibFlow4; |
jmitc91516 | 1:a5258871b33d | 109 | variablesForTouchArea[7].maxValue = 500; |
jmitc91516 | 1:a5258871b33d | 110 | variablesForTouchArea[7].easyGUIBackgroundColorVariablePtr = &GuiVar_gasCalibFlow4BackgroundColour; |
jmitc91516 | 1:a5258871b33d | 111 | strcpy(variablesForTouchArea[7].variableName, "Flow value 4"); |
jmitc91516 | 1:a5258871b33d | 112 | |
jmitc91516 | 1:a5258871b33d | 113 | variablesForTouchArea[8].touchAreaIndex = GAS_CALIB_DAC_5_VALUE_EDIT; |
jmitc91516 | 1:a5258871b33d | 114 | variablesForTouchArea[8].easyGUIVariablePtr = GuiVar_gasCalibDAC5; |
jmitc91516 | 1:a5258871b33d | 115 | variablesForTouchArea[8].maxValue = 4095; |
jmitc91516 | 1:a5258871b33d | 116 | variablesForTouchArea[8].easyGUIBackgroundColorVariablePtr = &GuiVar_gasCalibDAC5BackgroundColour; |
jmitc91516 | 1:a5258871b33d | 117 | strcpy(variablesForTouchArea[8].variableName, "DAC value 5"); |
jmitc91516 | 1:a5258871b33d | 118 | |
jmitc91516 | 1:a5258871b33d | 119 | variablesForTouchArea[9].touchAreaIndex = GAS_CALIB_FLOW_5_VALUE_EDIT; |
jmitc91516 | 1:a5258871b33d | 120 | variablesForTouchArea[9].easyGUIVariablePtr = GuiVar_gasCalibFlow5; |
jmitc91516 | 1:a5258871b33d | 121 | variablesForTouchArea[9].maxValue = 500; |
jmitc91516 | 1:a5258871b33d | 122 | variablesForTouchArea[9].easyGUIBackgroundColorVariablePtr = &GuiVar_gasCalibFlow5BackgroundColour; |
jmitc91516 | 1:a5258871b33d | 123 | strcpy(variablesForTouchArea[9].variableName, "Flow value 5"); |
jmitc91516 | 1:a5258871b33d | 124 | |
jmitc91516 | 1:a5258871b33d | 125 | variablesForTouchArea[10].touchAreaIndex = GAS_CALIB_DAC_6_VALUE_EDIT; |
jmitc91516 | 1:a5258871b33d | 126 | variablesForTouchArea[10].easyGUIVariablePtr = GuiVar_gasCalibDAC6; |
jmitc91516 | 1:a5258871b33d | 127 | variablesForTouchArea[10].maxValue = 4095; |
jmitc91516 | 1:a5258871b33d | 128 | variablesForTouchArea[10].easyGUIBackgroundColorVariablePtr = &GuiVar_gasCalibDAC6BackgroundColour; |
jmitc91516 | 1:a5258871b33d | 129 | strcpy(variablesForTouchArea[10].variableName, "DAC value 6"); |
jmitc91516 | 1:a5258871b33d | 130 | |
jmitc91516 | 1:a5258871b33d | 131 | variablesForTouchArea[11].touchAreaIndex = GAS_CALIB_FLOW_6_VALUE_EDIT; |
jmitc91516 | 1:a5258871b33d | 132 | variablesForTouchArea[11].easyGUIVariablePtr = GuiVar_gasCalibFlow6; |
jmitc91516 | 1:a5258871b33d | 133 | variablesForTouchArea[11].maxValue = 500; |
jmitc91516 | 1:a5258871b33d | 134 | variablesForTouchArea[11].easyGUIBackgroundColorVariablePtr = &GuiVar_gasCalibFlow6BackgroundColour; |
jmitc91516 | 1:a5258871b33d | 135 | strcpy(variablesForTouchArea[11].variableName, "Flow value 6"); |
jmitc91516 | 1:a5258871b33d | 136 | } |
jmitc91516 | 1:a5258871b33d | 137 | |
jmitc91516 | 1:a5258871b33d | 138 | // Private destructor also |
jmitc91516 | 1:a5258871b33d | 139 | GasCalibrationPageHandler::~GasCalibrationPageHandler() |
jmitc91516 | 1:a5258871b33d | 140 | { |
jmitc91516 | 1:a5258871b33d | 141 | //SaveCarrierGasSelectionToQSPISettings(); |
jmitc91516 | 1:a5258871b33d | 142 | } |
jmitc91516 | 1:a5258871b33d | 143 | |
jmitc91516 | 1:a5258871b33d | 144 | |
jmitc91516 | 1:a5258871b33d | 145 | /* |
jmitc91516 | 1:a5258871b33d | 146 | Tells the caller whether or not the specified touch index is on the easyGUI 'GasCalibrationPage', |
jmitc91516 | 1:a5258871b33d | 147 | and therefore needs to be handled by this class. |
jmitc91516 | 1:a5258871b33d | 148 | |
jmitc91516 | 1:a5258871b33d | 149 | Args: the touch area index in question |
jmitc91516 | 1:a5258871b33d | 150 | |
jmitc91516 | 1:a5258871b33d | 151 | Return code: true if the touch area is 'one of ours', false if not |
jmitc91516 | 1:a5258871b33d | 152 | */ |
jmitc91516 | 1:a5258871b33d | 153 | bool GasCalibrationPageHandler::TouchAreaIsOnCalibrationPage(int touchAreaIndex) |
jmitc91516 | 1:a5258871b33d | 154 | { |
jmitc91516 | 1:a5258871b33d | 155 | if((touchAreaIndex >= MIN_GAS_CALIB_TOUCHINDEX) && (touchAreaIndex <= MAX_GAS_CALIB_TOUCHINDEX)) { |
jmitc91516 | 1:a5258871b33d | 156 | return true; |
jmitc91516 | 1:a5258871b33d | 157 | } |
jmitc91516 | 1:a5258871b33d | 158 | |
jmitc91516 | 1:a5258871b33d | 159 | // 'else' |
jmitc91516 | 1:a5258871b33d | 160 | return false; |
jmitc91516 | 1:a5258871b33d | 161 | } |
jmitc91516 | 1:a5258871b33d | 162 | |
jmitc91516 | 1:a5258871b33d | 163 | |
jmitc91516 | 1:a5258871b33d | 164 | /* |
jmitc91516 | 1:a5258871b33d | 165 | If the specified touch area represents a key or field on the easyGUI 'GasCalibrationPage', |
jmitc91516 | 1:a5258871b33d | 166 | this function performs whatever action is appropriate for it. Provided so that the caller |
jmitc91516 | 1:a5258871b33d | 167 | can (in effect) say "if this is one of yours, deal with it", without needing to know |
jmitc91516 | 1:a5258871b33d | 168 | anything about what this class does, or how it handles the touch areas on that easyGUI page. |
jmitc91516 | 1:a5258871b33d | 169 | |
jmitc91516 | 1:a5258871b33d | 170 | Args: the touch area index in question |
jmitc91516 | 1:a5258871b33d | 171 | |
jmitc91516 | 1:a5258871b33d | 172 | Returns true if it dealt with the touch area (so the caller need not do anything else |
jmitc91516 | 1:a5258871b33d | 173 | with the value), or false if it did not deal with the touch area (implying that it |
jmitc91516 | 1:a5258871b33d | 174 | was not a touch area on the easyGUI 'Gas CalibrationPage', and so the caller |
jmitc91516 | 1:a5258871b33d | 175 | must deal with it some other way). |
jmitc91516 | 1:a5258871b33d | 176 | */ |
jmitc91516 | 1:a5258871b33d | 177 | bool GasCalibrationPageHandler::DealWithTouch(int touchAreaIndex) |
jmitc91516 | 1:a5258871b33d | 178 | { |
jmitc91516 | 1:a5258871b33d | 179 | bool dealtWithTouch = false; |
jmitc91516 | 1:a5258871b33d | 180 | |
jmitc91516 | 1:a5258871b33d | 181 | // Has the user selected a field to edit - |
jmitc91516 | 1:a5258871b33d | 182 | // if so, we will have an entry in our 'variablesForTouchArea' array that corresponds with this touch area |
jmitc91516 | 1:a5258871b33d | 183 | int indexOfValueToEdit = GetIndexOfValueToEditForTouchArea(touchAreaIndex); |
jmitc91516 | 1:a5258871b33d | 184 | if(indexOfValueToEdit != -1) { |
jmitc91516 | 1:a5258871b33d | 185 | // User has selected a field to edit |
jmitc91516 | 1:a5258871b33d | 186 | indexOfValueCurrentlyBeingEdited = indexOfValueToEdit; |
jmitc91516 | 1:a5258871b33d | 187 | NumericKeypadPageHandler* numericKeypadPageHandler = NumericKeypadPageHandler::GetInstance(usbDevice, usbHostGC); |
jmitc91516 | 1:a5258871b33d | 188 | if(numericKeypadPageHandler != NULL) { |
jmitc91516 | 1:a5258871b33d | 189 | numericKeypadPageHandler->StartEditing(variablesForTouchArea[indexOfValueCurrentlyBeingEdited].easyGUIVariablePtr); |
jmitc91516 | 1:a5258871b33d | 190 | numericKeypadPageHandler->SetEasyGUIVariableToEdit(variablesForTouchArea[indexOfValueCurrentlyBeingEdited].easyGUIVariablePtr); |
jmitc91516 | 1:a5258871b33d | 191 | numericKeypadPageHandler->SetEasyGUICallingPage(GuiStruct_GasCalibrationPage_Def); |
jmitc91516 | 1:a5258871b33d | 192 | numericKeypadPageHandler->SetEditVariableRange(0, variablesForTouchArea[indexOfValueCurrentlyBeingEdited].maxValue); |
jmitc91516 | 1:a5258871b33d | 193 | numericKeypadPageHandler->SetEditVariableName(variablesForTouchArea[indexOfValueCurrentlyBeingEdited].variableName); |
jmitc91516 | 1:a5258871b33d | 194 | numericKeypadPageHandler->DisplayEasyGUIPage(); |
jmitc91516 | 1:a5258871b33d | 195 | } |
jmitc91516 | 1:a5258871b33d | 196 | |
jmitc91516 | 1:a5258871b33d | 197 | dealtWithTouch = true; |
jmitc91516 | 1:a5258871b33d | 198 | } |
jmitc91516 | 1:a5258871b33d | 199 | |
jmitc91516 | 1:a5258871b33d | 200 | if(!dealtWithTouch) { |
jmitc91516 | 1:a5258871b33d | 201 | switch(touchAreaIndex) { |
jmitc91516 | 1:a5258871b33d | 202 | case GAS_CALIB_HELIUM: |
jmitc91516 | 1:a5258871b33d | 203 | if(GuiVar_gasCalibGasSelection != CARRIER_GAS_HELIUM) { |
jmitc91516 | 1:a5258871b33d | 204 | GuiVar_gasCalibGasSelection = CARRIER_GAS_HELIUM; |
jmitc91516 | 1:a5258871b33d | 205 | GetCurrentCalibrationFromGC(); |
jmitc91516 | 1:a5258871b33d | 206 | SetAllFieldBackgroundColoursToInactive(); |
jmitc91516 | 1:a5258871b33d | 207 | indexOfValueCurrentlyBeingEdited = -1; |
jmitc91516 | 1:a5258871b33d | 208 | UpdateEasyGUIPage(); |
jmitc91516 | 1:a5258871b33d | 209 | SaveCarrierGasSelectionToQSPISettings(); |
jmitc91516 | 1:a5258871b33d | 210 | } |
jmitc91516 | 1:a5258871b33d | 211 | dealtWithTouch = true; |
jmitc91516 | 1:a5258871b33d | 212 | break; |
jmitc91516 | 1:a5258871b33d | 213 | |
jmitc91516 | 1:a5258871b33d | 214 | case GAS_CALIB_HYDROGEN: |
jmitc91516 | 1:a5258871b33d | 215 | if(GuiVar_gasCalibGasSelection != CARRIER_GAS_HYDROGEN) { |
jmitc91516 | 1:a5258871b33d | 216 | GuiVar_gasCalibGasSelection = CARRIER_GAS_HYDROGEN; |
jmitc91516 | 1:a5258871b33d | 217 | GetCurrentCalibrationFromGC(); |
jmitc91516 | 1:a5258871b33d | 218 | SetAllFieldBackgroundColoursToInactive(); |
jmitc91516 | 1:a5258871b33d | 219 | indexOfValueCurrentlyBeingEdited = -1; |
jmitc91516 | 1:a5258871b33d | 220 | UpdateEasyGUIPage(); |
jmitc91516 | 1:a5258871b33d | 221 | SaveCarrierGasSelectionToQSPISettings(); |
jmitc91516 | 1:a5258871b33d | 222 | } |
jmitc91516 | 1:a5258871b33d | 223 | dealtWithTouch = true; |
jmitc91516 | 1:a5258871b33d | 224 | break; |
jmitc91516 | 1:a5258871b33d | 225 | |
jmitc91516 | 1:a5258871b33d | 226 | case GAS_CALIB_NITROGEN: |
jmitc91516 | 1:a5258871b33d | 227 | if(GuiVar_gasCalibGasSelection != CARRIER_GAS_NITROGEN) { |
jmitc91516 | 1:a5258871b33d | 228 | GuiVar_gasCalibGasSelection = CARRIER_GAS_NITROGEN; |
jmitc91516 | 1:a5258871b33d | 229 | GetCurrentCalibrationFromGC(); |
jmitc91516 | 1:a5258871b33d | 230 | SetAllFieldBackgroundColoursToInactive(); |
jmitc91516 | 1:a5258871b33d | 231 | indexOfValueCurrentlyBeingEdited = -1; |
jmitc91516 | 1:a5258871b33d | 232 | UpdateEasyGUIPage(); |
jmitc91516 | 1:a5258871b33d | 233 | SaveCarrierGasSelectionToQSPISettings(); |
jmitc91516 | 1:a5258871b33d | 234 | } |
jmitc91516 | 1:a5258871b33d | 235 | dealtWithTouch = true; |
jmitc91516 | 1:a5258871b33d | 236 | break; |
jmitc91516 | 1:a5258871b33d | 237 | |
jmitc91516 | 1:a5258871b33d | 238 | case GAS_CALIB_CANCEL_BUTTON: |
jmitc91516 | 1:a5258871b33d | 239 | GetCurrentCalibrationFromGC(); |
jmitc91516 | 1:a5258871b33d | 240 | SetAllFieldBackgroundColoursToInactive(); |
jmitc91516 | 1:a5258871b33d | 241 | indexOfValueCurrentlyBeingEdited = -1; |
jmitc91516 | 1:a5258871b33d | 242 | dealtWithTouch = true; |
jmitc91516 | 1:a5258871b33d | 243 | UpdateEasyGUIPage(); |
jmitc91516 | 1:a5258871b33d | 244 | break; |
jmitc91516 | 1:a5258871b33d | 245 | |
jmitc91516 | 1:a5258871b33d | 246 | case GAS_CALIB_APPLY_BUTTON: |
jmitc91516 | 1:a5258871b33d | 247 | SetCurrentCalibrationInGC(); |
jmitc91516 | 1:a5258871b33d | 248 | // Now deactivate all fields - shows user we have done something - |
jmitc91516 | 1:a5258871b33d | 249 | // also says "job done" |
jmitc91516 | 1:a5258871b33d | 250 | SetAllFieldBackgroundColoursToInactive(); |
jmitc91516 | 1:a5258871b33d | 251 | indexOfValueCurrentlyBeingEdited = -1; |
jmitc91516 | 1:a5258871b33d | 252 | dealtWithTouch = true; |
jmitc91516 | 1:a5258871b33d | 253 | UpdateEasyGUIPage(); |
jmitc91516 | 1:a5258871b33d | 254 | break; |
jmitc91516 | 1:a5258871b33d | 255 | |
jmitc91516 | 1:a5258871b33d | 256 | default: |
jmitc91516 | 1:a5258871b33d | 257 | // Leave 'dealtWithTouch' set false |
jmitc91516 | 1:a5258871b33d | 258 | break; |
jmitc91516 | 1:a5258871b33d | 259 | } |
jmitc91516 | 1:a5258871b33d | 260 | } |
jmitc91516 | 1:a5258871b33d | 261 | |
jmitc91516 | 1:a5258871b33d | 262 | return dealtWithTouch; |
jmitc91516 | 1:a5258871b33d | 263 | } |
jmitc91516 | 1:a5258871b33d | 264 | |
jmitc91516 | 1:a5258871b33d | 265 | |
jmitc91516 | 1:a5258871b33d | 266 | /* |
jmitc91516 | 1:a5258871b33d | 267 | Caller is telling us it is about to display the easyGUI 'GasCalibrationPage', |
jmitc91516 | 1:a5258871b33d | 268 | and that we should do whatever we have to do to get it ready, |
jmitc91516 | 1:a5258871b33d | 269 | before the caller displays it. |
jmitc91516 | 1:a5258871b33d | 270 | |
jmitc91516 | 1:a5258871b33d | 271 | No arguments, no return code |
jmitc91516 | 1:a5258871b33d | 272 | */ |
jmitc91516 | 1:a5258871b33d | 273 | void GasCalibrationPageHandler::DisplayingEasyGUIPage(bool updateEasyGUIVariables) |
jmitc91516 | 1:a5258871b33d | 274 | { |
jmitc91516 | 1:a5258871b33d | 275 | ReadCarrierGasSelectionFromQSPISettings(); |
jmitc91516 | 1:a5258871b33d | 276 | |
jmitc91516 | 1:a5258871b33d | 277 | if(updateEasyGUIVariables) { |
jmitc91516 | 1:a5258871b33d | 278 | GetCurrentCalibrationFromGC(); |
jmitc91516 | 1:a5258871b33d | 279 | } |
jmitc91516 | 1:a5258871b33d | 280 | |
jmitc91516 | 1:a5258871b33d | 281 | SetAllFieldBackgroundColoursToInactive(); |
jmitc91516 | 1:a5258871b33d | 282 | |
jmitc91516 | 1:a5258871b33d | 283 | indexOfValueCurrentlyBeingEdited = -1; |
jmitc91516 | 1:a5258871b33d | 284 | } |
jmitc91516 | 1:a5258871b33d | 285 | |
jmitc91516 | 1:a5258871b33d | 286 | |
jmitc91516 | 1:a5258871b33d | 287 | /* |
jmitc91516 | 1:a5258871b33d | 288 | Saves the current parameter values to QSPI settings, |
jmitc91516 | 1:a5258871b33d | 289 | so they are maintained even when the user powers off |
jmitc91516 | 1:a5258871b33d | 290 | |
jmitc91516 | 1:a5258871b33d | 291 | No arguments, no return value |
jmitc91516 | 1:a5258871b33d | 292 | */ |
jmitc91516 | 1:a5258871b33d | 293 | void GasCalibrationPageHandler::SaveCarrierGasSelectionToQSPISettings(void) |
jmitc91516 | 1:a5258871b33d | 294 | { |
jmitc91516 | 1:a5258871b33d | 295 | // Put values to QSPI settings, using SettingsHandler member functions |
jmitc91516 | 1:a5258871b33d | 296 | |
jmitc91516 | 1:a5258871b33d | 297 | SettingsHandler::PutIntegerValueToQSPISettings("CarrierGasSelection", GuiVar_gasCalibGasSelection); |
jmitc91516 | 1:a5258871b33d | 298 | } |
jmitc91516 | 1:a5258871b33d | 299 | |
jmitc91516 | 1:a5258871b33d | 300 | |
jmitc91516 | 1:a5258871b33d | 301 | /* |
jmitc91516 | 1:a5258871b33d | 302 | Reads the current parameter values from QSPI settings, |
jmitc91516 | 1:a5258871b33d | 303 | so they are maintained even when the user powers off |
jmitc91516 | 1:a5258871b33d | 304 | |
jmitc91516 | 1:a5258871b33d | 305 | No arguments, no return value |
jmitc91516 | 1:a5258871b33d | 306 | */ |
jmitc91516 | 1:a5258871b33d | 307 | void GasCalibrationPageHandler::ReadCarrierGasSelectionFromQSPISettings(void) |
jmitc91516 | 1:a5258871b33d | 308 | { |
jmitc91516 | 1:a5258871b33d | 309 | // Get values from QSPI settings, using SettingsHandler member functions |
jmitc91516 | 1:a5258871b33d | 310 | |
jmitc91516 | 1:a5258871b33d | 311 | GuiVar_gasCalibGasSelection = SettingsHandler::GetIntegerValueFromQSPISettings("CarrierGasSelection", CARRIER_GAS_HELIUM); |
jmitc91516 | 1:a5258871b33d | 312 | } |
jmitc91516 | 1:a5258871b33d | 313 | |
jmitc91516 | 1:a5258871b33d | 314 | |
jmitc91516 | 1:a5258871b33d | 315 | /* |
jmitc91516 | 1:a5258871b33d | 316 | Gets the current gas calibration DAC and flow values from the GC, |
jmitc91516 | 1:a5258871b33d | 317 | and puts them into the corresponding easyGUI variables |
jmitc91516 | 1:a5258871b33d | 318 | |
jmitc91516 | 1:a5258871b33d | 319 | No arguments, no return value |
jmitc91516 | 1:a5258871b33d | 320 | */ |
jmitc91516 | 1:a5258871b33d | 321 | void GasCalibrationPageHandler::GetCurrentCalibrationFromGC(void) |
jmitc91516 | 1:a5258871b33d | 322 | { |
jmitc91516 | 1:a5258871b33d | 323 | GetCalibrationDACAndFlowValuesFromGC(GuiVar_gasCalibGasSelection, 1, GuiVar_gasCalibDAC1, GuiVar_gasCalibFlow1); |
jmitc91516 | 1:a5258871b33d | 324 | GetCalibrationDACAndFlowValuesFromGC(GuiVar_gasCalibGasSelection, 2, GuiVar_gasCalibDAC2, GuiVar_gasCalibFlow2); |
jmitc91516 | 1:a5258871b33d | 325 | GetCalibrationDACAndFlowValuesFromGC(GuiVar_gasCalibGasSelection, 3, GuiVar_gasCalibDAC3, GuiVar_gasCalibFlow3); |
jmitc91516 | 1:a5258871b33d | 326 | GetCalibrationDACAndFlowValuesFromGC(GuiVar_gasCalibGasSelection, 4, GuiVar_gasCalibDAC4, GuiVar_gasCalibFlow4); |
jmitc91516 | 1:a5258871b33d | 327 | GetCalibrationDACAndFlowValuesFromGC(GuiVar_gasCalibGasSelection, 5, GuiVar_gasCalibDAC5, GuiVar_gasCalibFlow5); |
jmitc91516 | 1:a5258871b33d | 328 | GetCalibrationDACAndFlowValuesFromGC(GuiVar_gasCalibGasSelection, 6, GuiVar_gasCalibDAC6, GuiVar_gasCalibFlow6); |
jmitc91516 | 1:a5258871b33d | 329 | } |
jmitc91516 | 1:a5258871b33d | 330 | |
jmitc91516 | 1:a5258871b33d | 331 | /* |
jmitc91516 | 1:a5258871b33d | 332 | Sets the current gas calibration DAC and flow values in the GC, |
jmitc91516 | 1:a5258871b33d | 333 | getting the values from the corresponding easyGUI variables |
jmitc91516 | 1:a5258871b33d | 334 | |
jmitc91516 | 1:a5258871b33d | 335 | No arguments, no return value |
jmitc91516 | 1:a5258871b33d | 336 | */ |
jmitc91516 | 1:a5258871b33d | 337 | void GasCalibrationPageHandler::SetCurrentCalibrationInGC(void) |
jmitc91516 | 1:a5258871b33d | 338 | { |
jmitc91516 | 1:a5258871b33d | 339 | SetCalibrationDACAndFlowValuesInGC(GuiVar_gasCalibGasSelection, 1, GuiVar_gasCalibDAC1, GuiVar_gasCalibFlow1); |
jmitc91516 | 1:a5258871b33d | 340 | SetCalibrationDACAndFlowValuesInGC(GuiVar_gasCalibGasSelection, 2, GuiVar_gasCalibDAC2, GuiVar_gasCalibFlow2); |
jmitc91516 | 1:a5258871b33d | 341 | SetCalibrationDACAndFlowValuesInGC(GuiVar_gasCalibGasSelection, 3, GuiVar_gasCalibDAC3, GuiVar_gasCalibFlow3); |
jmitc91516 | 1:a5258871b33d | 342 | SetCalibrationDACAndFlowValuesInGC(GuiVar_gasCalibGasSelection, 4, GuiVar_gasCalibDAC4, GuiVar_gasCalibFlow4); |
jmitc91516 | 1:a5258871b33d | 343 | SetCalibrationDACAndFlowValuesInGC(GuiVar_gasCalibGasSelection, 5, GuiVar_gasCalibDAC5, GuiVar_gasCalibFlow5); |
jmitc91516 | 1:a5258871b33d | 344 | SetCalibrationDACAndFlowValuesInGC(GuiVar_gasCalibGasSelection, 6, GuiVar_gasCalibDAC6, GuiVar_gasCalibFlow6); |
jmitc91516 | 1:a5258871b33d | 345 | } |
jmitc91516 | 1:a5258871b33d | 346 | |
jmitc91516 | 1:a5258871b33d | 347 | |
jmitc91516 | 1:a5258871b33d | 348 | /* |
jmitc91516 | 1:a5258871b33d | 349 | Gets the gas calibration DAC and flow values for the specified carrier gas |
jmitc91516 | 1:a5258871b33d | 350 | and the specified index (1-6), and converts them to strings |
jmitc91516 | 1:a5258871b33d | 351 | |
jmitc91516 | 1:a5258871b33d | 352 | Arguments: carrier gas (integer - see enum in header file) |
jmitc91516 | 1:a5258871b33d | 353 | index (1-6) |
jmitc91516 | 1:a5258871b33d | 354 | buffer for DAC value |
jmitc91516 | 1:a5258871b33d | 355 | buffer for flow value |
jmitc91516 | 1:a5258871b33d | 356 | |
jmitc91516 | 1:a5258871b33d | 357 | Returns true if OK, false if error |
jmitc91516 | 1:a5258871b33d | 358 | */ |
jmitc91516 | 1:a5258871b33d | 359 | bool GasCalibrationPageHandler::GetCalibrationDACAndFlowValuesFromGC(int carrierGasSelection, int valueIndex, char *bufferForDACValue, char *bufferForFlowValue) |
jmitc91516 | 1:a5258871b33d | 360 | { |
jmitc91516 | 1:a5258871b33d | 361 | char cmd[8]; |
jmitc91516 | 1:a5258871b33d | 362 | char response[50]; |
jmitc91516 | 1:a5258871b33d | 363 | |
jmitc91516 | 1:a5258871b33d | 364 | |
jmitc91516 | 1:a5258871b33d | 365 | // DAC value first |
jmitc91516 | 1:a5258871b33d | 366 | |
jmitc91516 | 1:a5258871b33d | 367 | if(!ConstructGasCalibrationGCCommand(false, carrierGasSelection, valueIndex, true, cmd)) { |
jmitc91516 | 1:a5258871b33d | 368 | return false; |
jmitc91516 | 1:a5258871b33d | 369 | } |
jmitc91516 | 1:a5258871b33d | 370 | |
jmitc91516 | 1:a5258871b33d | 371 | while(usbHostGC->ExecutingSetDeviceReport()) {} |
jmitc91516 | 1:a5258871b33d | 372 | |
jmitc91516 | 1:a5258871b33d | 373 | usbHostGC->SetDeviceReport(usbDevice, cmd, response); |
jmitc91516 | 1:a5258871b33d | 374 | // We expect a response like this: "DHEAnnnn", when nnnn is the DAC value, |
jmitc91516 | 1:a5258871b33d | 375 | // or "EPKT" if something went wrong |
jmitc91516 | 1:a5258871b33d | 376 | if(response[0] == 'E') { |
jmitc91516 | 1:a5258871b33d | 377 | // Assume "EPKT" |
jmitc91516 | 1:a5258871b33d | 378 | return false; |
jmitc91516 | 1:a5258871b33d | 379 | } |
jmitc91516 | 1:a5258871b33d | 380 | |
jmitc91516 | 1:a5258871b33d | 381 | // 'else' - value received |
jmitc91516 | 1:a5258871b33d | 382 | CopyCommandResponseToBufferWithoutLeadingZeroes(&response[4], bufferForDACValue); |
jmitc91516 | 1:a5258871b33d | 383 | |
jmitc91516 | 1:a5258871b33d | 384 | |
jmitc91516 | 1:a5258871b33d | 385 | // Now the flow value |
jmitc91516 | 1:a5258871b33d | 386 | |
jmitc91516 | 1:a5258871b33d | 387 | if(!ConstructGasCalibrationGCCommand(false, carrierGasSelection, valueIndex, false, cmd)) { |
jmitc91516 | 1:a5258871b33d | 388 | return false; |
jmitc91516 | 1:a5258871b33d | 389 | } |
jmitc91516 | 1:a5258871b33d | 390 | |
jmitc91516 | 1:a5258871b33d | 391 | while(usbHostGC->ExecutingSetDeviceReport()) {} |
jmitc91516 | 1:a5258871b33d | 392 | |
jmitc91516 | 1:a5258871b33d | 393 | usbHostGC->SetDeviceReport(usbDevice, cmd, response); |
jmitc91516 | 1:a5258871b33d | 394 | // We expect a response like this: "DHEGnnnn", when nnnn is the flow value, |
jmitc91516 | 1:a5258871b33d | 395 | // or "EPKT" if something went wrong |
jmitc91516 | 1:a5258871b33d | 396 | if(response[0] == 'E') { |
jmitc91516 | 1:a5258871b33d | 397 | // Assume "EPKT" |
jmitc91516 | 1:a5258871b33d | 398 | return false; |
jmitc91516 | 1:a5258871b33d | 399 | } |
jmitc91516 | 1:a5258871b33d | 400 | |
jmitc91516 | 1:a5258871b33d | 401 | // 'else' - value received |
jmitc91516 | 1:a5258871b33d | 402 | CopyCommandResponseToBufferWithoutLeadingZeroes(&response[4], bufferForFlowValue); |
jmitc91516 | 1:a5258871b33d | 403 | |
jmitc91516 | 1:a5258871b33d | 404 | return true; |
jmitc91516 | 1:a5258871b33d | 405 | } |
jmitc91516 | 1:a5258871b33d | 406 | |
jmitc91516 | 1:a5258871b33d | 407 | /* |
jmitc91516 | 1:a5258871b33d | 408 | Sets the gas calibration DAC and flow values for the specified carrier gas |
jmitc91516 | 1:a5258871b33d | 409 | and the specified index (1-6) in the GC, using the string values passed to it |
jmitc91516 | 1:a5258871b33d | 410 | |
jmitc91516 | 1:a5258871b33d | 411 | Arguments: carrier gas (integer - see enum in header file) |
jmitc91516 | 1:a5258871b33d | 412 | index (1-6) |
jmitc91516 | 1:a5258871b33d | 413 | buffer containing the new DAC value as a string |
jmitc91516 | 1:a5258871b33d | 414 | buffer containing the new flow value as a string |
jmitc91516 | 1:a5258871b33d | 415 | |
jmitc91516 | 1:a5258871b33d | 416 | Returns true if OK, false if error |
jmitc91516 | 1:a5258871b33d | 417 | */ |
jmitc91516 | 1:a5258871b33d | 418 | bool GasCalibrationPageHandler::SetCalibrationDACAndFlowValuesInGC(int carrierGasSelection, int valueIndex, char *bufferForDACValue, char *bufferForFlowValue) |
jmitc91516 | 1:a5258871b33d | 419 | { |
jmitc91516 | 1:a5258871b33d | 420 | char cmd[8]; |
jmitc91516 | 1:a5258871b33d | 421 | char response[50]; |
jmitc91516 | 1:a5258871b33d | 422 | |
jmitc91516 | 1:a5258871b33d | 423 | // DAC value first |
jmitc91516 | 1:a5258871b33d | 424 | |
jmitc91516 | 1:a5258871b33d | 425 | if(!ConstructGasCalibrationGCCommand(true, carrierGasSelection, valueIndex, true, cmd)) { |
jmitc91516 | 1:a5258871b33d | 426 | return false; |
jmitc91516 | 1:a5258871b33d | 427 | } |
jmitc91516 | 1:a5258871b33d | 428 | |
jmitc91516 | 1:a5258871b33d | 429 | CopyBufferDigitsToCommand(cmd, bufferForDACValue); |
jmitc91516 | 1:a5258871b33d | 430 | |
jmitc91516 | 1:a5258871b33d | 431 | while(usbHostGC->ExecutingSetDeviceReport()) {} |
jmitc91516 | 1:a5258871b33d | 432 | |
jmitc91516 | 1:a5258871b33d | 433 | usbHostGC->SetDeviceReport(usbDevice, cmd, response); |
jmitc91516 | 1:a5258871b33d | 434 | // We expect "DACK" as the response for success, "DNAK" or "EPKT" if something went wrong |
jmitc91516 | 1:a5258871b33d | 435 | if(response[1] != 'A') { |
jmitc91516 | 1:a5258871b33d | 436 | return false; |
jmitc91516 | 1:a5258871b33d | 437 | } |
jmitc91516 | 1:a5258871b33d | 438 | |
jmitc91516 | 1:a5258871b33d | 439 | |
jmitc91516 | 1:a5258871b33d | 440 | // Now the flow value |
jmitc91516 | 1:a5258871b33d | 441 | |
jmitc91516 | 1:a5258871b33d | 442 | if(!ConstructGasCalibrationGCCommand(true, carrierGasSelection, valueIndex, false, cmd)) { |
jmitc91516 | 1:a5258871b33d | 443 | return false; |
jmitc91516 | 1:a5258871b33d | 444 | } |
jmitc91516 | 1:a5258871b33d | 445 | |
jmitc91516 | 1:a5258871b33d | 446 | CopyBufferDigitsToCommand(cmd, bufferForFlowValue); |
jmitc91516 | 1:a5258871b33d | 447 | |
jmitc91516 | 1:a5258871b33d | 448 | while(usbHostGC->ExecutingSetDeviceReport()) {} |
jmitc91516 | 1:a5258871b33d | 449 | |
jmitc91516 | 1:a5258871b33d | 450 | usbHostGC->SetDeviceReport(usbDevice, cmd, response); |
jmitc91516 | 1:a5258871b33d | 451 | // As before, we expect "DACK" as the response for success, "DNAK" or "EPKT" if something went wrong |
jmitc91516 | 1:a5258871b33d | 452 | if(response[1] != 'A') { |
jmitc91516 | 1:a5258871b33d | 453 | return false; |
jmitc91516 | 1:a5258871b33d | 454 | } |
jmitc91516 | 1:a5258871b33d | 455 | |
jmitc91516 | 1:a5258871b33d | 456 | // 'else' success with both commands |
jmitc91516 | 1:a5258871b33d | 457 | return true; |
jmitc91516 | 1:a5258871b33d | 458 | } |
jmitc91516 | 1:a5258871b33d | 459 | |
jmitc91516 | 1:a5258871b33d | 460 | |
jmitc91516 | 1:a5258871b33d | 461 | /* |
jmitc91516 | 1:a5258871b33d | 462 | (Re)display the easyGUI 'GasCalibrationPage' - |
jmitc91516 | 1:a5258871b33d | 463 | e.g. after the caller has updated one or more of the easyGUI variables |
jmitc91516 | 1:a5258871b33d | 464 | included in the page, and wants to display the new value to the user. |
jmitc91516 | 1:a5258871b33d | 465 | |
jmitc91516 | 1:a5258871b33d | 466 | No arguments, no return code |
jmitc91516 | 1:a5258871b33d | 467 | */ |
jmitc91516 | 1:a5258871b33d | 468 | void GasCalibrationPageHandler::UpdateEasyGUIPage(void) |
jmitc91516 | 1:a5258871b33d | 469 | { |
jmitc91516 | 1:a5258871b33d | 470 | GetGCStatusLoop *getGCStatusLoop = GetGCStatusLoop::GetInstance(); |
jmitc91516 | 1:a5258871b33d | 471 | |
jmitc91516 | 1:a5258871b33d | 472 | if(getGCStatusLoop != NULL) { |
jmitc91516 | 1:a5258871b33d | 473 | // The Gas Calibration page has a status rectangle for the gas - |
jmitc91516 | 1:a5258871b33d | 474 | // GetGCStatusLoop can display this, we cannot |
jmitc91516 | 1:a5258871b33d | 475 | getGCStatusLoop->ForceUpdateOfGasCalibrationPage(); |
jmitc91516 | 1:a5258871b33d | 476 | } |
jmitc91516 | 1:a5258871b33d | 477 | } |
jmitc91516 | 1:a5258871b33d | 478 | |
jmitc91516 | 1:a5258871b33d | 479 | |
jmitc91516 | 1:a5258871b33d | 480 | /* |
jmitc91516 | 1:a5258871b33d | 481 | The gas calibration GC commands are all very similar. This function returns the required command, |
jmitc91516 | 1:a5258871b33d | 482 | based on whether set or get is required, the carrier gas, DAC or Flow, and the index. |
jmitc91516 | 1:a5258871b33d | 483 | |
jmitc91516 | 1:a5258871b33d | 484 | Arguments: a boolean - true for set, false for get |
jmitc91516 | 1:a5258871b33d | 485 | carrier gas (integer - see enum in header file) |
jmitc91516 | 1:a5258871b33d | 486 | index (1-6) |
jmitc91516 | 1:a5258871b33d | 487 | a boolean - true for the DAC command, false for the flow command |
jmitc91516 | 1:a5258871b33d | 488 | pointer to a buffer to contain the command |
jmitc91516 | 1:a5258871b33d | 489 | |
jmitc91516 | 1:a5258871b33d | 490 | Returns true if the index was valid (1-6), false if not |
jmitc91516 | 1:a5258871b33d | 491 | */ |
jmitc91516 | 1:a5258871b33d | 492 | bool GasCalibrationPageHandler::ConstructGasCalibrationGCCommand(bool wantSetCommand, int carrierGasSelection, int valueIndex, bool wantDACCommand, char *commandBuffer) |
jmitc91516 | 1:a5258871b33d | 493 | { |
jmitc91516 | 1:a5258871b33d | 494 | if((valueIndex < 1) || (valueIndex > 6)) { |
jmitc91516 | 1:a5258871b33d | 495 | return false; |
jmitc91516 | 1:a5258871b33d | 496 | } |
jmitc91516 | 1:a5258871b33d | 497 | |
jmitc91516 | 1:a5258871b33d | 498 | commandBuffer[0] = wantSetCommand ? 'S' : 'G'; |
jmitc91516 | 1:a5258871b33d | 499 | |
jmitc91516 | 1:a5258871b33d | 500 | switch (carrierGasSelection) { |
jmitc91516 | 1:a5258871b33d | 501 | case CARRIER_GAS_HYDROGEN: |
jmitc91516 | 1:a5258871b33d | 502 | commandBuffer[1] = 'H'; |
jmitc91516 | 1:a5258871b33d | 503 | commandBuffer[2] = '2'; |
jmitc91516 | 1:a5258871b33d | 504 | break; |
jmitc91516 | 1:a5258871b33d | 505 | case CARRIER_GAS_NITROGEN: |
jmitc91516 | 1:a5258871b33d | 506 | commandBuffer[1] = 'N'; |
jmitc91516 | 1:a5258871b33d | 507 | commandBuffer[2] = '2'; |
jmitc91516 | 1:a5258871b33d | 508 | break; |
jmitc91516 | 1:a5258871b33d | 509 | default: // Assume helium |
jmitc91516 | 1:a5258871b33d | 510 | commandBuffer[1] = 'H'; |
jmitc91516 | 1:a5258871b33d | 511 | commandBuffer[2] = 'E'; |
jmitc91516 | 1:a5258871b33d | 512 | break; |
jmitc91516 | 1:a5258871b33d | 513 | } |
jmitc91516 | 1:a5258871b33d | 514 | |
jmitc91516 | 1:a5258871b33d | 515 | if(wantDACCommand) { |
jmitc91516 | 1:a5258871b33d | 516 | switch(valueIndex) { |
jmitc91516 | 1:a5258871b33d | 517 | case 1: |
jmitc91516 | 1:a5258871b33d | 518 | commandBuffer[3] = 'A'; |
jmitc91516 | 1:a5258871b33d | 519 | break; |
jmitc91516 | 1:a5258871b33d | 520 | case 2: |
jmitc91516 | 1:a5258871b33d | 521 | commandBuffer[3] = 'B'; |
jmitc91516 | 1:a5258871b33d | 522 | break; |
jmitc91516 | 1:a5258871b33d | 523 | case 3: |
jmitc91516 | 1:a5258871b33d | 524 | commandBuffer[3] = 'C'; |
jmitc91516 | 1:a5258871b33d | 525 | break; |
jmitc91516 | 1:a5258871b33d | 526 | case 4: |
jmitc91516 | 1:a5258871b33d | 527 | commandBuffer[3] = 'D'; |
jmitc91516 | 1:a5258871b33d | 528 | break; |
jmitc91516 | 1:a5258871b33d | 529 | case 5: |
jmitc91516 | 1:a5258871b33d | 530 | commandBuffer[3] = 'E'; |
jmitc91516 | 1:a5258871b33d | 531 | break; |
jmitc91516 | 1:a5258871b33d | 532 | default: // Assume 6 |
jmitc91516 | 1:a5258871b33d | 533 | commandBuffer[3] = 'F'; |
jmitc91516 | 1:a5258871b33d | 534 | break; |
jmitc91516 | 1:a5258871b33d | 535 | } |
jmitc91516 | 1:a5258871b33d | 536 | } else { |
jmitc91516 | 1:a5258871b33d | 537 | // Flow command |
jmitc91516 | 1:a5258871b33d | 538 | switch(valueIndex) { |
jmitc91516 | 1:a5258871b33d | 539 | case 1: |
jmitc91516 | 1:a5258871b33d | 540 | commandBuffer[3] = 'G'; |
jmitc91516 | 1:a5258871b33d | 541 | break; |
jmitc91516 | 1:a5258871b33d | 542 | case 2: |
jmitc91516 | 1:a5258871b33d | 543 | commandBuffer[3] = 'H'; |
jmitc91516 | 1:a5258871b33d | 544 | break; |
jmitc91516 | 1:a5258871b33d | 545 | case 3: |
jmitc91516 | 1:a5258871b33d | 546 | commandBuffer[3] = 'I'; |
jmitc91516 | 1:a5258871b33d | 547 | break; |
jmitc91516 | 1:a5258871b33d | 548 | case 4: |
jmitc91516 | 1:a5258871b33d | 549 | commandBuffer[3] = 'J'; |
jmitc91516 | 1:a5258871b33d | 550 | break; |
jmitc91516 | 1:a5258871b33d | 551 | case 5: |
jmitc91516 | 1:a5258871b33d | 552 | commandBuffer[3] = 'K'; |
jmitc91516 | 1:a5258871b33d | 553 | break; |
jmitc91516 | 1:a5258871b33d | 554 | default: // Assume 6 |
jmitc91516 | 1:a5258871b33d | 555 | commandBuffer[3] = 'L'; |
jmitc91516 | 1:a5258871b33d | 556 | break; |
jmitc91516 | 1:a5258871b33d | 557 | } |
jmitc91516 | 1:a5258871b33d | 558 | } |
jmitc91516 | 1:a5258871b33d | 559 | |
jmitc91516 | 1:a5258871b33d | 560 | commandBuffer[4] = '\0'; |
jmitc91516 | 1:a5258871b33d | 561 | |
jmitc91516 | 1:a5258871b33d | 562 | return true; |
jmitc91516 | 1:a5258871b33d | 563 | } |
jmitc91516 | 1:a5258871b33d | 564 | |
jmitc91516 | 1:a5258871b33d | 565 | |
jmitc91516 | 1:a5258871b33d | 566 | /* |
jmitc91516 | 1:a5258871b33d | 567 | Sets the background colours of all 'editable' fields to the 'inactive' colour. |
jmitc91516 | 1:a5258871b33d | 568 | |
jmitc91516 | 1:a5258871b33d | 569 | No arguments, no return code |
jmitc91516 | 1:a5258871b33d | 570 | */ |
jmitc91516 | 1:a5258871b33d | 571 | void GasCalibrationPageHandler::SetAllFieldBackgroundColoursToInactive(void) |
jmitc91516 | 1:a5258871b33d | 572 | { |
jmitc91516 | 1:a5258871b33d | 573 | GuiVar_gasCalibDAC1BackgroundColour = inactiveFieldBackgroundColour; |
jmitc91516 | 1:a5258871b33d | 574 | GuiVar_gasCalibFlow1BackgroundColour = inactiveFieldBackgroundColour; |
jmitc91516 | 1:a5258871b33d | 575 | |
jmitc91516 | 1:a5258871b33d | 576 | GuiVar_gasCalibDAC2BackgroundColour = inactiveFieldBackgroundColour; |
jmitc91516 | 1:a5258871b33d | 577 | GuiVar_gasCalibFlow2BackgroundColour = inactiveFieldBackgroundColour; |
jmitc91516 | 1:a5258871b33d | 578 | |
jmitc91516 | 1:a5258871b33d | 579 | GuiVar_gasCalibDAC3BackgroundColour = inactiveFieldBackgroundColour; |
jmitc91516 | 1:a5258871b33d | 580 | GuiVar_gasCalibFlow3BackgroundColour = inactiveFieldBackgroundColour; |
jmitc91516 | 1:a5258871b33d | 581 | |
jmitc91516 | 1:a5258871b33d | 582 | GuiVar_gasCalibDAC4BackgroundColour = inactiveFieldBackgroundColour; |
jmitc91516 | 1:a5258871b33d | 583 | GuiVar_gasCalibFlow4BackgroundColour = inactiveFieldBackgroundColour; |
jmitc91516 | 1:a5258871b33d | 584 | |
jmitc91516 | 1:a5258871b33d | 585 | GuiVar_gasCalibDAC5BackgroundColour = inactiveFieldBackgroundColour; |
jmitc91516 | 1:a5258871b33d | 586 | GuiVar_gasCalibFlow5BackgroundColour = inactiveFieldBackgroundColour; |
jmitc91516 | 1:a5258871b33d | 587 | |
jmitc91516 | 1:a5258871b33d | 588 | GuiVar_gasCalibDAC6BackgroundColour = inactiveFieldBackgroundColour; |
jmitc91516 | 1:a5258871b33d | 589 | GuiVar_gasCalibFlow6BackgroundColour = inactiveFieldBackgroundColour; |
jmitc91516 | 1:a5258871b33d | 590 | } |
jmitc91516 | 1:a5258871b33d | 591 | |
jmitc91516 | 1:a5258871b33d | 592 | |
jmitc91516 | 1:a5258871b33d | 593 | /* |
jmitc91516 | 1:a5258871b33d | 594 | Tells the caller if the specified touch area corresponds to a value the user can edit |
jmitc91516 | 1:a5258871b33d | 595 | on the easyGUI 'GasCalibrationPage', and if so, which one. |
jmitc91516 | 1:a5258871b33d | 596 | |
jmitc91516 | 1:a5258871b33d | 597 | Args: the touch area index in question |
jmitc91516 | 1:a5258871b33d | 598 | |
jmitc91516 | 1:a5258871b33d | 599 | Returns the index of the corresponding entry in our 'variablesForTouchArea' array, |
jmitc91516 | 1:a5258871b33d | 600 | or -1 if there is no such entry. It is up to the caller to check for -1 |
jmitc91516 | 1:a5258871b33d | 601 | ************************************** |
jmitc91516 | 1:a5258871b33d | 602 | */ |
jmitc91516 | 1:a5258871b33d | 603 | int GasCalibrationPageHandler::GetIndexOfValueToEditForTouchArea(int touchAreaIndex) |
jmitc91516 | 1:a5258871b33d | 604 | { |
jmitc91516 | 1:a5258871b33d | 605 | for (int index = 0; index < COUNT_OF_VARIABLES_FOR_TOUCH_AREAS; ++index) { |
jmitc91516 | 1:a5258871b33d | 606 | if(variablesForTouchArea[index].touchAreaIndex == touchAreaIndex) { |
jmitc91516 | 1:a5258871b33d | 607 | return index; |
jmitc91516 | 1:a5258871b33d | 608 | } |
jmitc91516 | 1:a5258871b33d | 609 | } |
jmitc91516 | 1:a5258871b33d | 610 | |
jmitc91516 | 1:a5258871b33d | 611 | // 'else' no Gas Calibration value corresponds to the specified touch area |
jmitc91516 | 1:a5258871b33d | 612 | return -1; |
jmitc91516 | 1:a5258871b33d | 613 | } |
jmitc91516 | 1:a5258871b33d | 614 | |
jmitc91516 | 1:a5258871b33d | 615 | |
jmitc91516 | 1:a5258871b33d | 616 | /* |
jmitc91516 | 1:a5258871b33d | 617 | The response to a "Get DAC/Flow value n" command will always consist of four digits, |
jmitc91516 | 1:a5258871b33d | 618 | padded with leading zeroes if necessary. We want to display it to the user |
jmitc91516 | 1:a5258871b33d | 619 | without the leading zeroes, but - obviously - *with* any zeroes contained in the number itself, |
jmitc91516 | 1:a5258871b33d | 620 | e.g. "0100" must be copied as "100", not "1". Note also that "0000" must be copied as "0" - |
jmitc91516 | 1:a5258871b33d | 621 | the destination string must not be left blank. |
jmitc91516 | 1:a5258871b33d | 622 | |
jmitc91516 | 1:a5258871b33d | 623 | Arguments: pointer to a character buffer containing the four-digit response [it is up to the caller to ensure this is valid] |
jmitc91516 | 1:a5258871b33d | 624 | pointer to a character buffer to which we are to copy the response without leading zeroes |
jmitc91516 | 1:a5258871b33d | 625 | |
jmitc91516 | 1:a5258871b33d | 626 | No return value |
jmitc91516 | 1:a5258871b33d | 627 | */ |
jmitc91516 | 1:a5258871b33d | 628 | void GasCalibrationPageHandler::CopyCommandResponseToBufferWithoutLeadingZeroes(char *commandResponse, char *buffer) |
jmitc91516 | 1:a5258871b33d | 629 | { |
jmitc91516 | 1:a5258871b33d | 630 | int bufferIndex = 0; |
jmitc91516 | 1:a5258871b33d | 631 | bool wantZeroes = false; |
jmitc91516 | 1:a5258871b33d | 632 | |
jmitc91516 | 1:a5258871b33d | 633 | for (int responseIndex = 0; responseIndex < 4; ++responseIndex) { |
jmitc91516 | 1:a5258871b33d | 634 | if(commandResponse[responseIndex] != '0') { |
jmitc91516 | 1:a5258871b33d | 635 | buffer[bufferIndex++] = commandResponse[responseIndex]; |
jmitc91516 | 1:a5258871b33d | 636 | wantZeroes = true; // We have had a non-zero character, so we want zeroes from now on |
jmitc91516 | 1:a5258871b33d | 637 | } else if (wantZeroes) { |
jmitc91516 | 1:a5258871b33d | 638 | buffer[bufferIndex++] = commandResponse[responseIndex]; |
jmitc91516 | 1:a5258871b33d | 639 | } |
jmitc91516 | 1:a5258871b33d | 640 | } |
jmitc91516 | 1:a5258871b33d | 641 | |
jmitc91516 | 1:a5258871b33d | 642 | if(bufferIndex == 0) { |
jmitc91516 | 1:a5258871b33d | 643 | // Response *is* zero - copied no chars at all so far |
jmitc91516 | 1:a5258871b33d | 644 | buffer[bufferIndex++] = '0'; |
jmitc91516 | 1:a5258871b33d | 645 | } |
jmitc91516 | 1:a5258871b33d | 646 | |
jmitc91516 | 1:a5258871b33d | 647 | buffer[bufferIndex] = '\0'; |
jmitc91516 | 1:a5258871b33d | 648 | } |
jmitc91516 | 1:a5258871b33d | 649 | |
jmitc91516 | 1:a5258871b33d | 650 | |
jmitc91516 | 1:a5258871b33d | 651 | /* |
jmitc91516 | 1:a5258871b33d | 652 | Gas calibration DAC and Flow values are stored in the easyGUI variables without leading zeroes, |
jmitc91516 | 1:a5258871b33d | 653 | but we must always pass them to the GC as four-digit values, padded with leading zeroes if less than four digits. |
jmitc91516 | 1:a5258871b33d | 654 | The four digits must be appended to the relevant GC 'Set' command, e.g. "SHEAnnnn". |
jmitc91516 | 1:a5258871b33d | 655 | This function does that - takes the raw 1-4 digit string, and appends it to the command as a 4-digit string. |
jmitc91516 | 1:a5258871b33d | 656 | |
jmitc91516 | 1:a5258871b33d | 657 | Arguments: pointer to a buffer containing the command |
jmitc91516 | 1:a5258871b33d | 658 | pointer to a buffer containing the raw (unpadded) value |
jmitc91516 | 1:a5258871b33d | 659 | |
jmitc91516 | 1:a5258871b33d | 660 | No return code |
jmitc91516 | 1:a5258871b33d | 661 | */ |
jmitc91516 | 1:a5258871b33d | 662 | void GasCalibrationPageHandler::CopyBufferDigitsToCommand(char *commandBuffer, char *digitsBuffer) |
jmitc91516 | 1:a5258871b33d | 663 | { |
jmitc91516 | 1:a5258871b33d | 664 | int n = strlen(digitsBuffer); |
jmitc91516 | 1:a5258871b33d | 665 | int commandBufferIndex = 4; |
jmitc91516 | 1:a5258871b33d | 666 | int digitsBufferIndex = 0; |
jmitc91516 | 1:a5258871b33d | 667 | |
jmitc91516 | 1:a5258871b33d | 668 | while(n < 4) { |
jmitc91516 | 1:a5258871b33d | 669 | commandBuffer[commandBufferIndex++] = '0'; |
jmitc91516 | 1:a5258871b33d | 670 | ++n; |
jmitc91516 | 1:a5258871b33d | 671 | } |
jmitc91516 | 1:a5258871b33d | 672 | |
jmitc91516 | 1:a5258871b33d | 673 | while(digitsBuffer[digitsBufferIndex] != '\0') { |
jmitc91516 | 1:a5258871b33d | 674 | commandBuffer[commandBufferIndex++] = digitsBuffer[digitsBufferIndex++]; |
jmitc91516 | 1:a5258871b33d | 675 | } |
jmitc91516 | 1:a5258871b33d | 676 | |
jmitc91516 | 1:a5258871b33d | 677 | commandBuffer[commandBufferIndex] = '\0'; |
jmitc91516 | 1:a5258871b33d | 678 | } |
jmitc91516 | 1:a5258871b33d | 679 |