une 30aine passés sans pb entre les trames

Dependencies:   ADS1015 ARNSRS_SENSORS DmTftLibrary MS5803_14BA SDFileSystem mbed

Fork of ARNSRS_SERVOS_USB_TFT by POTLESS

Revision:
20:bb8d2cea2076
Parent:
19:31ac20c07bb2
Child:
21:28a3f60b4bc2
--- a/main.cpp	Sun May 14 16:52:18 2017 +0000
+++ b/main.cpp	Thu May 18 06:03:24 2017 +0000
@@ -14,6 +14,14 @@
 #include "ble/services/UARTService.h"
 #include <string>
 
+//#include "DmTftHX8353C.h"
+//#include "DmTftS6D0164.h"
+//#include "DmTftIli9325.h"
+//#include "DmTftIli9341.h"
+//#include "DmTftSsd2119.h"
+//#include "DmTftRa8875.h"
+
+
 //Ecrit dans le moniteur série de l'ordi à 9600 bds si sur 1
 #define NEED_CONSOLE_OUTPUT 1
 //Pour utiliser le traceur du moniteur Arduino. Mettre NEED_CONSOLE_OUTPUT 0 si utilisé.
@@ -21,11 +29,9 @@
 #define NEED_GRAPH_OUTPUT 0
 //Datalog carte SD si sur 1
 #define NEED_SD_DATA_LOG 0
-//BLE avec app android
-#define NEED_BLE_ANDROID 1
 
 #if NEED_CONSOLE_OUTPUT
-#define DEBUG(...) { serialMonit.printf(__VA_ARGS__); }
+#define DEBUG(...) { serialMonit.printf(__VA_ARGS__); } //tft.drawString(0,0,__VA_ARGS__);
 #else
 #define DEBUG(...)
 #endif
@@ -40,16 +46,15 @@
 ////////////////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////////////////
 
-
 //Contrôle des servos
-PwmOut servo1(PB_5);
-AnalogIn FeedBack1(PB_0);
+PwmOut servo1(PB_15);
+AnalogIn FeedBack1(PC_2);
 float Servo1_POS;
 float Limit_min_S1, Limit_max_S1;
 float Delta_FB_1;
 
-PwmOut servo2(PB_4);
-AnalogIn FeedBack2(PA_4);
+PwmOut servo2(PB_1);
+AnalogIn FeedBack2(PC_3);
 float Servo2_POS;
 float Limit_min_S2, Limit_max_S2;
 float Delta_FB_2;
@@ -72,11 +77,18 @@
 float Temp2 = 0;
 float Humi = 0;
 
+//RTC
 //Pour stocker le format date / heure
 string DateHeure;
+time_t seconds;
 
 //SD card
 SDFileSystem sd(D11, D12, D13, D10, "sd"); // MOSI, MISO, SCK, CS
+//DigitalInOut csSDCard(D10, PIN_OUTPUT, PullUp, 1);
+
+//TFT
+//DmTftHX8353C tft(D2, D3, D4, D5, D6);  /* DmTftHX8353C(PinName mosi, PinName clk, PinName cs, PinName dc, PinName rst) DM_TFT18_101 */
+
 FILE *fp;
 char fileName[32];
 int points = 1;
