mbed-os github

Dependencies:   ADS1015 Faulhaber HTU21D_mod MS5837_potless Sensor_Head_RevB_3 USBDevice_dfu Utilsdfu beep

Fork of ARNSRS_testDFU by POTLESS

Files at this revision

API Documentation at this revision

Comitter:
POTLESS_2
Date:
Wed Jul 18 09:02:59 2018 +0000
Parent:
71:23e7435e236f
Child:
73:2bbea82bf1e5
Commit message:
nettoyage de code

Changed in this revision

Utils.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/Utils.lib	Mon Jul 16 18:24:08 2018 +0000
+++ b/Utils.lib	Wed Jul 18 09:02:59 2018 +0000
@@ -1,1 +1,1 @@
-https://os.mbed.com/teams/POTLESS/code/Utilsdfu/#143caac22d9f
+https://os.mbed.com/teams/POTLESS/code/Utilsdfu/#6e2d9ab4c69c
--- a/main.cpp	Mon Jul 16 18:24:08 2018 +0000
+++ b/main.cpp	Wed Jul 18 09:02:59 2018 +0000
@@ -91,10 +91,7 @@
 bool FLAG_O2 = true;
 
 //Flag si on débranche l'USB
-bool USB_UNPLUGGED = false;
-
-//Flag si on débranche les piles
-bool PILES_UNPLUGGED = false;
+bool ALIM_UNPLUGGED = false;
 
 //Variables de stockage des infos capteurs
 int co2 = 0;
@@ -194,7 +191,7 @@
 Thread thread_Volets_POUMON;
 Thread thread_Volets_FUITE;
 
-void save_position()
+void Save_Pos()
 {
 
     //Enregistrement position des servos sans mettre en sécu
@@ -212,72 +209,18 @@
 
 }
 
-
-void sleepDemande()
+//Passage en mode SECU
+void Mode_SECU()
 {
-    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);
-
-    Commande_IHM = 1;
-    IHM("<0 0 ;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;%d>\r\n", Commande_IHM);
-    FLAG_DISPLAY = false;
-    Commande_IHM = 0;
-
-    // mise à zero UART IHM pour éviter son redémarrage intempestif (le tx suffirait)
-    HAL_PWREx_EnableGPIOPullDown(PWR_GPIO_C, PWR_GPIO_BIT_4);
-    HAL_PWREx_EnableGPIOPullDown(PWR_GPIO_C, PWR_GPIO_BIT_5);
-
-    
-    UTILS::EffacePage(2, 29, 1);
-
-    UTILS::Write(FLAG_ADDR, 0xBABEFACE);
 
-    //Mise en veille
-    HAL_PWREx_EnablePullUpPullDownConfig() ;
-    HAL_PWREx_EnableGPIOPullDown(PWR_GPIO_A, PWR_GPIO_BIT_0);
-    HAL_PWR_DisableWakeUpPin(PWR_WAKEUP_PIN1_LOW); // pour PA_0
-    // Clear wake up Flag
-    __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WUF1);
-    // Enable wakeup pin WKUP2
-    HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN1_LOW); // high est la valeur par défaut
-    // Set RTC back-up register RTC_BKP31R to indicate
-    //later on that system has entered shutdown mode
-    WRITE_REG( RTC->BKP31R, 0x1 );
+    //Mise du PID en mode manuel (desactivation...)
+    FLAG_PID = 0;
 
