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:
Tue Sep 15 19:11:11 2020 +0000
Branch:
jpa
Revision:
10:41aff2b7acc6
Parent:
5:ceefd0cfa233
Child:
12:15ae35cfb03f
grov stream lib updated

Who changed what in which revision?

UserRevisionLine numberNew contents of line
38domo 0:48863a0964f5 1
38domo 0:48863a0964f5 2 #include "stm32746g_discovery_lcd.h"
38domo 0:48863a0964f5 3 #include "stm32746g_discovery_ts.h"
38domo 0:48863a0964f5 4 #include "mbed.h"
38domo 0:48863a0964f5 5 #include "GroveStreams.h"
38domo 0:48863a0964f5 6 #include "MbedJSONValue.h"
jeanpierreaulas 5:ceefd0cfa233 7 Timer timer_touch[16];
38domo 0:48863a0964f5 8
38domo 0:48863a0964f5 9 int initDisplayTemp();
38domo 0:48863a0964f5 10
38domo 0:48863a0964f5 11 // GroveStreams Settings
38domo 0:48863a0964f5 12 //extern const char gsApiKey[];// = "YOUR_SECRET_API_KEY_HERE"; //Change This!!!
38domo 0:48863a0964f5 13 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 14
38domo 0:48863a0964f5 15 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 16
38domo 0:48863a0964f5 17 ////GroveStreams groveStreams(gsApiKey, &lcd);
38domo 0:48863a0964f5 18 extern GroveStreams groveStreams;
38domo 0:48863a0964f5 19
38domo 0:48863a0964f5 20 extern const char* myMac;
38domo 0:48863a0964f5 21
38domo 0:48863a0964f5 22 extern time_t seconds;
38domo 0:48863a0964f5 23 time_t seconds_touches = 0;
38domo 0:48863a0964f5 24 extern time_t lastToucheTime;
38domo 10:41aff2b7acc6 25 // char touch1_text1;
38domo 0:48863a0964f5 26
38domo 10:41aff2b7acc6 27 // -----------------------------------------------------------------
38domo 0:48863a0964f5 28 int touchInitJPA1()
38domo 0:48863a0964f5 29 { //touch screen init
38domo 0:48863a0964f5 30 //touch screen
38domo 0:48863a0964f5 31 uint8_t status;
38domo 0:48863a0964f5 32 BSP_LCD_Init();
38domo 0:48863a0964f5 33 BSP_LCD_LayerDefaultInit(LTDC_ACTIVE_LAYER, LCD_FB_START_ADDRESS);
38domo 0:48863a0964f5 34 BSP_LCD_SelectLayer(LTDC_ACTIVE_LAYER);
38domo 0:48863a0964f5 35 BSP_LCD_SetFont(&Font12);
38domo 0:48863a0964f5 36 status = BSP_TS_Init(BSP_LCD_GetXSize(), BSP_LCD_GetYSize());
38domo 10:41aff2b7acc6 37 if (status != TS_OK)
38domo 10:41aff2b7acc6 38 { BSP_LCD_Clear(LCD_COLOR_RED);
38domo 0:48863a0964f5 39 BSP_LCD_SetBackColor(LCD_COLOR_RED);
38domo 0:48863a0964f5 40 BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
38domo 0:48863a0964f5 41 BSP_LCD_DisplayStringAt(0, LINE(5), (uint8_t *)"TOUCHSCREEN INIT FAIL", CENTER_MODE);
38domo 10:41aff2b7acc6 42 }
38domo 10:41aff2b7acc6 43 else
38domo 10:41aff2b7acc6 44 {
38domo 0:48863a0964f5 45 BSP_LCD_Clear(LCD_COLOR_DARKBLUE);
38domo 0:48863a0964f5 46 BSP_LCD_SetBackColor(LCD_COLOR_BLACK);
38domo 0:48863a0964f5 47 BSP_LCD_SetTextColor(LCD_COLOR_GREEN);
38domo 0:48863a0964f5 48 //BSP_LCD_DisplayStringAt(0, LINE(5), (uint8_t *)"TOUCHSCREEN INIT OK", CENTER_MODE);
38domo 10:41aff2b7acc6 49 }
jeanpierreaulas 5:ceefd0cfa233 50 int tt = 0;
jeanpierreaulas 5:ceefd0cfa233 51 for (tt=0;tt<16;tt++)
38domo 10:41aff2b7acc6 52 { if(timer_touch[tt].read_ms() > 500)
38domo 10:41aff2b7acc6 53 { timer_touch[tt].stop();timer_touch[tt].reset();
38domo 10:41aff2b7acc6 54 }
38domo 10:41aff2b7acc6 55 }
38domo 0:48863a0964f5 56 return 0;
38domo 0:48863a0964f5 57 }
38domo 10:41aff2b7acc6 58 // -------------------------------------------------------
38domo 0:48863a0964f5 59 int xButton[5],yButton[5],dxButton[5],dyButton[5],xTxtButton[5],yTxtButton[5];
38domo 0:48863a0964f5 60 uint32_t backColorButton[5], txtColorButton[5];
38domo 10:41aff2b7acc6 61 extern char textButton[5][8];
38domo 10:41aff2b7acc6 62 extern char text1Button[5][8];
38domo 0:48863a0964f5 63 char statusButton[5][30];
38domo 0:48863a0964f5 64
38domo 10:41aff2b7acc6 65 // -----------------------------------------------------------------------------------------
38domo 0:48863a0964f5 66 int touchButtonJPA1(int numButton)
38domo 0:48863a0964f5 67 {
38domo 0:48863a0964f5 68 if ((numButton > 0) && (numButton < 5))
38domo 0:48863a0964f5 69 {
38domo 0:48863a0964f5 70 BSP_LCD_SetBackColor(backColorButton[numButton]);
38domo 0:48863a0964f5 71 BSP_LCD_SetTextColor(backColorButton[numButton]);
38domo 0:48863a0964f5 72 BSP_LCD_FillRect(xButton[numButton], yButton[numButton], dxButton[numButton], dyButton[numButton]);
38domo 0:48863a0964f5 73 BSP_LCD_SetTextColor(txtColorButton[numButton]);
38domo 0:48863a0964f5 74 BSP_LCD_DrawRect(xButton[numButton], yButton[numButton], dxButton[numButton], dyButton[numButton]);
38domo 0:48863a0964f5 75 BSP_LCD_SetFont(&Font20);
38domo 0:48863a0964f5 76 BSP_LCD_DisplayStringAt(xTxtButton[numButton]+52, yTxtButton[numButton], (uint8_t *)statusButton[numButton], LEFT_MODE);
38domo 0:48863a0964f5 77 BSP_LCD_DisplayStringAt(xTxtButton[numButton], yTxtButton[numButton]+28, (uint8_t *)textButton[numButton], LEFT_MODE);
38domo 0:48863a0964f5 78 BSP_LCD_DisplayStringAt(xTxtButton[numButton], yTxtButton[numButton]+48, (uint8_t *)text1Button[numButton], LEFT_MODE);
38domo 0:48863a0964f5 79 }
38domo 0:48863a0964f5 80 return 0;
38domo 0:48863a0964f5 81 }
38domo 0:48863a0964f5 82
38domo 10:41aff2b7acc6 83 // ----------------------------------------------------------------------------------
38domo 0:48863a0964f5 84 // generation de fonts : http://omz-software.com/pythonista/docs/ios/ImageFont.html
38domo 0:48863a0964f5 85 int touchInitGuiJPA1()
38domo 10:41aff2b7acc6 86 { // button 1 en bas a gauche
38domo 0:48863a0964f5 87 xButton[1]=10;yButton[1]=185;dxButton[1]=100;dyButton[1]=80;xTxtButton[1]=12;yTxtButton[1]=190;
38domo 10:41aff2b7acc6 88 backColorButton[1] = LCD_COLOR_GRAY;
38domo 10:41aff2b7acc6 89 txtColorButton[1] = LCD_COLOR_GREEN;
38domo 10:41aff2b7acc6 90 //sprintf(textButton[1],"Lampe ");
38domo 10:41aff2b7acc6 91 //sprintf(text1Button[1],"Sejour");
38domo 0:48863a0964f5 92 sprintf(statusButton[1],"off");
38domo 10:41aff2b7acc6 93 // bouton 2 a cote bouton 1
38domo 0:48863a0964f5 94 xButton[2]=130;yButton[2]=185;dxButton[2]=100;dyButton[2]=80;xTxtButton[2]=132;yTxtButton[2]=190;
38domo 0:48863a0964f5 95 backColorButton[2] = LCD_COLOR_GRAY; txtColorButton[2] = LCD_COLOR_GREEN;
38domo 10:41aff2b7acc6 96 //sprintf(textButton[2],"Lampe ");
38domo 10:41aff2b7acc6 97 //sprintf(text1Button[2],"Sejours");
38domo 0:48863a0964f5 98 sprintf(statusButton[2],"off");
38domo 10:41aff2b7acc6 99 // bouton 3
38domo 0:48863a0964f5 100 xButton[3]=250;yButton[3]=185;dxButton[3]=100;dyButton[3]=80;xTxtButton[3]=252;yTxtButton[3]=190;
38domo 0:48863a0964f5 101 backColorButton[3] = LCD_COLOR_GRAY; txtColorButton[3] = LCD_COLOR_GREEN;
38domo 10:41aff2b7acc6 102 //sprintf(textButton[3],"Lampe ");
38domo 10:41aff2b7acc6 103 //sprintf(text1Button[3],"Sejour");
38domo 0:48863a0964f5 104 sprintf(statusButton[3],"off");
38domo 10:41aff2b7acc6 105 // bouton 4 en bas a ddroite
38domo 0:48863a0964f5 106 xButton[4]=370;yButton[4]=185;dxButton[4]=100;dyButton[4]=80;xTxtButton[4]=372;yTxtButton[4]=190;
38domo 0:48863a0964f5 107 backColorButton[4] = LCD_COLOR_GRAY; txtColorButton[4] = LCD_COLOR_GREEN;
38domo 10:41aff2b7acc6 108 //sprintf(textButton[4],"Lampe ");
38domo 10:41aff2b7acc6 109 //sprintf(text1Button[4],"Sejour");
38domo 0:48863a0964f5 110 sprintf(statusButton[4],"off");
38domo 0:48863a0964f5 111
38domo 0:48863a0964f5 112 touchButtonJPA1(1);
38domo 0:48863a0964f5 113 touchButtonJPA1(2);
38domo 0:48863a0964f5 114 touchButtonJPA1(3);
38domo 0:48863a0964f5 115 touchButtonJPA1(4);
38domo 0:48863a0964f5 116
38domo 0:48863a0964f5 117 BSP_LCD_SetFont(&FontFreeMono64);
38domo 0:48863a0964f5 118 //BSP_LCD_DisplayStringAt(20, 30, (uint8_t *)"0123456789", LEFT_MODE);
38domo 0:48863a0964f5 119 //BSP_LCD_DisplayCharJPA(20, 90, '8');
38domo 0:48863a0964f5 120 BSP_LCD_SetFont(&Font12);
38domo 0:48863a0964f5 121 return 0;
38domo 0:48863a0964f5 122 }
38domo 10:41aff2b7acc6 123
38domo 10:41aff2b7acc6 124 // --------------------------------------------------------------------------
38domo 0:48863a0964f5 125 int touchJPA1()
38domo 0:48863a0964f5 126 {
38domo 0:48863a0964f5 127 //touch screen
38domo 0:48863a0964f5 128 TS_StateTypeDef TS_State;
38domo 0:48863a0964f5 129 uint16_t x, y;
38domo 0:48863a0964f5 130 uint8_t text[30];
38domo 0:48863a0964f5 131 uint8_t status = 0;
38domo 0:48863a0964f5 132 uint8_t idx;
38domo 0:48863a0964f5 133 static uint8_t cleared = 0;
38domo 0:48863a0964f5 134 uint8_t prev_nb_touches = 0;
38domo 0:48863a0964f5 135
jeanpierreaulas 5:ceefd0cfa233 136 int tt = 0;
jeanpierreaulas 5:ceefd0cfa233 137 for (tt=0;tt<16;tt++)
jeanpierreaulas 5:ceefd0cfa233 138 {if(timer_touch[tt].read_ms() > 200)
jeanpierreaulas 5:ceefd0cfa233 139 {timer_touch[tt].stop();timer_touch[tt].reset();}}
38domo 0:48863a0964f5 140 //touch screen
38domo 0:48863a0964f5 141 BSP_TS_GetState(&TS_State);
38domo 0:48863a0964f5 142 if (TS_State.touchDetected) {
38domo 0:48863a0964f5 143 // Clear lines corresponding to old touches coordinates
38domo 0:48863a0964f5 144 if (TS_State.touchDetected < prev_nb_touches) {
38domo 0:48863a0964f5 145 for (idx = (TS_State.touchDetected + 1); idx <= 5; idx++) {
38domo 0:48863a0964f5 146 //BSP_LCD_ClearStringLine(idx);
38domo 0:48863a0964f5 147 }
38domo 0:48863a0964f5 148 }
38domo 0:48863a0964f5 149 prev_nb_touches = TS_State.touchDetected;
38domo 0:48863a0964f5 150
38domo 0:48863a0964f5 151 cleared = 0;
38domo 0:48863a0964f5 152
38domo 0:48863a0964f5 153 //sprintf((char*)text, "Touches: %d", TS_State.touchDetected);
38domo 0:48863a0964f5 154 //BSP_LCD_DisplayStringAt(0, LINE(0), (uint8_t *)&text, LEFT_MODE);
38domo 0:48863a0964f5 155
38domo 0:48863a0964f5 156 for (idx = 0; idx < TS_State.touchDetected; idx++) {
38domo 0:48863a0964f5 157 x = TS_State.touchX[idx];
38domo 0:48863a0964f5 158 y = TS_State.touchY[idx];
38domo 0:48863a0964f5 159 //sprintf((char*)text, "Touch %d: x=%d y=%d ", idx+1, x, y);
38domo 0:48863a0964f5 160 //BSP_LCD_DisplayStringAt(0, LINE(idx+1), (uint8_t *)&text, LEFT_MODE);
38domo 0:48863a0964f5 161 }
38domo 0:48863a0964f5 162
38domo 0:48863a0964f5 163 //BSP_LCD_DrawPixel(TS_State.touchX[0], TS_State.touchY[0], LCD_COLOR_ORANGE);
38domo 0:48863a0964f5 164
38domo 0:48863a0964f5 165 if ((TS_State.touchY[0] > 160) && (TS_State.touchY[0] < (160+80)))
38domo 0:48863a0964f5 166 {
38domo 0:48863a0964f5 167 int numTouche = 0;
jeanpierreaulas 5:ceefd0cfa233 168 if ((TS_State.touchX[0] > 10) && (TS_State.touchX[0] < (10+100)))
jeanpierreaulas 5:ceefd0cfa233 169 {if(timer_touch[0].read_ms() == 0) {numTouche = 1;timer_touch[0].start();}}
jeanpierreaulas 5:ceefd0cfa233 170 if ((TS_State.touchX[0] > 130) && (TS_State.touchX[0] < (130+100)))
jeanpierreaulas 5:ceefd0cfa233 171 {if(timer_touch[1].read_ms() == 0) {numTouche = 2;timer_touch[1].start();}}
jeanpierreaulas 5:ceefd0cfa233 172 if ((TS_State.touchX[0] > 250) && (TS_State.touchX[0] < (250+100)))
jeanpierreaulas 5:ceefd0cfa233 173 {if(timer_touch[2].read_ms() == 0) {numTouche = 3;timer_touch[2].start();}}
jeanpierreaulas 5:ceefd0cfa233 174 if ((TS_State.touchX[0] > 370) && (TS_State.touchX[0] < (370+100)))
jeanpierreaulas 5:ceefd0cfa233 175 {if(timer_touch[3].read_ms() == 0) {numTouche = 4;timer_touch[3].start();}}
38domo 0:48863a0964f5 176 if (numTouche >0)
38domo 0:48863a0964f5 177 {
38domo 0:48863a0964f5 178 printf("Touche : %d", numTouche);
38domo 0:48863a0964f5 179 sprintf((char*)text, "Touche : %d", numTouche);
38domo 0:48863a0964f5 180 //BSP_LCD_DisplayStringAt(200,0, (uint8_t *)&text, LEFT_MODE);
38domo 0:48863a0964f5 181 status = numTouche;
38domo 0:48863a0964f5 182 }
38domo 0:48863a0964f5 183 else {lastToucheTime = 0;}
38domo 0:48863a0964f5 184 }
38domo 0:48863a0964f5 185 } else {
38domo 0:48863a0964f5 186 lastToucheTime = 0;
38domo 0:48863a0964f5 187 if (!cleared) {
38domo 0:48863a0964f5 188 //BSP_LCD_Clear(LCD_COLOR_DARKBLUE);
38domo 0:48863a0964f5 189 //sprintf((char*)text, "Touches: 0");
38domo 0:48863a0964f5 190 //BSP_LCD_DisplayStringAt(0, LINE(0), (uint8_t *)&text, LEFT_MODE);
38domo 0:48863a0964f5 191 //cleared = 1;
38domo 0:48863a0964f5 192 //int ss = touchInitGuiJPA1();
38domo 0:48863a0964f5 193 //ss=initDisplayTemp();
38domo 0:48863a0964f5 194 }
38domo 0:48863a0964f5 195 }
38domo 0:48863a0964f5 196 //touch screen
38domo 0:48863a0964f5 197 return status;
38domo 0:48863a0964f5 198 }
38domo 10:41aff2b7acc6 199
38domo 10:41aff2b7acc6 200 // -----------------------------------------------------------------------
38domo 0:48863a0964f5 201 int sendTouchJPA(int xx)
38domo 0:48863a0964f5 202 {
38domo 0:48863a0964f5 203 uint8_t status = 0;
38domo 0:48863a0964f5 204 seconds = time(NULL);
38domo 0:48863a0964f5 205 if((seconds - lastToucheTime) > 1)
38domo 0:48863a0964f5 206 {
38domo 0:48863a0964f5 207 char samples[64] = {0};char resultBuffer[2000]= {0};
38domo 0:48863a0964f5 208 sprintf(samples,"&Touche=%i",xx);
38domo 0:48863a0964f5 209 printf("\nSend Touche=%i\n",xx);
38domo 0:48863a0964f5 210 int sendResult = groveStreams.sendJPA(myMac, samples, gsCompName, gsCompTmplId, resultBuffer, sizeof resultBuffer);
38domo 0:48863a0964f5 211 if (sendResult == 0) {
38domo 0:48863a0964f5 212 ////lcd.printf("Send Successful");
38domo 0:48863a0964f5 213 printf("Send Successful\n");
38domo 0:48863a0964f5 214 if (strlen(resultBuffer) > 0) {
38domo 0:48863a0964f5 215 //printf("HTTP string : %s\n", resultBuffer);
38domo 0:48863a0964f5 216 MbedJSONValue mbedJson;
38domo 0:48863a0964f5 217 parse(mbedJson, resultBuffer);
38domo 0:48863a0964f5 218
38domo 0:48863a0964f5 219 int displayOn = 0;
38domo 0:48863a0964f5 220 string s;
38domo 0:48863a0964f5 221 if (mbedJson.hasMember("Touche1")) {
38domo 0:48863a0964f5 222 s = mbedJson["Touche1"]["BackColor"].get<std::string>();
38domo 0:48863a0964f5 223 backColorButton[1] = (uint32_t)strtoul(s.c_str(), NULL,16);
38domo 0:48863a0964f5 224 s = mbedJson["Touche1"]["TextColor"].get<std::string>();
38domo 0:48863a0964f5 225 txtColorButton[1] = (uint32_t)strtoul(s.c_str(), NULL,16);
38domo 0:48863a0964f5 226 s = mbedJson["Touche1"]["Status"].get<std::string>();
38domo 0:48863a0964f5 227 sprintf(statusButton[1],s.c_str());
38domo 0:48863a0964f5 228 displayOn = (0x02 | displayOn);}
38domo 0:48863a0964f5 229
38domo 0:48863a0964f5 230 if (mbedJson.hasMember("Touche2")) {
38domo 0:48863a0964f5 231 s = mbedJson["Touche2"]["BackColor"].get<std::string>();
38domo 0:48863a0964f5 232 backColorButton[2] = (uint32_t)strtoul(s.c_str(), NULL,16);
38domo 0:48863a0964f5 233 s = mbedJson["Touche2"]["TextColor"].get<std::string>();
38domo 0:48863a0964f5 234 txtColorButton[2] = (uint32_t)strtoul(s.c_str(), NULL,16);
38domo 0:48863a0964f5 235 s = mbedJson["Touche2"]["Status"].get<std::string>();
38domo 0:48863a0964f5 236 sprintf(statusButton[2],s.c_str());
38domo 0:48863a0964f5 237 displayOn = (0x04 | displayOn);}
38domo 0:48863a0964f5 238
38domo 0:48863a0964f5 239 if (mbedJson.hasMember("Touche3")) {
38domo 0:48863a0964f5 240 s = mbedJson["Touche3"]["BackColor"].get<std::string>();
38domo 0:48863a0964f5 241 backColorButton[3] = (uint32_t)strtoul(s.c_str(), NULL,16);
38domo 0:48863a0964f5 242 s = mbedJson["Touche3"]["TextColor"].get<std::string>();
38domo 0:48863a0964f5 243 txtColorButton[3] = (uint32_t)strtoul(s.c_str(), NULL,16);
38domo 0:48863a0964f5 244 s = mbedJson["Touche3"]["Status"].get<std::string>();
38domo 0:48863a0964f5 245 sprintf(statusButton[3],s.c_str());
38domo 0:48863a0964f5 246 displayOn = (0x08 | displayOn);}
38domo 0:48863a0964f5 247
38domo 0:48863a0964f5 248 if (mbedJson.hasMember("Touche4")) {
38domo 0:48863a0964f5 249 s = mbedJson["Touche4"]["BackColor"].get<std::string>();
38domo 0:48863a0964f5 250 backColorButton[4] = (uint32_t)strtoul(s.c_str(), NULL,16);
38domo 0:48863a0964f5 251 s = mbedJson["Touche4"]["TextColor"].get<std::string>();
38domo 0:48863a0964f5 252 txtColorButton[4] = (uint32_t)strtoul(s.c_str(), NULL,16);
38domo 0:48863a0964f5 253 s = mbedJson["Touche4"]["Status"].get<std::string>();
38domo 0:48863a0964f5 254 sprintf(statusButton[4],s.c_str());
38domo 0:48863a0964f5 255 displayOn = (0x10 | displayOn);}
38domo 0:48863a0964f5 256
38domo 0:48863a0964f5 257 if ((displayOn & 0x02) > 0) {touchButtonJPA1(1);}
38domo 0:48863a0964f5 258 if ((displayOn & 0x04) > 0) {touchButtonJPA1(2);}
38domo 0:48863a0964f5 259 if ((displayOn & 0x08) > 0) {touchButtonJPA1(3);}
38domo 0:48863a0964f5 260 if ((displayOn & 0x10) > 0) {touchButtonJPA1(4);}
38domo 0:48863a0964f5 261 }
38domo 0:48863a0964f5 262 }
38domo 0:48863a0964f5 263 }
38domo 0:48863a0964f5 264
38domo 0:48863a0964f5 265 return status;
38domo 0:48863a0964f5 266 }