@@ -207,17 +219,17 @@
 {
     //Reglage date / heure depuis le terminal
     struct tm t;
-    printf("Entrer la date et l'heure :\n");
-    printf("YYYY MM DD HH MM SS [enter]\n");
-    scanf("%d %d %d %d %d %d", &t.tm_year, &t.tm_mon, &t.tm_mday
-          , &t.tm_hour, &t.tm_min, &t.tm_sec);
+    serialMonit.printf("Entrer la date et l'heure :\n");
+    serialMonit.printf("YYYY MM DD HH MM SS [enter]\n");
+    serialMonit.scanf("%d %d %d %d %d %d", &t.tm_year, &t.tm_mon, &t.tm_mday
+                      , &t.tm_hour, &t.tm_min, &t.tm_sec);
     t.tm_year = t.tm_year - 1900;
     t.tm_mon = t.tm_mon - 1;
 
     // set the time
     set_time(mktime(&t));
-    
-    if(NEED_CONSOLE_OUTPUT == 0) printf("OK. Vous pouvez fermer le moniteur serie");
+
+    if(NEED_CONSOLE_OUTPUT == 0) serialMonit.printf("OK. Vous pouvez fermer le moniteur serie");
 }
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -226,7 +238,6 @@
 
 void init_DATALOG()
 {
-
     DEBUG("Initialisation SD card\r\n");
     DEBUG("\r\n", "");
     fp = nextLogFile();
@@ -241,38 +252,13 @@
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-////                          Initialisation du BLE                         ////
-////////////////////////////////////////////////////////////////////////////////
-
-void init_BLE()
-{
-    ble.init();
-    ble.onDisconnection(disconnectionCallback);
-    ble.onDataWritten(onDataWritten);
-
-    /* setup advertising */
-    ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED);
-    ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
-    ble.accumulateAdvertisingPayload(GapAdvertisingData::SHORTENED_LOCAL_NAME,
-                                     (const uint8_t *)"ARNSRS", sizeof("ARNSRS") - 1);
-    ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS,
-                                     (const uint8_t *)UARTServiceUUID_reversed, sizeof(UARTServiceUUID_reversed));
-
-    ble.setAdvertisingInterval(1000); /* 1000ms; in multiples of 0.625ms. */
-    ble.startAdvertising();
-
-    UARTService uartService(ble);
-    uartServicePtr = &uartService;
-}
-
-////////////////////////////////////////////////////////////////////////////////
 ////           Fonction d'enregistrement des données sur carte SD           ////
 ////////////////////////////////////////////////////////////////////////////////
 
 void DATA_LOG()
 {
-    time_t seconds = time(NULL);
-    
+    seconds = time(NULL);
+
     if (fp) {
         fprintf(fp, "%s,%d,%d,%f,%f,%f,%f\r\n", ctime(&seconds), co2 , ppO2, pression, Temp1, Temp2, Humi);
         DEBUG("  Enregistrement d'un point sur la carte SD\r\n");
@@ -291,35 +277,47 @@
 void Calibration_servo()
 {
     //Servos, calibration du feedback
+    DEBUG("  Check Servos :\r\n")
+    DEBUG("\r\n");
     servo1.period(0.001);
     servo2.period(0.001);
-    
-    DEBUG("Check Servos :\r\n")
+    //Rentrer les servos à fond
     servo1 = 0;
     servo2 = 0;
     wait(4);
-    DEBUG("  FeedBack 1  MIN = %f\n", FeedBack1.read());
-    DEBUG("  FeedBack 2  MIN = %f\n", FeedBack2.read());
-    Limit_max_S1 = FeedBack1;
-    Limit_max_S2 = FeedBack2;
+    Limit_max_S1 = FeedBack1.read();
+    wait_ms(100);
+    Limit_max_S2 = FeedBack2.read();
+
+    DEBUG("  FeedBack 1  MIN = %f\n", Limit_max_S1);
+    DEBUG("  FeedBack 2  MIN = %f\n", Limit_max_S2);
+    DEBUG("\r\n");
+
+    //Sortir les servos à fond
     servo1 = 1;
     servo2 = 1;
     wait(4);
-    DEBUG("  FeedBack 1  MAX = %f\n", FeedBack1.read());
-    DEBUG("  FeedBack 2  MAX = %f\n", FeedBack2.read());
-    Limit_min_S1 = FeedBack1;
-    Limit_min_S2 = FeedBack2;
+    Limit_min_S1 = FeedBack1.read();
+    wait_ms(100);
+    Limit_min_S2 = FeedBack2.read();
+
+    DEBUG("  FeedBack 1  MAX = %f\n", Limit_min_S1);
+    DEBUG("  FeedBack 2  MAX = %f\n", Limit_min_S2);
+    DEBUG("\r\n");
+
+    //Position milieu
     servo1 = 0.5;
     servo2 = 0.5;
-    wait(4);
-    
+    wait(2);
+
     //Mesure du delta consigne / feedback
     Delta_FB_1 = abs(remap(FeedBack1, Limit_max_S1, Limit_min_S1, 0, 100) - 50);
-    Delta_FB_2 = abs(remap(FeedBack2, Limit_max_S1, Limit_min_S1, 0, 100) - 50);
-    
+    Delta_FB_2 = abs(remap(FeedBack2, Limit_max_S2, Limit_min_S2, 0, 100) - 50);
+
     DEBUG("  Delta Servo 1 = %f\n", Delta_FB_1);
     DEBUG("  Delta Servo 2 = %f\n", Delta_FB_2);
 
+    if(Delta_FB_1 > 10 || Delta_FB_1 > 10)  DEBUG("  Delta Servos non satisfaisant...");
 }
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -328,10 +326,9 @@
 
 void Debug_Complet()
 {
+    //RTC
+    seconds = time(NULL);
 
-    //RTC
-    time_t seconds = time(NULL);
-    
     DEBUG("  Date / Heure = %s\r\n", ctime(&seconds));
 
     //Retour capteurs
@@ -348,6 +345,7 @@
     //Retour position des servos
     DEBUG("  FeedBack 1   = %3.2f%%\n", Servo1_POS);
     DEBUG("  FeedBack 2   = %3.2f%%\n", Servo2_POS);
+    DEBUG("\r\n", "");
 
     //Traceur
     TRACE("%d"  , co2);
@@ -370,13 +368,14 @@
 
 void setup()
 {
+
     wait(2);
 
+    DEBUG("Initialisation TFT\r\n");
+    //tft.init();
+
     //Réglage de l'heure
-    SetTime();
-
-    //Initialisation BLE
-    init_BLE();
+    //SetTime();
 
     //Calibration des limites des servos pour remapper les feedback
     Calibration_servo();
@@ -399,6 +398,25 @@
 {
     setup();
 
+    //Initialisation BLE / ne marche pas si mise dans une fonction appelée ici ou dans le setup...
+    ble.init();
+    ble.onDisconnection(disconnectionCallback);
+    ble.onDataWritten(onDataWritten);
+
+    //setup advertising
+    ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED);
+    ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
+    ble.accumulateAdvertisingPayload(GapAdvertisingData::SHORTENED_LOCAL_NAME,
+                                     (const uint8_t *)"ARNSRS", sizeof("ARNSRS") - 1);
+    ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS,
+                                     (const uint8_t *)UARTServiceUUID_reversed, sizeof(UARTServiceUUID_reversed));
+
+    ble.setAdvertisingInterval(1000); /* 1000ms; in multiples of 0.625ms. */
+    ble.startAdvertising();
+
+    UARTService uartService(ble);
+    uartServicePtr = &uartService;
+
     while (1) {
 
         ble.waitForEvent();