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:
17:f3c5ec9ca00f
Parent:
16:f0d946e6da36
--- a/main.cpp	Wed Dec 30 17:22:27 2020 +0000
+++ b/main.cpp	Wed Jan 13 19:52:35 2021 +0000
@@ -1,5 +1,6 @@
 /* --------------------------------------------------------------------------
-
+// update 01/01/2021: remove ethernet calls : ok
+//
 // update 30/12 update libs
 //
 // test compile ok 31/07/2020 
@@ -57,12 +58,9 @@
 // need to add CAN and WiFi
 
  STM32F746 GroveStreams Stream Feed via Ethernet
-
  This GroveStreams example is designed for the STM32F746.
  https://www.grovestreams.com/developers/getting_started_stm32F746.html
-
  The STM32 uses DHCP and DNS for a simpler network setup.
-
 */
 
 #if !FEATURE_LWIP
@@ -71,13 +69,12 @@
 
 #include "mbed.h"
 #include "LcdDiscoF746NgTracer.h"
-#include "GroveStreams.h"
+// #include "GroveStreams.h"
 #include "MbedJSONValue.h"
 #include "stm32746g_discovery_lcd.h"
 #include "stm32746g_discovery_ts.h"
 #include "CANMsg.h"
 //#include "ManageBufferJPA.h"
-
 #include "main.h"
 
 extern char textButton[5][8];
@@ -100,6 +97,7 @@
 int setTemp1(std::string temp1);
 int setTemp2(std::string temp2);
 int sendInitDatasJPA(int xx);
+int timer_lcd_on = 0;
 
 //#SDCARD
 int mainSDCardJPA(); //in sdcardjpa.cpp in lib /sdfilesystem_warning_fixedd
@@ -157,6 +155,7 @@
 float           voltage;
 
 Timer           timer;
+extern Timer           timer_lcd;
 AnalogIn        analogIn(A0);
 
 // CAN ------------------------------------------------------------
