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 "GasChannelDACAndADCPageHandler.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 /*
jmitc91516 1:a5258871b33d 27 Displays the specified text string at the specified location in the currently-displayed easyGUI page.
jmitc91516 1:a5258871b33d 28
jmitc91516 1:a5258871b33d 29 Defined in main.cpp - and omits the 'ALLOW_DEBUG_PRINTS' #define
jmitc91516 1:a5258871b33d 30 */
jmitc91516 1:a5258871b33d 31 extern void SpecialDebugPrint(char *stuffToPrint, GuiConst_INT16S X, GuiConst_INT16S Y);
jmitc91516 1:a5258871b33d 32
jmitc91516 1:a5258871b33d 33
jmitc91516 1:a5258871b33d 34 /*
jmitc91516 1:a5258871b33d 35 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 36 (we do not want multiple values for the carrier gas selection, etc, and nor will we show
jmitc91516 1:a5258871b33d 37 more than one easyGUI 'GasCalibrationPage' to the user at the same time).
jmitc91516 1:a5258871b33d 38 */
jmitc91516 1:a5258871b33d 39 GasChannelDACAndADCPageHandler * GasChannelDACAndADCPageHandler::theGasChannelDACAndADCPageHandlerInstance = NULL;
jmitc91516 1:a5258871b33d 40
jmitc91516 1:a5258871b33d 41
jmitc91516 1:a5258871b33d 42 /*
jmitc91516 1:a5258871b33d 43 The minimum and maximum values for the DAC value
jmitc91516 1:a5258871b33d 44 */
jmitc91516 1:a5258871b33d 45 const int GasChannelDACAndADCPageHandler::minimumDACValue = 0;
jmitc91516 1:a5258871b33d 46 const int GasChannelDACAndADCPageHandler::maximumDACValue = 4095;
jmitc91516 1:a5258871b33d 47
jmitc91516 1:a5258871b33d 48 /*
jmitc91516 1:a5258871b33d 49 We distinguish the 'active' field - i.e. the one being edited by the user -
jmitc91516 1:a5258871b33d 50 from the inactive field(s), by its background colour
jmitc91516 1:a5258871b33d 51 */
jmitc91516 1:a5258871b33d 52 const GuiConst_INTCOLOR GasChannelDACAndADCPageHandler::inactiveFieldBackgroundColour = SixteenBitColorValue(192, 192, 192); // Grey
jmitc91516 1:a5258871b33d 53 const GuiConst_INTCOLOR GasChannelDACAndADCPageHandler::activeFieldBackgroundColour = SixteenBitColorValue(255, 255, 0); // Yellow
jmitc91516 1:a5258871b33d 54
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 GasChannelDACAndADCPageHandler * GasChannelDACAndADCPageHandler::GetInstance(USBDeviceConnected* newUsbDevice, USBHostGC* newUsbHostGC)
jmitc91516 1:a5258871b33d 60 {
jmitc91516 1:a5258871b33d 61 if (theGasChannelDACAndADCPageHandlerInstance == NULL) {
jmitc91516 1:a5258871b33d 62 theGasChannelDACAndADCPageHandlerInstance = new GasChannelDACAndADCPageHandler(newUsbDevice, newUsbHostGC);
jmitc91516 1:a5258871b33d 63 }
jmitc91516 1:a5258871b33d 64
jmitc91516 1:a5258871b33d 65 return theGasChannelDACAndADCPageHandlerInstance;
jmitc91516 1:a5258871b33d 66 }
jmitc91516 1:a5258871b33d 67
jmitc91516 1:a5258871b33d 68 // Singleton class - private constructor
jmitc91516 1:a5258871b33d 69 GasChannelDACAndADCPageHandler::GasChannelDACAndADCPageHandler(USBDeviceConnected* newUsbDevice, USBHostGC* newUsbHostGC)
jmitc91516 1:a5258871b33d 70 {
jmitc91516 1:a5258871b33d 71 usbDevice = newUsbDevice;
jmitc91516 1:a5258871b33d 72 usbHostGC = newUsbHostGC;
jmitc91516 1:a5258871b33d 73 }
jmitc91516 1:a5258871b33d 74
jmitc91516 1:a5258871b33d 75 // Private destructor also
jmitc91516 1:a5258871b33d 76 GasChannelDACAndADCPageHandler::~GasChannelDACAndADCPageHandler()
jmitc91516 1:a5258871b33d 77 {
jmitc91516 1:a5258871b33d 78
jmitc91516 1:a5258871b33d 79 }
jmitc91516 1:a5258871b33d 80
jmitc91516 1:a5258871b33d 81 /*
jmitc91516 1:a5258871b33d 82 Saves the current parameter values to QSPI settings,
jmitc91516 1:a5258871b33d 83 so they are maintained even when the user powers off
jmitc91516 1:a5258871b33d 84
jmitc91516 1:a5258871b33d 85 No arguments, no return value
jmitc91516 1:a5258871b33d 86 */
jmitc91516 1:a5258871b33d 87 void GasChannelDACAndADCPageHandler::SaveGasChannelSelectionToQSPISettings(void)
jmitc91516 1:a5258871b33d 88 {
jmitc91516 1:a5258871b33d 89 // Put values to QSPI settings, using SettingsHandler member functions
jmitc91516 1:a5258871b33d 90
jmitc91516 1:a5258871b33d 91 SettingsHandler::PutIntegerValueToQSPISettings("GasDACChannelSelection", channelSelection);
jmitc91516 1:a5258871b33d 92 }
jmitc91516 1:a5258871b33d 93
jmitc91516 1:a5258871b33d 94
jmitc91516 1:a5258871b33d 95 /*
jmitc91516 1:a5258871b33d 96 Reads the current parameter values from QSPI settings,
jmitc91516 1:a5258871b33d 97 so they are maintained even when the user powers off
jmitc91516 1:a5258871b33d 98
jmitc91516 1:a5258871b33d 99 No arguments, no return value
jmitc91516 1:a5258871b33d 100 */
jmitc91516 1:a5258871b33d 101 void GasChannelDACAndADCPageHandler::ReadGasChannelSelectionFromQSPISettings(void)
jmitc91516 1:a5258871b33d 102 {
jmitc91516 1:a5258871b33d 103 // Get values from QSPI settings, using SettingsHandler member functions
jmitc91516 1:a5258871b33d 104
jmitc91516 1:a5258871b33d 105 // Get round C++ casting rules from integer to enumeration - assign to integer first
jmitc91516 1:a5258871b33d 106 int intChannelSelection = SettingsHandler::GetIntegerValueFromQSPISettings("GasDACChannelSelection", TOTAL_FLOW);
jmitc91516 1:a5258871b33d 107
jmitc91516 1:a5258871b33d 108 // Correct for possible error (e.g. off by one)
jmitc91516 1:a5258871b33d 109 if(intChannelSelection < TOTAL_FLOW) intChannelSelection = TOTAL_FLOW;
jmitc91516 1:a5258871b33d 110 if(intChannelSelection > AIR) intChannelSelection = AIR;
jmitc91516 1:a5258871b33d 111
jmitc91516 1:a5258871b33d 112 channelSelection = (ChannelSelection) intChannelSelection;
jmitc91516 1:a5258871b33d 113
jmitc91516 1:a5258871b33d 114 // Channel index starts at 1 (GC code requires this), but easyGUI radio button indices start at zero
jmitc91516 1:a5258871b33d 115 GuiVar_gasChannelDACSelection = channelSelection - 1;
jmitc91516 1:a5258871b33d 116 }
jmitc91516 1:a5258871b33d 117
jmitc91516 1:a5258871b33d 118
jmitc91516 1:a5258871b33d 119 /*
jmitc91516 1:a5258871b33d 120 Tells the caller whether or not the specified touch index is on the easyGUI 'GasChannelDACAndADCPage',
jmitc91516 1:a5258871b33d 121 and therefore needs to be handled by this class.
jmitc91516 1:a5258871b33d 122
jmitc91516 1:a5258871b33d 123 Args: the touch area index in question
jmitc91516 1:a5258871b33d 124
jmitc91516 1:a5258871b33d 125 Return code: true if the touch area is 'one of ours', false if not
jmitc91516 1:a5258871b33d 126 */
jmitc91516 1:a5258871b33d 127 bool GasChannelDACAndADCPageHandler::TouchAreaIsOnGasChannelDACAndADCPage(int touchAreaIndex)
jmitc91516 1:a5258871b33d 128 {
jmitc91516 1:a5258871b33d 129 if((touchAreaIndex >= MIN_GAS_CHANNEL_DAC_AND_ADC_TOUCHINDEX) && (touchAreaIndex <= MAX_GAS_CHANNEL_DAC_AND_ADC_TOUCHINDEX)) {
jmitc91516 1:a5258871b33d 130 return true;
jmitc91516 1:a5258871b33d 131 }
jmitc91516 1:a5258871b33d 132
jmitc91516 1:a5258871b33d 133 // 'else'
jmitc91516 1:a5258871b33d 134 return false;
jmitc91516 1:a5258871b33d 135 }
jmitc91516 1:a5258871b33d 136
jmitc91516 1:a5258871b33d 137
jmitc91516 1:a5258871b33d 138 /*
jmitc91516 1:a5258871b33d 139 If the specified touch area represents a key or field on the easyGUI 'GasChannelDACAndADCPage',
jmitc91516 1:a5258871b33d 140 this function performs whatever action is appropriate for it. Provided so that the caller
jmitc91516 1:a5258871b33d 141 can (in effect) say "if this is one of yours, deal with it", without needing to know
jmitc91516 1:a5258871b33d 142 anything about what this class does, or how it handles the touch areas on that easyGUI page.
jmitc91516 1:a5258871b33d 143
jmitc91516 1:a5258871b33d 144 Args: the touch area index in question
jmitc91516 1:a5258871b33d 145
jmitc91516 1:a5258871b33d 146 Returns true if it dealt with the touch area (so the caller need not do anything else
jmitc91516 1:a5258871b33d 147 with the value), or false if it did not deal with the touch area (implying that it
jmitc91516 1:a5258871b33d 148 was not a touch area on the easyGUI 'GasChannelDACAndADCPage', and so the caller
jmitc91516 1:a5258871b33d 149 must deal with it some other way).
jmitc91516 1:a5258871b33d 150 */
jmitc91516 1:a5258871b33d 151 bool GasChannelDACAndADCPageHandler::DealWithTouch(int touchAreaIndex)
jmitc91516 1:a5258871b33d 152 {
jmitc91516 1:a5258871b33d 153 if(touchAreaIndex == GAS_CHANNEL_DAC_AND_ADC_TOTALFLOW) {
jmitc91516 1:a5258871b33d 154 if(channelSelection != TOTAL_FLOW) {
jmitc91516 1:a5258871b33d 155 channelSelection = TOTAL_FLOW;
jmitc91516 1:a5258871b33d 156 // Channel index starts at 1 (GC code requires this), but easyGUI radio button indices start at zero
jmitc91516 1:a5258871b33d 157 GuiVar_gasChannelDACSelection = channelSelection - 1;
jmitc91516 1:a5258871b33d 158 // UpdateEasyGUIPage();
jmitc91516 1:a5258871b33d 159 SaveGasChannelSelectionToQSPISettings();
jmitc91516 1:a5258871b33d 160 GetGasChannelADCValue(channelSelection, GuiVar_gasChannelDAC_ADCValue);
jmitc91516 1:a5258871b33d 161 UpdateEasyGUIPage(); // Surely this makes more sense here?
jmitc91516 1:a5258871b33d 162 }
jmitc91516 1:a5258871b33d 163 return true;
jmitc91516 1:a5258871b33d 164 }
jmitc91516 1:a5258871b33d 165
jmitc91516 1:a5258871b33d 166 if(touchAreaIndex == GAS_CHANNEL_DAC_AND_ADC_BACKPRESSURE) {
jmitc91516 1:a5258871b33d 167 if(channelSelection != BACK_PRESSURE) {
jmitc91516 1:a5258871b33d 168 channelSelection = BACK_PRESSURE;
jmitc91516 1:a5258871b33d 169 // Channel index starts at 1 (GC code requires this), but easyGUI radio button indices start at zero
jmitc91516 1:a5258871b33d 170 GuiVar_gasChannelDACSelection = channelSelection - 1;
jmitc91516 1:a5258871b33d 171 // UpdateEasyGUIPage();
jmitc91516 1:a5258871b33d 172 SaveGasChannelSelectionToQSPISettings();
jmitc91516 1:a5258871b33d 173 GetGasChannelADCValue(channelSelection, GuiVar_gasChannelDAC_ADCValue);
jmitc91516 1:a5258871b33d 174 UpdateEasyGUIPage(); // Surely this makes more sense here?
jmitc91516 1:a5258871b33d 175 }
jmitc91516 1:a5258871b33d 176 return true;
jmitc91516 1:a5258871b33d 177 }
jmitc91516 1:a5258871b33d 178
jmitc91516 1:a5258871b33d 179 if(touchAreaIndex == GAS_CHANNEL_DAC_AND_ADC_FUEL) {
jmitc91516 1:a5258871b33d 180 if(channelSelection != FUEL) {
jmitc91516 1:a5258871b33d 181 channelSelection = FUEL;
jmitc91516 1:a5258871b33d 182 // Channel index starts at 1 (GC code requires this), but easyGUI radio button indices start at zero
jmitc91516 1:a5258871b33d 183 GuiVar_gasChannelDACSelection = channelSelection - 1;
jmitc91516 1:a5258871b33d 184 // UpdateEasyGUIPage();
jmitc91516 1:a5258871b33d 185 SaveGasChannelSelectionToQSPISettings();
jmitc91516 1:a5258871b33d 186 GetGasChannelADCValue(channelSelection, GuiVar_gasChannelDAC_ADCValue);
jmitc91516 1:a5258871b33d 187 UpdateEasyGUIPage(); // Surely this makes more sense here?
jmitc91516 1:a5258871b33d 188 }
jmitc91516 1:a5258871b33d 189 return true;
jmitc91516 1:a5258871b33d 190 }
jmitc91516 1:a5258871b33d 191
jmitc91516 1:a5258871b33d 192 if(touchAreaIndex == GAS_CHANNEL_DAC_AND_ADC_AIR) {
jmitc91516 1:a5258871b33d 193 if(channelSelection != AIR) {
jmitc91516 1:a5258871b33d 194 channelSelection = AIR;
jmitc91516 1:a5258871b33d 195 // Channel index starts at 1 (GC code requires this), but easyGUI radio button indices start at zero
jmitc91516 1:a5258871b33d 196 GuiVar_gasChannelDACSelection = channelSelection - 1;
jmitc91516 1:a5258871b33d 197 // UpdateEasyGUIPage();
jmitc91516 1:a5258871b33d 198 SaveGasChannelSelectionToQSPISettings();
jmitc91516 1:a5258871b33d 199 GetGasChannelADCValue(channelSelection, GuiVar_gasChannelDAC_ADCValue);
jmitc91516 1:a5258871b33d 200 UpdateEasyGUIPage(); // Surely this makes more sense here?
jmitc91516 1:a5258871b33d 201 }
jmitc91516 1:a5258871b33d 202 return true;
jmitc91516 1:a5258871b33d 203 }
jmitc91516 1:a5258871b33d 204
jmitc91516 1:a5258871b33d 205 if(touchAreaIndex == GAS_CHANNEL_DAC_AND_ADC_GET_ADC_VALUE_BUTTON) {
jmitc91516 1:a5258871b33d 206 GetGasChannelADCValue(channelSelection, GuiVar_gasChannelDAC_ADCValue);
jmitc91516 1:a5258871b33d 207 UpdateEasyGUIPage();
jmitc91516 1:a5258871b33d 208 return true;
jmitc91516 1:a5258871b33d 209 }
jmitc91516 1:a5258871b33d 210
jmitc91516 1:a5258871b33d 211 if(touchAreaIndex == GAS_CHANNEL_DAC_AND_ADC_SET_DAC_VALUE_BUTTON) {
jmitc91516 1:a5258871b33d 212 SetGasChannelDACValue(channelSelection, GuiVar_gasChannelDAC_DACValue);
jmitc91516 1:a5258871b33d 213 return true;
jmitc91516 1:a5258871b33d 214 }
jmitc91516 1:a5258871b33d 215
jmitc91516 1:a5258871b33d 216 if(touchAreaIndex == GAS_CHANNEL_DAC_AND_ADC_DAC_VALUE_EDIT) {
jmitc91516 1:a5258871b33d 217 NumericKeypadPageHandler* numericKeypadPageHandler = NumericKeypadPageHandler::GetInstance(usbDevice, usbHostGC);
jmitc91516 1:a5258871b33d 218 if(numericKeypadPageHandler != NULL) {
jmitc91516 1:a5258871b33d 219 numericKeypadPageHandler->StartEditing(GuiVar_gasChannelDAC_DACValue);
jmitc91516 1:a5258871b33d 220 numericKeypadPageHandler->SetEasyGUIVariableToEdit(GuiVar_gasChannelDAC_DACValue);
jmitc91516 1:a5258871b33d 221 numericKeypadPageHandler->SetEasyGUICallingPage(GuiStruct_GasChannelDACAndADCPage_Def);
jmitc91516 1:a5258871b33d 222 numericKeypadPageHandler->SetEditVariableRange(minimumDACValue, maximumDACValue);
jmitc91516 1:a5258871b33d 223 numericKeypadPageHandler->SetEditVariableName("DAC");
jmitc91516 1:a5258871b33d 224 numericKeypadPageHandler->DisplayEasyGUIPage();
jmitc91516 1:a5258871b33d 225 }
jmitc91516 1:a5258871b33d 226 }
jmitc91516 1:a5258871b33d 227
jmitc91516 1:a5258871b33d 228 // 'else' - none of the above
jmitc91516 1:a5258871b33d 229 return false;
jmitc91516 1:a5258871b33d 230 }
jmitc91516 1:a5258871b33d 231
jmitc91516 1:a5258871b33d 232
jmitc91516 1:a5258871b33d 233 /*
jmitc91516 1:a5258871b33d 234 (Re)display the easyGUI 'GasChannelDACAndADCPage' -
jmitc91516 1:a5258871b33d 235 e.g. after the caller has updated one or more of the easyGUI variables
jmitc91516 1:a5258871b33d 236 included in the page, and wants to display the new value to the user.
jmitc91516 1:a5258871b33d 237
jmitc91516 1:a5258871b33d 238 No arguments, no return code
jmitc91516 1:a5258871b33d 239 */
jmitc91516 1:a5258871b33d 240 void GasChannelDACAndADCPageHandler::UpdateEasyGUIPage(void)
jmitc91516 1:a5258871b33d 241 {
jmitc91516 1:a5258871b33d 242 GetGCStatusLoop *getGCStatusLoop = GetGCStatusLoop::GetInstance();
jmitc91516 1:a5258871b33d 243
jmitc91516 1:a5258871b33d 244 if(getGCStatusLoop != NULL) {
jmitc91516 1:a5258871b33d 245 // The GasChannelDACAndADC page has a status rectangle for the gas -
jmitc91516 1:a5258871b33d 246 // GetGCStatusLoop can display this, we cannot
jmitc91516 1:a5258871b33d 247 getGCStatusLoop->ForceUpdateOfGasChannelDACAndADCPage();
jmitc91516 1:a5258871b33d 248 }
jmitc91516 1:a5258871b33d 249 }
jmitc91516 1:a5258871b33d 250
jmitc91516 1:a5258871b33d 251
jmitc91516 1:a5258871b33d 252 /*
jmitc91516 1:a5258871b33d 253 Caller is telling us it is about to display the easyGUI 'GasChannelDACAndADCPage',
jmitc91516 1:a5258871b33d 254 and that we should do whatever we have to do to get it ready,
jmitc91516 1:a5258871b33d 255 before the caller displays it.
jmitc91516 1:a5258871b33d 256
jmitc91516 1:a5258871b33d 257 No arguments, no return code
jmitc91516 1:a5258871b33d 258 */
jmitc91516 1:a5258871b33d 259 void GasChannelDACAndADCPageHandler::DisplayingEasyGUIPage(void)
jmitc91516 1:a5258871b33d 260 {
jmitc91516 1:a5258871b33d 261 ReadGasChannelSelectionFromQSPISettings();
jmitc91516 1:a5258871b33d 262
jmitc91516 1:a5258871b33d 263 // Make both fields grey - text on page tells user what to do, no need to show them which one is active
jmitc91516 1:a5258871b33d 264 GuiVar_gasChannelDAC_DACValueBackgroundColour = inactiveFieldBackgroundColour; // = activeFieldBackgroundColour;
jmitc91516 1:a5258871b33d 265 GuiVar_gasChannelDAC_ADCValueBackgroundColour = inactiveFieldBackgroundColour;
jmitc91516 1:a5258871b33d 266
jmitc91516 1:a5258871b33d 267 GetGasChannelADCValue(channelSelection, GuiVar_gasChannelDAC_ADCValue);
jmitc91516 1:a5258871b33d 268 }
jmitc91516 1:a5258871b33d 269
jmitc91516 1:a5258871b33d 270
jmitc91516 1:a5258871b33d 271 /*
jmitc91516 1:a5258871b33d 272 Gets the ADC value for the specified gas channel, as a null-terminated string
jmitc91516 1:a5258871b33d 273
jmitc91516 1:a5258871b33d 274 Arguments: the channel number
jmitc91516 1:a5258871b33d 275 pointer to a buffer to contain the ADC value
jmitc91516 1:a5258871b33d 276
jmitc91516 1:a5258871b33d 277 Returns true on success, false on error
jmitc91516 1:a5258871b33d 278 */
jmitc91516 1:a5258871b33d 279 bool GasChannelDACAndADCPageHandler::GetGasChannelADCValue(int channel, char* buffer)
jmitc91516 1:a5258871b33d 280 {
jmitc91516 1:a5258871b33d 281 char cmd[20];
jmitc91516 1:a5258871b33d 282 sprintf(cmd, "QGA%1d", channel);
jmitc91516 1:a5258871b33d 283
jmitc91516 1:a5258871b33d 284 char response[50];
jmitc91516 1:a5258871b33d 285 while(usbHostGC->ExecutingSetDeviceReport()) {}
jmitc91516 1:a5258871b33d 286 usbHostGC->SetDeviceReport(usbDevice, cmd, response);
jmitc91516 1:a5258871b33d 287 //#define DEBUG_PRINTS_HERE
jmitc91516 1:a5258871b33d 288 #ifdef DEBUG_PRINTS_HERE
jmitc91516 1:a5258871b33d 289 char dbg[100];
jmitc91516 1:a5258871b33d 290 sprintf(dbg, "GetGasChannADC %s %s", cmd, response);
jmitc91516 1:a5258871b33d 291 SpecialDebugPrint(dbg, 6, 300);
jmitc91516 1:a5258871b33d 292 #undef DEBUG_PRINTS_HERE
jmitc91516 1:a5258871b33d 293 #endif
jmitc91516 1:a5258871b33d 294 // We expect a response like this: "DGAnnnnn", where nnnnn (5 digits) is the ADC value,
jmitc91516 1:a5258871b33d 295 // or "EPKT" if something went wrong
jmitc91516 1:a5258871b33d 296 if(response[0] == 'E') {
jmitc91516 1:a5258871b33d 297 // Assume "EPKT"
jmitc91516 1:a5258871b33d 298 return false;
jmitc91516 1:a5258871b33d 299 }
jmitc91516 1:a5258871b33d 300
jmitc91516 1:a5258871b33d 301 //Ensure null terminator
jmitc91516 1:a5258871b33d 302 response[8] = '\0';
jmitc91516 1:a5258871b33d 303
jmitc91516 1:a5258871b33d 304 // Ignore leading zeroes - but make sure we leave the final digit, whether zero or not
jmitc91516 1:a5258871b33d 305 int startIndex;
jmitc91516 1:a5258871b33d 306 for(startIndex = 3; startIndex < 7; ++startIndex) {
jmitc91516 1:a5258871b33d 307 if(response[startIndex] != '0') {
jmitc91516 1:a5258871b33d 308 break;
jmitc91516 1:a5258871b33d 309 }
jmitc91516 1:a5258871b33d 310 }
jmitc91516 1:a5258871b33d 311
jmitc91516 1:a5258871b33d 312 strcpy(buffer, &response[startIndex]);
jmitc91516 1:a5258871b33d 313
jmitc91516 1:a5258871b33d 314 return true;
jmitc91516 1:a5258871b33d 315 }
jmitc91516 1:a5258871b33d 316
jmitc91516 1:a5258871b33d 317
jmitc91516 1:a5258871b33d 318 /*
jmitc91516 1:a5258871b33d 319 Sets the DAC value for the specified gas channel, as a null-terminated string
jmitc91516 1:a5258871b33d 320
jmitc91516 1:a5258871b33d 321 Arguments: the channel number
jmitc91516 1:a5258871b33d 322 pointer to a buffer that contains the new DAC value, as a null-terminated string
jmitc91516 1:a5258871b33d 323
jmitc91516 1:a5258871b33d 324 Returns true on success, false on error
jmitc91516 1:a5258871b33d 325 */
jmitc91516 1:a5258871b33d 326 bool GasChannelDACAndADCPageHandler::SetGasChannelDACValue(int channel, char* buffer)
jmitc91516 1:a5258871b33d 327 {
jmitc91516 1:a5258871b33d 328 char command[20];
jmitc91516 1:a5258871b33d 329 sprintf(command, "SGD%1d", channel);
jmitc91516 1:a5258871b33d 330
jmitc91516 1:a5258871b33d 331 int startIndex = 8 - strlen(buffer);
jmitc91516 1:a5258871b33d 332 int index = 4;
jmitc91516 1:a5258871b33d 333 while(index < startIndex) {
jmitc91516 1:a5258871b33d 334 command[index++] = '0';
jmitc91516 1:a5258871b33d 335 }
jmitc91516 1:a5258871b33d 336 int bufferIndex = 0;
jmitc91516 1:a5258871b33d 337 while(index < 8) {
jmitc91516 1:a5258871b33d 338 command[index++] = buffer[bufferIndex++];
jmitc91516 1:a5258871b33d 339 }
jmitc91516 1:a5258871b33d 340 command[8] = '\0';
jmitc91516 1:a5258871b33d 341
jmitc91516 1:a5258871b33d 342 char response[50];
jmitc91516 1:a5258871b33d 343 while(usbHostGC->ExecutingSetDeviceReport()) {}
jmitc91516 1:a5258871b33d 344 usbHostGC->SetDeviceReport(usbDevice, command, response);
jmitc91516 1:a5258871b33d 345 //#define DEBUG_PRINTS_HERE
jmitc91516 1:a5258871b33d 346 #ifdef DEBUG_PRINTS_HERE
jmitc91516 1:a5258871b33d 347 char dbg[100];
jmitc91516 1:a5258871b33d 348 sprintf(dbg, "SetGasChannDAC %s %s", command, response);
jmitc91516 1:a5258871b33d 349 SpecialDebugPrint(dbg, 6, 300);
jmitc91516 1:a5258871b33d 350 #undef DEBUG_PRINTS_HERE
jmitc91516 1:a5258871b33d 351 #endif
jmitc91516 1:a5258871b33d 352 // We expect a "DACK" response, or "DNAK" or "EPKT" if something went wrong
jmitc91516 1:a5258871b33d 353 if((response[0] == 'E') || (response [1] == 'N')) { // "EPKT" or "DNAK"
jmitc91516 1:a5258871b33d 354 return false;
jmitc91516 1:a5258871b33d 355 }
jmitc91516 1:a5258871b33d 356
jmitc91516 1:a5258871b33d 357 return true;
jmitc91516 1:a5258871b33d 358 }
jmitc91516 1:a5258871b33d 359