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

Files at this revision

API Documentation at this revision

Comitter:
38domo
Date:
Thu Sep 17 20:32:02 2020 +0000
Branch:
jpa
Parent:
11:b198b2f2676f
Child:
13:fdec444a7b30
Commit message:
version with buttons operational

Changed in this revision

GuiJPA.cpp Show annotated file Show diff for this revision Revisions of this file
SDFileSystem_Warning_Fixed.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
touchScreenJPA.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/GuiJPA.cpp	Wed Sep 16 05:47:02 2020 +0000
+++ b/GuiJPA.cpp	Thu Sep 17 20:32:02 2020 +0000
@@ -1,3 +1,34 @@
+/*
+   
+var LCD_COLOR_BLUE          = "0xFF0000FF";
+var LCD_COLOR_GREEN         = "0xFF00FF00";
+var LCD_COLOR_RED           = "0xFFFF0000";
+var LCD_COLOR_CYAN          = "0xFF00FFFF";
+var LCD_COLOR_MAGENTA       = "0xFFFF00FF";
+var LCD_COLOR_YELLOW        = "0xFFFFFF00";
+var LCD_COLOR_LIGHTBLUE     = "0xFF8080FF";
+var LCD_COLOR_LIGHTGREEN    = "0xFF80FF80";
+var LCD_COLOR_LIGHTRED      = "0xFFFF8080";
+var LCD_COLOR_LIGHTCYAN     = "0xFF80FFFF";
+var LCD_COLOR_LIGHTMAGENTA  = "0xFFFF80FF";
+var LCD_COLOR_LIGHTYELLOW   = "0xFFFFFF80";
+var LCD_COLOR_DARKBLUE      = "0xFF000080";
+var LCD_COLOR_DARKGREEN     = "0xFF008000";
+var LCD_COLOR_DARKRED       = "0xFF800000";
+var LCD_COLOR_DARKCYAN      = "0xFF008080";
+var LCD_COLOR_DARKMAGENTA   = "0xFF800080";
+var LCD_COLOR_DARKYELLOW    = "0xFF808000";
+var LCD_COLOR_WHITE         = "0xFFFFFFFF";
+var LCD_COLOR_LIGHTGRAY     = "0xFFD3D3D3";
+var LCD_COLOR_GRAY          = "0xFF808080";
+var LCD_COLOR_DARKGRAY      = "0xFF404040";
+var LCD_COLOR_BLACK         = "0xFF000000";
+var LCD_COLOR_BROWN         = "0xFFA52A2A";
+var LCD_COLOR_ORANGE        = "0xFFFFA500";
+var LCD_COLOR_TRANSPARENT   = "0xFF000000";
+*/
+
+
 #include "stm32746g_discovery_lcd.h"
 #include "stm32746g_discovery_ts.h"
 #include "MbedJSONValue.h"
@@ -122,7 +153,16 @@
                txtColorTemp1 = (uint32_t)strtoul("0xFFFFFF00", NULL,16) ;
                backColorTemp2 = (uint32_t)strtoul("0xFF808080", NULL,16);
                txtColorTemp2 = (uint32_t)strtoul("0xFFFFFF00", NULL,16) ;
