mbed-os github
Dependencies: ADS1015 Faulhaber HTU21D_mod MS5837_potless Sensor_Head_RevB_3 USBDevice_dfu Utilsdfu beep
Fork of ARNSRS_testDFU by
Diff: main.cpp
- Revision:
- 67:92972b960226
- Parent:
- 64:a85cddb22fff
diff -r a85cddb22fff -r 92972b960226 main.cpp --- a/main.cpp Tue Jul 10 16:35:57 2018 +0000 +++ b/main.cpp Wed Jul 11 06:22:10 2018 +0000 @@ -135,8 +135,8 @@ int consigne = 210; float Max_Input = 1000; float Min_Input = 80; -float Max_Output = 85;//Vérifier la valeur pour angle à laisser ouvert... -float Min_Output = 5; +float Max_Output = 90; +float Min_Output = 0; //Init PID PID control_Servo(Kc, Ti, Td, RATE_PID); @@ -179,6 +179,21 @@ Thread thread_Volets_POUMON; Thread thread_Volets_FUITE; +void Save_Position() +{ + //Enregistrement position des volets + UTILS::EffacePage(2, 31, 1); + + uint64_t Pos_P = Servo_Poumon.getPulses(); + UTILS::Write(VOLET_POUMON_ADDR, Pos_P); + DEBUG(" position volet poumon sauvegardée = %d pulse(s)\r\n", (int) Pos_P); + + uint64_t Pos_F = Servo_Fuite.getPulses(); + UTILS::Write(VOLET_FUITE_ADDR, Pos_F); + DEBUG(" position volet fuite sauvegardée = %d pulse(s)\r\n", (int) Pos_F); +} + + void sleepDemande() { buzzer.beep(1000,0.1); @@ -189,22 +204,22 @@ 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); - + E5V = 0; - + UTILS::EffacePage(2, 29, 1); - + UTILS::Write(DFU_ADDR, 0xBABEFACE); - + //Mise en veille HAL_PWREx_EnablePullUpPullDownConfig() ; HAL_PWREx_EnableGPIOPullDown(PWR_GPIO_A, PWR_GPIO_BIT_0); @@ -216,25 +231,26 @@ // 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 HAL_PWREx_EnterSHUTDOWNMode(); } -// gestion du cas où le sleep est demandé volontairement +// gestion du cas où le sleep est demandé volontairement // et où l'utilisateur coupe ensuite l'alimentation en débranchant ou interrupteur sur off // on refait un shutdown mais avec un wake up sur le branchement du cable + interrupteur sur ON -void flagSleep(){ - +void flagSleep() +{ + if ((int) UTILS::Read(DFU_ADDR) == 0xBABEFACE ) { DEBUG(" Re démarrage sur BABEFACE.\n"); - + UTILS::EffacePage(2, 29, 1); - + // 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); - + HAL_PWREx_EnablePullUpPullDownConfig() ; HAL_PWREx_EnableGPIOPullDown(PWR_GPIO_A, PWR_GPIO_BIT_0); HAL_PWR_DisableWakeUpPin(PWR_WAKEUP_PIN1); // pour PA_0 @@ -245,20 +261,20 @@ // Set RTC back-up register RTC_BKP31R to indicate //later on that system has entered shutdown mode WRITE_REG( RTC->BKP31R, 0x1 ); - + DEBUG(" Mise en veille.\n"); - + //Enter shutdown mode HAL_PWREx_EnterSHUTDOWNMode(); - - } - + } +} + void USB_unplugged() { DEBUG(" La prise USB a été débranchée.\n"); - + buzzer.beep(1000,0.1); wait_ms(100); buzzer.beep(1000,0.1); @@ -273,21 +289,24 @@ 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); - + E5V = 0; - + //Arrêt des enregistrements FLAG_REC = false; UTILS::UnMount_Flash(); + + Save_Position(); + /* //Enregistrement position des servos sans mettre en sécu UTILS::EffacePage(2, 31, 1); - + uint64_t Pos_P = Servo_Poumon.getPulses(); UTILS::Write(VOLET_POUMON_ADDR, Pos_P); DEBUG(" position volet poumon sauvegardée = %d pulse(s)\r\n", (int) Pos_P); @@ -295,7 +314,9 @@ uint64_t Pos_F = Servo_Fuite.getPulses(); UTILS::Write(VOLET_FUITE_ADDR, Pos_F); DEBUG(" position volet fuite sauvegardée = %d pulse(s)\r\n", (int) Pos_F); - + */ + + //Mise en veille version cable arraché DEBUG(" Mise en veille...\r\n"); //wait(1); @@ -310,7 +331,7 @@ // 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 HAL_PWREx_EnterSHUTDOWNMode(); } @@ -318,21 +339,24 @@ void PILES_unpluged() { DEBUG(" Les piles ont été débranchées.\n"); - + buzzer.beep(1000,0.3); wait_ms(500); buzzer.beep(1000,0.3); wait(1); - + //Arrêt des enregistrements FLAG_REC = false; //Ejection flash UTILS::UnMount_Flash(); + + Save_Position(); + /* //Enregistrement position des servos sans mettre en sécu UTILS::EffacePage(2, 31, 1); - + uint64_t Pos_P = Servo_Poumon.getPulses(); UTILS::Write(VOLET_POUMON_ADDR, Pos_P); DEBUG(" position volet poumon sauvegardée = %d pulse(s)\r\n", (int) Pos_P); @@ -340,13 +364,15 @@ uint64_t Pos_F = Servo_Fuite.getPulses(); UTILS::Write(VOLET_FUITE_ADDR, Pos_F); DEBUG(" position volet fuite sauvegardée = %d pulse(s)\r\n", (int) Pos_F); + */ + //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); FLAG_DISPLAY = false; Commande_IHM = 0; - + //Mise en veille DEBUG(" Mise en veille...\r\n"); //wait(1); @@ -395,12 +421,12 @@ Volets_Speed = 1; Volet_DeadBand = 10; +//TODO attention a pas être bloqué dans ce loop.... 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); @@ -408,7 +434,13 @@ 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"); + + /* UTILS::EffacePage(2, 31, 1); //Enregistrement position des servos en sécu pour plus de précision uint64_t Pos_P = Servo_Poumon.getPulses(); @@ -420,7 +452,8 @@ UTILS::Write(VOLET_FUITE_ADDR, Pos_F); DEBUG(" position volet fuite sauvegardée = %d pulse(s)\r\n",(int) Pos_F); OUTPUT(" Volet fuite en sécu\r\n"); - + */ + Servo_Poumon.Sleep(); Servo_Fuite.Sleep(); } @@ -519,6 +552,7 @@ //Calcul des OTU //Calcul_OTU(); + wait(Ref_Time); } } @@ -527,11 +561,11 @@ { while (true) { //DEEP_DEBUG(" GO_TO_Thread_POUMON\r\n"); - + Servo_Poumon.Go_To_Prop(Consigne_poumon); //Servo_Poumon.Go_To_PID(Consigne_poumon, Volet_DeadBand);//Nécessite de déclarer un dernier terme true dans l'init du moteur //Servo_Poumon.Go_To(Consigne_poumon, Volets_Speed, Volet_DeadBand); - + } } @@ -543,7 +577,7 @@ Servo_Fuite.Go_To_Prop(Consigne_fuite); //Servo_Fuite.Go_To_PID(Consigne_fuite, Volet_DeadBand); //Servo_Fuite.Go_To(Consigne_fuite, Volets_Speed, Volet_DeadBand); - + } } @@ -606,6 +640,8 @@ if (0 == strcmp(com, "secu")) { Mode_SECU(); + } else if (0 == strcmp(com, "save_pos")) { + Save_Position(); } else if (0 == strcmp(com, "PING")) { 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); @@ -837,13 +873,13 @@ int main() { flagSleep(); // 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(); - + E5V = 1; E3V = 1; @@ -859,14 +895,14 @@ //Montage Flash UTILS::Mount_Flash(); - + /* if (UTILS::File_Exist("ARNSRS_ID.sys") == false) { UTILS::Store_A_Val(000, "ARNSRS_ID.sys"); DEBUG("ARNSRS ID forcée à 000\r\n"); } */ - + //pour le premier lancement quand l'appareil n'a pas d'ID. //int ID = 0; //UTILS::Write(ADRESSE_ID, ID); @@ -904,51 +940,51 @@ */ DEBUG(" Demarrage des threads...\r\n\r\n"); - - /* - + + /* + Pour mémoire, les réglage de priorité des thread - - osPriorityIdle = -3, ///< priority: idle (lowest) - osPriorityLow = -2, ///< priority: low - osPriorityBelowNormal = -1, ///< priority: below normal - osPriorityNormal = 0, ///< priority: normal (default) - osPriorityAboveNormal = +1, ///< priority: above normal - osPriorityHigh = +2, ///< priority: high - osPriorityRealtime = +3, ///< priority: realtime (highest) - osPriorityError = 0x84 ///< system cannot determine priority or thread has illegal priority + + osPriorityIdle = -3, ///< priority: idle (lowest) + osPriorityLow = -2, ///< priority: low + osPriorityBelowNormal = -1, ///< priority: below normal + osPriorityNormal = 0, ///< priority: normal (default) + osPriorityAboveNormal = +1, ///< priority: above normal + osPriorityHigh = +2, ///< priority: high + osPriorityRealtime = +3, ///< priority: realtime (highest) + osPriorityError = 0x84 ///< system cannot determine priority or thread has illegal priority */ - + thread_Volets_POUMON.set_priority(osPriorityHigh); - + thread_Volets_POUMON.start(callback(GO_TO_thread_POUMON)); - + DEBUG(" Contrôle volet Poumon démarré\r\n\r\n"); - + wait(1); - + thread_Volets_FUITE.set_priority(osPriorityHigh); - + thread_Volets_FUITE.start(callback(GO_TO_thread_FUITE)); - + DEBUG(" Contrôle volet Fuite démarré\r\n\r\n"); - + wait(1); - + thread_Secu.set_priority(osPriorityNormal); - + thread_Secu.start(callback(SECU_thread)); - + DEBUG(" Contrôle des paramètres de sécu démarré\r\n\r\n"); - + wait(1); - + thread_Head.set_priority(osPriorityNormal); - + thread_Head.start(callback(SENSORS_thread)); - + DEBUG(" Tête capteurs démarrée\r\n\r\n"); - + wait(1); @@ -973,11 +1009,11 @@ serialMonit.attach(&callbackParam); display.attach(&callbackIHM); - + OTU_Ticker.attach(&Calcul_OTU, 60); - + vusb_off_on.fall(&USB_unplugged); - + vpiles_off_on.fall(&PILES_unpluged); buzzer.beep(1000,0.3);