Repository for import to local machine
Dependencies: DMBasicGUI DMSupport
Diff: GCHeatControl.cpp
- Revision:
- 0:47c880c1463d
- Child:
- 1:a5258871b33d
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/GCHeatControl.cpp Wed Jan 13 13:17:05 2016 +0000 @@ -0,0 +1,98 @@ +#include "GCHeatControl.h" + +extern void EasyGUIDebugPrint(char *stuffToPrint, short X, short Y); + + +GCHeatControl::GCHeatControl(USBDeviceConnected* newUsbDevice, USBHostGC* newUsbHostGC) +{ + usbDevice = newUsbDevice; + usbHostGC = newUsbHostGC; + +#ifdef DEBUG_TEST + heatIsOn = false; +#endif +} + +bool GCHeatControl::IsHeatOn(void) +{ +#ifdef DEBUG_TEST + return heatIsOn; +#else + while(usbHostGC->ExecutingSetDeviceReport()) {} + + char response[50]; + usbHostGC->SetDeviceReport(usbDevice, "QHTS", response); + // We expect a response like this: "QHTS0000" for off, "QHTS0001" for on + + char dbg[100]; + sprintf(dbg, "QHTS returned %s", response); + EasyGUIDebugPrint(dbg, 100, 100); + + return (response[7] != '0'); +#endif +} + +bool GCHeatControl::TurnHeatOn(void) +{ +#ifdef DEBUG_TEST + if(heatIsOn) { + // Heat is already on + return false; + } + + heatIsOn = true; + + return true; +#else + while(usbHostGC->ExecutingSetDeviceReport()) {} + + if(IsHeatOn()) { + // Heat is already on + return false; + } + + char response[50]; + usbHostGC->SetDeviceReport(usbDevice, "CHON", response); + // We expect a response like this: "DACK" for success, "DNAK" for failure + + char dbg[100]; + sprintf(dbg, "CHON returned %s", response); + EasyGUIDebugPrint(dbg, 100, 150); + + return (response[1] == 'A'); +#endif +} + +bool GCHeatControl::TurnHeatOff(void) +{ +#ifdef DEBUG_TEST + if(!heatIsOn) { + // Heat is already off + return false; + } + + heatIsOn = false; + + return true; +#else + while(usbHostGC->ExecutingSetDeviceReport()) {} + + if(!IsHeatOn()) { + // Heat is already off + return false; + } + + char response[50]; + usbHostGC->SetDeviceReport(usbDevice, "CHOF", response); + // We expect a response like this: "DACK" for success, "DNAK" for failure + + char dbg[100]; + sprintf(dbg, "CHOF returned %s", response); + EasyGUIDebugPrint(dbg, 100, 200); + + return (response[1] == 'A'); +#endif +} + + +