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:
70:0ae5fd4f826c
Parent:
69:9afe54d53bb0
Child:
71:23e7435e236f
--- a/main.cpp	Thu Jul 12 13:27:37 2018 +0000
+++ b/main.cpp	Fri Jul 13 06:05:47 2018 +0000
@@ -75,7 +75,7 @@
 //Flag pour interrompre l'affichage si on veut...
 bool FLAG_AFF = false;
 
-//Flag pour interrompre l'affichage si on veut...
+//Flag pour interrompre le traceur  si on veut...
 bool FLAG_TRACE = false;
 
 //Flag pour envoyer à l'app windev...
@@ -87,9 +87,11 @@
 //Flag pour interrompre l'enregistrement si on veut...
 bool FLAG_REC = true;
 
-//Flag pour interrompre les demandes O2 en cours ed calibration...
+//Flag pour interrompre les demandes O2 en cours de calibration...
 bool FLAG_O2 = true;
 
+//Flag si on débranche l'USB
+bool USB_UNPLUGGED = false;
 
 //Variables de stockage des infos capteurs
 int co2 = 0;
@@ -166,12 +168,13 @@
 //3 -> Big problème
 int Commande_IHM = 0;
 
+//Pin connexion USB et Piles
+//DigitalIn vusb(PIN_V_USB_DIGI);
+//DigitalIn vpiles(PIN_V_PILES_DIGI);
+
 //Interruption pin
 InterruptIn vpiles_off_on(PIN_V_PILES_DIGI);
-//InterruptIn vusb_off_on(PIN_V_USB_DIGI);
-
-//Pin connexion USB
-DigitalIn vusb(PIN_V_USB_DIGI);
+InterruptIn vusb_off_on(PIN_V_USB_DIGI);
 
 //Pin enable du régulateur 5 v
 DigitalOut E5V(PA_4);
@@ -225,8 +228,7 @@
     HAL_PWREx_EnableGPIOPullDown(PWR_GPIO_C, PWR_GPIO_BIT_4);
     HAL_PWREx_EnableGPIOPullDown(PWR_GPIO_C, PWR_GPIO_BIT_5);
 
-    E5V = 0;
-
+    
     UTILS::EffacePage(2, 29, 1);
 
     UTILS::Write(DFU_ADDR, 0xBABEFACE);
@@ -281,21 +283,15 @@
     }
 
 }
-    
+ 
+void USB_is_unplugged() 
+{
+    USB_UNPLUGGED = true;
+    }
+       
 void USB_unplugged()
 {
     DEBUG("  La prise USB a été débranchée.\n");
-    
-    __disable_irq(); 
-
-    buzzer.beep(1000,0.1);
-    wait_ms(100);
-    buzzer.beep(1000,0.1);
-    wait_ms(100);
-    buzzer.beep(1000,0.1);
-    wait_ms(100);
-    buzzer.beep(1000,0.1);
-    wait(1);
 
     //Mise en veille de l'IHM
     Commande_IHM = 1;
@@ -312,20 +308,16 @@
     Consigne_poumon = HOME_SERVO_POUMON;
     Consigne_fuite = HOME_SERVO_FUITE;
 
-    Volets_Speed = 1;
-    Volet_DeadBand = 10;
-
     while(1) {
         wait_ms(100);
         if (Servo_Poumon.Pos_OK() == true && Servo_Fuite.Pos_OK() == true) break;
     }
 
-
     OUTPUT("  Appareil en mode SECU\r\n");
     
     save_position();
        
-    //wait(1);
+    wait(1);
     
     //Arrêt des enregistrements
     FLAG_REC = false;
@@ -334,7 +326,7 @@
 
     //Mise en veille version cable arraché
     DEBUG("  Mise en veille...\r\n");
-    //wait(1);
+       
     //Mise en veille
     HAL_PWREx_EnablePullUpPullDownConfig() ;
     HAL_PWREx_EnableGPIOPullDown(PWR_GPIO_A, PWR_GPIO_BIT_0);
@@ -348,8 +340,8 @@
     WRITE_REG( RTC->BKP31R, 0x1 );
 
     //Enter shutdown mode
-    HAL_PWREx_EnterSHUTDOWNMode();
-    
+    HAL_PWREx_EnterSHUTDOWNMode(); 
+      
 }
 
 void PILES_unplugged()
@@ -366,8 +358,7 @@
 
     //Ejection flash
     UTILS::UnMount_Flash();
-
-    
+   
     //Enregistrement position des servos sans mettre en sécu
     save_position();
 
@@ -381,6 +372,7 @@
     DEBUG("  Mise en veille...\r\n");
     //wait(1);
     sleepDemande();
+    
 }
 
 void Affichage()
@@ -617,7 +609,7 @@
 {
     while (true) {
         //Mettre toutes les vérifs de sécu....
-        if (Power_Test(vusb) == 0) USB_unplugged();
+        if (USB_UNPLUGGED) USB_unplugged();
     }
 }
 
@@ -1057,7 +1049,7 @@
 
     OTU_Ticker.attach(&Calcul_OTU, 60);
 
-    //vusb_off_on.fall(&USB_unplugged);
+    vusb_off_on.fall(&USB_is_unplugged);
 
     vpiles_off_on.fall(&PILES_unplugged);
 
@@ -1148,11 +1140,11 @@
         if (FLAG_PID == 1 && EN_MODE_SECU == false) {
             control_Servo.setProcessValue(ppO2);
             //pour visu sur graph IDE arduino
-            DEBUG("ppo2 : %d , consigne : %d \r\n",ppO2, consigne);
+            //DEBUG("ppo2 : %d , consigne : %d \r\n",ppO2, consigne);
             //Nouvelle sortie servo poumon si on est pas en mode SECU
-            Consigne_poumon = 90-control_Servo.compute();
+            Consigne_poumon = 90 - control_Servo.compute();
             // mode volets asservis (simule un seul moteur)
-            Consigne_fuite = Consigne_poumon-90;
+            Consigne_fuite = Consigne_poumon - 90;
         }
 
         //Arrêt du Timer mesurant le temps d'éxecution du code