-    //Enter shutdown mode
-    HAL_PWREx_EnterSHUTDOWNMode();
-}
- 
-void USB_is_unplugged() 
-{
-    USB_UNPLUGGED = true;
-    }
-
-void USB_unplugged()
-{
-    DEBUG("  La prise USB a été débranchée.\n");
-    
-    buzzer.beep(1000,0.1);
-  
-    //Mise en veille de l'IHM
-    Commande_IHM = 1;
-    IHM("<0 0 ;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;%d>\r\n", Commande_IHM);
-    
-    // mise à zero UART IHM pour éviter son redémarrage intempestif (le tx suffirait)
-    HAL_PWREx_EnableGPIOPullDown(PWR_GPIO_C, PWR_GPIO_BIT_4);
-    HAL_PWREx_EnableGPIOPullDown(PWR_GPIO_C, PWR_GPIO_BIT_5);
-    
     //On coupe les thread car on va utiliser une autre fonction
     thread_Volets_POUMON.terminate();
     thread_Volets_FUITE.terminate();
 
-    //A fond et avec une erreur tolérée de +- 5 deg autour du Home
+    //A fond et avec une erreur tolérée de +- 5 deg autour du Home. Cohérent avec le future init qui recherche une erreur > 5 deg
     Volets_Speed = 1;
     Volet_DeadBand = 10;
     
@@ -287,16 +230,37 @@
     Servo_Fuite.Go_To(Consigne_fuite, Volets_Speed, Volet_DeadBand);
         
     Servo_Poumon.Go_To(Consigne_poumon, Volets_Speed, Volet_DeadBand);
-        
-    DEBUG("  Appareil en mode SECU\r\n");
+    
+    Save_Pos();
     
-    E5V = 0;
+    OUTPUT("  Volet poumon en sécu\r\n");
+    OUTPUT("  Volet fuite en sécu\r\n");
+
+    Servo_Poumon.Sleep();
+    Servo_Fuite.Sleep();
+}
+
+void Sleep_IHM()
+{
+    //Mise en veille de l'IHM
+    Commande_IHM = 1;
+    IHM("<0 0 ;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;%d>\r\n", Commande_IHM);
     
-    save_position();
+    wait(0.5);
+    
+    // mise à zero UART IHM pour éviter son redémarrage intempestif (le tx suffirait)
+    HAL_PWREx_EnableGPIOPullDown(PWR_GPIO_C, PWR_GPIO_BIT_4);
+    HAL_PWREx_EnableGPIOPullDown(PWR_GPIO_C, PWR_GPIO_BIT_5);
+    
+}
+
+void Sleep_HIGHT_WakeUp()
+{
+        
+    E5V = 0;
  
     UTILS::UnMount_Flash();
  
-    //Mise en veille version cable arraché
     DEBUG("  Mise en veille...\r\n");
       
     //Mise en veille
@@ -313,73 +277,70 @@
  
     //Enter shutdown mode
     E3V=0;
-    HAL_PWREx_EnterSHUTDOWNMode(); // n’est pas exécuté à cause du E3V=0 précédent
+    //n’est pas exécuté à cause du E3V=0 précédent
+    HAL_PWREx_EnterSHUTDOWNMode();
      
 }
 
-void Piles_are_unplugged() 
+void Sleep_LOW_WakeUp()
 {
-    PILES_UNPLUGGED = true;
+    E5V = 0;
+    
+    UTILS::UnMount_Flash();
+ 
+    DEBUG("  Mise en veille...\r\n");
+    
+    UTILS::EffacePage(2, PAGE_FLAG_ADDR, 1);
+
+    UTILS::Write(FLAG_ADDR, 0xBABEFACE);
+
+    //Mise en veille
+    HAL_PWREx_EnablePullUpPullDownConfig() ;
+    HAL_PWREx_EnableGPIOPullDown(PWR_GPIO_A, PWR_GPIO_BIT_0);
+    HAL_PWR_DisableWakeUpPin(PWR_WAKEUP_PIN1_LOW); // pour PA_0
+    // Clear wake up Flag
+    __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WUF1);
+    // Enable wakeup pin WKUP2
+    HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN1_LOW); // high est la valeur par défaut
+    // Set RTC back-up register RTC_BKP31R to indicate
+    //later on that system has entered shutdown mode
+    WRITE_REG( RTC->BKP31R, 0x1 );
+    
+    //Enter shutdown mode
+    //E3V=0;
+    //Enter shutdown mode
+    HAL_PWREx_EnterSHUTDOWNMode();
+}
+ 
+void ALIM_is_unplugged() 
+{
+    ALIM_UNPLUGGED = true;
     }
