Repository for import to local machine
Dependencies: DMBasicGUI DMSupport
main.cpp@0:47c880c1463d, 2016-01-13 (annotated)
- Committer:
- jmitc91516
- Date:
- Wed Jan 13 13:17:05 2016 +0000
- Revision:
- 0:47c880c1463d
- Child:
- 1:a5258871b33d
First revision of 5 inch display version of GC500_2. Dated 13 Jan 2016
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jmitc91516 | 0:47c880c1463d | 1 | #include "mbed.h" |
jmitc91516 | 0:47c880c1463d | 2 | #include "DMBoard.h" |
jmitc91516 | 0:47c880c1463d | 3 | #include "lpc_swim.h" |
jmitc91516 | 0:47c880c1463d | 4 | #include "lpc_swim_font.h" |
jmitc91516 | 0:47c880c1463d | 5 | |
jmitc91516 | 0:47c880c1463d | 6 | #include <string.h> |
jmitc91516 | 0:47c880c1463d | 7 | |
jmitc91516 | 0:47c880c1463d | 8 | #include "GuiLib.h" |
jmitc91516 | 0:47c880c1463d | 9 | #include "GuiDisplay.h" |
jmitc91516 | 0:47c880c1463d | 10 | |
jmitc91516 | 0:47c880c1463d | 11 | #include "USBHostGC.h" |
jmitc91516 | 0:47c880c1463d | 12 | #include "TouchListener.h" |
jmitc91516 | 0:47c880c1463d | 13 | #include "TouchPanelPageSelector.h" |
jmitc91516 | 0:47c880c1463d | 14 | #include "GCHeatControl.h" |
jmitc91516 | 0:47c880c1463d | 15 | #include "GetGCStatusLoop.h" |
jmitc91516 | 0:47c880c1463d | 16 | #include "GCComponentStatusColorArea.h" |
jmitc91516 | 0:47c880c1463d | 17 | #include "EthernetTimerHandler.h" |
jmitc91516 | 0:47c880c1463d | 18 | |
jmitc91516 | 0:47c880c1463d | 19 | |
jmitc91516 | 0:47c880c1463d | 20 | // ** Start of timeout code to guard against multiple presses of the Heat On/Off button ** |
jmitc91516 | 0:47c880c1463d | 21 | // (which is in the same position as the Abort Run button) |
jmitc91516 | 0:47c880c1463d | 22 | Timeout heatOnOffTimeout; |
jmitc91516 | 0:47c880c1463d | 23 | |
jmitc91516 | 0:47c880c1463d | 24 | bool heatOnOffAvailable = true; |
jmitc91516 | 0:47c880c1463d | 25 | |
jmitc91516 | 0:47c880c1463d | 26 | void MakeHeatOnOffAvailableAgain(void) |
jmitc91516 | 0:47c880c1463d | 27 | { |
jmitc91516 | 0:47c880c1463d | 28 | heatOnOffAvailable = true; |
jmitc91516 | 0:47c880c1463d | 29 | } |
jmitc91516 | 0:47c880c1463d | 30 | |
jmitc91516 | 0:47c880c1463d | 31 | void StartHeatOnOffTimeout(void) |
jmitc91516 | 0:47c880c1463d | 32 | { |
jmitc91516 | 0:47c880c1463d | 33 | heatOnOffAvailable = false; |
jmitc91516 | 0:47c880c1463d | 34 | heatOnOffTimeout.attach(&MakeHeatOnOffAvailableAgain, 1.0); // Wait 1.0 sec before accepting touches again on Heat On/Off button |
jmitc91516 | 0:47c880c1463d | 35 | } |
jmitc91516 | 0:47c880c1463d | 36 | // ** End of Heat On/Off timeout code ** |
jmitc91516 | 0:47c880c1463d | 37 | |
jmitc91516 | 0:47c880c1463d | 38 | |
jmitc91516 | 0:47c880c1463d | 39 | // These are 'global' - TouchCallback function, as well as main(), needs to access them |
jmitc91516 | 0:47c880c1463d | 40 | TouchPanelPageSelectors touchPanelPageSelectors; |
jmitc91516 | 0:47c880c1463d | 41 | GCHeatControl* theGCHeatControl; |
jmitc91516 | 0:47c880c1463d | 42 | |
jmitc91516 | 0:47c880c1463d | 43 | TouchListener* mainTouchListener = NULL; |
jmitc91516 | 0:47c880c1463d | 44 | GetGCStatusLoop* getGCStatusLoop = NULL; |
jmitc91516 | 0:47c880c1463d | 45 | |
jmitc91516 | 0:47c880c1463d | 46 | HomePageGCComponentStatusColorAreas homePageGCComponentStatusColorAreas; |
jmitc91516 | 0:47c880c1463d | 47 | SingleGCComponentPageStatusColorAreas singleGCComponentPageStatusColorAreas; |
jmitc91516 | 0:47c880c1463d | 48 | |
jmitc91516 | 0:47c880c1463d | 49 | EthernetTimerHandler* theEthernetTimerHandler = NULL; |
jmitc91516 | 0:47c880c1463d | 50 | |
jmitc91516 | 0:47c880c1463d | 51 | |
jmitc91516 | 0:47c880c1463d | 52 | GuiConst_INTCOLOR SixteenBitColorValue(GuiConst_INT8U red, GuiConst_INT8U green, GuiConst_INT8U blue) |
jmitc91516 | 0:47c880c1463d | 53 | { |
jmitc91516 | 0:47c880c1463d | 54 | // Make sure we don't have numeric overflow problems during the conversion |
jmitc91516 | 0:47c880c1463d | 55 | GuiConst_INT32U red32 = red; |
jmitc91516 | 0:47c880c1463d | 56 | GuiConst_INT32U green32 = green; |
jmitc91516 | 0:47c880c1463d | 57 | GuiConst_INT32U blue32 = blue; |
jmitc91516 | 0:47c880c1463d | 58 | |
jmitc91516 | 0:47c880c1463d | 59 | GuiConst_INT32U rgb = (blue32 << 16) | (green32 << 8) | red32; |
jmitc91516 | 0:47c880c1463d | 60 | |
jmitc91516 | 0:47c880c1463d | 61 | return GuiLib_RgbToPixelColor(rgb); |
jmitc91516 | 0:47c880c1463d | 62 | } |
jmitc91516 | 0:47c880c1463d | 63 | |
jmitc91516 | 0:47c880c1463d | 64 | void DebugPrint(char *stuffToPrint, GuiConst_INT16S X, GuiConst_INT16S Y) |
jmitc91516 | 0:47c880c1463d | 65 | { |
jmitc91516 | 0:47c880c1463d | 66 | char buff[200]; |
jmitc91516 | 0:47c880c1463d | 67 | |
jmitc91516 | 0:47c880c1463d | 68 | const GuiConst_INT16U fontNo = GuiFont_Helv1; |
jmitc91516 | 0:47c880c1463d | 69 | |
jmitc91516 | 0:47c880c1463d | 70 | GuiDisplay_Lock(); |
jmitc91516 | 0:47c880c1463d | 71 | |
jmitc91516 | 0:47c880c1463d | 72 | // (Attempt to) clear previous strings from display |
jmitc91516 | 0:47c880c1463d | 73 | sprintf(buff, " "); |
jmitc91516 | 0:47c880c1463d | 74 | GuiLib_DrawStr( |
jmitc91516 | 0:47c880c1463d | 75 | X, //GuiConst_INT16S X, |
jmitc91516 | 0:47c880c1463d | 76 | Y, //GuiConst_INT16S Y, |
jmitc91516 | 0:47c880c1463d | 77 | fontNo, //GuiConst_INT16U FontNo, |
jmitc91516 | 0:47c880c1463d | 78 | buff, //GuiConst_TEXT PrefixLocate *String, |
jmitc91516 | 0:47c880c1463d | 79 | GuiLib_ALIGN_LEFT, //GuiConst_INT8U Alignment, |
jmitc91516 | 0:47c880c1463d | 80 | GuiLib_PS_ON, //GuiConst_INT8U PsWriting, |
jmitc91516 | 0:47c880c1463d | 81 | GuiLib_TRANSPARENT_OFF, //GuiConst_INT8U Transparent, |
jmitc91516 | 0:47c880c1463d | 82 | GuiLib_UNDERLINE_OFF, //GuiConst_INT8U Underlining, |
jmitc91516 | 0:47c880c1463d | 83 | 0, //GuiConst_INT16S BackBoxSizeX, |
jmitc91516 | 0:47c880c1463d | 84 | 0, //GuiConst_INT16S BackBoxSizeY1, |
jmitc91516 | 0:47c880c1463d | 85 | 0, //GuiConst_INT16S BackBoxSizeY2, |
jmitc91516 | 0:47c880c1463d | 86 | GuiLib_BBP_NONE, //GuiConst_INT8U BackBorderPixels, |
jmitc91516 | 0:47c880c1463d | 87 | SixteenBitColorValue(0, 0, 0xFF), //GuiConst_INTCOLOR ForeColor, |
jmitc91516 | 0:47c880c1463d | 88 | SixteenBitColorValue(0, 0xFF, 0) //GuiConst_INTCOLOR BackColor |
jmitc91516 | 0:47c880c1463d | 89 | ); |
jmitc91516 | 0:47c880c1463d | 90 | |
jmitc91516 | 0:47c880c1463d | 91 | GuiLib_DrawStr( |
jmitc91516 | 0:47c880c1463d | 92 | X, //GuiConst_INT16S X, |
jmitc91516 | 0:47c880c1463d | 93 | Y, //GuiConst_INT16S Y, |
jmitc91516 | 0:47c880c1463d | 94 | fontNo, //GuiConst_INT16U FontNo, |
jmitc91516 | 0:47c880c1463d | 95 | stuffToPrint, //GuiConst_TEXT PrefixLocate *String, |
jmitc91516 | 0:47c880c1463d | 96 | GuiLib_ALIGN_LEFT, //GuiConst_INT8U Alignment, |
jmitc91516 | 0:47c880c1463d | 97 | GuiLib_PS_ON, //GuiConst_INT8U PsWriting, |
jmitc91516 | 0:47c880c1463d | 98 | GuiLib_TRANSPARENT_OFF, //GuiConst_INT8U Transparent, |
jmitc91516 | 0:47c880c1463d | 99 | GuiLib_UNDERLINE_OFF, //GuiConst_INT8U Underlining, |
jmitc91516 | 0:47c880c1463d | 100 | 0, //GuiConst_INT16S BackBoxSizeX, |
jmitc91516 | 0:47c880c1463d | 101 | 0, //GuiConst_INT16S BackBoxSizeY1, |
jmitc91516 | 0:47c880c1463d | 102 | 0, //GuiConst_INT16S BackBoxSizeY2, |
jmitc91516 | 0:47c880c1463d | 103 | GuiLib_BBP_NONE, //GuiConst_INT8U BackBorderPixels, |
jmitc91516 | 0:47c880c1463d | 104 | SixteenBitColorValue(0, 0, 0xFF), //GuiConst_INTCOLOR ForeColor, |
jmitc91516 | 0:47c880c1463d | 105 | SixteenBitColorValue(0, 0xFF, 0) //GuiConst_INTCOLOR BackColor |
jmitc91516 | 0:47c880c1463d | 106 | ); |
jmitc91516 | 0:47c880c1463d | 107 | |
jmitc91516 | 0:47c880c1463d | 108 | GuiLib_Refresh(); |
jmitc91516 | 0:47c880c1463d | 109 | |
jmitc91516 | 0:47c880c1463d | 110 | GuiDisplay_Unlock(); |
jmitc91516 | 0:47c880c1463d | 111 | } |
jmitc91516 | 0:47c880c1463d | 112 | |
jmitc91516 | 0:47c880c1463d | 113 | void EasyGUIDebugPrint(char *stuffToPrint, short X, short Y) |
jmitc91516 | 0:47c880c1463d | 114 | { |
jmitc91516 | 0:47c880c1463d | 115 | #define DEBUG_HERE |
jmitc91516 | 0:47c880c1463d | 116 | #ifdef DEBUG_HERE |
jmitc91516 | 0:47c880c1463d | 117 | DebugPrint(stuffToPrint, (GuiConst_INT16S) X, (GuiConst_INT16S) Y); |
jmitc91516 | 0:47c880c1463d | 118 | #undef DEBUG_HERE |
jmitc91516 | 0:47c880c1463d | 119 | #endif |
jmitc91516 | 0:47c880c1463d | 120 | } |
jmitc91516 | 0:47c880c1463d | 121 | |
jmitc91516 | 0:47c880c1463d | 122 | void DummyEasyGUIDebugPrint(char *stuffToPrint, short X, short Y) |
jmitc91516 | 0:47c880c1463d | 123 | { |
jmitc91516 | 0:47c880c1463d | 124 | //DebugPrint(stuffToPrint, (GuiConst_INT16S) X, (GuiConst_INT16S) Y); |
jmitc91516 | 0:47c880c1463d | 125 | } |
jmitc91516 | 0:47c880c1463d | 126 | |
jmitc91516 | 0:47c880c1463d | 127 | int DummyDebugFunction(int i) |
jmitc91516 | 0:47c880c1463d | 128 | { |
jmitc91516 | 0:47c880c1463d | 129 | return i^2; |
jmitc91516 | 0:47c880c1463d | 130 | } |
jmitc91516 | 0:47c880c1463d | 131 | |
jmitc91516 | 0:47c880c1463d | 132 | bool GCIsReadyToRun(USBDeviceConnected* usbDevice, USBHostGC* usbHostGC) |
jmitc91516 | 0:47c880c1463d | 133 | { |
jmitc91516 | 0:47c880c1463d | 134 | while(usbHostGC->ExecutingSetDeviceReport()) {} |
jmitc91516 | 0:47c880c1463d | 135 | |
jmitc91516 | 0:47c880c1463d | 136 | char response[50]; |
jmitc91516 | 0:47c880c1463d | 137 | |
jmitc91516 | 0:47c880c1463d | 138 | // Ensure we always have valid chars in the positions we are interested in, |
jmitc91516 | 0:47c880c1463d | 139 | // in case we get "DNAK" or "EPKT" back |
jmitc91516 | 0:47c880c1463d | 140 | response[6] = '0'; |
jmitc91516 | 0:47c880c1463d | 141 | response[7] = '0'; |
jmitc91516 | 0:47c880c1463d | 142 | |
jmitc91516 | 0:47c880c1463d | 143 | usbHostGC->SetDeviceReport(usbDevice, "QSTA", response); |
jmitc91516 | 0:47c880c1463d | 144 | // We expect a response like "QSTA00nn", where "nn" is the status. |
jmitc91516 | 0:47c880c1463d | 145 | // "33" means ready to run, anything else means "not ready" |
jmitc91516 | 0:47c880c1463d | 146 | |
jmitc91516 | 0:47c880c1463d | 147 | return ((response[6] == '3') && (response[7]== '3')); |
jmitc91516 | 0:47c880c1463d | 148 | } |
jmitc91516 | 0:47c880c1463d | 149 | |
jmitc91516 | 0:47c880c1463d | 150 | void DrawRunButton(bool enabled) |
jmitc91516 | 0:47c880c1463d | 151 | { |
jmitc91516 | 0:47c880c1463d | 152 | // Black if enabled, grey if disabled |
jmitc91516 | 0:47c880c1463d | 153 | GuiConst_INTCOLOR buttonColor = (enabled) ? 0 : SixteenBitColorValue(0x80, 0x80, 0x80); |
jmitc91516 | 0:47c880c1463d | 154 | |
jmitc91516 | 0:47c880c1463d | 155 | |
jmitc91516 | 0:47c880c1463d | 156 | GuiConst_TEXT *buttonText = "Run"; |
jmitc91516 | 0:47c880c1463d | 157 | |
jmitc91516 | 0:47c880c1463d | 158 | // These are hard-coded to match the corresponding definitions in easyGUI |
jmitc91516 | 0:47c880c1463d | 159 | // (I have not found a way of getting these values from easyGUI at run time) |
jmitc91516 | 0:47c880c1463d | 160 | const GuiConst_INT16S textX1 = 400; |
jmitc91516 | 0:47c880c1463d | 161 | const GuiConst_INT16S textY1 = 220; |
jmitc91516 | 0:47c880c1463d | 162 | const GuiConst_INT16U textFont = GuiFont_Helv1; |
jmitc91516 | 0:47c880c1463d | 163 | |
jmitc91516 | 0:47c880c1463d | 164 | const GuiConst_INT16S boxX1 = 338; |
jmitc91516 | 0:47c880c1463d | 165 | const GuiConst_INT16S boxY1 = 195; |
jmitc91516 | 0:47c880c1463d | 166 | const GuiConst_INT16S boxX2 = 462; |
jmitc91516 | 0:47c880c1463d | 167 | const GuiConst_INT16S boxY2 = 235; |
jmitc91516 | 0:47c880c1463d | 168 | |
jmitc91516 | 0:47c880c1463d | 169 | GuiLib_Box(boxX1, boxY1, boxX2, boxY2, buttonColor); |
jmitc91516 | 0:47c880c1463d | 170 | |
jmitc91516 | 0:47c880c1463d | 171 | GuiLib_DrawStr( |
jmitc91516 | 0:47c880c1463d | 172 | textX1, //GuiConst_INT16S X, |
jmitc91516 | 0:47c880c1463d | 173 | textY1, //GuiConst_INT16S Y, |
jmitc91516 | 0:47c880c1463d | 174 | textFont, //GuiConst_INT16U FontNo, |
jmitc91516 | 0:47c880c1463d | 175 | buttonText, //GuiConst_TEXT PrefixLocate *String, |
jmitc91516 | 0:47c880c1463d | 176 | GuiLib_ALIGN_CENTER, //GuiConst_INT8U Alignment, |
jmitc91516 | 0:47c880c1463d | 177 | GuiLib_PS_ON, //GuiConst_INT8U PsWriting, |
jmitc91516 | 0:47c880c1463d | 178 | GuiLib_TRANSPARENT_ON, //GuiConst_INT8U Transparent, |
jmitc91516 | 0:47c880c1463d | 179 | GuiLib_UNDERLINE_OFF, //GuiConst_INT8U Underlining, |
jmitc91516 | 0:47c880c1463d | 180 | 0, //GuiConst_INT16S BackBoxSizeX, |
jmitc91516 | 0:47c880c1463d | 181 | 0, //GuiConst_INT16S BackBoxSizeY1, |
jmitc91516 | 0:47c880c1463d | 182 | 0, //GuiConst_INT16S BackBoxSizeY2, |
jmitc91516 | 0:47c880c1463d | 183 | GuiLib_BBP_NONE, //GuiConst_INT8U BackBorderPixels, |
jmitc91516 | 0:47c880c1463d | 184 | buttonColor, //GuiConst_INTCOLOR ForeColor, |
jmitc91516 | 0:47c880c1463d | 185 | SixteenBitColorValue(0xFF, 0xFF, 0xFF) //GuiConst_INTCOLOR BackColor (should be ignored with GuiLib_TRANSPARENT_ON) |
jmitc91516 | 0:47c880c1463d | 186 | ); |
jmitc91516 | 0:47c880c1463d | 187 | } |
jmitc91516 | 0:47c880c1463d | 188 | |
jmitc91516 | 0:47c880c1463d | 189 | |
jmitc91516 | 0:47c880c1463d | 190 | void DisplayEasyGuiStructure(int structureIndex, USBDeviceConnected* usbDevice, USBHostGC* usbHostGC) |
jmitc91516 | 0:47c880c1463d | 191 | { |
jmitc91516 | 0:47c880c1463d | 192 | // If required, query the GC to find out if it is ready to run *before* clearing the display - |
jmitc91516 | 0:47c880c1463d | 193 | // otherwise the display remains clear while we talk to the GC - causes noticeable flickering |
jmitc91516 | 0:47c880c1463d | 194 | bool gcIsReadyToRun = false; |
jmitc91516 | 0:47c880c1463d | 195 | if((structureIndex == GuiStruct_HomePage_1) && (usbDevice != NULL) && (usbHostGC != NULL)) { |
jmitc91516 | 0:47c880c1463d | 196 | gcIsReadyToRun = GCIsReadyToRun(usbDevice, usbHostGC); |
jmitc91516 | 0:47c880c1463d | 197 | } |
jmitc91516 | 0:47c880c1463d | 198 | |
jmitc91516 | 0:47c880c1463d | 199 | GuiLib_Clear(); |
jmitc91516 | 0:47c880c1463d | 200 | |
jmitc91516 | 0:47c880c1463d | 201 | // Note - we draw the status rectangles after GuiLib_Clear - otherwise we wouldn't see the rectangles at all - |
jmitc91516 | 0:47c880c1463d | 202 | // and before GuiLib_ShowScreen - so text, etc, is drawn on top of the rectangles |
jmitc91516 | 0:47c880c1463d | 203 | switch(structureIndex) { |
jmitc91516 | 0:47c880c1463d | 204 | case GuiStruct_HomePage_1: |
jmitc91516 | 0:47c880c1463d | 205 | homePageGCComponentStatusColorAreas.DisplayAll(); |
jmitc91516 | 0:47c880c1463d | 206 | break; |
jmitc91516 | 0:47c880c1463d | 207 | case GuiStruct_ColumnPage1_2: |
jmitc91516 | 0:47c880c1463d | 208 | case GuiStruct_ColumnPage2_9: |
jmitc91516 | 0:47c880c1463d | 209 | case GuiStruct_ColumnPage3_10: |
jmitc91516 | 0:47c880c1463d | 210 | singleGCComponentPageStatusColorAreas.DisplayGCComponentStatus(COLUMN); |
jmitc91516 | 0:47c880c1463d | 211 | break; |
jmitc91516 | 0:47c880c1463d | 212 | case GuiStruct_InjectorPage1_3: |
jmitc91516 | 0:47c880c1463d | 213 | singleGCComponentPageStatusColorAreas.DisplayGCComponentStatus(INJECTOR); |
jmitc91516 | 0:47c880c1463d | 214 | break; |
jmitc91516 | 0:47c880c1463d | 215 | case GuiStruct_DetectorPage1_4: |
jmitc91516 | 0:47c880c1463d | 216 | singleGCComponentPageStatusColorAreas.DisplayGCComponentStatus(DETECTOR); |
jmitc91516 | 0:47c880c1463d | 217 | break; |
jmitc91516 | 0:47c880c1463d | 218 | case GuiStruct_GasPage1_6: |
jmitc91516 | 0:47c880c1463d | 219 | singleGCComponentPageStatusColorAreas.DisplayGCComponentStatus(GAS); |
jmitc91516 | 0:47c880c1463d | 220 | break; |
jmitc91516 | 0:47c880c1463d | 221 | default: // Don't need to display status rectangle for this page |
jmitc91516 | 0:47c880c1463d | 222 | break; |
jmitc91516 | 0:47c880c1463d | 223 | } |
jmitc91516 | 0:47c880c1463d | 224 | |
jmitc91516 | 0:47c880c1463d | 225 | GuiLib_ShowScreen(structureIndex, GuiLib_NO_CURSOR, GuiLib_RESET_AUTO_REDRAW); |
jmitc91516 | 0:47c880c1463d | 226 | |
jmitc91516 | 0:47c880c1463d | 227 | // But draw the run button, if required, on top of the fixed part of the home page |
jmitc91516 | 0:47c880c1463d | 228 | if(structureIndex == GuiStruct_HomePage_1) { |
jmitc91516 | 0:47c880c1463d | 229 | DrawRunButton(gcIsReadyToRun); |
jmitc91516 | 0:47c880c1463d | 230 | } |
jmitc91516 | 0:47c880c1463d | 231 | |
jmitc91516 | 0:47c880c1463d | 232 | GuiLib_Refresh(); |
jmitc91516 | 0:47c880c1463d | 233 | #define DEBUG_HERE |
jmitc91516 | 0:47c880c1463d | 234 | #ifdef DEBUG_HERE |
jmitc91516 | 0:47c880c1463d | 235 | char dbg[100]; |
jmitc91516 | 0:47c880c1463d | 236 | sprintf(dbg, "After GuiLib_Refresh main 1"); |
jmitc91516 | 0:47c880c1463d | 237 | EasyGUIDebugPrint(dbg, 100, 100); |
jmitc91516 | 0:47c880c1463d | 238 | #undef DEBUG_HERE |
jmitc91516 | 0:47c880c1463d | 239 | #endif |
jmitc91516 | 0:47c880c1463d | 240 | |
jmitc91516 | 0:47c880c1463d | 241 | if(getGCStatusLoop != NULL) { |
jmitc91516 | 0:47c880c1463d | 242 | getGCStatusLoop->SetCurrentPage(structureIndex); |
jmitc91516 | 0:47c880c1463d | 243 | } |
jmitc91516 | 0:47c880c1463d | 244 | } |
jmitc91516 | 0:47c880c1463d | 245 | |
jmitc91516 | 0:47c880c1463d | 246 | void DrawErrorMessage(char *msg) |
jmitc91516 | 0:47c880c1463d | 247 | { |
jmitc91516 | 0:47c880c1463d | 248 | const GuiConst_INT16U fontNo = GuiFont_Helv1; |
jmitc91516 | 0:47c880c1463d | 249 | |
jmitc91516 | 0:47c880c1463d | 250 | GuiLib_DrawStr( |
jmitc91516 | 0:47c880c1463d | 251 | 90, //GuiConst_INT16S X, |
jmitc91516 | 0:47c880c1463d | 252 | 240, //GuiConst_INT16S Y, |
jmitc91516 | 0:47c880c1463d | 253 | fontNo, //GuiConst_INT16U FontNo, |
jmitc91516 | 0:47c880c1463d | 254 | msg, //GuiConst_TEXT PrefixLocate *String, |
jmitc91516 | 0:47c880c1463d | 255 | GuiLib_ALIGN_LEFT, //GuiConst_INT8U Alignment, |
jmitc91516 | 0:47c880c1463d | 256 | GuiLib_PS_ON, //GuiConst_INT8U PsWriting, |
jmitc91516 | 0:47c880c1463d | 257 | GuiLib_TRANSPARENT_OFF, //GuiConst_INT8U Transparent, |
jmitc91516 | 0:47c880c1463d | 258 | GuiLib_UNDERLINE_OFF, //GuiConst_INT8U Underlining, |
jmitc91516 | 0:47c880c1463d | 259 | 0, //GuiConst_INT16S BackBoxSizeX, |
jmitc91516 | 0:47c880c1463d | 260 | 0, //GuiConst_INT16S BackBoxSizeY1, |
jmitc91516 | 0:47c880c1463d | 261 | 0, //GuiConst_INT16S BackBoxSizeY2, |
jmitc91516 | 0:47c880c1463d | 262 | GuiLib_BBP_NONE, //GuiConst_INT8U BackBorderPixels, |
jmitc91516 | 0:47c880c1463d | 263 | SixteenBitColorValue(0, 0, 0xFF), //GuiConst_INTCOLOR ForeColor, |
jmitc91516 | 0:47c880c1463d | 264 | SixteenBitColorValue(0, 0xFF, 0) //GuiConst_INTCOLOR BackColor |
jmitc91516 | 0:47c880c1463d | 265 | ); |
jmitc91516 | 0:47c880c1463d | 266 | } |
jmitc91516 | 0:47c880c1463d | 267 | |
jmitc91516 | 0:47c880c1463d | 268 | void UpdateHeatOnOffEasyGuiVariable(void) |
jmitc91516 | 0:47c880c1463d | 269 | { |
jmitc91516 | 0:47c880c1463d | 270 | // Note that the easyGUI variable is not the current status of the heat on the GC, |
jmitc91516 | 0:47c880c1463d | 271 | // but the command to toggle its current state |
jmitc91516 | 0:47c880c1463d | 272 | if(theGCHeatControl != NULL) { |
jmitc91516 | 0:47c880c1463d | 273 | if(theGCHeatControl->IsHeatOn()) { |
jmitc91516 | 0:47c880c1463d | 274 | strcpy(GuiVar_heatOnOffCommand, "Heat Off"); |
jmitc91516 | 0:47c880c1463d | 275 | } else { |
jmitc91516 | 0:47c880c1463d | 276 | strcpy(GuiVar_heatOnOffCommand, "Heat On"); |
jmitc91516 | 0:47c880c1463d | 277 | } |
jmitc91516 | 0:47c880c1463d | 278 | } |
jmitc91516 | 0:47c880c1463d | 279 | } |
jmitc91516 | 0:47c880c1463d | 280 | |
jmitc91516 | 0:47c880c1463d | 281 | bool StartGCRun(USBDeviceConnected* usbDevice, USBHostGC* usbHostGC) |
jmitc91516 | 0:47c880c1463d | 282 | { |
jmitc91516 | 0:47c880c1463d | 283 | while(usbHostGC->ExecutingSetDeviceReport()) {} |
jmitc91516 | 0:47c880c1463d | 284 | |
jmitc91516 | 0:47c880c1463d | 285 | char response[50]; |
jmitc91516 | 0:47c880c1463d | 286 | usbHostGC->SetDeviceReport(usbDevice, "CRUN", response); |
jmitc91516 | 0:47c880c1463d | 287 | // We expect a response like this: "DACK" for success, "DNAK" for failure |
jmitc91516 | 0:47c880c1463d | 288 | |
jmitc91516 | 0:47c880c1463d | 289 | #define DEBUG_HERE |
jmitc91516 | 0:47c880c1463d | 290 | #ifdef DEBUG_HERE |
jmitc91516 | 0:47c880c1463d | 291 | char dbg[100]; |
jmitc91516 | 0:47c880c1463d | 292 | sprintf(dbg, "CRUN returned %s", response); |
jmitc91516 | 0:47c880c1463d | 293 | EasyGUIDebugPrint(dbg, 100, 150); |
jmitc91516 | 0:47c880c1463d | 294 | #endif |
jmitc91516 | 0:47c880c1463d | 295 | #undef DEBUG_HERE |
jmitc91516 | 0:47c880c1463d | 296 | |
jmitc91516 | 0:47c880c1463d | 297 | return (response[1] == 'A'); |
jmitc91516 | 0:47c880c1463d | 298 | } |
jmitc91516 | 0:47c880c1463d | 299 | |
jmitc91516 | 0:47c880c1463d | 300 | bool StopGCRun(USBDeviceConnected* usbDevice, USBHostGC* usbHostGC) |
jmitc91516 | 0:47c880c1463d | 301 | { |
jmitc91516 | 0:47c880c1463d | 302 | while(usbHostGC->ExecutingSetDeviceReport()) {} |
jmitc91516 | 0:47c880c1463d | 303 | |
jmitc91516 | 0:47c880c1463d | 304 | char response[50]; |
jmitc91516 | 0:47c880c1463d | 305 | // TODO: Find out which is the correct command here |
jmitc91516 | 0:47c880c1463d | 306 | // char *cmd = "CSTP"; |
jmitc91516 | 0:47c880c1463d | 307 | char *cmd = "CABT"; |
jmitc91516 | 0:47c880c1463d | 308 | usbHostGC->SetDeviceReport(usbDevice, cmd, response); |
jmitc91516 | 0:47c880c1463d | 309 | // We expect a response like this: "DACK" for success, "DNAK" for failure |
jmitc91516 | 0:47c880c1463d | 310 | |
jmitc91516 | 0:47c880c1463d | 311 | #define DEBUG_HERE |
jmitc91516 | 0:47c880c1463d | 312 | #ifdef DEBUG_HERE |
jmitc91516 | 0:47c880c1463d | 313 | char dbg[100]; |
jmitc91516 | 0:47c880c1463d | 314 | sprintf(dbg, "%s returned %s", cmd, response); |
jmitc91516 | 0:47c880c1463d | 315 | EasyGUIDebugPrint(dbg, 100, 150); |
jmitc91516 | 0:47c880c1463d | 316 | #endif |
jmitc91516 | 0:47c880c1463d | 317 | #undef DEBUG_HERE |
jmitc91516 | 0:47c880c1463d | 318 | |
jmitc91516 | 0:47c880c1463d | 319 | return (response[1] == 'A'); |
jmitc91516 | 0:47c880c1463d | 320 | } |
jmitc91516 | 0:47c880c1463d | 321 | |
jmitc91516 | 0:47c880c1463d | 322 | bool ExitGCStandbyMode(USBDeviceConnected* usbDevice, USBHostGC* usbHostGC) |
jmitc91516 | 0:47c880c1463d | 323 | { |
jmitc91516 | 0:47c880c1463d | 324 | while(usbHostGC->ExecutingSetDeviceReport()) {} |
jmitc91516 | 0:47c880c1463d | 325 | |
jmitc91516 | 0:47c880c1463d | 326 | char response[50]; |
jmitc91516 | 0:47c880c1463d | 327 | usbHostGC->SetDeviceReport(usbDevice, "CDIS", response); |
jmitc91516 | 0:47c880c1463d | 328 | // We expect a response like this: "DACK" for success, "DNAK" for failure |
jmitc91516 | 0:47c880c1463d | 329 | |
jmitc91516 | 0:47c880c1463d | 330 | char dbg[100]; |
jmitc91516 | 0:47c880c1463d | 331 | sprintf(dbg, "CDIS returned %s", response); |
jmitc91516 | 0:47c880c1463d | 332 | EasyGUIDebugPrint(dbg, 100, 150); |
jmitc91516 | 0:47c880c1463d | 333 | |
jmitc91516 | 0:47c880c1463d | 334 | if(getGCStatusLoop != NULL) { |
jmitc91516 | 0:47c880c1463d | 335 | getGCStatusLoop->ExitedGCStandbyMode(); |
jmitc91516 | 0:47c880c1463d | 336 | } |
jmitc91516 | 0:47c880c1463d | 337 | |
jmitc91516 | 0:47c880c1463d | 338 | return (response[1] == 'A'); |
jmitc91516 | 0:47c880c1463d | 339 | } |
jmitc91516 | 0:47c880c1463d | 340 | |
jmitc91516 | 0:47c880c1463d | 341 | bool ClearGCErrors(USBDeviceConnected* usbDevice, USBHostGC* usbHostGC) |
jmitc91516 | 0:47c880c1463d | 342 | { |
jmitc91516 | 0:47c880c1463d | 343 | while(usbHostGC->ExecutingSetDeviceReport()) {} |
jmitc91516 | 0:47c880c1463d | 344 | |
jmitc91516 | 0:47c880c1463d | 345 | char response[50]; |
jmitc91516 | 0:47c880c1463d | 346 | usbHostGC->SetDeviceReport(usbDevice, "CCLR", response); |
jmitc91516 | 0:47c880c1463d | 347 | // We expect a response like this: "DACK" for success, "DNAK" for failure |
jmitc91516 | 0:47c880c1463d | 348 | |
jmitc91516 | 0:47c880c1463d | 349 | char dbg[100]; |
jmitc91516 | 0:47c880c1463d | 350 | sprintf(dbg, "CCLR returned %s", response); |
jmitc91516 | 0:47c880c1463d | 351 | EasyGUIDebugPrint(dbg, 100, 150); |
jmitc91516 | 0:47c880c1463d | 352 | |
jmitc91516 | 0:47c880c1463d | 353 | return (response[1] == 'A'); |
jmitc91516 | 0:47c880c1463d | 354 | } |
jmitc91516 | 0:47c880c1463d | 355 | |
jmitc91516 | 0:47c880c1463d | 356 | void TouchCallback(touch_coordinate_t touchCoords, USBDeviceConnected* usbDevice, USBHostGC* usbHostGC, int tickCount, bool newTouch) |
jmitc91516 | 0:47c880c1463d | 357 | { |
jmitc91516 | 0:47c880c1463d | 358 | GuiConst_INT32S touchAreaIndex = GuiLib_TouchCheck((GuiConst_INT16S)touchCoords.x, (GuiConst_INT16S)touchCoords.y); |
jmitc91516 | 0:47c880c1463d | 359 | |
jmitc91516 | 0:47c880c1463d | 360 | if(touchAreaIndex >= 0) { |
jmitc91516 | 0:47c880c1463d | 361 | bool dealtWithTouch = false; |
jmitc91516 | 0:47c880c1463d | 362 | |
jmitc91516 | 0:47c880c1463d | 363 | // page selector? |
jmitc91516 | 0:47c880c1463d | 364 | TouchPanelPageSelector* touchPanelPageSelector = touchPanelPageSelectors.GetTouchPanelPageSelector(touchAreaIndex); |
jmitc91516 | 0:47c880c1463d | 365 | |
jmitc91516 | 0:47c880c1463d | 366 | if( touchPanelPageSelector != NULL) { |
jmitc91516 | 0:47c880c1463d | 367 | // Do not keep switching pages if the user keeps 'touching' - |
jmitc91516 | 0:47c880c1463d | 368 | // switch only if he 'lets go', then presses again |
jmitc91516 | 0:47c880c1463d | 369 | if(newTouch) { |
jmitc91516 | 0:47c880c1463d | 370 | if(touchAreaIndex == 200) { |
jmitc91516 | 0:47c880c1463d | 371 | // Stop run - as well as displaying the home page, do this... |
jmitc91516 | 0:47c880c1463d | 372 | StopGCRun(usbDevice, usbHostGC); |
jmitc91516 | 0:47c880c1463d | 373 | } |
jmitc91516 | 0:47c880c1463d | 374 | |
jmitc91516 | 0:47c880c1463d | 375 | if(touchAreaIndex == 400) { |
jmitc91516 | 0:47c880c1463d | 376 | // Take GC out of standby mode |
jmitc91516 | 0:47c880c1463d | 377 | ExitGCStandbyMode(usbDevice, usbHostGC); |
jmitc91516 | 0:47c880c1463d | 378 | } |
jmitc91516 | 0:47c880c1463d | 379 | |
jmitc91516 | 0:47c880c1463d | 380 | if(touchAreaIndex == 600) { |
jmitc91516 | 0:47c880c1463d | 381 | // Take GC out of error state |
jmitc91516 | 0:47c880c1463d | 382 | ClearGCErrors(usbDevice, usbHostGC); |
jmitc91516 | 0:47c880c1463d | 383 | } |
jmitc91516 | 0:47c880c1463d | 384 | |
jmitc91516 | 0:47c880c1463d | 385 | DisplayEasyGuiStructure(touchPanelPageSelector->GetPageNumber(), usbDevice, usbHostGC); |
jmitc91516 | 0:47c880c1463d | 386 | } |
jmitc91516 | 0:47c880c1463d | 387 | |
jmitc91516 | 0:47c880c1463d | 388 | dealtWithTouch = true; // The user touched a page selector, so we have still 'dealt' with this, |
jmitc91516 | 0:47c880c1463d | 389 | // whether we had a 'new touch' or not |
jmitc91516 | 0:47c880c1463d | 390 | |
jmitc91516 | 0:47c880c1463d | 391 | if(touchAreaIndex == 200) { |
jmitc91516 | 0:47c880c1463d | 392 | // Is in same place as Heat On/Off button |
jmitc91516 | 0:47c880c1463d | 393 | StartHeatOnOffTimeout(); |
jmitc91516 | 0:47c880c1463d | 394 | } |
jmitc91516 | 0:47c880c1463d | 395 | } |
jmitc91516 | 0:47c880c1463d | 396 | |
jmitc91516 | 0:47c880c1463d | 397 | if(!dealtWithTouch) { |
jmitc91516 | 0:47c880c1463d | 398 | if(touchAreaIndex == 100) { // Run button |
jmitc91516 | 0:47c880c1463d | 399 | if(newTouch) { // As above - do not do this repeatedly - GC does not like it... |
jmitc91516 | 0:47c880c1463d | 400 | if(GCIsReadyToRun(usbDevice, usbHostGC)) { |
jmitc91516 | 0:47c880c1463d | 401 | // Start run - if this works, display the 'Run' page, else do nothing |
jmitc91516 | 0:47c880c1463d | 402 | if(StartGCRun(usbDevice, usbHostGC)) { |
jmitc91516 | 0:47c880c1463d | 403 | DisplayEasyGuiStructure(GuiStruct_RunningPage_7, usbDevice, usbHostGC); |
jmitc91516 | 0:47c880c1463d | 404 | } else { |
jmitc91516 | 0:47c880c1463d | 405 | DrawErrorMessage("*** Run failed to start ***"); |
jmitc91516 | 0:47c880c1463d | 406 | |
jmitc91516 | 0:47c880c1463d | 407 | // Give user time to read error, then erase it |
jmitc91516 | 0:47c880c1463d | 408 | Thread::wait(2000); |
jmitc91516 | 0:47c880c1463d | 409 | |
jmitc91516 | 0:47c880c1463d | 410 | DisplayEasyGuiStructure(GuiStruct_HomePage_1, usbDevice, usbHostGC); |
jmitc91516 | 0:47c880c1463d | 411 | } |
jmitc91516 | 0:47c880c1463d | 412 | } |
jmitc91516 | 0:47c880c1463d | 413 | // else GC is not ready to run (button should be greyed out) - ignore |
jmitc91516 | 0:47c880c1463d | 414 | } |
jmitc91516 | 0:47c880c1463d | 415 | |
jmitc91516 | 0:47c880c1463d | 416 | dealtWithTouch = true; |
jmitc91516 | 0:47c880c1463d | 417 | } |
jmitc91516 | 0:47c880c1463d | 418 | } |
jmitc91516 | 0:47c880c1463d | 419 | |
jmitc91516 | 0:47c880c1463d | 420 | if(!dealtWithTouch) { |
jmitc91516 | 0:47c880c1463d | 421 | if(touchAreaIndex == 300) { // Heat on/off button |
jmitc91516 | 0:47c880c1463d | 422 | if(newTouch) { // As above - do not do this repeatedly - GC does not like it... |
jmitc91516 | 0:47c880c1463d | 423 | if(heatOnOffAvailable) { |
jmitc91516 | 0:47c880c1463d | 424 | if(theGCHeatControl != NULL) { |
jmitc91516 | 0:47c880c1463d | 425 | if(theGCHeatControl->IsHeatOn()) { |
jmitc91516 | 0:47c880c1463d | 426 | theGCHeatControl->TurnHeatOff(); |
jmitc91516 | 0:47c880c1463d | 427 | } else { |
jmitc91516 | 0:47c880c1463d | 428 | theGCHeatControl->TurnHeatOn(); |
jmitc91516 | 0:47c880c1463d | 429 | } |
jmitc91516 | 0:47c880c1463d | 430 | UpdateHeatOnOffEasyGuiVariable(); |
jmitc91516 | 0:47c880c1463d | 431 | |
jmitc91516 | 0:47c880c1463d | 432 | // Make GuiVar_heatOnOffCommand update visible on screen |
jmitc91516 | 0:47c880c1463d | 433 | DisplayEasyGuiStructure(GuiStruct_HomePage_1, usbDevice, usbHostGC); |
jmitc91516 | 0:47c880c1463d | 434 | |
jmitc91516 | 0:47c880c1463d | 435 | StartHeatOnOffTimeout(); |
jmitc91516 | 0:47c880c1463d | 436 | } |
jmitc91516 | 0:47c880c1463d | 437 | } |
jmitc91516 | 0:47c880c1463d | 438 | } |
jmitc91516 | 0:47c880c1463d | 439 | |
jmitc91516 | 0:47c880c1463d | 440 | // Whether we changed the heat or not, the user still 'touched' our area, |
jmitc91516 | 0:47c880c1463d | 441 | // so no-one else should try and deal with this touch |
jmitc91516 | 0:47c880c1463d | 442 | dealtWithTouch = true; |
jmitc91516 | 0:47c880c1463d | 443 | } |
jmitc91516 | 0:47c880c1463d | 444 | } |
jmitc91516 | 0:47c880c1463d | 445 | } |
jmitc91516 | 0:47c880c1463d | 446 | } |
jmitc91516 | 0:47c880c1463d | 447 | |
jmitc91516 | 0:47c880c1463d | 448 | void SetupUSBGCTouchListener(DMBoard* board, USBDeviceConnected* usbDevice, USBHostGC* usbHostGC) |
jmitc91516 | 0:47c880c1463d | 449 | { |
jmitc91516 | 0:47c880c1463d | 450 | // Note that TouchListener is a singleton - we do not need or want there to be more than one instance of it |
jmitc91516 | 0:47c880c1463d | 451 | // (there is only one board, and only one touch panel) |
jmitc91516 | 0:47c880c1463d | 452 | mainTouchListener = TouchListener::GetInstance(board->touchPanel(), usbDevice, usbHostGC); |
jmitc91516 | 0:47c880c1463d | 453 | |
jmitc91516 | 0:47c880c1463d | 454 | if(mainTouchListener != NULL) { |
jmitc91516 | 0:47c880c1463d | 455 | mainTouchListener->SetTouchCallbackFunction(&TouchCallback); |
jmitc91516 | 0:47c880c1463d | 456 | |
jmitc91516 | 0:47c880c1463d | 457 | // Not yet... |
jmitc91516 | 0:47c880c1463d | 458 | // mainTouchListener->SetTouchReleasedCallbackFunction(&TouchReleasedCallback); |
jmitc91516 | 0:47c880c1463d | 459 | // |
jmitc91516 | 0:47c880c1463d | 460 | // mainTouchListener->SetTimerOneSecondCallbackFunction(&TimerOneSecondCallback); |
jmitc91516 | 0:47c880c1463d | 461 | } |
jmitc91516 | 0:47c880c1463d | 462 | } |
jmitc91516 | 0:47c880c1463d | 463 | |
jmitc91516 | 0:47c880c1463d | 464 | |
jmitc91516 | 0:47c880c1463d | 465 | int main() |
jmitc91516 | 0:47c880c1463d | 466 | { |
jmitc91516 | 0:47c880c1463d | 467 | DMBoard::BoardError err; |
jmitc91516 | 0:47c880c1463d | 468 | DMBoard* board = &DMBoard::instance(); |
jmitc91516 | 0:47c880c1463d | 469 | RtosLog* log = board->logger(); |
jmitc91516 | 0:47c880c1463d | 470 | Display* disp = board->display(); |
jmitc91516 | 0:47c880c1463d | 471 | |
jmitc91516 | 0:47c880c1463d | 472 | do { |
jmitc91516 | 0:47c880c1463d | 473 | err = board->init(); |
jmitc91516 | 0:47c880c1463d | 474 | if (err != DMBoard::Ok) { |
jmitc91516 | 0:47c880c1463d | 475 | log->printf("Failed to initialize the board, got error %d\r\n", err); |
jmitc91516 | 0:47c880c1463d | 476 | break; |
jmitc91516 | 0:47c880c1463d | 477 | } |
jmitc91516 | 0:47c880c1463d | 478 | |
jmitc91516 | 0:47c880c1463d | 479 | log->printf("\n\nHello World!\n\n"); |
jmitc91516 | 0:47c880c1463d | 480 | |
jmitc91516 | 0:47c880c1463d | 481 | void* fb = disp->allocateFramebuffer(); |
jmitc91516 | 0:47c880c1463d | 482 | if (fb == NULL) { |
jmitc91516 | 0:47c880c1463d | 483 | log->printf("Failed to allocate memory for a frame buffer\r\n"); |
jmitc91516 | 0:47c880c1463d | 484 | err = DMBoard::MemoryError; |
jmitc91516 | 0:47c880c1463d | 485 | break; |
jmitc91516 | 0:47c880c1463d | 486 | } |
jmitc91516 | 0:47c880c1463d | 487 | |
jmitc91516 | 0:47c880c1463d | 488 | |
jmitc91516 | 0:47c880c1463d | 489 | // Display::DisplayError disperr = disp->powerUp(fb, Display::Resolution_24bit_rgb888); |
jmitc91516 | 0:47c880c1463d | 490 | // Start display in default mode (16-bit) (24-bit uses too much memory) |
jmitc91516 | 0:47c880c1463d | 491 | Display::DisplayError disperr = disp->powerUp(fb); |
jmitc91516 | 0:47c880c1463d | 492 | if (disperr != Display::DisplayError_Ok) { |
jmitc91516 | 0:47c880c1463d | 493 | log->printf("Failed to initialize the display, got error %d\r\n", disperr); |
jmitc91516 | 0:47c880c1463d | 494 | break; |
jmitc91516 | 0:47c880c1463d | 495 | } |
jmitc91516 | 0:47c880c1463d | 496 | |
jmitc91516 | 0:47c880c1463d | 497 | } while(false); |
jmitc91516 | 0:47c880c1463d | 498 | |
jmitc91516 | 0:47c880c1463d | 499 | if (err != DMBoard::Ok) { |
jmitc91516 | 0:47c880c1463d | 500 | log->printf("\nTERMINATING\n"); |
jmitc91516 | 0:47c880c1463d | 501 | wait_ms(2000); // allow RtosLog to flush messages |
jmitc91516 | 0:47c880c1463d | 502 | mbed_die(); |
jmitc91516 | 0:47c880c1463d | 503 | } |
jmitc91516 | 0:47c880c1463d | 504 | |
jmitc91516 | 0:47c880c1463d | 505 | |
jmitc91516 | 0:47c880c1463d | 506 | // easyGUI stuff - note function calls require 'extern "C"' in relevant header |
jmitc91516 | 0:47c880c1463d | 507 | |
jmitc91516 | 0:47c880c1463d | 508 | // Need to set up heat on/off command easyGUI variable |
jmitc91516 | 0:47c880c1463d | 509 | // before we display the home page for the first time - |
jmitc91516 | 0:47c880c1463d | 510 | // but we do not have a heat control object at this point - |
jmitc91516 | 0:47c880c1463d | 511 | // default to 'Heat On' |
jmitc91516 | 0:47c880c1463d | 512 | strcpy(GuiVar_heatOnOffCommand, "Heat On"); |
jmitc91516 | 0:47c880c1463d | 513 | |
jmitc91516 | 0:47c880c1463d | 514 | GuiDisplay_Lock(); |
jmitc91516 | 0:47c880c1463d | 515 | |
jmitc91516 | 0:47c880c1463d | 516 | GuiLib_Init(); |
jmitc91516 | 0:47c880c1463d | 517 | |
jmitc91516 | 0:47c880c1463d | 518 | GuiLib_Refresh(); |
jmitc91516 | 0:47c880c1463d | 519 | |
jmitc91516 | 0:47c880c1463d | 520 | DisplayEasyGuiStructure(GuiStruct_HomePage_1, NULL, NULL); |
jmitc91516 | 0:47c880c1463d | 521 | |
jmitc91516 | 0:47c880c1463d | 522 | GuiLib_Refresh(); |
jmitc91516 | 0:47c880c1463d | 523 | |
jmitc91516 | 0:47c880c1463d | 524 | GuiDisplay_Unlock(); |
jmitc91516 | 0:47c880c1463d | 525 | |
jmitc91516 | 0:47c880c1463d | 526 | |
jmitc91516 | 0:47c880c1463d | 527 | // Now the USB 'stuff' |
jmitc91516 | 0:47c880c1463d | 528 | |
jmitc91516 | 0:47c880c1463d | 529 | USBHost* usbHost = USBHost::getHostInst(); |
jmitc91516 | 0:47c880c1463d | 530 | USBDeviceConnected* usbDevice; |
jmitc91516 | 0:47c880c1463d | 531 | USBHostGC usbHostGC; |
jmitc91516 | 0:47c880c1463d | 532 | |
jmitc91516 | 0:47c880c1463d | 533 | usbDevice = NULL; |
jmitc91516 | 0:47c880c1463d | 534 | |
jmitc91516 | 0:47c880c1463d | 535 | DrawErrorMessage("Waiting for USB device..."); |
jmitc91516 | 0:47c880c1463d | 536 | |
jmitc91516 | 0:47c880c1463d | 537 | // Wait (indefinitely) for a USB device to be connected - |
jmitc91516 | 0:47c880c1463d | 538 | // note that, if there is no USB device, we will hang at this point - |
jmitc91516 | 0:47c880c1463d | 539 | // there is no timeout |
jmitc91516 | 0:47c880c1463d | 540 | while(usbDevice == NULL) { |
jmitc91516 | 0:47c880c1463d | 541 | for (uint8_t i = 0; i < MAX_DEVICE_CONNECTED; ++i) { |
jmitc91516 | 0:47c880c1463d | 542 | usbDevice = usbHost->getDevice(i); |
jmitc91516 | 0:47c880c1463d | 543 | |
jmitc91516 | 0:47c880c1463d | 544 | if (usbDevice) { |
jmitc91516 | 0:47c880c1463d | 545 | break; |
jmitc91516 | 0:47c880c1463d | 546 | } |
jmitc91516 | 0:47c880c1463d | 547 | } |
jmitc91516 | 0:47c880c1463d | 548 | } |
jmitc91516 | 0:47c880c1463d | 549 | |
jmitc91516 | 0:47c880c1463d | 550 | DrawErrorMessage(" "); |
jmitc91516 | 0:47c880c1463d | 551 | |
jmitc91516 | 0:47c880c1463d | 552 | if(usbDevice != NULL) { |
jmitc91516 | 0:47c880c1463d | 553 | USB_TYPE enumerateRetVal = usbHost->enumerate(usbDevice, &usbHostGC); |
jmitc91516 | 0:47c880c1463d | 554 | |
jmitc91516 | 0:47c880c1463d | 555 | if (usbHostGC.DeviceIsGC()) { |
jmitc91516 | 0:47c880c1463d | 556 | if (usbHostGC.AttachGCDevice(usbDevice)) { |
jmitc91516 | 0:47c880c1463d | 557 | |
jmitc91516 | 0:47c880c1463d | 558 | DrawErrorMessage("Found GC device "); |
jmitc91516 | 0:47c880c1463d | 559 | |
jmitc91516 | 0:47c880c1463d | 560 | |
jmitc91516 | 0:47c880c1463d | 561 | SetupUSBGCTouchListener(board, usbDevice, &usbHostGC); |
jmitc91516 | 0:47c880c1463d | 562 | |
jmitc91516 | 0:47c880c1463d | 563 | DrawErrorMessage("After call to SetupUSBGCTouchListener "); |
jmitc91516 | 0:47c880c1463d | 564 | |
jmitc91516 | 0:47c880c1463d | 565 | |
jmitc91516 | 0:47c880c1463d | 566 | getGCStatusLoop = GetGCStatusLoop::GetInstance(usbDevice, &usbHostGC); |
jmitc91516 | 0:47c880c1463d | 567 | |
jmitc91516 | 0:47c880c1463d | 568 | DrawErrorMessage("After creation of GetGCStatusLoop instance "); |
jmitc91516 | 0:47c880c1463d | 569 | |
jmitc91516 | 0:47c880c1463d | 570 | |
jmitc91516 | 0:47c880c1463d | 571 | theGCHeatControl = new GCHeatControl(usbDevice, &usbHostGC); |
jmitc91516 | 0:47c880c1463d | 572 | |
jmitc91516 | 0:47c880c1463d | 573 | UpdateHeatOnOffEasyGuiVariable(); |
jmitc91516 | 0:47c880c1463d | 574 | |
jmitc91516 | 0:47c880c1463d | 575 | DrawErrorMessage("After UpdateHeatOnOffEasyGuiVariable "); |
jmitc91516 | 0:47c880c1463d | 576 | |
jmitc91516 | 0:47c880c1463d | 577 | |
jmitc91516 | 0:47c880c1463d | 578 | //theEthernetTimerHandler = EthernetTimerHandler::GetInstance(usbDevice, &usbHostGC); |
jmitc91516 | 0:47c880c1463d | 579 | |
jmitc91516 | 0:47c880c1463d | 580 | |
jmitc91516 | 0:47c880c1463d | 581 | getGCStatusLoop->SetHomePageGCComponentStatusColorAreas(&homePageGCComponentStatusColorAreas); |
jmitc91516 | 0:47c880c1463d | 582 | getGCStatusLoop->SetSingleGCComponentPageStatusColorAreas(&singleGCComponentPageStatusColorAreas); |
jmitc91516 | 0:47c880c1463d | 583 | |
jmitc91516 | 0:47c880c1463d | 584 | DrawErrorMessage("Point 1 "); |
jmitc91516 | 0:47c880c1463d | 585 | |
jmitc91516 | 0:47c880c1463d | 586 | getGCStatusLoop->SetupAllEasyGUIVariables(); |
jmitc91516 | 0:47c880c1463d | 587 | |
jmitc91516 | 0:47c880c1463d | 588 | DrawErrorMessage("Point 2 "); |
jmitc91516 | 0:47c880c1463d | 589 | |
jmitc91516 | 0:47c880c1463d | 590 | getGCStatusLoop->SetCurrentPage(GuiStruct_HomePage_1); |
jmitc91516 | 0:47c880c1463d | 591 | |
jmitc91516 | 0:47c880c1463d | 592 | DrawErrorMessage("Point 3 "); |
jmitc91516 | 0:47c880c1463d | 593 | |
jmitc91516 | 0:47c880c1463d | 594 | DisplayEasyGuiStructure(GuiStruct_HomePage_1, usbDevice, &usbHostGC); |
jmitc91516 | 0:47c880c1463d | 595 | |
jmitc91516 | 0:47c880c1463d | 596 | // Currently, this never returns - but it allows time for the TouchCallback function to be invoked |
jmitc91516 | 0:47c880c1463d | 597 | //getGCStatusLoop->MainLoop(); |
jmitc91516 | 0:47c880c1463d | 598 | getGCStatusLoop->MainLoopWithEthernet(); |
jmitc91516 | 0:47c880c1463d | 599 | |
jmitc91516 | 0:47c880c1463d | 600 | // Should never reach this code - but just in case... |
jmitc91516 | 0:47c880c1463d | 601 | delete theGCHeatControl; |
jmitc91516 | 0:47c880c1463d | 602 | |
jmitc91516 | 0:47c880c1463d | 603 | } else { |
jmitc91516 | 0:47c880c1463d | 604 | DrawErrorMessage("Failed to attach GC device to host "); |
jmitc91516 | 0:47c880c1463d | 605 | } |
jmitc91516 | 0:47c880c1463d | 606 | } else { |
jmitc91516 | 0:47c880c1463d | 607 | DrawErrorMessage(" *** USB device found, is *not* a GC *** "); |
jmitc91516 | 0:47c880c1463d | 608 | } |
jmitc91516 | 0:47c880c1463d | 609 | } else { |
jmitc91516 | 0:47c880c1463d | 610 | DrawErrorMessage(" *** No USB device found *** "); |
jmitc91516 | 0:47c880c1463d | 611 | } |
jmitc91516 | 0:47c880c1463d | 612 | |
jmitc91516 | 0:47c880c1463d | 613 | while(true) {} |
jmitc91516 | 0:47c880c1463d | 614 | } |
jmitc91516 | 0:47c880c1463d | 615 | |
jmitc91516 | 0:47c880c1463d | 616 |