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:
18:e3827d5dbdd9
Parent:
17:6e0c4c0e0fe2
Child:
19:31ac20c07bb2
--- a/main.cpp	Wed May 10 08:54:18 2017 +0000
+++ b/main.cpp	Thu May 11 15:50:35 2017 +0000
@@ -39,6 +39,12 @@
 #define TRACE(...)
 #endif
 
+//Contrôle des servos
+PwmOut servo1(PB_5);
+//PwmOut servo2(PB_4);
+float servo1_move = 0.0005;
+//float servo2_move = 0.0005;
+
 //Init BLE
 BLEDevice  ble;
 UARTService *uartServicePtr;
@@ -125,12 +131,39 @@
         }
 */
         // chaine reçue de l'app android (à dimensionner selon besoin)
-        char commande [bytesRead] ;
+        char message [bytesRead] ;
 
         // conversion de la commande uint8_t en chaine pour permettre comparaison avec commandes connues
         for (int j=0; j<bytesRead; j++) {
-            commande [j] = (*((params->data)+j));
+            message [j] = (*((params->data)+j));
         }
+        
+        //Variables pour décomposition du message
+        char *commande, *valeur;
+        
+        //La commande
+        commande = strtok(message, ",;");
+        DEBUG("Commande = %s\n", commande);
+        //La valeur associée
+        valeur = strtok(NULL, ",;");
+        DEBUG("Valeur   = %s\n", valeur);
+        
+        //On compare la commande pour faire les actions
+        
+        //Commande servo1 
+        if(strcmp(commande, "[S1]") == 0) {
+            servo1_move = atoi(valeur) * 0.00001;
+            DEBUG("Servo 1    =  %f\r\n", servo1_move);
+            servo1.pulsewidth(servo1_move);
+            }
+            /* 
+        //Commande servo2    
+        if(strcmp(commande, "[S2]") == 0) {
+            servo2_move = atoi(valeur) * 0.00001;
+            DEBUG("Servo 2    =  %f\r\n", servo2_move);
+            servo2.pulsewidth(servo2_move);
+            } 
+        */
 /*
         DEBUG("received %u bytes => ", bytesRead);
         DEBUG("commande recue -%s-\r\n",commande);
@@ -157,7 +190,7 @@
 */
 
         //En accord avec app Android
-        if (strcmp(commande, "t") == 0) {
+        /*if (strcmp(commande, "t") == 0) {
             build_send_Message_int("t", co2, ppO2);
         }else
         if (strcmp(commande, "u") == 0) {
@@ -165,9 +198,12 @@
         }else
         if (strcmp(commande, "v") == 0) {
             build_send_Message_float("v", Humi, pression);
+        }else
+        if (strchr(commande, "s") == 0) {
+           replace(commande, "s","");*/
         }
     }
-}
+
 
 //Fonction qui change le nom du fichier ouvert pour le LOG
 FILE *nextLogFile(void)
@@ -233,9 +269,16 @@
 ///////////////////////////////////
 void setup()
 {
+    wait(2);
     //Réglage de l'heure
     SetTime();
-
+    
+    //Servos
+    servo1.period(0.001);
+    //servo2.period(0.001);  
+    servo1.pulsewidth(servo1_move);//position initiale 1/2
+    //servo2.pulsewidth(servo2_move);
+    
     //Initialisation du Data log
     if (NEED_SD_DATA_LOG == 1) init_DATALOG();