-            
-void PILES_unplugged()
+
+void ALIM_unplugged()
 {
-    DEBUG("  La prise USB a été débranchée.\n");
+    DEBUG("  L'alimentation a été débranchée.\n");
     
     buzzer.beep(1000,0.1);
   
-    //Mise en veille de l'IHM
-    Commande_IHM = 1;
-    IHM("<0 0 ;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;%d>\r\n", Commande_IHM);
-    
-    // mise à zero UART IHM pour éviter son redémarrage intempestif (le tx suffirait)
-    HAL_PWREx_EnableGPIOPullDown(PWR_GPIO_C, PWR_GPIO_BIT_4);
-    HAL_PWREx_EnableGPIOPullDown(PWR_GPIO_C, PWR_GPIO_BIT_5);
+    Sleep_IHM();
     
-    //On coupe les thread car on va utiliser une autre fonction
-    thread_Volets_POUMON.terminate();
-    thread_Volets_FUITE.terminate();
-
-    //A fond et avec une erreur tolérée de +- 5 deg autour du Home
-    Volets_Speed = 1;
-    Volet_DeadBand = 5;
-    
-    Consigne_poumon = HOME_SERVO_POUMON;
-    Consigne_fuite = HOME_SERVO_FUITE;
-    
-    //Cette méthode n'oscile pas car le pwm reste alimenté...donc pas de multiples pics de démarrage
-    Servo_Fuite.Go_To(Consigne_fuite, Volets_Speed, Volet_DeadBand);
-    //Pas besoin du wait car comme on execute pas les goto dans des thread séparés, ils s'éxécuteront l'un après l'autre...je commence par la fuite
-    Servo_Poumon.Go_To(Consigne_poumon, Volets_Speed, Volet_DeadBand);
-     
-    DEBUG("  Appareil en mode SECU\r\n");
+    Mode_SECU();
     
-    E5V = 0;
+    Sleep_HIGHT_WakeUp();
+     
+}
+
+//Sequence d'arrêt demandé par commande "sleep"
+void Stop_Sequence()
+{
+    OUTPUT("  Mise en veille de l'appareil.\r\n");
     
-    save_position();
- 
-    UTILS::UnMount_Flash();
- 
-    //Mise en veille version cable arraché
-    DEBUG("  Mise en veille...\r\n");
-      
-    //Mise en veille
-    HAL_PWREx_EnablePullUpPullDownConfig() ;
-    HAL_PWREx_EnableGPIOPullDown(PWR_GPIO_A, PWR_GPIO_BIT_0);
-    HAL_PWR_DisableWakeUpPin(PWR_WAKEUP_PIN1); // pour PA_0
-    // Clear wake up Flag
-    __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WUF1);
-    // Enable wakeup pin WKUP2
-    HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN1); // high est la valeur par défaut
-    // Set RTC back-up register RTC_BKP31R to indicate
-    //later on that system has entered shutdown mode
-    WRITE_REG( RTC->BKP31R, 0x1 );
- 
-    //Enter shutdown mode
-    E3V=0;
-    HAL_PWREx_EnterSHUTDOWNMode(); // n’est pas exécuté à cause du E3V=0 précédent
-     
+    Sleep_IHM();
     
+    Mode_SECU();
+
+    Sleep_LOW_WakeUp();
 }
 
 void Affichage()
@@ -451,65 +412,8 @@
     
     //Toujours finir par \r\n
     TRACEUR_DEBUG("\r\n");    
-    }
-
-//Passage en mode SECU
-void Mode_SECU()
-{
-
-    //Mise du PID en mode manuel (desactivation...)
-    //control_Servo.setMode(MANUAL_MODE);
-    FLAG_PID = 0;
-
-    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");
-
-    wait_ms(100);
-
-    EN_MODE_SECU = true;
-
-    wait_ms(100);
-
-    save_position();
-    
-    OUTPUT("  Volet poumon en sécu\r\n");
-    OUTPUT("  Volet fuite en sécu\r\n");
-
-    Servo_Poumon.Sleep();
-    Servo_Fuite.Sleep();
 }
 
-//Sequence d'arrêt
-void Stop_Sequence()
-{
-    OUTPUT("  Mise en veille de l'appareil.\r\n");
-
-    wait(1);
-
-    Mode_SECU();
-
-    wait(1);
-
-    //ejection de la flash pour pas crasher le system de fichiers
-    UTILS::UnMount_Flash();
-
-    OUTPUT("  Ejection de la Flash\r\n");
-
-    wait(1);
-
-    sleepDemande();
-}
 
 //Fonction test de valeur d'entrée digitale
 int Power_Test(DigitalIn& pin)
@@ -616,8 +520,7 @@
 {
     while (true) {
         //Mettre toutes les vérifs de sécu....
-        if (USB_UNPLUGGED) USB_unplugged();
-        if (PILES_UNPLUGGED) PILES_unplugged();
+        if (ALIM_UNPLUGGED) ALIM_unplugged();
     }
 }
 
@@ -674,7 +577,7 @@
     if (0 == strcmp(com, "secu")) {
         Mode_SECU();
     } else if (0 == strcmp(com, "save_pos")) {
-        save_position();
+        Save_Pos();
     } else if (0 == strcmp(com, "trace")) {
             if (FLAG_TRACE) {
             FLAG_TRACE = false;
@@ -919,14 +822,14 @@
 
 int main()
 {
-    UTILS::Flag_Sleep(); // on vérifie si la demande de sleep n'est pas active (permet de redémarrer sur un front haut)
 
     HAL_Init();
     __HAL_RCC_PWR_CLK_ENABLE();
     HAL_PWR_EnableBkUpAccess();
-
-    UTILS::DFU();
-
+    
+    //Vérifications Flag de démarrage
+    UTILS::START_FLAG();
+    
     E5V = 1;
     E3V = 1;
 
@@ -1059,9 +962,9 @@
 
     OTU_Ticker.attach(&Calcul_OTU, 60);
 
-    vusb_off_on.fall(&USB_is_unplugged);
+    vusb_off_on.fall(&ALIM_is_unplugged);
 
-    vpiles_off_on.fall(&Piles_are_unplugged);
+    vpiles_off_on.fall(&ALIM_is_unplugged);
 
     buzzer.beep(1000,0.3);
     wait_ms(500);