![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
updated version with parameters loaded from sdcard
Dependencies: F7_Ethernet mbed MbedJSONValue LCD_DISCO_F746NG mbed-rtos BSP_DISCO_F746NG CANMsg NetworkAPI SDFileSystem_Warning_Fixed GroveStreamsmodified LcdDiscoF746NgTracer JSON
GuiJPA.cpp@0:48863a0964f5, 2020-08-31 (annotated)
- Committer:
- 38domo
- Date:
- Mon Aug 31 19:19:48 2020 +0000
- Revision:
- 0:48863a0964f5
- Child:
- 10:41aff2b7acc6
grove stream upated 31/08
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
38domo | 0:48863a0964f5 | 1 | #include "stm32746g_discovery_lcd.h" |
38domo | 0:48863a0964f5 | 2 | #include "stm32746g_discovery_ts.h" |
38domo | 0:48863a0964f5 | 3 | #include "MbedJSONValue.h" |
38domo | 0:48863a0964f5 | 4 | #include "GroveStreams.h" |
38domo | 0:48863a0964f5 | 5 | #include <string> |
38domo | 0:48863a0964f5 | 6 | |
38domo | 0:48863a0964f5 | 7 | int touchButtonJPA1(int numButton); |
38domo | 0:48863a0964f5 | 8 | extern uint32_t backColorButton[5]; |
38domo | 0:48863a0964f5 | 9 | extern uint32_t txtColorButton[5]; |
38domo | 0:48863a0964f5 | 10 | extern char textButton[5][30]; |
38domo | 0:48863a0964f5 | 11 | extern char text1Button[5][30]; |
38domo | 0:48863a0964f5 | 12 | extern char statusButton[5][30]; |
38domo | 0:48863a0964f5 | 13 | uint32_t backColorTemp1=LCD_COLOR_BLACK, txtColorTemp1=LCD_COLOR_GREEN; |
38domo | 0:48863a0964f5 | 14 | uint32_t backColorTemp2=LCD_COLOR_BLACK, txtColorTemp2=LCD_COLOR_GREEN; |
38domo | 0:48863a0964f5 | 15 | |
38domo | 0:48863a0964f5 | 16 | int setTemp1(std::string temp1) |
38domo | 0:48863a0964f5 | 17 | { |
38domo | 0:48863a0964f5 | 18 | printf("\nTemp1 : %s\n", temp1.c_str()); |
38domo | 0:48863a0964f5 | 19 | BSP_LCD_SetBackColor(backColorTemp1); |
38domo | 0:48863a0964f5 | 20 | BSP_LCD_SetTextColor(txtColorTemp1); |
38domo | 0:48863a0964f5 | 21 | BSP_LCD_SetFont(&FontFreeMono64); |
38domo | 0:48863a0964f5 | 22 | BSP_LCD_DisplayStringAt(10, 60, (uint8_t *)temp1.c_str(), LEFT_MODE); |
38domo | 0:48863a0964f5 | 23 | BSP_LCD_SetFont(&Font12); |
38domo | 0:48863a0964f5 | 24 | return 1; |
38domo | 0:48863a0964f5 | 25 | } |
38domo | 0:48863a0964f5 | 26 | |
38domo | 0:48863a0964f5 | 27 | int setTemp2(std::string temp2) |
38domo | 0:48863a0964f5 | 28 | { |
38domo | 0:48863a0964f5 | 29 | printf("\nTemp2 : %s\n", temp2.c_str()); |
38domo | 0:48863a0964f5 | 30 | BSP_LCD_SetBackColor(backColorTemp2); |
38domo | 0:48863a0964f5 | 31 | BSP_LCD_SetTextColor(txtColorTemp2); |
38domo | 0:48863a0964f5 | 32 | BSP_LCD_SetFont(&FontFreeMono64); |
38domo | 0:48863a0964f5 | 33 | BSP_LCD_DisplayStringAt(260, 60, (uint8_t *)temp2.c_str(), LEFT_MODE); |
38domo | 0:48863a0964f5 | 34 | BSP_LCD_SetFont(&Font12); |
38domo | 0:48863a0964f5 | 35 | return 1; |
38domo | 0:48863a0964f5 | 36 | } |
38domo | 0:48863a0964f5 | 37 | |
38domo | 0:48863a0964f5 | 38 | int xTempTitle[3],yTempTitle[3],dxTempTitle[3],dyTempTitle[3],xTxtTempTitle[3],yTxtTempTitle[3]; |
38domo | 0:48863a0964f5 | 39 | uint32_t backColorTempTitle[3], txtColorTempTitle[3]; |
38domo | 0:48863a0964f5 | 40 | char textTempTitle[3][30]; |
38domo | 0:48863a0964f5 | 41 | |
38domo | 0:48863a0964f5 | 42 | int setDisplayTemp() |
38domo | 0:48863a0964f5 | 43 | { int numTemp=0; |
38domo | 0:48863a0964f5 | 44 | for (numTemp=1;numTemp<3;numTemp=numTemp+1) |
38domo | 0:48863a0964f5 | 45 | { |
38domo | 0:48863a0964f5 | 46 | BSP_LCD_SetFont(&Font16); |
38domo | 0:48863a0964f5 | 47 | BSP_LCD_SetBackColor(backColorTempTitle[numTemp]); |
38domo | 0:48863a0964f5 | 48 | BSP_LCD_SetTextColor(backColorTempTitle[numTemp]); |
38domo | 0:48863a0964f5 | 49 | BSP_LCD_FillRect(xTempTitle[numTemp], yTempTitle[numTemp], dxTempTitle[numTemp], dyTempTitle[numTemp]); |
38domo | 0:48863a0964f5 | 50 | BSP_LCD_SetTextColor(txtColorTempTitle[numTemp]); |
38domo | 0:48863a0964f5 | 51 | BSP_LCD_DrawRect(xTempTitle[numTemp], yTempTitle[numTemp], dxTempTitle[numTemp], dyTempTitle[numTemp]); |
38domo | 0:48863a0964f5 | 52 | BSP_LCD_DisplayStringAt(xTxtTempTitle[numTemp], yTxtTempTitle[numTemp], (uint8_t *)textTempTitle[numTemp], LEFT_MODE); |
38domo | 0:48863a0964f5 | 53 | } |
38domo | 0:48863a0964f5 | 54 | BSP_LCD_SetFont(&Font8); |
38domo | 0:48863a0964f5 | 55 | return 1; |
38domo | 0:48863a0964f5 | 56 | } |
38domo | 0:48863a0964f5 | 57 | |
38domo | 0:48863a0964f5 | 58 | int initDisplayTemp() |
38domo | 0:48863a0964f5 | 59 | { printf("\nInit DisplayTemp \n"); |
38domo | 0:48863a0964f5 | 60 | xTempTitle[1]=14;yTempTitle[1]=30; |
38domo | 0:48863a0964f5 | 61 | dxTempTitle[1]=200;dyTempTitle[1]=23; |
38domo | 0:48863a0964f5 | 62 | xTxtTempTitle[1]=15;yTxtTempTitle[1]=34; |
38domo | 0:48863a0964f5 | 63 | backColorTempTitle[1]=LCD_COLOR_BLACK;txtColorTempTitle[1]=LCD_COLOR_GREEN; |
38domo | 0:48863a0964f5 | 64 | sprintf(textTempTitle[1]," temp Salon "); |
38domo | 0:48863a0964f5 | 65 | xTempTitle[2]=264;yTempTitle[2]=30;dxTempTitle[2]=200;dyTempTitle[2]=23;xTxtTempTitle[2]=265;yTxtTempTitle[2]=34; |
38domo | 0:48863a0964f5 | 66 | backColorTempTitle[2]=LCD_COLOR_BLACK;txtColorTempTitle[2]=LCD_COLOR_GREEN; |
38domo | 0:48863a0964f5 | 67 | sprintf(textTempTitle[2]," temp Ext "); |
38domo | 0:48863a0964f5 | 68 | int xx=setDisplayTemp(); |
38domo | 0:48863a0964f5 | 69 | return 1; |
38domo | 0:48863a0964f5 | 70 | } |
38domo | 0:48863a0964f5 | 71 | |
38domo | 0:48863a0964f5 | 72 | // GroveStreams Settings |
38domo | 0:48863a0964f5 | 73 | extern const char gsApiKey[] = "YOUR_SECRET_API_KEY_HERE"; //Change This!!! |
38domo | 0:48863a0964f5 | 74 | extern const char gsCompName[] = "STM32F746+Discovery"; //Optionally change. Set this to give your component a name when it initially registers. Encode special chars such as spaces. |
38domo | 0:48863a0964f5 | 75 | |
38domo | 0:48863a0964f5 | 76 | extern const char gsCompTmplId[]= ""; //Optional. Tells GS what template to use when the feed initially arrives and a new component needs to be created. |
38domo | 0:48863a0964f5 | 77 | |
38domo | 0:48863a0964f5 | 78 | ////GroveStreams groveStreams(gsApiKey, &lcd); |
38domo | 0:48863a0964f5 | 79 | extern GroveStreams groveStreams; |
38domo | 0:48863a0964f5 | 80 | |
38domo | 0:48863a0964f5 | 81 | extern const char* myMac; |
38domo | 0:48863a0964f5 | 82 | |
38domo | 0:48863a0964f5 | 83 | int initDatasGuiJPA() |
38domo | 0:48863a0964f5 | 84 | { ////lcd.clear(); |
38domo | 0:48863a0964f5 | 85 | ////lcd.printf("Getting Samples..."); |
38domo | 0:48863a0964f5 | 86 | printf("Getting Samples...\n"); |
38domo | 0:48863a0964f5 | 87 | //Assemble the samples into URL parameters which are seperated with the "&" character |
38domo | 0:48863a0964f5 | 88 | // Example: &s1=6.2&s2=78.231 |
38domo | 0:48863a0964f5 | 89 | char samples[64] = {0}; |
38domo | 0:48863a0964f5 | 90 | sprintf(samples, "&datas=init"); |
38domo | 0:48863a0964f5 | 91 | //Append on command requests (request stream values) |
38domo | 0:48863a0964f5 | 92 | //This will indicate to GroveStreams to return the last value |
38domo | 0:48863a0964f5 | 93 | // of each request stream during the sample upload |
38domo | 0:48863a0964f5 | 94 | //strcat(samples, "&rsid=freq&rsid=led"); |
38domo | 0:48863a0964f5 | 95 | char resultBuffer[2000]= {0}; |
38domo | 0:48863a0964f5 | 96 | //Sending Samples (and returning current command stream values) |
38domo | 0:48863a0964f5 | 97 | int sendResult=1; |
38domo | 0:48863a0964f5 | 98 | sendResult = groveStreams.sendInitDatasJPA(myMac, samples, gsCompName, gsCompTmplId, resultBuffer, sizeof resultBuffer); |
38domo | 0:48863a0964f5 | 99 | if (sendResult == 0) { |
38domo | 0:48863a0964f5 | 100 | ////lcd.printf("Send Successful"); |
38domo | 0:48863a0964f5 | 101 | printf("Send Successful\n"); |
38domo | 0:48863a0964f5 | 102 | //Handle command streams |
38domo | 0:48863a0964f5 | 103 | if (strlen(resultBuffer) > 0 && resultBuffer[0] == '{') { |
38domo | 0:48863a0964f5 | 104 | printf("Datas : %s\n",resultBuffer); |
38domo | 0:48863a0964f5 | 105 | MbedJSONValue mbedJson; |
38domo | 0:48863a0964f5 | 106 | parse(mbedJson, resultBuffer); |
38domo | 0:48863a0964f5 | 107 | //sprintf((char*)text, "HTTP string : %s\n", resultBuffer); |
38domo | 0:48863a0964f5 | 108 | //BSP_LCD_DisplayStringAt(0, LINE(10), (uint8_t *)&text, LEFT_MODE); |
38domo | 0:48863a0964f5 | 109 | int displayOn = 0; |
38domo | 0:48863a0964f5 | 110 | string s; |
38domo | 0:48863a0964f5 | 111 | if (mbedJson.hasMember("Temp1")) { |
38domo | 0:48863a0964f5 | 112 | s = mbedJson["Temp1"]["backColorTemp"].get<std::string>(); |
38domo | 0:48863a0964f5 | 113 | backColorTemp1 = (uint32_t)strtoul(s.c_str(), NULL,16); |
38domo | 0:48863a0964f5 | 114 | //printf("Temp1 backColorTemp1 : %s %X\n",s.c_str(),(uint32_t)strtoul(s.c_str(), NULL,0)); |
38domo | 0:48863a0964f5 | 115 | s = mbedJson["Temp1"]["txtColorTemp"].get<std::string>(); |
38domo | 0:48863a0964f5 | 116 | txtColorTemp1 = (uint32_t)strtoul(s.c_str(), NULL,16) ; |
38domo | 0:48863a0964f5 | 117 | //printf("Temp1 txtColorTemp1 : %s %X\n",s.c_str(),(uint32_t)strtoul(s.c_str(), NULL,0)); |
38domo | 0:48863a0964f5 | 118 | s = mbedJson["Temp1"]["text"].get<std::string>(); |
38domo | 0:48863a0964f5 | 119 | sprintf(textTempTitle[1],s.c_str()); |
38domo | 0:48863a0964f5 | 120 | printf("Temp1 text : %s\n",s.c_str()); |
38domo | 0:48863a0964f5 | 121 | displayOn = (0x01 | displayOn); |
38domo | 0:48863a0964f5 | 122 | } |
38domo | 0:48863a0964f5 | 123 | if (mbedJson.hasMember("Temp2")) { |
38domo | 0:48863a0964f5 | 124 | s = mbedJson["Temp2"]["backColorTemp"].get<std::string>(); |
38domo | 0:48863a0964f5 | 125 | backColorTemp2 = (uint32_t)strtoul(s.c_str(), NULL,16); |
38domo | 0:48863a0964f5 | 126 | //printf("Temp2 text : %s\n",s.c_str()); |
38domo | 0:48863a0964f5 | 127 | s = mbedJson["Temp2"]["txtColorTemp"].get<std::string>(); |
38domo | 0:48863a0964f5 | 128 | txtColorTemp2 = (uint32_t)strtoul(s.c_str(), NULL,16) ; |
38domo | 0:48863a0964f5 | 129 | //printf("Temp2 backColorTemp2 : %s\n",s.c_str()); |
38domo | 0:48863a0964f5 | 130 | s = mbedJson["Temp2"]["text"].get<std::string>(); |
38domo | 0:48863a0964f5 | 131 | sprintf(textTempTitle[2],s.c_str()); |
38domo | 0:48863a0964f5 | 132 | printf("Temp2 text : %s\n",s.c_str()); |
38domo | 0:48863a0964f5 | 133 | displayOn = (0x01 | displayOn); |
38domo | 0:48863a0964f5 | 134 | } |
38domo | 0:48863a0964f5 | 135 | if (mbedJson.hasMember("Touche1")) { |
38domo | 0:48863a0964f5 | 136 | s = mbedJson["Touche1"]["Status"].get<std::string>(); |
38domo | 0:48863a0964f5 | 137 | sprintf(statusButton[1],s.c_str()); |
38domo | 0:48863a0964f5 | 138 | printf("Touche1 Status : %s\n",s.c_str()); |
38domo | 0:48863a0964f5 | 139 | s = mbedJson["Touche1"]["BackColor"].get<std::string>(); |
38domo | 0:48863a0964f5 | 140 | backColorButton[1] = (uint32_t)strtoul(s.c_str(), NULL,16); |
38domo | 0:48863a0964f5 | 141 | printf("Touche1 BackColor : %s\n",s.c_str()); |
38domo | 0:48863a0964f5 | 142 | s = mbedJson["Touche1"]["TextColor"].get<std::string>(); |
38domo | 0:48863a0964f5 | 143 | txtColorButton[1] = (uint32_t)strtoul(s.c_str(), NULL,16); |
38domo | 0:48863a0964f5 | 144 | printf("Touche1 TextColor : %s\n",s.c_str()); |
38domo | 0:48863a0964f5 | 145 | s = mbedJson["Touche1"]["text"].get<std::string>(); |
38domo | 0:48863a0964f5 | 146 | sprintf(textButton[1],s.c_str()); |
38domo | 0:48863a0964f5 | 147 | printf("Touche1 text : %s\n",s.c_str()); |
38domo | 0:48863a0964f5 | 148 | s = mbedJson["Touche1"]["text1"].get<std::string>(); |
38domo | 0:48863a0964f5 | 149 | sprintf(text1Button[1],s.c_str()); |
38domo | 0:48863a0964f5 | 150 | printf("Touche1 text1 : %s\n",s.c_str()); |
38domo | 0:48863a0964f5 | 151 | displayOn = (0x02 | displayOn); |
38domo | 0:48863a0964f5 | 152 | } |
38domo | 0:48863a0964f5 | 153 | if (mbedJson.hasMember("Touche2")) { |
38domo | 0:48863a0964f5 | 154 | s = mbedJson["Touche2"]["Status"].get<std::string>(); |
38domo | 0:48863a0964f5 | 155 | sprintf(statusButton[2],s.c_str()); |
38domo | 0:48863a0964f5 | 156 | printf("Touche2 Status : %s\n",s.c_str()); |
38domo | 0:48863a0964f5 | 157 | s = mbedJson["Touche2"]["BackColor"].get<std::string>(); |
38domo | 0:48863a0964f5 | 158 | backColorButton[2] = (uint32_t)strtoul(s.c_str(), NULL,16); |
38domo | 0:48863a0964f5 | 159 | printf("Touche1 BackColor : %s\n",s.c_str()); |
38domo | 0:48863a0964f5 | 160 | s = mbedJson["Touche2"]["TextColor"].get<std::string>(); |
38domo | 0:48863a0964f5 | 161 | txtColorButton[2] = (uint32_t)strtoul(s.c_str(), NULL,16); |
38domo | 0:48863a0964f5 | 162 | printf("Touche2 TextColor : %s\n",s.c_str()); |
38domo | 0:48863a0964f5 | 163 | s = mbedJson["Touche2"]["text"].get<std::string>(); |
38domo | 0:48863a0964f5 | 164 | sprintf(textButton[2],s.c_str()); |
38domo | 0:48863a0964f5 | 165 | printf("Touche2 text : %s\n",s.c_str()); |
38domo | 0:48863a0964f5 | 166 | s = mbedJson["Touche2"]["text1"].get<std::string>(); |
38domo | 0:48863a0964f5 | 167 | sprintf(text1Button[2],s.c_str()); |
38domo | 0:48863a0964f5 | 168 | printf("Touche2 text1 : %s\n",s.c_str()); |
38domo | 0:48863a0964f5 | 169 | displayOn = (0x04 | displayOn); |
38domo | 0:48863a0964f5 | 170 | } |
38domo | 0:48863a0964f5 | 171 | if (mbedJson.hasMember("Touche3")) { |
38domo | 0:48863a0964f5 | 172 | s = mbedJson["Touche3"]["Status"].get<std::string>(); |
38domo | 0:48863a0964f5 | 173 | sprintf(statusButton[3],s.c_str()); |
38domo | 0:48863a0964f5 | 174 | printf("Touche3 Status : %s\n",s.c_str()); |
38domo | 0:48863a0964f5 | 175 | s = mbedJson["Touche3"]["BackColor"].get<std::string>(); |
38domo | 0:48863a0964f5 | 176 | backColorButton[3] = (uint32_t)strtoul(s.c_str(), NULL,16); |
38domo | 0:48863a0964f5 | 177 | printf("Touche3 BackColor : %s\n",s.c_str()); |
38domo | 0:48863a0964f5 | 178 | s = mbedJson["Touche3"]["TextColor"].get<std::string>(); |
38domo | 0:48863a0964f5 | 179 | txtColorButton[3] = (uint32_t)strtoul(s.c_str(), NULL,16); |
38domo | 0:48863a0964f5 | 180 | printf("Touche3 TextColor : %s\n",s.c_str()); |
38domo | 0:48863a0964f5 | 181 | s = mbedJson["Touche3"]["text"].get<std::string>(); |
38domo | 0:48863a0964f5 | 182 | sprintf(textButton[3],s.c_str()); |
38domo | 0:48863a0964f5 | 183 | printf("Touche3 text : %s\n",s.c_str()); |
38domo | 0:48863a0964f5 | 184 | s = mbedJson["Touche3"]["text1"].get<std::string>(); |
38domo | 0:48863a0964f5 | 185 | sprintf(text1Button[3],s.c_str()); |
38domo | 0:48863a0964f5 | 186 | printf("Touche3 text1 : %s\n",s.c_str()); |
38domo | 0:48863a0964f5 | 187 | displayOn = (0x08 | displayOn); |
38domo | 0:48863a0964f5 | 188 | } |
38domo | 0:48863a0964f5 | 189 | if (mbedJson.hasMember("Touche4")) { |
38domo | 0:48863a0964f5 | 190 | s = mbedJson["Touche4"]["Status"].get<std::string>(); |
38domo | 0:48863a0964f5 | 191 | sprintf(statusButton[4],s.c_str()); |
38domo | 0:48863a0964f5 | 192 | printf("Touche4 Status : %s\n",s.c_str()); |
38domo | 0:48863a0964f5 | 193 | s = mbedJson["Touche4"]["BackColor"].get<std::string>(); |
38domo | 0:48863a0964f5 | 194 | backColorButton[4] = (uint32_t)strtoul(s.c_str(), NULL,16); |
38domo | 0:48863a0964f5 | 195 | printf("Touche4 BackColor : %s\n",s.c_str()); |
38domo | 0:48863a0964f5 | 196 | s = mbedJson["Touche4"]["TextColor"].get<std::string>(); |
38domo | 0:48863a0964f5 | 197 | txtColorButton[4] = (uint32_t)strtoul(s.c_str(), NULL,16); |
38domo | 0:48863a0964f5 | 198 | printf("Touche4 TextColor : %s\n",s.c_str()); |
38domo | 0:48863a0964f5 | 199 | s = mbedJson["Touche4"]["text"].get<std::string>(); |
38domo | 0:48863a0964f5 | 200 | sprintf(textButton[4],s.c_str()); |
38domo | 0:48863a0964f5 | 201 | printf("Touche4 text : %s\n",s.c_str()); |
38domo | 0:48863a0964f5 | 202 | s = mbedJson["Touche4"]["text1"].get<std::string>(); |
38domo | 0:48863a0964f5 | 203 | sprintf(text1Button[4],s.c_str()); |
38domo | 0:48863a0964f5 | 204 | printf("Touche4 text1 : %s\n",s.c_str()); |
38domo | 0:48863a0964f5 | 205 | displayOn = (0x10 | displayOn); |
38domo | 0:48863a0964f5 | 206 | } |
38domo | 0:48863a0964f5 | 207 | if (mbedJson.hasMember("Temp1")) { |
38domo | 0:48863a0964f5 | 208 | //int pp=setTemp1(mbedJson["Temp1"].get<std::string>()); |
38domo | 0:48863a0964f5 | 209 | } |
38domo | 0:48863a0964f5 | 210 | if (mbedJson.hasMember("Temp2")) { |
38domo | 0:48863a0964f5 | 211 | //int pp=setTemp1(mbedJson["Temp2"].get<std::string>()); |
38domo | 0:48863a0964f5 | 212 | } |
38domo | 0:48863a0964f5 | 213 | if ((displayOn & 0x01) > 0) {setDisplayTemp();} |
38domo | 0:48863a0964f5 | 214 | if ((displayOn & 0x02) > 0) {touchButtonJPA1(1);} |
38domo | 0:48863a0964f5 | 215 | if ((displayOn & 0x04) > 0) {touchButtonJPA1(2);} |
38domo | 0:48863a0964f5 | 216 | if ((displayOn & 0x08) > 0) {touchButtonJPA1(3);} |
38domo | 0:48863a0964f5 | 217 | if ((displayOn & 0x10) > 0) {touchButtonJPA1(4);} |
38domo | 0:48863a0964f5 | 218 | } |
38domo | 0:48863a0964f5 | 219 | } |
38domo | 0:48863a0964f5 | 220 | return 1; |
38domo | 0:48863a0964f5 | 221 | } |
38domo | 0:48863a0964f5 | 222 |