-               displayOn = (0x01 | displayOn);// display temp1 & temp2 box              
+               displayOn = (0x01 | displayOn);// display temp1 & temp2 box 
+               displayOn = (0x02 | displayOn); // touche 1
+               displayOn = (0x04 | displayOn); // touche 2
+               displayOn = (0x08 | displayOn); // touche 3
+               displayOn = (0x10 | displayOn); //touche  4
+               if ((displayOn & 0x02) > 0) {touchButtonJPA1(1);}
+                    if ((displayOn & 0x04) > 0) {touchButtonJPA1(2);}
+                    if ((displayOn & 0x08) > 0) {touchButtonJPA1(3);}
+                    if ((displayOn & 0x10) > 0) {touchButtonJPA1(4);}
+                            
             }
             else
             {    
--- a/SDFileSystem_Warning_Fixed.lib	Wed Sep 16 05:47:02 2020 +0000
+++ b/SDFileSystem_Warning_Fixed.lib	Thu Sep 17 20:32:02 2020 +0000
@@ -1,1 +1,1 @@
-https://os.mbed.com/users/38domo/code/SDFileSystem_Warning_Fixed/#f76a96b18109
+https://os.mbed.com/users/38domo/code/SDFileSystem_Warning_Fixed/#03a26c21cdaf
--- a/main.cpp	Wed Sep 16 05:47:02 2020 +0000
+++ b/main.cpp	Thu Sep 17 20:32:02 2020 +0000
@@ -9,22 +9,38 @@
 
 // 02/08/2020
 // add sd parameters: read ok
-// ip address
-// ethernet actif
-// wifi actif
-// can actif
-// serial actif
-// fonction
-// Touche1 status (0/1)
-// Touche1 backcolor
-// touche1 text color
-// Touche1 text
-// Touche1 text1
-// Touche2
-// Touche3
-// Touche4
-// Temp1 text
-// Temp2 text
+192.168.1.30
+0;Ethernet
+1;WiFi
+1;can
+1;serial
+F;Fonction
+0;Touche1 status : off
+0xFF00FF00;Touche1 BackColor
+0xFF000000;Touche1 TextColor
+Pompe  ; Touche1 text
+Piscine ; Touche1 text1
+1;Touche2 Status : off
+0xFFFF0000; Touche2 BackColor
+0xFFFFFFFF; Touche2 TextColor
+Eclair ;Touche2 text 
+Piscine ;Touche2 text1
+0; Touche3 Status : off
+0xFF00FF00; Touche3 BackColor
+0xFFFFFF00; Touche3 TextColor
+Leds Bl ;Touche3 text
+Piscine ; Touche3 text1
+1; Touche4 Status : off
+0xFF800000; Touche4 BackColor
+0xFFFFFF00; Touche4 TextColor
+Porche ; Touche4 text
+entree ; Touche4 text1
+Temp Piscine ; Temp1 text
+0xFF404040; backColorTemp1
+0xFFFFFF00;  txtColorTemp1   
+Temp Exterieur ; Temp2 text 
+0xFF404040; backColorTemp2
+0xFFFFFF00; txtColorTemp2
 
 // works ok 31/07/2020
 // updated package from jpa
@@ -64,6 +80,8 @@
 extern char textButton[5][8];
 extern char text1Button[5][8];
 extern char textTempTitle[3][30];
+extern uint32_t backColorButton[5], txtColorButton[5];
+extern char statusButton[5][30];
 
 //#include "touchScreen.cpp"
 int touchInitJPA1();
@@ -271,17 +289,8 @@
     //BSP_LCD_SetBackColor(LCD_COLOR_RED);
     BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
     BSP_LCD_SetBackColor(LCD_COLOR_RED);
-        BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
- //             backColorTemp1 = (uint32_t)strtoul("0xFF808080", NULL,16); //gray
- //              txtColorTemp1 = (uint32_t)strtoul("0xFFFFFF00", NULL,16) ;
- //              //sprintf(textTempTitle[1],s.c_str());
-               //printf("Temp1 text : %s\n",s.c_str());
- //              backColorTemp2 = (uint32_t)strtoul("0xFF808080", NULL,16);
- //              txtColorTemp2 = (uint32_t)strtoul("0xFFFFFF00", NULL,16) ;
-
-    int pp = setTemp1("temp1");  // display temp1 on lcd
-    BSP_LCD_DisplayStringAt(0, LINE(7), (uint8_t *)"displ temp1", CENTER_MODE);
-    
+    BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
+   
     // main loop ---------------------------------------------------
     while (true) {       
         if (CanRcv > 0)
@@ -308,27 +317,87 @@
             //resultBuffer = stringSerial2;
             //if (strlen(resultBuffer) > 0 && resultBuffer[0] == '{') 
             if (strlen(stringSerial2) > 0 && stringSerial2[0] == '{') 
-            {        MbedJSONValue mbedJson;
-                    //parse(mbedJson, resultBuffer); 
+            {       MbedJSONValue mbedJson;        //parse(mbedJson, resultBuffer); 
                     parse(mbedJson, stringSerial2);                   
-                    //sprintf((char*)text, "HTTP string : %s\n", resultBuffer);
-                    sprintf((char*)text, "HTTP string : %s\n", stringSerial2);
-                    //BSP_LCD_DisplayStringAt(0, LINE(1), (uint8_t *)&text, LEFT_MODE);                
-                    if (mbedJson.hasMember("Temp1")) {
-                         printf("Serial2 temp1: %s",stringSerial2);
-                        //int pp=setTemp1(mbedJson["Temp1"].get<std::string>());
-                        int pp = setTemp1(mbedJson["Temp1"].get<std::string>());  // display temp1 on lcd
-                        
+                    sprintf((char*)text, "HTTP string : %s\n", stringSerial2);                
+                    if (mbedJson.hasMember("Temp1")) 
+                    {     printf("Serial2 temp1: %s",stringSerial2);
+                        int pp = setTemp1(mbedJson["Temp1"].get<std::string>());  // display temp1 on lcd                     
+                    }
+                    if (mbedJson.hasMember("Temp2")) 
+                    {    int tt=setTemp2(mbedJson["Temp2"].get<std::string>());                      
+                    }
+                    // add buttons parameters 
+                    // decode button trame
+                    if (mbedJson.hasMember("Touche4")) 
+                    {    printf("Touche 4 update status received");
+                        string s; 
+                        s = mbedJson["Touche4"]["Status"].get<std::string>();
+                        sprintf(statusButton[4],s.c_str());
+                        printf(s.c_str());
+                        printf("\n");   
+                        if (s=="on")
+                        {   txtColorButton[4] = (uint32_t)strtoul("0xFF00FF00", NULL,16);
+                            backColorButton[4] = (uint32_t)strtoul("0xFF000000", NULL,16);
+                        }
+                        else
+                        {   txtColorButton[4] = (uint32_t)strtoul("0xFF000000", NULL,16);
+                            backColorButton[4] = (uint32_t)strtoul("0xFF00FF00", NULL,16);
+                        }    
+                        touchButtonJPA1(4);                                                                  
                     }
-                    if (mbedJson.hasMember("Temp2")) {
-                        int tt=setTemp2(mbedJson["Temp2"].get<std::string>());
-                        
+                    if (mbedJson.hasMember("Touche1")) 
+                    {    printf("Touche 1 update status received");
+                        string s; 
+                        s = mbedJson["Touche1"]["Status"].get<std::string>();
+                        sprintf(statusButton[1],s.c_str());
+                        printf(s.c_str());
+                        printf("\n");   
+                        if (s=="on")
+                        {   txtColorButton[1] = (uint32_t)strtoul("0xFF00FF00", NULL,16);
+                            backColorButton[1] = (uint32_t)strtoul("0xFF000000", NULL,16);
+                        }
+                        else
+                        {   txtColorButton[1] = (uint32_t)strtoul("0xFF000000", NULL,16);
+                            backColorButton[1] = (uint32_t)strtoul("0xFF00FF00", NULL,16);
+                        }    
+                        touchButtonJPA1(1);                                                                  
                     }
-                    
-                }
-            
-              
-            
+                    if (mbedJson.hasMember("Touche2")) 
+                    {    printf("Touche 2 update status received");
+                        string s; 
+                        s = mbedJson["Touche2"]["Status"].get<std::string>();
+                        sprintf(statusButton[2],s.c_str());
+                        printf(s.c_str());
+                        printf("\n");   
+                        if (s=="on")
+                        {   txtColorButton[2] = (uint32_t)strtoul("0xFF00FF00", NULL,16);
+                            backColorButton[2] = (uint32_t)strtoul("0xFF000000", NULL,16);
+                        }
+                        else
+                        {   txtColorButton[2] = (uint32_t)strtoul("0xFF000000", NULL,16);
+                            backColorButton[2] = (uint32_t)strtoul("0xFF00FF00", NULL,16);
+                        }    
+                        touchButtonJPA1(2);                                                                  
+                    }
+                    if (mbedJson.hasMember("Touche3")) 
+                    {    printf("Touche 3 update status received");
+                        string s; 
+                        s = mbedJson["Touche3"]["Status"].get<std::string>();
+                        sprintf(statusButton[3],s.c_str());
+                        printf(s.c_str());
+                        printf("\n");   
+                        if (s=="on")
+                        {   txtColorButton[3] = (uint32_t)strtoul("0xFF00FF00", NULL,16);
+                            backColorButton[3] = (uint32_t)strtoul("0xFF000000", NULL,16);
+                        }
+                        else
+                        {   txtColorButton[3] = (uint32_t)strtoul("0xFF000000", NULL,16);
+                            backColorButton[3] = (uint32_t)strtoul("0xFF00FF00", NULL,16);
+                        }    
+                        touchButtonJPA1(3);                                                                  
+                    }             
+                }                                     
         }       
         if (msgSerial7 > 0) {receiveSerial7();}
         if (stringSerial7ok == 1) {printf("Trame Serial7 : %s",stringSerial7);stringSerial7ok=0;}
@@ -346,14 +415,16 @@
             txMsg.data[0]=8;txMsg.data[1]=counter;        // append data (total data length must be <= 8 bytes!)           
             if(can.write(txMsg))       // transmit message
             {   //if(can->write(txMsg)) {             // transmit the CAN message
+                printf("TX CAN OK \n");
                 printMsg(txMsg,0);
-                BSP_LCD_DisplayStringAt(0, LINE(3), (uint8_t *)"TX CAN OK", CENTER_MODE);
-                BSP_LCD_DisplayStringAt(0, LINE(4), (uint8_t *)"--------", CENTER_MODE);
+                //BSP_LCD_DisplayStringAt(0, LINE(3), (uint8_t *)"TX CAN OK", CENTER_MODE);
+                //BSP_LCD_DisplayStringAt(0, LINE(4), (uint8_t *)"--------", CENTER_MODE);
             }
             else
             {   //serialUSB.printf("Transmission error\r\n");
-                BSP_LCD_DisplayStringAt(0, LINE(4), (uint8_t *)"TX CAN Fail", CENTER_MODE);
-                BSP_LCD_DisplayStringAt(0, LINE(3), (uint8_t *)"-----------", CENTER_MODE);
+                printf("TX CAN Fail \n");
+                //BSP_LCD_DisplayStringAt(0, LINE(4), (uint8_t *)"TX CAN Fail", CENTER_MODE);
+                //BSP_LCD_DisplayStringAt(0, LINE(3), (uint8_t *)"-----------", CENTER_MODE);
             }    
             timer.start();                  // insert transmission lag
         }  // end if timer
@@ -369,11 +440,13 @@
           
            if(can.write(txMsg))       // transmit message
             {   printMsg(txMsg,0);
-                BSP_LCD_DisplayStringAt(0, LINE(3), (uint8_t *)"TX CAN OK", CENTER_MODE);
-                BSP_LCD_DisplayStringAt(0, LINE(4), (uint8_t *)"--------", CENTER_MODE);
+                printf("TX CAN OK \n");
+                //BSP_LCD_DisplayStringAt(0, LINE(3), (uint8_t *)"TX CAN OK", CENTER_MODE);
+                //BSP_LCD_DisplayStringAt(0, LINE(4), (uint8_t *)"--------", CENTER_MODE);
              }
             else
-            {   BSP_LCD_DisplayStringAt(0, LINE(4), (uint8_t *)"TX CAN Fail", CENTER_MODE);
+            {   printf("TX CAN Fail \n");
+                BSP_LCD_DisplayStringAt(0, LINE(4), (uint8_t *)"TX CAN Fail", CENTER_MODE);
                 BSP_LCD_DisplayStringAt(0, LINE(3), (uint8_t *)"-----------", CENTER_MODE);
             }    
            }    
--- 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;    
     }