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

Committer:
38domo
Date:
Tue Sep 15 19:11:11 2020 +0000
Branch:
jpa
Revision:
10:41aff2b7acc6
Parent:
0:48863a0964f5
Child:
11:b198b2f2676f
grov stream lib updated

Who changed what in which revision?

UserRevisionLine numberNew 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 10:41aff2b7acc6 10 char textButton[5][30];
38domo 10:41aff2b7acc6 11 char text1Button[5][30];
38domo 0:48863a0964f5 12 extern char statusButton[5][30];
38domo 10:41aff2b7acc6 13
38domo 10:41aff2b7acc6 14 extern int ethernet_actif ; // use ethernet connection
38domo 10:41aff2b7acc6 15 extern int wifi_actif ; // use wifi connection
38domo 10:41aff2b7acc6 16
38domo 0:48863a0964f5 17 uint32_t backColorTemp1=LCD_COLOR_BLACK, txtColorTemp1=LCD_COLOR_GREEN;
38domo 0:48863a0964f5 18 uint32_t backColorTemp2=LCD_COLOR_BLACK, txtColorTemp2=LCD_COLOR_GREEN;
38domo 0:48863a0964f5 19
38domo 10:41aff2b7acc6 20 // ----------------------------------------------------
38domo 0:48863a0964f5 21 int setTemp1(std::string temp1)
38domo 0:48863a0964f5 22 {
38domo 0:48863a0964f5 23 printf("\nTemp1 : %s\n", temp1.c_str());
38domo 0:48863a0964f5 24 BSP_LCD_SetBackColor(backColorTemp1);
38domo 0:48863a0964f5 25 BSP_LCD_SetTextColor(txtColorTemp1);
38domo 0:48863a0964f5 26 BSP_LCD_SetFont(&FontFreeMono64);
38domo 0:48863a0964f5 27 BSP_LCD_DisplayStringAt(10, 60, (uint8_t *)temp1.c_str(), LEFT_MODE);
38domo 0:48863a0964f5 28 BSP_LCD_SetFont(&Font12);
38domo 0:48863a0964f5 29 return 1;
38domo 0:48863a0964f5 30 }
38domo 10:41aff2b7acc6 31 // ------------------------------------------------
38domo 0:48863a0964f5 32 int setTemp2(std::string temp2)
38domo 0:48863a0964f5 33 {
38domo 0:48863a0964f5 34 printf("\nTemp2 : %s\n", temp2.c_str());
38domo 0:48863a0964f5 35 BSP_LCD_SetBackColor(backColorTemp2);
38domo 0:48863a0964f5 36 BSP_LCD_SetTextColor(txtColorTemp2);
38domo 0:48863a0964f5 37 BSP_LCD_SetFont(&FontFreeMono64);
38domo 0:48863a0964f5 38 BSP_LCD_DisplayStringAt(260, 60, (uint8_t *)temp2.c_str(), LEFT_MODE);
38domo 0:48863a0964f5 39 BSP_LCD_SetFont(&Font12);
38domo 0:48863a0964f5 40 return 1;
38domo 0:48863a0964f5 41 }
38domo 0:48863a0964f5 42
38domo 0:48863a0964f5 43 int xTempTitle[3],yTempTitle[3],dxTempTitle[3],dyTempTitle[3],xTxtTempTitle[3],yTxtTempTitle[3];
38domo 0:48863a0964f5 44 uint32_t backColorTempTitle[3], txtColorTempTitle[3];
38domo 0:48863a0964f5 45 char textTempTitle[3][30];
38domo 0:48863a0964f5 46
38domo 10:41aff2b7acc6 47 // ------------------------------------------------------------
38domo 0:48863a0964f5 48 int setDisplayTemp()
38domo 0:48863a0964f5 49 { int numTemp=0;
38domo 0:48863a0964f5 50 for (numTemp=1;numTemp<3;numTemp=numTemp+1)
38domo 0:48863a0964f5 51 {
38domo 0:48863a0964f5 52 BSP_LCD_SetFont(&Font16);
38domo 0:48863a0964f5 53 BSP_LCD_SetBackColor(backColorTempTitle[numTemp]);
38domo 0:48863a0964f5 54 BSP_LCD_SetTextColor(backColorTempTitle[numTemp]);
38domo 0:48863a0964f5 55 BSP_LCD_FillRect(xTempTitle[numTemp], yTempTitle[numTemp], dxTempTitle[numTemp], dyTempTitle[numTemp]);
38domo 0:48863a0964f5 56 BSP_LCD_SetTextColor(txtColorTempTitle[numTemp]);
38domo 0:48863a0964f5 57 BSP_LCD_DrawRect(xTempTitle[numTemp], yTempTitle[numTemp], dxTempTitle[numTemp], dyTempTitle[numTemp]);
38domo 0:48863a0964f5 58 BSP_LCD_DisplayStringAt(xTxtTempTitle[numTemp], yTxtTempTitle[numTemp], (uint8_t *)textTempTitle[numTemp], LEFT_MODE);
38domo 0:48863a0964f5 59 }
38domo 0:48863a0964f5 60 BSP_LCD_SetFont(&Font8);
38domo 0:48863a0964f5 61 return 1;
38domo 0:48863a0964f5 62 }
38domo 0:48863a0964f5 63
38domo 10:41aff2b7acc6 64 // -------------------------------------------------------
38domo 0:48863a0964f5 65 int initDisplayTemp()
38domo 0:48863a0964f5 66 { printf("\nInit DisplayTemp \n");
38domo 0:48863a0964f5 67 xTempTitle[1]=14;yTempTitle[1]=30;
38domo 0:48863a0964f5 68 dxTempTitle[1]=200;dyTempTitle[1]=23;
38domo 0:48863a0964f5 69 xTxtTempTitle[1]=15;yTxtTempTitle[1]=34;
38domo 0:48863a0964f5 70 backColorTempTitle[1]=LCD_COLOR_BLACK;txtColorTempTitle[1]=LCD_COLOR_GREEN;
38domo 0:48863a0964f5 71 sprintf(textTempTitle[1]," temp Salon ");
38domo 0:48863a0964f5 72 xTempTitle[2]=264;yTempTitle[2]=30;dxTempTitle[2]=200;dyTempTitle[2]=23;xTxtTempTitle[2]=265;yTxtTempTitle[2]=34;
38domo 0:48863a0964f5 73 backColorTempTitle[2]=LCD_COLOR_BLACK;txtColorTempTitle[2]=LCD_COLOR_GREEN;
38domo 0:48863a0964f5 74 sprintf(textTempTitle[2]," temp Ext ");
38domo 0:48863a0964f5 75 int xx=setDisplayTemp();
38domo 0:48863a0964f5 76 return 1;
38domo 0:48863a0964f5 77 }
38domo 0:48863a0964f5 78
38domo 0:48863a0964f5 79 // GroveStreams Settings
38domo 0:48863a0964f5 80 extern const char gsApiKey[] = "YOUR_SECRET_API_KEY_HERE"; //Change This!!!
38domo 0:48863a0964f5 81 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 82
38domo 0:48863a0964f5 83 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 84
38domo 0:48863a0964f5 85 ////GroveStreams groveStreams(gsApiKey, &lcd);
38domo 0:48863a0964f5 86 extern GroveStreams groveStreams;
38domo 0:48863a0964f5 87
38domo 0:48863a0964f5 88 extern const char* myMac;
38domo 10:41aff2b7acc6 89 int displayOn = 0;
38domo 10:41aff2b7acc6 90 // ------------------------------------------------------------
38domo 0:48863a0964f5 91 int initDatasGuiJPA()
38domo 0:48863a0964f5 92 { ////lcd.clear();
38domo 0:48863a0964f5 93 ////lcd.printf("Getting Samples...");
38domo 0:48863a0964f5 94 printf("Getting Samples...\n");
38domo 0:48863a0964f5 95 //Assemble the samples into URL parameters which are seperated with the "&" character
38domo 0:48863a0964f5 96 // Example: &s1=6.2&s2=78.231
38domo 0:48863a0964f5 97 char samples[64] = {0};
38domo 0:48863a0964f5 98 sprintf(samples, "&datas=init");
38domo 0:48863a0964f5 99 //Append on command requests (request stream values)
38domo 0:48863a0964f5 100 //This will indicate to GroveStreams to return the last value
38domo 0:48863a0964f5 101 // of each request stream during the sample upload
38domo 0:48863a0964f5 102 //strcat(samples, "&rsid=freq&rsid=led");
38domo 0:48863a0964f5 103 char resultBuffer[2000]= {0};
38domo 0:48863a0964f5 104 //Sending Samples (and returning current command stream values)
38domo 0:48863a0964f5 105 int sendResult=1;
38domo 10:41aff2b7acc6 106 printf("InitDataGuiJPA - Ethernet actif %i \n", ethernet_actif);
38domo 10:41aff2b7acc6 107 if (ethernet_actif == 0) // ethernet inactif
38domo 10:41aff2b7acc6 108 { // on n'utilise pas ethernet. lecture valeurs from sdcard
38domo 10:41aff2b7acc6 109 printf("Use local graphic datas\n");
38domo 10:41aff2b7acc6 110 // display temp1 window
38domo 10:41aff2b7acc6 111 // display temp2
38domo 10:41aff2b7acc6 112 // add wifi test.
38domo 10:41aff2b7acc6 113 // if wifi actif send request tasmota to retrieve values text box & buttons status
38domo 10:41aff2b7acc6 114 if (wifi_actif == 0)
38domo 10:41aff2b7acc6 115 { // si wifi actif launch tasmota request
38domo 10:41aff2b7acc6 116
38domo 10:41aff2b7acc6 117 // reteive tasmota results to display
38domo 10:41aff2b7acc6 118 }
38domo 10:41aff2b7acc6 119 displayOn = (0x01 | displayOn);// display temp1 & temp2 box
38domo 10:41aff2b7acc6 120
38domo 10:41aff2b7acc6 121 }
38domo 10:41aff2b7acc6 122 else
38domo 10:41aff2b7acc6 123 {
38domo 0:48863a0964f5 124 sendResult = groveStreams.sendInitDatasJPA(myMac, samples, gsCompName, gsCompTmplId, resultBuffer, sizeof resultBuffer);
38domo 10:41aff2b7acc6 125 if (sendResult == 0)
38domo 10:41aff2b7acc6 126 { ////lcd.printf("Send Successful");
38domo 0:48863a0964f5 127 printf("Send Successful\n");
38domo 0:48863a0964f5 128 //Handle command streams
38domo 10:41aff2b7acc6 129 if (strlen(resultBuffer) > 0 && resultBuffer[0] == '{')
38domo 10:41aff2b7acc6 130 { printf("Datas : %s\n",resultBuffer);
38domo 0:48863a0964f5 131 MbedJSONValue mbedJson;
38domo 0:48863a0964f5 132 parse(mbedJson, resultBuffer);
38domo 0:48863a0964f5 133 //sprintf((char*)text, "HTTP string : %s\n", resultBuffer);
38domo 0:48863a0964f5 134 //BSP_LCD_DisplayStringAt(0, LINE(10), (uint8_t *)&text, LEFT_MODE);
38domo 10:41aff2b7acc6 135 //int displayOn = 0;
38domo 0:48863a0964f5 136 string s;
38domo 10:41aff2b7acc6 137 if (mbedJson.hasMember("Temp1"))
38domo 10:41aff2b7acc6 138 { s = mbedJson["Temp1"]["backColorTemp"].get<std::string>();
38domo 0:48863a0964f5 139 backColorTemp1 = (uint32_t)strtoul(s.c_str(), NULL,16);
38domo 0:48863a0964f5 140 //printf("Temp1 backColorTemp1 : %s %X\n",s.c_str(),(uint32_t)strtoul(s.c_str(), NULL,0));
38domo 0:48863a0964f5 141 s = mbedJson["Temp1"]["txtColorTemp"].get<std::string>();
38domo 0:48863a0964f5 142 txtColorTemp1 = (uint32_t)strtoul(s.c_str(), NULL,16) ;
38domo 0:48863a0964f5 143 //printf("Temp1 txtColorTemp1 : %s %X\n",s.c_str(),(uint32_t)strtoul(s.c_str(), NULL,0));
38domo 0:48863a0964f5 144 s = mbedJson["Temp1"]["text"].get<std::string>();
38domo 0:48863a0964f5 145 sprintf(textTempTitle[1],s.c_str());
38domo 0:48863a0964f5 146 printf("Temp1 text : %s\n",s.c_str());
38domo 0:48863a0964f5 147 displayOn = (0x01 | displayOn);
38domo 10:41aff2b7acc6 148 }
38domo 10:41aff2b7acc6 149 if (mbedJson.hasMember("Temp2"))
38domo 10:41aff2b7acc6 150 { s = mbedJson["Temp2"]["backColorTemp"].get<std::string>();
38domo 0:48863a0964f5 151 backColorTemp2 = (uint32_t)strtoul(s.c_str(), NULL,16);
38domo 0:48863a0964f5 152 //printf("Temp2 text : %s\n",s.c_str());
38domo 0:48863a0964f5 153 s = mbedJson["Temp2"]["txtColorTemp"].get<std::string>();
38domo 0:48863a0964f5 154 txtColorTemp2 = (uint32_t)strtoul(s.c_str(), NULL,16) ;
38domo 0:48863a0964f5 155 //printf("Temp2 backColorTemp2 : %s\n",s.c_str());
38domo 0:48863a0964f5 156 s = mbedJson["Temp2"]["text"].get<std::string>();
38domo 0:48863a0964f5 157 sprintf(textTempTitle[2],s.c_str());
38domo 0:48863a0964f5 158 printf("Temp2 text : %s\n",s.c_str());
38domo 0:48863a0964f5 159 displayOn = (0x01 | displayOn);
38domo 10:41aff2b7acc6 160 }
38domo 10:41aff2b7acc6 161 if (mbedJson.hasMember("Touche1"))
38domo 10:41aff2b7acc6 162 { s = mbedJson["Touche1"]["Status"].get<std::string>();
38domo 0:48863a0964f5 163 sprintf(statusButton[1],s.c_str());
38domo 0:48863a0964f5 164 printf("Touche1 Status : %s\n",s.c_str());
38domo 0:48863a0964f5 165 s = mbedJson["Touche1"]["BackColor"].get<std::string>();
38domo 0:48863a0964f5 166 backColorButton[1] = (uint32_t)strtoul(s.c_str(), NULL,16);
38domo 0:48863a0964f5 167 printf("Touche1 BackColor : %s\n",s.c_str());
38domo 0:48863a0964f5 168 s = mbedJson["Touche1"]["TextColor"].get<std::string>();
38domo 0:48863a0964f5 169 txtColorButton[1] = (uint32_t)strtoul(s.c_str(), NULL,16);
38domo 0:48863a0964f5 170 printf("Touche1 TextColor : %s\n",s.c_str());
38domo 0:48863a0964f5 171 s = mbedJson["Touche1"]["text"].get<std::string>();
38domo 0:48863a0964f5 172 sprintf(textButton[1],s.c_str());
38domo 0:48863a0964f5 173 printf("Touche1 text : %s\n",s.c_str());
38domo 0:48863a0964f5 174 s = mbedJson["Touche1"]["text1"].get<std::string>();
38domo 0:48863a0964f5 175 sprintf(text1Button[1],s.c_str());
38domo 0:48863a0964f5 176 printf("Touche1 text1 : %s\n",s.c_str());
38domo 0:48863a0964f5 177 displayOn = (0x02 | displayOn);
38domo 10:41aff2b7acc6 178 }
38domo 10:41aff2b7acc6 179 if (mbedJson.hasMember("Touche2"))
38domo 10:41aff2b7acc6 180 { s = mbedJson["Touche2"]["Status"].get<std::string>();
38domo 0:48863a0964f5 181 sprintf(statusButton[2],s.c_str());
38domo 0:48863a0964f5 182 printf("Touche2 Status : %s\n",s.c_str());
38domo 0:48863a0964f5 183 s = mbedJson["Touche2"]["BackColor"].get<std::string>();
38domo 0:48863a0964f5 184 backColorButton[2] = (uint32_t)strtoul(s.c_str(), NULL,16);
38domo 0:48863a0964f5 185 printf("Touche1 BackColor : %s\n",s.c_str());
38domo 0:48863a0964f5 186 s = mbedJson["Touche2"]["TextColor"].get<std::string>();
38domo 0:48863a0964f5 187 txtColorButton[2] = (uint32_t)strtoul(s.c_str(), NULL,16);
38domo 0:48863a0964f5 188 printf("Touche2 TextColor : %s\n",s.c_str());
38domo 0:48863a0964f5 189 s = mbedJson["Touche2"]["text"].get<std::string>();
38domo 0:48863a0964f5 190 sprintf(textButton[2],s.c_str());
38domo 0:48863a0964f5 191 printf("Touche2 text : %s\n",s.c_str());
38domo 0:48863a0964f5 192 s = mbedJson["Touche2"]["text1"].get<std::string>();
38domo 0:48863a0964f5 193 sprintf(text1Button[2],s.c_str());
38domo 0:48863a0964f5 194 printf("Touche2 text1 : %s\n",s.c_str());
38domo 0:48863a0964f5 195 displayOn = (0x04 | displayOn);
38domo 10:41aff2b7acc6 196 }
38domo 10:41aff2b7acc6 197 if (mbedJson.hasMember("Touche3"))
38domo 10:41aff2b7acc6 198 { s = mbedJson["Touche3"]["Status"].get<std::string>();
38domo 0:48863a0964f5 199 sprintf(statusButton[3],s.c_str());
38domo 0:48863a0964f5 200 printf("Touche3 Status : %s\n",s.c_str());
38domo 0:48863a0964f5 201 s = mbedJson["Touche3"]["BackColor"].get<std::string>();
38domo 0:48863a0964f5 202 backColorButton[3] = (uint32_t)strtoul(s.c_str(), NULL,16);
38domo 0:48863a0964f5 203 printf("Touche3 BackColor : %s\n",s.c_str());
38domo 0:48863a0964f5 204 s = mbedJson["Touche3"]["TextColor"].get<std::string>();
38domo 0:48863a0964f5 205 txtColorButton[3] = (uint32_t)strtoul(s.c_str(), NULL,16);
38domo 0:48863a0964f5 206 printf("Touche3 TextColor : %s\n",s.c_str());
38domo 0:48863a0964f5 207 s = mbedJson["Touche3"]["text"].get<std::string>();
38domo 0:48863a0964f5 208 sprintf(textButton[3],s.c_str());
38domo 0:48863a0964f5 209 printf("Touche3 text : %s\n",s.c_str());
38domo 0:48863a0964f5 210 s = mbedJson["Touche3"]["text1"].get<std::string>();
38domo 0:48863a0964f5 211 sprintf(text1Button[3],s.c_str());
38domo 0:48863a0964f5 212 printf("Touche3 text1 : %s\n",s.c_str());
38domo 0:48863a0964f5 213 displayOn = (0x08 | displayOn);
38domo 10:41aff2b7acc6 214 }
38domo 10:41aff2b7acc6 215 if (mbedJson.hasMember("Touche4"))
38domo 10:41aff2b7acc6 216 { s = mbedJson["Touche4"]["Status"].get<std::string>();
38domo 0:48863a0964f5 217 sprintf(statusButton[4],s.c_str());
38domo 0:48863a0964f5 218 printf("Touche4 Status : %s\n",s.c_str());
38domo 0:48863a0964f5 219 s = mbedJson["Touche4"]["BackColor"].get<std::string>();
38domo 0:48863a0964f5 220 backColorButton[4] = (uint32_t)strtoul(s.c_str(), NULL,16);
38domo 0:48863a0964f5 221 printf("Touche4 BackColor : %s\n",s.c_str());
38domo 0:48863a0964f5 222 s = mbedJson["Touche4"]["TextColor"].get<std::string>();
38domo 0:48863a0964f5 223 txtColorButton[4] = (uint32_t)strtoul(s.c_str(), NULL,16);
38domo 0:48863a0964f5 224 printf("Touche4 TextColor : %s\n",s.c_str());
38domo 0:48863a0964f5 225 s = mbedJson["Touche4"]["text"].get<std::string>();
38domo 0:48863a0964f5 226 sprintf(textButton[4],s.c_str());
38domo 0:48863a0964f5 227 printf("Touche4 text : %s\n",s.c_str());
38domo 0:48863a0964f5 228 s = mbedJson["Touche4"]["text1"].get<std::string>();
38domo 0:48863a0964f5 229 sprintf(text1Button[4],s.c_str());
38domo 0:48863a0964f5 230 printf("Touche4 text1 : %s\n",s.c_str());
38domo 0:48863a0964f5 231 displayOn = (0x10 | displayOn);
38domo 10:41aff2b7acc6 232 }
38domo 10:41aff2b7acc6 233 if (mbedJson.hasMember("Temp1"))
38domo 10:41aff2b7acc6 234 { //int pp=setTemp1(mbedJson["Temp1"].get<std::string>());
38domo 10:41aff2b7acc6 235 }
38domo 10:41aff2b7acc6 236 if (mbedJson.hasMember("Temp2"))
38domo 10:41aff2b7acc6 237 { //int pp=setTemp1(mbedJson["Temp2"].get<std::string>());
38domo 10:41aff2b7acc6 238 }
38domo 10:41aff2b7acc6 239
38domo 0:48863a0964f5 240 if ((displayOn & 0x02) > 0) {touchButtonJPA1(1);}
38domo 0:48863a0964f5 241 if ((displayOn & 0x04) > 0) {touchButtonJPA1(2);}
38domo 0:48863a0964f5 242 if ((displayOn & 0x08) > 0) {touchButtonJPA1(3);}
38domo 0:48863a0964f5 243 if ((displayOn & 0x10) > 0) {touchButtonJPA1(4);}
38domo 0:48863a0964f5 244 }
38domo 10:41aff2b7acc6 245 } // fin test send result
38domo 10:41aff2b7acc6 246 } // fin test ethernet actif
38domo 10:41aff2b7acc6 247 if ((displayOn & 0x01) > 0) {setDisplayTemp();}
38domo 10:41aff2b7acc6 248
38domo 0:48863a0964f5 249 return 1;
38domo 0:48863a0964f5 250 }
38domo 0:48863a0964f5 251