@@ -240,11 +239,11 @@
 {   initSerial();   
    // attach ISR to handle received messages
     timer.start();          // start timer
-    sendSerialUSB("CAN_Hello board serialUSB #1\r\n");
-    
+    timer_lcd.start();      // start timer lcd off
+    timer_lcd_on = 1;
+    sendSerialUSB("CAN_Hello board serialUSB #1\r\n");   
     sendSerial2("CAN_Hello board serial2 #1\r\n");
     sendSerial7("CAN_Hello board serial7 #1\r\n");
-    
     printf("\nInit SDCard ...\n");
     mainSDCardJPA() ;  // init SD - read  prog parameters from SD (from sdcardjpa.cpp in sdfilesystem_warning_fixed lib
     // reaf following datas
@@ -280,7 +279,7 @@
     ////lcd.printf("Starting...");
     printf("Starting...\n");
     lastToucheTime = time(NULL);
-     char data[5];
+    char data[5];
      
    // config can --------------------------------------
     can.frequency(125000); // set CAN bit rate to 125 kbps
@@ -296,7 +295,7 @@
    
     // main loop ---------------------------------------------------
     while (true) {       
-        if (CanRcv > 0)
+        if (CanRcv > 0)  // message CAN received ---------------------
         {   CanRcv = 0;    
             printMsg(rxMsg,1);  
             BSP_LCD_DisplayStringAt(0, LINE(5), (uint8_t *)"Can msg rec", CENTER_MODE);
@@ -307,10 +306,10 @@
                 //serialUSB.printf("  voltage = %e V\r\n", voltage);
             }
         }
-        if (msgSerialUSB > 0) {receiveSerialUSB();}
+        if (msgSerialUSB > 0) {receiveSerialUSB();}  // serial USB message received ----------------
         if (stringSerialUSBok == 1) {printf("Trame SerialUSB : %s",stringSerialUSB);stringSerialUSBok=0;}
         
-        if (msgSerial2 > 0) {receiveSerial2();}
+        if (msgSerial2 > 0) {receiveSerial2();}  // serial bridge message received -----------------
         if (stringSerial2ok == 1) 
         {   printf("Trame Serial2 : %s",stringSerial2);
             stringSerial2ok=0;
@@ -324,16 +323,16 @@
                     parse(mbedJson, stringSerial2);                   
                     sprintf((char*)text, "HTTP string : %s\n", stringSerial2);                
                     if (mbedJson.hasMember("Temp1")) 
-                    {     printf("Serial2 temp1: %s",stringSerial2);
+                    {   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>());                      
+                    {   int tt=setTemp2(mbedJson["Temp2"].get<std::string>());                      
                     }
                     // add buttons parameters 
                     // decode button trame
                     if (mbedJson.hasMember("Touche4")) 
-                    {    printf("Touche 4 update status received");
+                    {   printf("Touche 4 update status received");
                         string s; 
                         s = mbedJson["Touche4"]["Status"].get<std::string>();
                         sprintf(statusButton[4],s.c_str());
@@ -350,7 +349,7 @@
                         touchButtonJPA1(4);                                                                  
                     }
                     if (mbedJson.hasMember("Touche1")) 
-                    {    printf("Touche 1 update status received");
+                    {   printf("Touche 1 update status received");
                         string s; 
                         s = mbedJson["Touche1"]["Status"].get<std::string>();
                         sprintf(statusButton[1],s.c_str());
@@ -384,7 +383,7 @@
                         touchButtonJPA1(2);                                                                  
                     }
                     if (mbedJson.hasMember("Touche3")) 
-                    {    printf("Touche 3 update status received");
+                    {   printf("Touche 3 update status received");
                         string s; 
                         s = mbedJson["Touche3"]["Status"].get<std::string>();
                         sprintf(statusButton[3],s.c_str());
@@ -401,11 +400,18 @@
                         touchButtonJPA1(3);                                                                  
                     }             
                 }                                     
-        }       
-        if (msgSerial7 > 0) {receiveSerial7();}
+        }      // end serial bridge message received ----------- 
+        if (msgSerial7 > 0) {receiveSerial7();}// serial7 message received - not working ---------------
         if (stringSerial7ok == 1) {printf("Trame Serial7 : %s",stringSerial7);stringSerial7ok=0;}
      
-        // timer send can 
+        // timer lcd  --------------------
+        if(timer_lcd.read() >= 1000)            // check for timeout
+       {    timer_lcd.stop();                       // stop the timer
+            timer_lcd.reset();                      // reset the timer
+            timer_lcd_on =0;
+            BSP_LCD_DisplayOff();
+       } 
+        // timer send can ------------------------
        if(timer.read_ms() >= 10000)            // check for timeout
        {    timer.stop();                       // stop the timer
             timer.reset();                      // reset the timer
@@ -430,28 +436,32 @@
                 //BSP_LCD_DisplayStringAt(0, LINE(3), (uint8_t *)"-----------", CENTER_MODE);
             }    
             timer.start();                  // insert transmission lag
-        }  // end if timer
-        //touch screen
-        int xx = touchJPA1();  //
-        if (xx > 0) 
-        {  if (xx == 4)
-           { // send trame to can
-            txMsg.id = 0x100130CB;//TX_ID;                   // set the message ID
-            txMsg.format = CANExtended ; //extended
-            txMsg.len=2;
-            txMsg.data[0]=8;txMsg.data[1]=2;        // append data (total data length must be <= 8 bytes!)
-          
-           if(can.write(txMsg))       // transmit message
-            {   printMsg(txMsg,0);
-                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
-            {   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);
-            }    
+        }  // end if timer send can -------------------
+        // touch screen detection -------------------------------
+        int xx = touchJPA1();  //       
+        if (xx > 0) // touch detected
+        {  if (xx==9)  // display pressed but not a touch
+           {  timer_lcd.stop();                       // stop the timer
+              timer_lcd.reset();                      // reset the timer
+              /////////BSP_LCD_DisplayOn();
+           }    
+           if (xx == 4)  // touch 4 pressed
+           {  // send trame to can
+              txMsg.id = 0x100130CB;//TX_ID;                   // set the message ID
+              txMsg.format = CANExtended ; //extended
+              txMsg.len=2;
+              txMsg.data[0]=8;txMsg.data[1]=2;        // append data (total data length must be <= 8 bytes!)        
+              if(can.write(txMsg))       // transmit message
+              {   printMsg(txMsg,0);
+                  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
+              {   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);
+              }    
            }    
            xx = sendTouchJPA(xx);              
            lastToucheTime = time(NULL);          
@@ -478,8 +488,8 @@
             char resultBuffer[700]= {0};
             //Sending Samples (and returning current command stream values)
             time_t connectAttemptTime = time(NULL);
-            int sendResult = groveStreams.send(myMac, samples, gsCompName, gsCompTmplId, resultBuffer, sizeof resultBuffer);  //receive mqtt
-            
+/////////            int sendResult = groveStreams.send(myMac, samples, gsCompName, gsCompTmplId, resultBuffer, sizeof resultBuffer);  //receive mqtt
+            int sendResult = 0;
             if (sendResult == 0) {
                 ////lcd.printf("Send Successful");
                 printf("Send Successful\n");