mbed-os github

Dependencies:   ADS1015 Faulhaber HTU21D_mod MS5837_potless Sensor_Head_RevB_3 USBDevice_dfu Utilsdfu beep

Fork of ARNSRS_testDFU by POTLESS

Revision:
20:5f79fb4565a7
Parent:
19:cac3761a5d0b
Child:
21:b8900130ca05
--- a/main.cpp	Tue Feb 06 13:18:34 2018 +0000
+++ b/main.cpp	Wed Feb 07 14:52:47 2018 +0000
@@ -144,6 +144,7 @@
 //Thread d'intérogation des capteurs et de positionnement des volets
 Thread thread_Sensors;
 Thread thread_Volets;
+Thread thread_Secu;
 
 //Contrôle des servos
 float Consigne_poumon = 0;
@@ -170,6 +171,8 @@
 
 //Boolean du status de l'appareil, en mode SECU ou nominal
 bool EN_MODE_SECU = false;
+AnalogIn V_USB(PC_4);
+float Vusb = 1;
 
 //Passage en mode SECU
 void Mode_SECU()
@@ -201,13 +204,20 @@
 void Stop_Sequence()
 {
     Mode_SECU();
-    printf("ARRET DE L'APPAREIL");
-    wait(2);
     thread_Sensors.terminate();
+    printf("----------------ARRET DE L'APPAREIL--------------------\r\n");
+    Servo_Poumon.Sleep();
     wait(2);
     deepsleep();
 }
 
+//Fonction test de valeur d'entrée convertie en Hight / Low
+void Power_Test(AnalogIn& pin)
+{
+    float Val = pin.read();
+    if(Val < 0.6f) Stop_Sequence();
+}
+
 //Contrôle du status de l'appareil / des constantes
 bool Check()
 {
@@ -256,8 +266,8 @@
 
         //Retour position des servos
         volet_poumon_Position = Servo_Poumon.Get_Position();
+        //volet_fuite_Position = Servo_Fuite.Get_Position();
 
-        if(!Check()) Mode_SECU();
     }
 }
 
@@ -265,13 +275,24 @@
 {
     while (true) {
         //Servo_Poumon.Go_To_Prop(Consigne_poumon);
-        //Servo_Poumon.Go_To_PID(Consigne_poumon);
-        Servo_Poumon.Go_To(Consigne_poumon);
+        Servo_Poumon.Go_To_PID(Consigne_poumon);
+        //Servo_Poumon.Go_To(Consigne_poumon);
+        
         //Servo_Fuite.Go_To_Prop(Consigne_fuite);
         //Servo_Fuite.Go_To_PID(Consigne_fuite);
     }
 }
 
+void SECU_thread()
+{
+    while (true) {       
+        //Alim USB
+        Power_Test(V_USB);
+        //Divers problèmes à implémenter
+        //if(!Check()) Mode_SECU();
+    }
+}
+
 void Affichage_moniteur()
 {
 
@@ -295,6 +316,8 @@
     printf("\r\n");
     printf("A enregistrer = %s\n", to_store);
     printf("\r\n");
+    printf("V_USB = %f", Vusb);
+    printf("\r\n");
 }
 
 //Callback de l'intérruption des envois de commandes depuis le terminal
@@ -336,7 +359,9 @@
 
     if ((char)commande == 'S') {
         Mode_SECU();
-    } else if ((char)commande == 'R') {
+    } else if ((char)commande == 'r') {
+        Consigne_poumon = 0;
+        volet_poumon_Position = 0;
         Servo_Poumon.reset();
     } else if ((char)commande == 'Q') {
         Stop_Sequence();
@@ -442,11 +467,12 @@
        sensors.Sensors_INIT(true, true, true, 5, SPOOLING, DIGI_FILTER32, CALIB_AIR);
 
     */
-    sensors.Sensors_INIT(true, false);
+    sensors.Sensors_INIT(false, false);
 
     wait(1);
 
-    Servo_Poumon.Faulhaber_Init();
+    Servo_Poumon.Init();
+    //Servo_Fuite.Init();
 
     serialMonit.printf("  Demarrage...\r\n\r\n  Entrez les comandes COZIR si besoin :\r\n");
 
@@ -471,6 +497,10 @@
     thread_Volets.start(GO_TO_thread);
 
     thread_Volets.set_priority(osPriorityNormal);
+    
+    thread_Secu.start(SECU_thread);
+
+    thread_Secu.set_priority(osPriorityNormal);
 
 #ifdef PID_MODE
     //Init PID
@@ -540,9 +570,9 @@
                 volet_poumon_Position,
                 volet_fuite_Position,
                 MODE_FLAG,
-                0,
-                0,
-                0,
+                0.0,
+                0.0,
+                0.0,
                 0
                );
 #endif
@@ -559,7 +589,7 @@
         //Calcul des OTU
         Calcul_OTU();
 
-        //Vers le moniteur dérie
+        //Vers le moniteur série
         Affichage_moniteur();