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

Branch:
jpa
Revision:
12:15ae35cfb03f
Parent:
10:41aff2b7acc6
Child:
17:f3c5ec9ca00f
--- a/touchScreenJPA.cpp	Wed Sep 16 05:47:02 2020 +0000
+++ b/touchScreenJPA.cpp	Thu Sep 17 20:32:02 2020 +0000
@@ -6,6 +6,9 @@
 #include "MbedJSONValue.h"
 Timer    timer_touch[16];
 
+void sendSerial2(char * str);
+void sendSerial7(char * str);
+
 int initDisplayTemp();
 
 // GroveStreams Settings
@@ -23,6 +26,8 @@
 time_t seconds_touches = 0;
 extern time_t lastToucheTime;  
 // char touch1_text1;
+extern int ethernet_actif ;  // use ethernet connection
+extern int wifi_actif ;  // use wifi connection
 
 // -----------------------------------------------------------------
 int touchInitJPA1()
@@ -199,68 +204,80 @@
  
  // -----------------------------------------------------------------------   
 int sendTouchJPA(int xx)
-    {
-    uint8_t status = 0;
-            seconds = time(NULL);
-            if((seconds - lastToucheTime) > 1) 
-                {
-                char samples[64] = {0};char resultBuffer[2000]= {0};
-                sprintf(samples,"&Touche=%i",xx);
-                printf("\nSend Touche=%i\n",xx);
-                int sendResult = groveStreams.sendJPA(myMac, samples, gsCompName, gsCompTmplId, resultBuffer, sizeof resultBuffer);
-                if (sendResult == 0) {
-                        ////lcd.printf("Send Successful");
+    {   uint8_t status = 0;
+        seconds = time(NULL);
+        if((seconds - lastToucheTime) > 1) 
+        {    char samples[64] = {0};char resultBuffer[2000]= {0};
+             sprintf(samples,"&Touche=%i",xx);
+             printf("\nSend Touche=%i\n",xx);               
+             // modifier pour rajouter test ethernet / wifi et action en fonction                 
+             if (ethernet_actif == 1 )  // ethernet actif
+             {   printf("\ntraitement Ethernet\n",xx);               
+                 int sendResult = groveStreams.sendJPA(myMac, samples, gsCompName, gsCompTmplId, resultBuffer, sizeof resultBuffer);
+                 if (sendResult == 0) 
+                 {      ////lcd.printf("Send Successful");
                         printf("Send Successful\n");
-                        if (strlen(resultBuffer) > 0) {
-                            //printf("HTTP string : %s\n", resultBuffer);
+                        if (strlen(resultBuffer) > 0) 
+                        {   //printf("HTTP string : %s\n", resultBuffer);
                             MbedJSONValue mbedJson;
-                            parse(mbedJson, resultBuffer);
-                            
+                            parse(mbedJson, resultBuffer);                            
                             int displayOn = 0;
                             string s;
-                            if (mbedJson.hasMember("Touche1")) {
-                                s = mbedJson["Touche1"]["BackColor"].get<std::string>();
+                            if (mbedJson.hasMember("Touche1")) 
+                            {    s = mbedJson["Touche1"]["BackColor"].get<std::string>();
                                 backColorButton[1] = (uint32_t)strtoul(s.c_str(), NULL,16);
                                 s = mbedJson["Touche1"]["TextColor"].get<std::string>();
                                 txtColorButton[1] = (uint32_t)strtoul(s.c_str(), NULL,16);
                                 s = mbedJson["Touche1"]["Status"].get<std::string>();
                                 sprintf(statusButton[1],s.c_str());
-                                displayOn = (0x02 | displayOn);}
- 
-                             if (mbedJson.hasMember("Touche2")) {
-                                s = mbedJson["Touche2"]["BackColor"].get<std::string>();
+                                displayOn = (0x02 | displayOn);
+                            }
+                             if (mbedJson.hasMember("Touche2")) 
+                             {   s = mbedJson["Touche2"]["BackColor"].get<std::string>();
                                 backColorButton[2] = (uint32_t)strtoul(s.c_str(), NULL,16);
                                 s = mbedJson["Touche2"]["TextColor"].get<std::string>();
                                 txtColorButton[2] = (uint32_t)strtoul(s.c_str(), NULL,16);
                                 s = mbedJson["Touche2"]["Status"].get<std::string>();
                                 sprintf(statusButton[2],s.c_str());
-                                displayOn = (0x04 | displayOn);}
-
-                            if (mbedJson.hasMember("Touche3")) {
-                                s = mbedJson["Touche3"]["BackColor"].get<std::string>();
+                                displayOn = (0x04 | displayOn);
+                            }
+                            if (mbedJson.hasMember("Touche3")) 
+                            {    s = mbedJson["Touche3"]["BackColor"].get<std::string>();
                                 backColorButton[3] = (uint32_t)strtoul(s.c_str(), NULL,16);
                                 s = mbedJson["Touche3"]["TextColor"].get<std::string>();
                                 txtColorButton[3] = (uint32_t)strtoul(s.c_str(), NULL,16);
                                 s = mbedJson["Touche3"]["Status"].get<std::string>();
                                 sprintf(statusButton[3],s.c_str());
-                                displayOn = (0x08 | displayOn);}
-                                
-                            if (mbedJson.hasMember("Touche4")) {
-                                s = mbedJson["Touche4"]["BackColor"].get<std::string>();
+                                displayOn = (0x08 | displayOn);
+                            }    
+                            if (mbedJson.hasMember("Touche4")) 
+                            {    s = mbedJson["Touche4"]["BackColor"].get<std::string>();
                                 backColorButton[4] = (uint32_t)strtoul(s.c_str(), NULL,16);
                                 s = mbedJson["Touche4"]["TextColor"].get<std::string>();
                                 txtColorButton[4] = (uint32_t)strtoul(s.c_str(), NULL,16);
                                 s = mbedJson["Touche4"]["Status"].get<std::string>();
                                 sprintf(statusButton[4],s.c_str());
-                                displayOn = (0x10 | displayOn);}  
-                                                             
+                                displayOn = (0x10 | displayOn);  
+                            }                                 
                             if ((displayOn & 0x02) > 0) {touchButtonJPA1(1);}
                             if ((displayOn & 0x04) > 0) {touchButtonJPA1(2);}
                             if ((displayOn & 0x08) > 0) {touchButtonJPA1(3);}
                             if ((displayOn & 0x10) > 0) {touchButtonJPA1(4);}
-                            }
-                        }
-                }
-    
+                         }// fin test result buffer
+                      } // fin test send result                   
+                }  // fin test ethernet actif
+                else if (wifi_actif == 1)  // wifi actif --------------------------------
+                {   // send trame to wifi to inform touch pressed
+                    printf("\nSend Touche=%i status=%s \n ",xx,statusButton[4] ); 
+                    // {"Touche":{ "No":"4","Statusl":"Off"}}
+                    sprintf(samples,"{\"Touche\":{\"No\":\"%i\",\"Status\":\"%s\"}}",xx,statusButton[xx]);
+                    printf(samples); 
+                    printf ("\n");                  
+                    sendSerial2(samples);
+                 }   
+                else      // traitement en local
+                {  printf("\nTraitement local\n");                     
+                }                                              
+             }    
     return status;    
     }