Repository for import to local machine
Dependencies: DMBasicGUI DMSupport
GCHeatControl.cpp@1:a5258871b33d, 2017-07-20 (annotated)
- Committer:
- jmitc91516
- Date:
- Thu Jul 20 08:42:29 2017 +0000
- Revision:
- 1:a5258871b33d
- Parent:
- 0:47c880c1463d
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 | 0:47c880c1463d | 1 | #include "GCHeatControl.h" |
jmitc91516 | 0:47c880c1463d | 2 | |
jmitc91516 | 1:a5258871b33d | 3 | /* |
jmitc91516 | 1:a5258871b33d | 4 | A class to 'encapsulate' the heat control on the GC |
jmitc91516 | 1:a5258871b33d | 5 | |
jmitc91516 | 1:a5258871b33d | 6 | Requires a pointer to the USBHostGC instance that corresponds to the GC, |
jmitc91516 | 1:a5258871b33d | 7 | a pointer to the USBDeviceConnected instance that (also) corresponds to the GC |
jmitc91516 | 1:a5258871b33d | 8 | |
jmitc91516 | 1:a5258871b33d | 9 | */ |
jmitc91516 | 1:a5258871b33d | 10 | |
jmitc91516 | 1:a5258871b33d | 11 | // Defined in main.cpp |
jmitc91516 | 0:47c880c1463d | 12 | extern void EasyGUIDebugPrint(char *stuffToPrint, short X, short Y); |
jmitc91516 | 0:47c880c1463d | 13 | |
jmitc91516 | 0:47c880c1463d | 14 | |
jmitc91516 | 1:a5258871b33d | 15 | /* |
jmitc91516 | 1:a5258871b33d | 16 | Constructor - passed the USBHostGC and USBDeviceConnected instances for the GC |
jmitc91516 | 1:a5258871b33d | 17 | */ |
jmitc91516 | 0:47c880c1463d | 18 | GCHeatControl::GCHeatControl(USBDeviceConnected* newUsbDevice, USBHostGC* newUsbHostGC) |
jmitc91516 | 0:47c880c1463d | 19 | { |
jmitc91516 | 0:47c880c1463d | 20 | usbDevice = newUsbDevice; |
jmitc91516 | 0:47c880c1463d | 21 | usbHostGC = newUsbHostGC; |
jmitc91516 | 0:47c880c1463d | 22 | |
jmitc91516 | 0:47c880c1463d | 23 | #ifdef DEBUG_TEST |
jmitc91516 | 0:47c880c1463d | 24 | heatIsOn = false; |
jmitc91516 | 0:47c880c1463d | 25 | #endif |
jmitc91516 | 0:47c880c1463d | 26 | } |
jmitc91516 | 0:47c880c1463d | 27 | |
jmitc91516 | 1:a5258871b33d | 28 | /* |
jmitc91516 | 1:a5258871b33d | 29 | Tells the caller if the heat is currently on. |
jmitc91516 | 1:a5258871b33d | 30 | |
jmitc91516 | 1:a5258871b33d | 31 | Returns true if it is on, false if not. |
jmitc91516 | 1:a5258871b33d | 32 | */ |
jmitc91516 | 0:47c880c1463d | 33 | bool GCHeatControl::IsHeatOn(void) |
jmitc91516 | 0:47c880c1463d | 34 | { |
jmitc91516 | 0:47c880c1463d | 35 | #ifdef DEBUG_TEST |
jmitc91516 | 0:47c880c1463d | 36 | return heatIsOn; |
jmitc91516 | 0:47c880c1463d | 37 | #else |
jmitc91516 | 0:47c880c1463d | 38 | while(usbHostGC->ExecutingSetDeviceReport()) {} |
jmitc91516 | 0:47c880c1463d | 39 | |
jmitc91516 | 0:47c880c1463d | 40 | char response[50]; |
jmitc91516 | 0:47c880c1463d | 41 | usbHostGC->SetDeviceReport(usbDevice, "QHTS", response); |
jmitc91516 | 0:47c880c1463d | 42 | // We expect a response like this: "QHTS0000" for off, "QHTS0001" for on |
jmitc91516 | 0:47c880c1463d | 43 | |
jmitc91516 | 0:47c880c1463d | 44 | char dbg[100]; |
jmitc91516 | 0:47c880c1463d | 45 | sprintf(dbg, "QHTS returned %s", response); |
jmitc91516 | 0:47c880c1463d | 46 | EasyGUIDebugPrint(dbg, 100, 100); |
jmitc91516 | 0:47c880c1463d | 47 | |
jmitc91516 | 0:47c880c1463d | 48 | return (response[7] != '0'); |
jmitc91516 | 0:47c880c1463d | 49 | #endif |
jmitc91516 | 0:47c880c1463d | 50 | } |
jmitc91516 | 0:47c880c1463d | 51 | |
jmitc91516 | 1:a5258871b33d | 52 | /* |
jmitc91516 | 1:a5258871b33d | 53 | Turns the heat on. Returns true if this was successful, false if not. |
jmitc91516 | 1:a5258871b33d | 54 | |
jmitc91516 | 1:a5258871b33d | 55 | Note that it will return false if the heat is already on. |
jmitc91516 | 1:a5258871b33d | 56 | */ |
jmitc91516 | 0:47c880c1463d | 57 | bool GCHeatControl::TurnHeatOn(void) |
jmitc91516 | 0:47c880c1463d | 58 | { |
jmitc91516 | 0:47c880c1463d | 59 | #ifdef DEBUG_TEST |
jmitc91516 | 0:47c880c1463d | 60 | if(heatIsOn) { |
jmitc91516 | 0:47c880c1463d | 61 | // Heat is already on |
jmitc91516 | 0:47c880c1463d | 62 | return false; |
jmitc91516 | 0:47c880c1463d | 63 | } |
jmitc91516 | 0:47c880c1463d | 64 | |
jmitc91516 | 0:47c880c1463d | 65 | heatIsOn = true; |
jmitc91516 | 0:47c880c1463d | 66 | |
jmitc91516 | 0:47c880c1463d | 67 | return true; |
jmitc91516 | 0:47c880c1463d | 68 | #else |
jmitc91516 | 0:47c880c1463d | 69 | while(usbHostGC->ExecutingSetDeviceReport()) {} |
jmitc91516 | 0:47c880c1463d | 70 | |
jmitc91516 | 0:47c880c1463d | 71 | if(IsHeatOn()) { |
jmitc91516 | 0:47c880c1463d | 72 | // Heat is already on |
jmitc91516 | 0:47c880c1463d | 73 | return false; |
jmitc91516 | 0:47c880c1463d | 74 | } |
jmitc91516 | 0:47c880c1463d | 75 | |
jmitc91516 | 0:47c880c1463d | 76 | char response[50]; |
jmitc91516 | 0:47c880c1463d | 77 | usbHostGC->SetDeviceReport(usbDevice, "CHON", response); |
jmitc91516 | 0:47c880c1463d | 78 | // We expect a response like this: "DACK" for success, "DNAK" for failure |
jmitc91516 | 0:47c880c1463d | 79 | |
jmitc91516 | 0:47c880c1463d | 80 | char dbg[100]; |
jmitc91516 | 0:47c880c1463d | 81 | sprintf(dbg, "CHON returned %s", response); |
jmitc91516 | 0:47c880c1463d | 82 | EasyGUIDebugPrint(dbg, 100, 150); |
jmitc91516 | 0:47c880c1463d | 83 | |
jmitc91516 | 0:47c880c1463d | 84 | return (response[1] == 'A'); |
jmitc91516 | 0:47c880c1463d | 85 | #endif |
jmitc91516 | 0:47c880c1463d | 86 | } |
jmitc91516 | 0:47c880c1463d | 87 | |
jmitc91516 | 1:a5258871b33d | 88 | /* |
jmitc91516 | 1:a5258871b33d | 89 | Turns the heat off. Returns true if this was successful, false if not. |
jmitc91516 | 1:a5258871b33d | 90 | |
jmitc91516 | 1:a5258871b33d | 91 | Note that it will return false if the heat is already off. |
jmitc91516 | 1:a5258871b33d | 92 | */ |
jmitc91516 | 0:47c880c1463d | 93 | bool GCHeatControl::TurnHeatOff(void) |
jmitc91516 | 0:47c880c1463d | 94 | { |
jmitc91516 | 0:47c880c1463d | 95 | #ifdef DEBUG_TEST |
jmitc91516 | 0:47c880c1463d | 96 | if(!heatIsOn) { |
jmitc91516 | 0:47c880c1463d | 97 | // Heat is already off |
jmitc91516 | 0:47c880c1463d | 98 | return false; |
jmitc91516 | 0:47c880c1463d | 99 | } |
jmitc91516 | 0:47c880c1463d | 100 | |
jmitc91516 | 0:47c880c1463d | 101 | heatIsOn = false; |
jmitc91516 | 0:47c880c1463d | 102 | |
jmitc91516 | 0:47c880c1463d | 103 | return true; |
jmitc91516 | 0:47c880c1463d | 104 | #else |
jmitc91516 | 0:47c880c1463d | 105 | while(usbHostGC->ExecutingSetDeviceReport()) {} |
jmitc91516 | 0:47c880c1463d | 106 | |
jmitc91516 | 0:47c880c1463d | 107 | if(!IsHeatOn()) { |
jmitc91516 | 0:47c880c1463d | 108 | // Heat is already off |
jmitc91516 | 0:47c880c1463d | 109 | return false; |
jmitc91516 | 0:47c880c1463d | 110 | } |
jmitc91516 | 0:47c880c1463d | 111 | |
jmitc91516 | 0:47c880c1463d | 112 | char response[50]; |
jmitc91516 | 0:47c880c1463d | 113 | usbHostGC->SetDeviceReport(usbDevice, "CHOF", response); |
jmitc91516 | 0:47c880c1463d | 114 | // We expect a response like this: "DACK" for success, "DNAK" for failure |
jmitc91516 | 0:47c880c1463d | 115 | |
jmitc91516 | 0:47c880c1463d | 116 | char dbg[100]; |
jmitc91516 | 0:47c880c1463d | 117 | sprintf(dbg, "CHOF returned %s", response); |
jmitc91516 | 0:47c880c1463d | 118 | EasyGUIDebugPrint(dbg, 100, 200); |
jmitc91516 | 0:47c880c1463d | 119 | |
jmitc91516 | 0:47c880c1463d | 120 | return (response[1] == 'A'); |
jmitc91516 | 0:47c880c1463d | 121 | #endif |
jmitc91516 | 0:47c880c1463d | 122 | } |
jmitc91516 | 0:47c880c1463d | 123 | |
jmitc91516 | 0:47c880c1463d | 124 | |
jmitc91516 | 0:47c880c1463d | 125 |