version with updated libs

Dependencies:   F7_Ethernet mbed MbedJSONValue LCD_DISCO_F746NG mbed-rtos BSP_DISCO_F746NG CANMsg NetworkAPI SDFileSystem_Warning_Fixed GroveStreamsmodified LcdDiscoF746NgTracer JSON

Committer:
38domo
Date:
Wed Sep 16 05:47:02 2020 +0000
Branch:
jpa
Revision:
11:b198b2f2676f
Parent:
10:41aff2b7acc6
Child:
12:15ae35cfb03f
display temp ok

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 11:b198b2f2676f 107
38domo 11:b198b2f2676f 108
38domo 11:b198b2f2676f 109 if (ethernet_actif == 0) // ethernet inactif -------------------------------------
38domo 10:41aff2b7acc6 110 { // on n'utilise pas ethernet. lecture valeurs from sdcard
38domo 10:41aff2b7acc6 111 printf("Use local graphic datas\n");
38domo 10:41aff2b7acc6 112 // display temp1 window
38domo 10:41aff2b7acc6 113 // display temp2
38domo 10:41aff2b7acc6 114 // add wifi test.
38domo 10:41aff2b7acc6 115 // if wifi actif send request tasmota to retrieve values text box & buttons status
38domo 10:41aff2b7acc6 116 if (wifi_actif == 0)
38domo 10:41aff2b7acc6 117 { // si wifi actif launch tasmota request
38domo 10:41aff2b7acc6 118
38domo 10:41aff2b7acc6 119 // reteive tasmota results to display
38domo 11:b198b2f2676f 120 }
38domo 11:b198b2f2676f 121 backColorTemp1 = (uint32_t)strtoul("0xFF808080", NULL,16); //gray
38domo 11:b198b2f2676f 122 txtColorTemp1 = (uint32_t)strtoul("0xFFFFFF00", NULL,16) ;
38domo 11:b198b2f2676f 123 backColorTemp2 = (uint32_t)strtoul("0xFF808080", NULL,16);
38domo 11:b198b2f2676f 124 txtColorTemp2 = (uint32_t)strtoul("0xFFFFFF00", NULL,16) ;
38domo 11:b198b2f2676f 125 displayOn = (0x01 | displayOn);// display temp1 & temp2 box
38domo 10:41aff2b7acc6 126 }
38domo 10:41aff2b7acc6 127 else
38domo 10:41aff2b7acc6 128 {
38domo 0:48863a0964f5 129 sendResult = groveStreams.sendInitDatasJPA(myMac, samples, gsCompName, gsCompTmplId, resultBuffer, sizeof resultBuffer);
38domo 10:41aff2b7acc6 130 if (sendResult == 0)
38domo 10:41aff2b7acc6 131 { ////lcd.printf("Send Successful");
38domo 0:48863a0964f5 132 printf("Send Successful\n");
38domo 0:48863a0964f5 133 //Handle command streams
38domo 10:41aff2b7acc6 134 if (strlen(resultBuffer) > 0 && resultBuffer[0] == '{')
38domo 10:41aff2b7acc6 135 { printf("Datas : %s\n",resultBuffer);
38domo 0:48863a0964f5 136 MbedJSONValue mbedJson;
38domo 0:48863a0964f5 137 parse(mbedJson, resultBuffer);
38domo 0:48863a0964f5 138 //sprintf((char*)text, "HTTP string : %s\n", resultBuffer);
38domo 0:48863a0964f5 139 //BSP_LCD_DisplayStringAt(0, LINE(10), (uint8_t *)&text, LEFT_MODE);
38domo 10:41aff2b7acc6 140 //int displayOn = 0;
38domo 0:48863a0964f5 141 string s;
38domo 10:41aff2b7acc6 142 if (mbedJson.hasMember("Temp1"))
38domo 10:41aff2b7acc6 143 { s = mbedJson["Temp1"]["backColorTemp"].get<std::string>();
38domo 0:48863a0964f5 144 backColorTemp1 = (uint32_t)strtoul(s.c_str(), NULL,16);
38domo 0:48863a0964f5 145 //printf("Temp1 backColorTemp1 : %s %X\n",s.c_str(),(uint32_t)strtoul(s.c_str(), NULL,0));
38domo 0:48863a0964f5 146 s = mbedJson["Temp1"]["txtColorTemp"].get<std::string>();
38domo 0:48863a0964f5 147 txtColorTemp1 = (uint32_t)strtoul(s.c_str(), NULL,16) ;
38domo 0:48863a0964f5 148 //printf("Temp1 txtColorTemp1 : %s %X\n",s.c_str(),(uint32_t)strtoul(s.c_str(), NULL,0));
38domo 0:48863a0964f5 149 s = mbedJson["Temp1"]["text"].get<std::string>();
38domo 0:48863a0964f5 150 sprintf(textTempTitle[1],s.c_str());
38domo 0:48863a0964f5 151 printf("Temp1 text : %s\n",s.c_str());
38domo 0:48863a0964f5 152 displayOn = (0x01 | displayOn);
38domo 10:41aff2b7acc6 153 }
38domo 10:41aff2b7acc6 154 if (mbedJson.hasMember("Temp2"))
38domo 10:41aff2b7acc6 155 { s = mbedJson["Temp2"]["backColorTemp"].get<std::string>();
38domo 0:48863a0964f5 156 backColorTemp2 = (uint32_t)strtoul(s.c_str(), NULL,16);
38domo 0:48863a0964f5 157 //printf("Temp2 text : %s\n",s.c_str());
38domo 0:48863a0964f5 158 s = mbedJson["Temp2"]["txtColorTemp"].get<std::string>();
38domo 0:48863a0964f5 159 txtColorTemp2 = (uint32_t)strtoul(s.c_str(), NULL,16) ;
38domo 0:48863a0964f5 160 //printf("Temp2 backColorTemp2 : %s\n",s.c_str());
38domo 0:48863a0964f5 161 s = mbedJson["Temp2"]["text"].get<std::string>();
38domo 0:48863a0964f5 162 sprintf(textTempTitle[2],s.c_str());
38domo 0:48863a0964f5 163 printf("Temp2 text : %s\n",s.c_str());
38domo 0:48863a0964f5 164 displayOn = (0x01 | displayOn);
38domo 10:41aff2b7acc6 165 }
38domo 10:41aff2b7acc6 166 if (mbedJson.hasMember("Touche1"))
38domo 10:41aff2b7acc6 167 { s = mbedJson["Touche1"]["Status"].get<std::string>();
38domo 0:48863a0964f5 168 sprintf(statusButton[1],s.c_str());
38domo 0:48863a0964f5 169 printf("Touche1 Status : %s\n",s.c_str());
38domo 0:48863a0964f5 170 s = mbedJson["Touche1"]["BackColor"].get<std::string>();
38domo 0:48863a0964f5 171 backColorButton[1] = (uint32_t)strtoul(s.c_str(), NULL,16);
38domo 0:48863a0964f5 172 printf("Touche1 BackColor : %s\n",s.c_str());
38domo 0:48863a0964f5 173 s = mbedJson["Touche1"]["TextColor"].get<std::string>();
38domo 0:48863a0964f5 174 txtColorButton[1] = (uint32_t)strtoul(s.c_str(), NULL,16);
38domo 0:48863a0964f5 175 printf("Touche1 TextColor : %s\n",s.c_str());
38domo 0:48863a0964f5 176 s = mbedJson["Touche1"]["text"].get<std::string>();
38domo 0:48863a0964f5 177 sprintf(textButton[1],s.c_str());
38domo 0:48863a0964f5 178 printf("Touche1 text : %s\n",s.c_str());
38domo 0:48863a0964f5 179 s = mbedJson["Touche1"]["text1"].get<std::string>();
38domo 0:48863a0964f5 180 sprintf(text1Button[1],s.c_str());
38domo 0:48863a0964f5 181 printf("Touche1 text1 : %s\n",s.c_str());
38domo 0:48863a0964f5 182 displayOn = (0x02 | displayOn);
38domo 10:41aff2b7acc6 183 }
38domo 10:41aff2b7acc6 184 if (mbedJson.hasMember("Touche2"))
38domo 10:41aff2b7acc6 185 { s = mbedJson["Touche2"]["Status"].get<std::string>();
38domo 0:48863a0964f5 186 sprintf(statusButton[2],s.c_str());
38domo 0:48863a0964f5 187 printf("Touche2 Status : %s\n",s.c_str());
38domo 0:48863a0964f5 188 s = mbedJson["Touche2"]["BackColor"].get<std::string>();
38domo 0:48863a0964f5 189 backColorButton[2] = (uint32_t)strtoul(s.c_str(), NULL,16);
38domo 0:48863a0964f5 190 printf("Touche1 BackColor : %s\n",s.c_str());
38domo 0:48863a0964f5 191 s = mbedJson["Touche2"]["TextColor"].get<std::string>();
38domo 0:48863a0964f5 192 txtColorButton[2] = (uint32_t)strtoul(s.c_str(), NULL,16);
38domo 0:48863a0964f5 193 printf("Touche2 TextColor : %s\n",s.c_str());
38domo 0:48863a0964f5 194 s = mbedJson["Touche2"]["text"].get<std::string>();
38domo 0:48863a0964f5 195 sprintf(textButton[2],s.c_str());
38domo 0:48863a0964f5 196 printf("Touche2 text : %s\n",s.c_str());
38domo 0:48863a0964f5 197 s = mbedJson["Touche2"]["text1"].get<std::string>();
38domo 0:48863a0964f5 198 sprintf(text1Button[2],s.c_str());
38domo 0:48863a0964f5 199 printf("Touche2 text1 : %s\n",s.c_str());
38domo 0:48863a0964f5 200 displayOn = (0x04 | displayOn);
38domo 10:41aff2b7acc6 201 }
38domo 10:41aff2b7acc6 202 if (mbedJson.hasMember("Touche3"))
38domo 10:41aff2b7acc6 203 { s = mbedJson["Touche3"]["Status"].get<std::string>();
38domo 0:48863a0964f5 204 sprintf(statusButton[3],s.c_str());
38domo 0:48863a0964f5 205 printf("Touche3 Status : %s\n",s.c_str());
38domo 0:48863a0964f5 206 s = mbedJson["Touche3"]["BackColor"].get<std::string>();
38domo 0:48863a0964f5 207 backColorButton[3] = (uint32_t)strtoul(s.c_str(), NULL,16);
38domo 0:48863a0964f5 208 printf("Touche3 BackColor : %s\n",s.c_str());
38domo 0:48863a0964f5 209 s = mbedJson["Touche3"]["TextColor"].get<std::string>();
38domo 0:48863a0964f5 210 txtColorButton[3] = (uint32_t)strtoul(s.c_str(), NULL,16);
38domo 0:48863a0964f5 211 printf("Touche3 TextColor : %s\n",s.c_str());
38domo 0:48863a0964f5 212 s = mbedJson["Touche3"]["text"].get<std::string>();
38domo 0:48863a0964f5 213 sprintf(textButton[3],s.c_str());
38domo 0:48863a0964f5 214 printf("Touche3 text : %s\n",s.c_str());
38domo 0:48863a0964f5 215 s = mbedJson["Touche3"]["text1"].get<std::string>();
38domo 0:48863a0964f5 216 sprintf(text1Button[3],s.c_str());
38domo 0:48863a0964f5 217 printf("Touche3 text1 : %s\n",s.c_str());
38domo 0:48863a0964f5 218 displayOn = (0x08 | displayOn);
38domo 10:41aff2b7acc6 219 }
38domo 10:41aff2b7acc6 220 if (mbedJson.hasMember("Touche4"))
38domo 10:41aff2b7acc6 221 { s = mbedJson["Touche4"]["Status"].get<std::string>();
38domo 0:48863a0964f5 222 sprintf(statusButton[4],s.c_str());
38domo 0:48863a0964f5 223 printf("Touche4 Status : %s\n",s.c_str());
38domo 0:48863a0964f5 224 s = mbedJson["Touche4"]["BackColor"].get<std::string>();
38domo 0:48863a0964f5 225 backColorButton[4] = (uint32_t)strtoul(s.c_str(), NULL,16);
38domo 0:48863a0964f5 226 printf("Touche4 BackColor : %s\n",s.c_str());
38domo 0:48863a0964f5 227 s = mbedJson["Touche4"]["TextColor"].get<std::string>();
38domo 0:48863a0964f5 228 txtColorButton[4] = (uint32_t)strtoul(s.c_str(), NULL,16);
38domo 0:48863a0964f5 229 printf("Touche4 TextColor : %s\n",s.c_str());
38domo 0:48863a0964f5 230 s = mbedJson["Touche4"]["text"].get<std::string>();
38domo 0:48863a0964f5 231 sprintf(textButton[4],s.c_str());
38domo 0:48863a0964f5 232 printf("Touche4 text : %s\n",s.c_str());
38domo 0:48863a0964f5 233 s = mbedJson["Touche4"]["text1"].get<std::string>();
38domo 0:48863a0964f5 234 sprintf(text1Button[4],s.c_str());
38domo 0:48863a0964f5 235 printf("Touche4 text1 : %s\n",s.c_str());
38domo 0:48863a0964f5 236 displayOn = (0x10 | displayOn);
38domo 10:41aff2b7acc6 237 }
38domo 10:41aff2b7acc6 238 if (mbedJson.hasMember("Temp1"))
38domo 10:41aff2b7acc6 239 { //int pp=setTemp1(mbedJson["Temp1"].get<std::string>());
38domo 10:41aff2b7acc6 240 }
38domo 10:41aff2b7acc6 241 if (mbedJson.hasMember("Temp2"))
38domo 10:41aff2b7acc6 242 { //int pp=setTemp1(mbedJson["Temp2"].get<std::string>());
38domo 10:41aff2b7acc6 243 }
38domo 10:41aff2b7acc6 244
38domo 0:48863a0964f5 245 if ((displayOn & 0x02) > 0) {touchButtonJPA1(1);}
38domo 0:48863a0964f5 246 if ((displayOn & 0x04) > 0) {touchButtonJPA1(2);}
38domo 0:48863a0964f5 247 if ((displayOn & 0x08) > 0) {touchButtonJPA1(3);}
38domo 0:48863a0964f5 248 if ((displayOn & 0x10) > 0) {touchButtonJPA1(4);}
38domo 0:48863a0964f5 249 }
38domo 10:41aff2b7acc6 250 } // fin test send result
38domo 10:41aff2b7acc6 251 } // fin test ethernet actif
38domo 10:41aff2b7acc6 252 if ((displayOn & 0x01) > 0) {setDisplayTemp();}
38domo 10:41aff2b7acc6 253
38domo 0:48863a0964f5 254 return 1;
38domo 0:48863a0964f5 255 }
38domo 0:48863a0964f5 256