![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
mbed-os github
Dependencies: ADS1015 Faulhaber HTU21D_mod MS5837_potless Sensor_Head_RevB_3 USBDevice_dfu Utilsdfu beep
Fork of ARNSRS_testDFU by
main.cpp@62:891379d80b1b, 2018-07-03 (annotated)
- Committer:
- POTLESS_2
- Date:
- Tue Jul 03 16:24:59 2018 +0000
- Revision:
- 62:891379d80b1b
- Parent:
- 60:e2922f9e309c
- Child:
- 63:69f6d600807e
reprise fonctions moteurs
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
potless | 1:bef7856b5c0a | 1 | #include "mbed.h" |
potless | 2:4a8bf1d53439 | 2 | #include <string> |
POTLESS_2 | 7:ad15c386e960 | 3 | #include "Sensor_head_revB.h" |
POTLESS_2 | 8:a750d531b381 | 4 | #include "HTU21D.h" |
POTLESS_2 | 12:7f3aadd79f89 | 5 | #include "PID.h" |
POTLESS_2 | 19:cac3761a5d0b | 6 | #include "Faulhaber.h" |
POTLESS_2 | 29:5b822d18bce6 | 7 | #include "Utils.h" |
POTLESS_2 | 47:89a088bc8866 | 8 | #include "beep.h" |
POTLESS_2 | 47:89a088bc8866 | 9 | #include "USBSerial.h" |
POTLESS_2 | 4:d84250f67dec | 10 | |
potless | 48:9ceb095f397a | 11 | |
POTLESS_2 | 17:bef8abc445f2 | 12 | //Commandes des servos |
POTLESS_2 | 19:cac3761a5d0b | 13 | #define PWM_SERVO_POUMON PB_15 |
POTLESS_2 | 19:cac3761a5d0b | 14 | #define nSleep_SERVO_POUMON PC_6 |
POTLESS_2 | 19:cac3761a5d0b | 15 | #define FWD_SERVO_POUMON PB_14 |
POTLESS_2 | 19:cac3761a5d0b | 16 | #define REV_SERVO_POUMON PB_13 |
POTLESS_2 | 55:6536e02d729e | 17 | #define Channel_A_SERVO_POUMON PB_1 |
POTLESS_2 | 55:6536e02d729e | 18 | #define Channel_B_SERVO_POUMON PB_2 |
POTLESS_2 | 19:cac3761a5d0b | 19 | #define HOME_SERVO_POUMON 0 |
POTLESS_2 | 17:bef8abc445f2 | 20 | |
POTLESS_2 | 19:cac3761a5d0b | 21 | #define PWM_SERVO_FUITE PB_10 |
POTLESS_2 | 43:5ae8baf28e32 | 22 | #define nSleep_SERVO_FUITE PB_0 |
POTLESS_2 | 55:6536e02d729e | 23 | #define FWD_SERVO_FUITE PB_5 |
POTLESS_2 | 55:6536e02d729e | 24 | #define REV_SERVO_FUITE PB_4 |
POTLESS_2 | 43:5ae8baf28e32 | 25 | #define Channel_A_SERVO_FUITE PC_9 |
POTLESS_2 | 43:5ae8baf28e32 | 26 | #define Channel_B_SERVO_FUITE PA_8 |
POTLESS_2 | 19:cac3761a5d0b | 27 | #define HOME_SERVO_FUITE 90 |
POTLESS_2 | 17:bef8abc445f2 | 28 | |
POTLESS_2 | 43:5ae8baf28e32 | 29 | //Pin de test des alims |
POTLESS_2 | 43:5ae8baf28e32 | 30 | #define PIN_V_PILES_ANALOG PA_1 |
POTLESS_2 | 59:fd64ca9dae27 | 31 | #define PIN_V_PILES_DIGI PC_3 |
POTLESS_2 | 43:5ae8baf28e32 | 32 | #define PIN_V_USB_DIGI PA_0 |
POTLESS_2 | 11:b2feed92584a | 33 | |
potless | 44:5cd6f84a62ec | 34 | //#define OUTPUT(...) { NVIC_DisableIRQ(USART3_IRQn); serialMonit.printf(__VA_ARGS__); fflush(stdout);NVIC_EnableIRQ(USART3_IRQn);} |
POTLESS_2 | 56:61b0f4d6a890 | 35 | //#define OUTPUT(...) { NVIC_DisableIRQ(USART2_IRQn); serialMonit.printf(__VA_ARGS__); fflush(stdout);NVIC_EnableIRQ(USART2_IRQn);} |
POTLESS_2 | 57:a0827fa46b03 | 36 | //#define OUTPUT(...) { NVIC_DisableIRQ(OTG_FS_IRQn);serialMonit.printf(__VA_ARGS__); fflush(stdout);NVIC_EnableIRQ(OTG_FS_IRQn);} |
POTLESS_2 | 56:61b0f4d6a890 | 37 | #define OUTPUT(...) { serialMonit.printf(__VA_ARGS__); fflush(stdout);} |
POTLESS_2 | 46:28298df0ac55 | 38 | #define IHM(...) { NVIC_DisableIRQ(USART3_IRQn); display.printf(__VA_ARGS__); fflush(stdout);NVIC_EnableIRQ(USART3_IRQn);} |
POTLESS_2 | 34:26f6e3dbefb9 | 39 | |
POTLESS_2 | 57:a0827fa46b03 | 40 | //Communication USB, OTG_FS |
POTLESS_2 | 57:a0827fa46b03 | 41 | USBSerial serialMonit(0x0483, 0x5740, 0x0001, false); |
POTLESS_2 | 57:a0827fa46b03 | 42 | //USBSerial serialMonit;//Pour pilotes windows Olivier |
POTLESS_2 | 10:aca745a66d51 | 43 | |
POTLESS_2 | 57:a0827fa46b03 | 44 | //Moniteur série debug, Serial 2 |
POTLESS_2 | 57:a0827fa46b03 | 45 | Serial serial(PA_2, PA_3,115200); // UART2 à décommenter / commenter pour DEBUG et Deep DEBUG |
POTLESS_2 | 43:5ae8baf28e32 | 46 | |
POTLESS_2 | 57:a0827fa46b03 | 47 | //Communication avec l'IHM, Serial 3 |
POTLESS_2 | 57:a0827fa46b03 | 48 | Serial display(PC_4, PC_5, 115200); |
POTLESS_2 | 4:d84250f67dec | 49 | |
POTLESS_2 | 62:891379d80b1b | 50 | //PinName pwm, PinName nSleep, PinName fwd, PinName rev, PinName channelA, PinName channelB, int pulsesPerRev, int Rapport, Encoding encoding = X2_ENCODING |
POTLESS_2 | 62:891379d80b1b | 51 | //Angle 0 -> tuyau fermé, Angle 90 -> tuyau ouvert |
POTLESS_2 | 62:891379d80b1b | 52 | Faulhaber Servo_Poumon(VOLET_POUMON_ADDR, PWM_SERVO_POUMON, nSleep_SERVO_POUMON, FWD_SERVO_POUMON, REV_SERVO_POUMON, Channel_A_SERVO_POUMON, Channel_B_SERVO_POUMON, 16, 1257, HOME_SERVO_POUMON, Faulhaber::X2_ENCODING); |
POTLESS_2 | 62:891379d80b1b | 53 | Faulhaber Servo_Fuite(VOLET_FUITE_ADDR, PWM_SERVO_FUITE, nSleep_SERVO_FUITE, FWD_SERVO_FUITE, REV_SERVO_FUITE, Channel_A_SERVO_FUITE, Channel_B_SERVO_FUITE, 16, 207, HOME_SERVO_FUITE, Faulhaber::X2_ENCODING); |
POTLESS_2 | 62:891379d80b1b | 54 | |
POTLESS_2 | 7:ad15c386e960 | 55 | //Init de la lib ARNSRS; |
POTLESS_2 | 7:ad15c386e960 | 56 | SENSOR_HEAD_REV_B sensors; |
potless | 2:4a8bf1d53439 | 57 | |
POTLESS_2 | 34:26f6e3dbefb9 | 58 | //pour Param Venant du PV |
POTLESS_2 | 42:3591ec9903b4 | 59 | const int sizeParam = 50; |
POTLESS_2 | 11:b2feed92584a | 60 | char param[sizeParam]; |
POTLESS_2 | 11:b2feed92584a | 61 | volatile int indexParam = 0; |
POTLESS_2 | 6:ebed9093d661 | 62 | bool newParamFlag = false; |
potless | 2:4a8bf1d53439 | 63 | |
POTLESS_2 | 56:61b0f4d6a890 | 64 | //pour Param Venant de l'IHM |
POTLESS_2 | 56:61b0f4d6a890 | 65 | const int sizeIHM = 50; |
POTLESS_2 | 56:61b0f4d6a890 | 66 | char IHM[sizeIHM]; |
POTLESS_2 | 56:61b0f4d6a890 | 67 | volatile int indexIHM = 0; |
POTLESS_2 | 56:61b0f4d6a890 | 68 | bool newIHMFlag = false; |
POTLESS_2 | 56:61b0f4d6a890 | 69 | |
POTLESS_2 | 43:5ae8baf28e32 | 70 | //Flag PID ON / OFF |
POTLESS_2 | 43:5ae8baf28e32 | 71 | int FLAG_PID = 0; |
POTLESS_2 | 42:3591ec9903b4 | 72 | |
POTLESS_2 | 42:3591ec9903b4 | 73 | //Flag pour interrompre l'affichage si on veut... |
POTLESS_2 | 42:3591ec9903b4 | 74 | bool FLAG_AFF = false; |
POTLESS_2 | 25:322ef9488e65 | 75 | |
POTLESS_2 | 40:32d89e04ead1 | 76 | //Flag pour envoyer à l'app windev... |
POTLESS_2 | 40:32d89e04ead1 | 77 | bool FLAG_WINDEV = false; |
POTLESS_2 | 40:32d89e04ead1 | 78 | |
POTLESS_2 | 43:5ae8baf28e32 | 79 | //Flag pour envoyer à l'IHM... |
POTLESS_2 | 46:28298df0ac55 | 80 | bool FLAG_DISPLAY = true; |
POTLESS_2 | 43:5ae8baf28e32 | 81 | |
POTLESS_2 | 29:5b822d18bce6 | 82 | //Flag pour interrompre l'enregistrement si on veut... |
POTLESS_2 | 29:5b822d18bce6 | 83 | bool FLAG_REC = true; |
POTLESS_2 | 29:5b822d18bce6 | 84 | |
POTLESS_2 | 33:f5d4bae05f16 | 85 | //Flag pour interrompre les demandes O2 en cours ed calibration... |
POTLESS_2 | 33:f5d4bae05f16 | 86 | bool FLAG_O2 = true; |
POTLESS_2 | 33:f5d4bae05f16 | 87 | |
POTLESS_2 | 7:ad15c386e960 | 88 | //Variables de stockage des infos capteurs |
POTLESS_2 | 7:ad15c386e960 | 89 | int co2 = 0; |
POTLESS_2 | 7:ad15c386e960 | 90 | float pression = 0; |
POTLESS_2 | 9:04bfdfc029cb | 91 | float Temp1 = 0; |
POTLESS_2 | 7:ad15c386e960 | 92 | int ppO2 = 0; |
POTLESS_2 | 7:ad15c386e960 | 93 | int CellO2_1 = 0; |
POTLESS_2 | 7:ad15c386e960 | 94 | int CellO2_2 = 0; |
POTLESS_2 | 36:1f5e2247b073 | 95 | |
POTLESS_2 | 18:bfd78c05b589 | 96 | //Variables et constantes OTU |
POTLESS_2 | 58:694d4d00407c | 97 | Ticker OTU_Ticker; |
POTLESS_2 | 18:bfd78c05b589 | 98 | float OTU = 0; |
POTLESS_2 | 58:694d4d00407c | 99 | float EXP_OTU = 0.83; |
POTLESS_2 | 18:bfd78c05b589 | 100 | |
POTLESS_2 | 17:bef8abc445f2 | 101 | //Mesure du temps d'éxecution du loop |
POTLESS_2 | 7:ad15c386e960 | 102 | Timer REAL_RATE; |
POTLESS_2 | 7:ad15c386e960 | 103 | float RATE = 0; |
POTLESS_2 | 11:b2feed92584a | 104 | float RATE_TRUE = 0; |
POTLESS_2 | 29:5b822d18bce6 | 105 | float Ref_Time = 2.0; //La durée de la boucle désirée... |
POTLESS_2 | 7:ad15c386e960 | 106 | |
POTLESS_2 | 17:bef8abc445f2 | 107 | //HTU21D sur l'I2C |
POTLESS_2 | 8:a750d531b381 | 108 | HTU21D temphumid(PB_9, PB_8); //Temp humid sensor || SDA, SCL |
POTLESS_2 | 9:04bfdfc029cb | 109 | float Temp2; |
POTLESS_2 | 9:04bfdfc029cb | 110 | int Humid; |
POTLESS_2 | 9:04bfdfc029cb | 111 | |
POTLESS_2 | 9:04bfdfc029cb | 112 | //Data LOG |
POTLESS_2 | 9:04bfdfc029cb | 113 | char to_store[50]; |
POTLESS_2 | 9:04bfdfc029cb | 114 | time_t seconds; |
POTLESS_2 | 25:322ef9488e65 | 115 | char Log_File_Name[] = " "; |
POTLESS_2 | 42:3591ec9903b4 | 116 | int count = 0; |
POTLESS_2 | 42:3591ec9903b4 | 117 | int Max_Log_Size = 1800;//1 heure, 1800 lignes donc à multiplier par la fréquence d'enregistrement, Ref_Time, pour voir combien de temps représente un Log... |
POTLESS_2 | 8:a750d531b381 | 118 | |
POTLESS_2 | 10:aca745a66d51 | 119 | //Contrôle des servos |
POTLESS_2 | 56:61b0f4d6a890 | 120 | float Consigne_poumon = HOME_SERVO_POUMON; |
POTLESS_2 | 56:61b0f4d6a890 | 121 | float volet_poumon_Position; |
POTLESS_2 | 62:891379d80b1b | 122 | |
POTLESS_2 | 56:61b0f4d6a890 | 123 | float Consigne_fuite = HOME_SERVO_FUITE; |
POTLESS_2 | 56:61b0f4d6a890 | 124 | float volet_fuite_Position; |
POTLESS_2 | 62:891379d80b1b | 125 | |
potless | 45:61ba3cc4fc55 | 126 | float Volets_Speed = 1; |
POTLESS_2 | 62:891379d80b1b | 127 | float Volet_DeadBand = 5; |
POTLESS_2 | 10:aca745a66d51 | 128 | |
POTLESS_2 | 12:7f3aadd79f89 | 129 | //Paramètre du PID |
POTLESS_2 | 12:7f3aadd79f89 | 130 | float Kc = 40; |
POTLESS_2 | 12:7f3aadd79f89 | 131 | float Ti = 0; |
POTLESS_2 | 12:7f3aadd79f89 | 132 | float Td = 0; |
POTLESS_2 | 12:7f3aadd79f89 | 133 | float RATE_PID = Ref_Time; |
POTLESS_2 | 12:7f3aadd79f89 | 134 | float Commande_PID; |
POTLESS_2 | 43:5ae8baf28e32 | 135 | int consigne = 210; |
POTLESS_2 | 15:efd3b3bf3f37 | 136 | float Max_Input = 1000; |
POTLESS_2 | 15:efd3b3bf3f37 | 137 | float Min_Input = 80; |
POTLESS_2 | 19:cac3761a5d0b | 138 | float Max_Output = 85;//Vérifier la valeur pour angle à laisser ouvert... |
POTLESS_2 | 19:cac3761a5d0b | 139 | float Min_Output = 5; |
POTLESS_2 | 10:aca745a66d51 | 140 | |
POTLESS_2 | 12:7f3aadd79f89 | 141 | //Init PID |
POTLESS_2 | 17:bef8abc445f2 | 142 | PID control_Servo(Kc, Ti, Td, RATE_PID); |
POTLESS_2 | 10:aca745a66d51 | 143 | |
POTLESS_2 | 19:cac3761a5d0b | 144 | //Boolean du status de l'appareil, en mode SECU ou nominal |
POTLESS_2 | 19:cac3761a5d0b | 145 | bool EN_MODE_SECU = false; |
POTLESS_2 | 31:231a96d1d1c8 | 146 | |
POTLESS_2 | 43:5ae8baf28e32 | 147 | //Test voltage piles |
POTLESS_2 | 43:5ae8baf28e32 | 148 | AnalogIn V_PILES_ANALOG(PIN_V_PILES_ANALOG); |
POTLESS_2 | 31:231a96d1d1c8 | 149 | |
POTLESS_2 | 31:231a96d1d1c8 | 150 | int Vusb = 1; |
POTLESS_2 | 31:231a96d1d1c8 | 151 | int VPiles = 1; |
POTLESS_2 | 43:5ae8baf28e32 | 152 | float VPiles_val = 1; |
POTLESS_2 | 18:bfd78c05b589 | 153 | |
POTLESS_2 | 58:694d4d00407c | 154 | bool flag_USB = false; |
POTLESS_2 | 59:fd64ca9dae27 | 155 | bool flag_Piles = false; |
POTLESS_2 | 58:694d4d00407c | 156 | |
POTLESS_2 | 56:61b0f4d6a890 | 157 | //Commande à envoyer à l'IHM |
POTLESS_2 | 56:61b0f4d6a890 | 158 | //0 -> Marche |
POTLESS_2 | 56:61b0f4d6a890 | 159 | //1 -> Au dodo |
POTLESS_2 | 56:61b0f4d6a890 | 160 | //3 -> Big problème |
POTLESS_2 | 56:61b0f4d6a890 | 161 | int Commande_IHM = 0; |
potless | 48:9ceb095f397a | 162 | |
POTLESS_2 | 43:5ae8baf28e32 | 163 | //Interruption pin |
POTLESS_2 | 59:fd64ca9dae27 | 164 | InterruptIn vpiles_off_on(PIN_V_PILES_DIGI); |
POTLESS_2 | 43:5ae8baf28e32 | 165 | InterruptIn vusb_off_on(PIN_V_USB_DIGI); |
POTLESS_2 | 21:b8900130ca05 | 166 | |
POTLESS_2 | 57:a0827fa46b03 | 167 | //Pin enable du régulateur 5 v |
POTLESS_2 | 57:a0827fa46b03 | 168 | DigitalOut E5V(PA_4); |
POTLESS_2 | 57:a0827fa46b03 | 169 | |
POTLESS_2 | 57:a0827fa46b03 | 170 | //Pin enable du régulateur 3.3 v |
POTLESS_2 | 58:694d4d00407c | 171 | DigitalOut E3V(PB_11, PullDown); |
POTLESS_2 | 57:a0827fa46b03 | 172 | |
POTLESS_2 | 57:a0827fa46b03 | 173 | //Pin du Buzzer |
POTLESS_2 | 57:a0827fa46b03 | 174 | Beep buzzer(PC_8); |
POTLESS_2 | 57:a0827fa46b03 | 175 | |
POTLESS_2 | 58:694d4d00407c | 176 | //Déclaration des Threads |
POTLESS_2 | 62:891379d80b1b | 177 | Thread thread_Secu; |
POTLESS_2 | 62:891379d80b1b | 178 | Thread thread_Head; |
POTLESS_2 | 62:891379d80b1b | 179 | Thread thread_Volets_POUMON; |
POTLESS_2 | 62:891379d80b1b | 180 | Thread thread_Volets_FUITE; |
POTLESS_2 | 47:89a088bc8866 | 181 | |
potless | 60:e2922f9e309c | 182 | void sleepDemande() |
POTLESS_2 | 56:61b0f4d6a890 | 183 | { |
potless | 60:e2922f9e309c | 184 | buzzer.beep(1000,0.1); |
potless | 60:e2922f9e309c | 185 | wait_ms(100); |
potless | 60:e2922f9e309c | 186 | buzzer.beep(1000,0.1); |
potless | 60:e2922f9e309c | 187 | wait_ms(100); |
potless | 60:e2922f9e309c | 188 | buzzer.beep(1000,0.1); |
potless | 60:e2922f9e309c | 189 | wait_ms(100); |
potless | 60:e2922f9e309c | 190 | buzzer.beep(1000,0.1); |
potless | 60:e2922f9e309c | 191 | wait(1); |
potless | 60:e2922f9e309c | 192 | |
potless | 60:e2922f9e309c | 193 | Commande_IHM = 1; |
potless | 60:e2922f9e309c | 194 | IHM("<0 0 ;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;%d>\r\n", Commande_IHM); |
potless | 60:e2922f9e309c | 195 | FLAG_DISPLAY = false; |
potless | 60:e2922f9e309c | 196 | Commande_IHM = 0; |
POTLESS_2 | 62:891379d80b1b | 197 | |
potless | 60:e2922f9e309c | 198 | // mise à zero UART IHM pour éviter son redémarrage intempestif (le tx suffirait) |
potless | 60:e2922f9e309c | 199 | HAL_PWREx_EnableGPIOPullDown(PWR_GPIO_C, PWR_GPIO_BIT_4); |
potless | 60:e2922f9e309c | 200 | HAL_PWREx_EnableGPIOPullDown(PWR_GPIO_C, PWR_GPIO_BIT_5); |
POTLESS_2 | 59:fd64ca9dae27 | 201 | |
POTLESS_2 | 57:a0827fa46b03 | 202 | E5V = 0; |
POTLESS_2 | 62:891379d80b1b | 203 | |
potless | 60:e2922f9e309c | 204 | UTILS::EffacePage(2, 29, 1); |
potless | 60:e2922f9e309c | 205 | UTILS::Write(DFU_ADDR, 0xBABEFACE); |
POTLESS_2 | 59:fd64ca9dae27 | 206 | |
POTLESS_2 | 59:fd64ca9dae27 | 207 | //Mise en veille |
POTLESS_2 | 59:fd64ca9dae27 | 208 | HAL_PWREx_EnablePullUpPullDownConfig() ; |
POTLESS_2 | 59:fd64ca9dae27 | 209 | HAL_PWREx_EnableGPIOPullDown(PWR_GPIO_A, PWR_GPIO_BIT_0); |
potless | 60:e2922f9e309c | 210 | HAL_PWR_DisableWakeUpPin(PWR_WAKEUP_PIN1_LOW); // pour PA_0 |
POTLESS_2 | 59:fd64ca9dae27 | 211 | // Clear wake up Flag |
POTLESS_2 | 59:fd64ca9dae27 | 212 | __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WUF1); |
POTLESS_2 | 59:fd64ca9dae27 | 213 | // Enable wakeup pin WKUP2 |
potless | 60:e2922f9e309c | 214 | HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN1_LOW); // high est la valeur par défaut |
POTLESS_2 | 59:fd64ca9dae27 | 215 | // Set RTC back-up register RTC_BKP31R to indicate |
POTLESS_2 | 59:fd64ca9dae27 | 216 | //later on that system has entered shutdown mode |
POTLESS_2 | 59:fd64ca9dae27 | 217 | WRITE_REG( RTC->BKP31R, 0x1 ); |
potless | 60:e2922f9e309c | 218 | |
POTLESS_2 | 59:fd64ca9dae27 | 219 | //Enter shutdown mode |
POTLESS_2 | 59:fd64ca9dae27 | 220 | HAL_PWREx_EnterSHUTDOWNMode(); |
POTLESS_2 | 56:61b0f4d6a890 | 221 | } |
POTLESS_2 | 58:694d4d00407c | 222 | |
potless | 60:e2922f9e309c | 223 | // gestion du cas où le sleep est demandé volontairement |
potless | 60:e2922f9e309c | 224 | // et où l'utilisateur coupe ensuite l'alimentation en débranchant ou interrupteur sur off |
potless | 60:e2922f9e309c | 225 | // on refait un shutdown mais avec un wake up sur le branchement du cable + interrupteur sur ON |
potless | 60:e2922f9e309c | 226 | void flagSleep(){ |
potless | 60:e2922f9e309c | 227 | |
potless | 60:e2922f9e309c | 228 | if ((int) UTILS::Read(DFU_ADDR) == 0xBABEFACE ) { |
POTLESS_2 | 62:891379d80b1b | 229 | DEBUG(" Re démarrage BABEFACE.\n"); |
POTLESS_2 | 62:891379d80b1b | 230 | /* |
potless | 60:e2922f9e309c | 231 | Commande_IHM = 1; |
potless | 60:e2922f9e309c | 232 | IHM("<0 0 ;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;%d>\r\n", Commande_IHM); |
potless | 60:e2922f9e309c | 233 | FLAG_DISPLAY = false; |
potless | 60:e2922f9e309c | 234 | Commande_IHM = 0; |
potless | 60:e2922f9e309c | 235 | |
potless | 60:e2922f9e309c | 236 | HAL_PWREx_EnableGPIOPullDown(PWR_GPIO_C, PWR_GPIO_BIT_4); |
potless | 60:e2922f9e309c | 237 | HAL_PWREx_EnableGPIOPullDown(PWR_GPIO_C, PWR_GPIO_BIT_5); |
POTLESS_2 | 62:891379d80b1b | 238 | |
potless | 60:e2922f9e309c | 239 | buzzer.beep(1000,0.1); |
potless | 60:e2922f9e309c | 240 | wait_ms(100); |
potless | 60:e2922f9e309c | 241 | buzzer.beep(1000,0.1); |
potless | 60:e2922f9e309c | 242 | wait(1); |
POTLESS_2 | 62:891379d80b1b | 243 | */ |
POTLESS_2 | 62:891379d80b1b | 244 | |
POTLESS_2 | 62:891379d80b1b | 245 | E5V = 0; |
POTLESS_2 | 62:891379d80b1b | 246 | |
potless | 60:e2922f9e309c | 247 | UTILS::EffacePage(2, 29, 1); |
POTLESS_2 | 62:891379d80b1b | 248 | |
potless | 60:e2922f9e309c | 249 | HAL_PWREx_EnablePullUpPullDownConfig() ; |
potless | 60:e2922f9e309c | 250 | HAL_PWREx_EnableGPIOPullDown(PWR_GPIO_A, PWR_GPIO_BIT_0); |
potless | 60:e2922f9e309c | 251 | HAL_PWR_DisableWakeUpPin(PWR_WAKEUP_PIN1); // pour PA_0 |
potless | 60:e2922f9e309c | 252 | // Clear wake up Flag |
potless | 60:e2922f9e309c | 253 | __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WUF1); |
potless | 60:e2922f9e309c | 254 | // Enable wakeup pin WKUP2 |
potless | 60:e2922f9e309c | 255 | HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN1); // high est la valeur par défaut |
potless | 60:e2922f9e309c | 256 | // Set RTC back-up register RTC_BKP31R to indicate |
potless | 60:e2922f9e309c | 257 | //later on that system has entered shutdown mode |
potless | 60:e2922f9e309c | 258 | WRITE_REG( RTC->BKP31R, 0x1 ); |
potless | 60:e2922f9e309c | 259 | |
potless | 60:e2922f9e309c | 260 | //Enter shutdown mode |
potless | 60:e2922f9e309c | 261 | E3V = 0; |
potless | 60:e2922f9e309c | 262 | //HAL_PWREx_EnterSHUTDOWNMode(); |
potless | 60:e2922f9e309c | 263 | } |
potless | 60:e2922f9e309c | 264 | |
potless | 60:e2922f9e309c | 265 | } |
potless | 60:e2922f9e309c | 266 | |
potless | 60:e2922f9e309c | 267 | void USB_unplugged() |
POTLESS_2 | 56:61b0f4d6a890 | 268 | { |
POTLESS_2 | 56:61b0f4d6a890 | 269 | DEBUG(" La prise USB a été débranchée.\n"); |
POTLESS_2 | 59:fd64ca9dae27 | 270 | |
POTLESS_2 | 59:fd64ca9dae27 | 271 | buzzer.beep(1000,0.3); |
POTLESS_2 | 59:fd64ca9dae27 | 272 | wait_ms(500); |
POTLESS_2 | 59:fd64ca9dae27 | 273 | buzzer.beep(1000,0.3); |
POTLESS_2 | 62:891379d80b1b | 274 | |
POTLESS_2 | 59:fd64ca9dae27 | 275 | wait(1); |
POTLESS_2 | 59:fd64ca9dae27 | 276 | |
POTLESS_2 | 62:891379d80b1b | 277 | E5V = 0; |
POTLESS_2 | 62:891379d80b1b | 278 | |
POTLESS_2 | 56:61b0f4d6a890 | 279 | //Arrêt des enregistrements |
POTLESS_2 | 56:61b0f4d6a890 | 280 | FLAG_REC = false; |
POTLESS_2 | 58:694d4d00407c | 281 | |
POTLESS_2 | 59:fd64ca9dae27 | 282 | UTILS::UnMount_Flash(); |
POTLESS_2 | 59:fd64ca9dae27 | 283 | |
POTLESS_2 | 56:61b0f4d6a890 | 284 | //Enregistrement position des servos sans mettre en sécu |
POTLESS_2 | 58:694d4d00407c | 285 | UTILS::EffacePage(2, 31, 1); |
POTLESS_2 | 59:fd64ca9dae27 | 286 | |
POTLESS_2 | 58:694d4d00407c | 287 | uint64_t Pos_P = Servo_Poumon.getPulses(); |
POTLESS_2 | 58:694d4d00407c | 288 | UTILS::Write(VOLET_POUMON_ADDR, Pos_P); |
POTLESS_2 | 58:694d4d00407c | 289 | DEBUG(" position volet poumon sauvegardée = %d pulse(s)\r\n", (int) Pos_P); |
POTLESS_2 | 57:a0827fa46b03 | 290 | |
POTLESS_2 | 58:694d4d00407c | 291 | uint64_t Pos_F = Servo_Fuite.getPulses(); |
POTLESS_2 | 58:694d4d00407c | 292 | UTILS::Write(VOLET_FUITE_ADDR, Pos_F); |
POTLESS_2 | 58:694d4d00407c | 293 | DEBUG(" position volet fuite sauvegardée = %d pulse(s)\r\n", (int) Pos_F); |
POTLESS_2 | 59:fd64ca9dae27 | 294 | |
POTLESS_2 | 59:fd64ca9dae27 | 295 | //Mise en veille de l'IHM |
POTLESS_2 | 59:fd64ca9dae27 | 296 | Commande_IHM = 1; |
POTLESS_2 | 59:fd64ca9dae27 | 297 | IHM("<0 0 ;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;%d>\r\n", Commande_IHM); |
POTLESS_2 | 59:fd64ca9dae27 | 298 | FLAG_DISPLAY = false; |
POTLESS_2 | 59:fd64ca9dae27 | 299 | Commande_IHM = 0; |
potless | 60:e2922f9e309c | 300 | |
potless | 60:e2922f9e309c | 301 | // mise à zero UART IHM pour éviter son redémarrage intempestif (le tx suffirait) |
potless | 60:e2922f9e309c | 302 | HAL_PWREx_EnableGPIOPullDown(PWR_GPIO_C, PWR_GPIO_BIT_4); |
potless | 60:e2922f9e309c | 303 | HAL_PWREx_EnableGPIOPullDown(PWR_GPIO_C, PWR_GPIO_BIT_5); |
POTLESS_2 | 59:fd64ca9dae27 | 304 | |
potless | 60:e2922f9e309c | 305 | //Mise en veille version cable arraché |
POTLESS_2 | 59:fd64ca9dae27 | 306 | DEBUG(" Mise en veille...\r\n"); |
POTLESS_2 | 59:fd64ca9dae27 | 307 | //wait(1); |
POTLESS_2 | 62:891379d80b1b | 308 | //Mise en veille |
potless | 60:e2922f9e309c | 309 | HAL_PWREx_EnablePullUpPullDownConfig() ; |
potless | 60:e2922f9e309c | 310 | HAL_PWREx_EnableGPIOPullDown(PWR_GPIO_A, PWR_GPIO_BIT_0); |
potless | 60:e2922f9e309c | 311 | HAL_PWR_DisableWakeUpPin(PWR_WAKEUP_PIN1); // pour PA_0 |
potless | 60:e2922f9e309c | 312 | // Clear wake up Flag |
potless | 60:e2922f9e309c | 313 | __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WUF1); |
potless | 60:e2922f9e309c | 314 | // Enable wakeup pin WKUP2 |
potless | 60:e2922f9e309c | 315 | HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN1); // high est la valeur par défaut |
potless | 60:e2922f9e309c | 316 | // Set RTC back-up register RTC_BKP31R to indicate |
potless | 60:e2922f9e309c | 317 | //later on that system has entered shutdown mode |
potless | 60:e2922f9e309c | 318 | WRITE_REG( RTC->BKP31R, 0x1 ); |
potless | 60:e2922f9e309c | 319 | |
potless | 60:e2922f9e309c | 320 | //Enter shutdown mode |
potless | 60:e2922f9e309c | 321 | HAL_PWREx_EnterSHUTDOWNMode(); |
POTLESS_2 | 56:61b0f4d6a890 | 322 | } |
POTLESS_2 | 58:694d4d00407c | 323 | |
POTLESS_2 | 59:fd64ca9dae27 | 324 | void PILES_unpluged() |
POTLESS_2 | 52:4e36a88711d6 | 325 | { |
POTLESS_2 | 59:fd64ca9dae27 | 326 | DEBUG(" Les piles ont été débranchées.\n"); |
POTLESS_2 | 59:fd64ca9dae27 | 327 | |
POTLESS_2 | 59:fd64ca9dae27 | 328 | buzzer.beep(1000,0.3); |
POTLESS_2 | 59:fd64ca9dae27 | 329 | wait_ms(500); |
POTLESS_2 | 59:fd64ca9dae27 | 330 | buzzer.beep(1000,0.3); |
potless | 54:2062e5786a66 | 331 | wait(1); |
POTLESS_2 | 59:fd64ca9dae27 | 332 | |
POTLESS_2 | 59:fd64ca9dae27 | 333 | //Arrêt des enregistrements |
POTLESS_2 | 59:fd64ca9dae27 | 334 | FLAG_REC = false; |
POTLESS_2 | 59:fd64ca9dae27 | 335 | |
POTLESS_2 | 59:fd64ca9dae27 | 336 | UTILS::UnMount_Flash(); |
POTLESS_2 | 59:fd64ca9dae27 | 337 | |
POTLESS_2 | 59:fd64ca9dae27 | 338 | //Enregistrement position des servos sans mettre en sécu |
POTLESS_2 | 59:fd64ca9dae27 | 339 | UTILS::EffacePage(2, 31, 1); |
POTLESS_2 | 59:fd64ca9dae27 | 340 | |
POTLESS_2 | 59:fd64ca9dae27 | 341 | uint64_t Pos_P = Servo_Poumon.getPulses(); |
POTLESS_2 | 59:fd64ca9dae27 | 342 | UTILS::Write(VOLET_POUMON_ADDR, Pos_P); |
POTLESS_2 | 59:fd64ca9dae27 | 343 | DEBUG(" position volet poumon sauvegardée = %d pulse(s)\r\n", (int) Pos_P); |
POTLESS_2 | 52:4e36a88711d6 | 344 | |
POTLESS_2 | 59:fd64ca9dae27 | 345 | uint64_t Pos_F = Servo_Fuite.getPulses(); |
POTLESS_2 | 59:fd64ca9dae27 | 346 | UTILS::Write(VOLET_FUITE_ADDR, Pos_F); |
POTLESS_2 | 59:fd64ca9dae27 | 347 | DEBUG(" position volet fuite sauvegardée = %d pulse(s)\r\n", (int) Pos_F); |
POTLESS_2 | 59:fd64ca9dae27 | 348 | |
POTLESS_2 | 59:fd64ca9dae27 | 349 | //Mise en veille de l'IHM |
POTLESS_2 | 59:fd64ca9dae27 | 350 | Commande_IHM = 1; |
POTLESS_2 | 59:fd64ca9dae27 | 351 | IHM("<0 0 ;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;%d>\r\n", Commande_IHM); |
POTLESS_2 | 59:fd64ca9dae27 | 352 | FLAG_DISPLAY = false; |
POTLESS_2 | 59:fd64ca9dae27 | 353 | Commande_IHM = 0; |
POTLESS_2 | 59:fd64ca9dae27 | 354 | |
POTLESS_2 | 59:fd64ca9dae27 | 355 | //Mise en veille |
POTLESS_2 | 59:fd64ca9dae27 | 356 | DEBUG(" Mise en veille...\r\n"); |
POTLESS_2 | 59:fd64ca9dae27 | 357 | //wait(1); |
potless | 60:e2922f9e309c | 358 | sleepDemande(); |
POTLESS_2 | 52:4e36a88711d6 | 359 | } |
POTLESS_2 | 47:89a088bc8866 | 360 | |
POTLESS_2 | 29:5b822d18bce6 | 361 | void Affichage() |
POTLESS_2 | 53:84571a5e2cda | 362 | { |
POTLESS_2 | 42:3591ec9903b4 | 363 | //serialMonit.printf("\r\n"); |
POTLESS_2 | 29:5b822d18bce6 | 364 | serialMonit.printf(" CO2 = %d ppm\r\n" , co2); |
POTLESS_2 | 29:5b822d18bce6 | 365 | serialMonit.printf(" PPO2 = %d mb\r\n", ppO2); |
POTLESS_2 | 31:231a96d1d1c8 | 366 | serialMonit.printf(" OTU = %d \r\n", (int)OTU); |
POTLESS_2 | 29:5b822d18bce6 | 367 | serialMonit.printf(" Pression = %f msw\r\n", pression); |
POTLESS_2 | 29:5b822d18bce6 | 368 | serialMonit.printf(" Temp MS5837 = %f C\r\n", Temp1); |
POTLESS_2 | 29:5b822d18bce6 | 369 | serialMonit.printf(" Temp HTU21D = %f C\n\r", Temp2); |
POTLESS_2 | 29:5b822d18bce6 | 370 | serialMonit.printf(" Humidity = %d %%\n\r", Humid); |
POTLESS_2 | 42:3591ec9903b4 | 371 | //serialMonit.printf("\n\r"); |
POTLESS_2 | 29:5b822d18bce6 | 372 | serialMonit.printf(" Cell O2 n 1 = %d\r\n" , CellO2_1); |
POTLESS_2 | 29:5b822d18bce6 | 373 | serialMonit.printf(" Cell O2 n 2 = %d\r\n" , CellO2_2); |
POTLESS_2 | 42:3591ec9903b4 | 374 | //serialMonit.printf("\r\n"); |
POTLESS_2 | 29:5b822d18bce6 | 375 | serialMonit.printf(" Volet Poumon = %f\r\n" , volet_poumon_Position); |
POTLESS_2 | 29:5b822d18bce6 | 376 | serialMonit.printf(" Volet Fuite = %f\r\n" , volet_fuite_Position); |
POTLESS_2 | 42:3591ec9903b4 | 377 | //serialMonit.printf("\r\n"); |
POTLESS_2 | 42:3591ec9903b4 | 378 | serialMonit.printf(" Temps d execution de la boucle = %f seconde(s)\r\n", (RATE + RATE_TRUE / 1000)); |
POTLESS_2 | 42:3591ec9903b4 | 379 | //serialMonit.printf("\r\n"); |
POTLESS_2 | 42:3591ec9903b4 | 380 | if (FLAG_REC) serialMonit.printf(" Chaine enregistrée = %s\r\n", to_store); |
POTLESS_2 | 30:7a16a66d76f3 | 381 | else serialMonit.printf(" Pas d'enregistrement en cours."); |
POTLESS_2 | 42:3591ec9903b4 | 382 | //serialMonit.printf("\r\n"); |
POTLESS_2 | 42:3591ec9903b4 | 383 | serialMonit.printf(" V_USB = %f\r\n", Vusb); |
POTLESS_2 | 42:3591ec9903b4 | 384 | //serialMonit.printf("\r\n\r\n"); |
POTLESS_2 | 29:5b822d18bce6 | 385 | fflush(stdout); |
POTLESS_2 | 29:5b822d18bce6 | 386 | } |
POTLESS_2 | 29:5b822d18bce6 | 387 | |
potless | 38:fe77b68eec37 | 388 | |
POTLESS_2 | 19:cac3761a5d0b | 389 | //Passage en mode SECU |
POTLESS_2 | 19:cac3761a5d0b | 390 | void Mode_SECU() |
POTLESS_2 | 18:bfd78c05b589 | 391 | { |
POTLESS_2 | 43:5ae8baf28e32 | 392 | |
POTLESS_2 | 18:bfd78c05b589 | 393 | //Mise du PID en mode manuel (desactivation...) |
POTLESS_2 | 62:891379d80b1b | 394 | //control_Servo.setMode(MANUAL_MODE); |
POTLESS_2 | 62:891379d80b1b | 395 | FLAG_PID = 0; |
POTLESS_2 | 43:5ae8baf28e32 | 396 | |
POTLESS_2 | 19:cac3761a5d0b | 397 | Consigne_poumon = HOME_SERVO_POUMON; |
POTLESS_2 | 19:cac3761a5d0b | 398 | Consigne_fuite = HOME_SERVO_FUITE; |
POTLESS_2 | 34:26f6e3dbefb9 | 399 | |
POTLESS_2 | 57:a0827fa46b03 | 400 | Volets_Speed = 1; |
POTLESS_2 | 25:322ef9488e65 | 401 | Volet_DeadBand = 10; |
POTLESS_2 | 25:322ef9488e65 | 402 | |
POTLESS_2 | 58:694d4d00407c | 403 | while(1) { |
POTLESS_2 | 58:694d4d00407c | 404 | wait_ms(100); |
POTLESS_2 | 58:694d4d00407c | 405 | if (Servo_Poumon.Pos_OK() == true && Servo_Fuite.Pos_OK() == true) break; |
POTLESS_2 | 58:694d4d00407c | 406 | } |
POTLESS_2 | 62:891379d80b1b | 407 | |
POTLESS_2 | 62:891379d80b1b | 408 | |
POTLESS_2 | 43:5ae8baf28e32 | 409 | OUTPUT(" Appareil en mode SECU\r\n"); |
POTLESS_2 | 34:26f6e3dbefb9 | 410 | |
POTLESS_2 | 25:322ef9488e65 | 411 | wait_ms(100); |
POTLESS_2 | 34:26f6e3dbefb9 | 412 | |
POTLESS_2 | 19:cac3761a5d0b | 413 | EN_MODE_SECU = true; |
POTLESS_2 | 43:5ae8baf28e32 | 414 | |
POTLESS_2 | 25:322ef9488e65 | 415 | wait_ms(100); |
POTLESS_2 | 58:694d4d00407c | 416 | |
POTLESS_2 | 58:694d4d00407c | 417 | UTILS::EffacePage(2, 31, 1); |
POTLESS_2 | 58:694d4d00407c | 418 | //Enregistrement position des servos en sécu pour plus de précision |
POTLESS_2 | 58:694d4d00407c | 419 | uint64_t Pos_P = Servo_Poumon.getPulses(); |
POTLESS_2 | 58:694d4d00407c | 420 | UTILS::Write(VOLET_POUMON_ADDR, Pos_P); |
POTLESS_2 | 58:694d4d00407c | 421 | DEBUG(" position volet poumon sauvegardée = %d pulse(s)\r\n", (int) Pos_P); |
POTLESS_2 | 58:694d4d00407c | 422 | OUTPUT(" Volet poumon en sécu\r\n"); |
POTLESS_2 | 58:694d4d00407c | 423 | |
POTLESS_2 | 58:694d4d00407c | 424 | uint64_t Pos_F = Servo_Fuite.getPulses(); |
POTLESS_2 | 58:694d4d00407c | 425 | UTILS::Write(VOLET_FUITE_ADDR, Pos_F); |
POTLESS_2 | 58:694d4d00407c | 426 | DEBUG(" position volet fuite sauvegardée = %d pulse(s)\r\n",(int) Pos_F); |
POTLESS_2 | 58:694d4d00407c | 427 | OUTPUT(" Volet fuite en sécu\r\n"); |
POTLESS_2 | 53:84571a5e2cda | 428 | |
POTLESS_2 | 23:7477dc855fad | 429 | Servo_Poumon.Sleep(); |
POTLESS_2 | 43:5ae8baf28e32 | 430 | Servo_Fuite.Sleep(); |
POTLESS_2 | 19:cac3761a5d0b | 431 | } |
POTLESS_2 | 19:cac3761a5d0b | 432 | |
POTLESS_2 | 19:cac3761a5d0b | 433 | //Sequence d'arrêt |
POTLESS_2 | 19:cac3761a5d0b | 434 | void Stop_Sequence() |
POTLESS_2 | 34:26f6e3dbefb9 | 435 | { |
POTLESS_2 | 43:5ae8baf28e32 | 436 | OUTPUT(" Mise en veille de l'appareil.\r\n"); |
POTLESS_2 | 43:5ae8baf28e32 | 437 | |
POTLESS_2 | 43:5ae8baf28e32 | 438 | wait(1); |
POTLESS_2 | 43:5ae8baf28e32 | 439 | |
POTLESS_2 | 34:26f6e3dbefb9 | 440 | Mode_SECU(); |
POTLESS_2 | 53:84571a5e2cda | 441 | |
POTLESS_2 | 47:89a088bc8866 | 442 | wait(1); |
POTLESS_2 | 58:694d4d00407c | 443 | |
POTLESS_2 | 39:65ff3c4f9675 | 444 | //ejection de la flash pour pas crasher le system de fichiers |
POTLESS_2 | 39:65ff3c4f9675 | 445 | UTILS::UnMount_Flash(); |
POTLESS_2 | 53:84571a5e2cda | 446 | |
POTLESS_2 | 47:89a088bc8866 | 447 | OUTPUT(" Ejection de la Flash\r\n"); |
POTLESS_2 | 56:61b0f4d6a890 | 448 | |
POTLESS_2 | 47:89a088bc8866 | 449 | wait(1); |
POTLESS_2 | 58:694d4d00407c | 450 | |
potless | 60:e2922f9e309c | 451 | sleepDemande(); |
POTLESS_2 | 18:bfd78c05b589 | 452 | } |
POTLESS_2 | 18:bfd78c05b589 | 453 | |
POTLESS_2 | 31:231a96d1d1c8 | 454 | //Fonction test de valeur d'entrée digitale |
POTLESS_2 | 29:5b822d18bce6 | 455 | int Power_Test(DigitalIn& pin) |
POTLESS_2 | 20:5f79fb4565a7 | 456 | { |
POTLESS_2 | 29:5b822d18bce6 | 457 | pin.mode(PullDown); |
POTLESS_2 | 34:26f6e3dbefb9 | 458 | |
POTLESS_2 | 34:26f6e3dbefb9 | 459 | if(!pin) { |
POTLESS_2 | 34:26f6e3dbefb9 | 460 | Stop_Sequence(); |
POTLESS_2 | 34:26f6e3dbefb9 | 461 | return 0; |
POTLESS_2 | 34:26f6e3dbefb9 | 462 | } else { |
POTLESS_2 | 34:26f6e3dbefb9 | 463 | return 1; |
POTLESS_2 | 34:26f6e3dbefb9 | 464 | } |
POTLESS_2 | 20:5f79fb4565a7 | 465 | } |
POTLESS_2 | 20:5f79fb4565a7 | 466 | |
POTLESS_2 | 31:231a96d1d1c8 | 467 | //Fonction test de valeur d'entrée analogique |
POTLESS_2 | 31:231a96d1d1c8 | 468 | float Power_Test(AnalogIn& pin) |
POTLESS_2 | 31:231a96d1d1c8 | 469 | { |
POTLESS_2 | 31:231a96d1d1c8 | 470 | float Val = pin.read(); |
POTLESS_2 | 31:231a96d1d1c8 | 471 | return Val; |
POTLESS_2 | 31:231a96d1d1c8 | 472 | } |
POTLESS_2 | 31:231a96d1d1c8 | 473 | |
POTLESS_2 | 18:bfd78c05b589 | 474 | //Contrôle du status de l'appareil / des constantes |
POTLESS_2 | 18:bfd78c05b589 | 475 | bool Check() |
POTLESS_2 | 18:bfd78c05b589 | 476 | { |
POTLESS_2 | 18:bfd78c05b589 | 477 | if (ppO2 > 100) |
POTLESS_2 | 19:cac3761a5d0b | 478 | return true;//Situation OK |
POTLESS_2 | 18:bfd78c05b589 | 479 | else |
POTLESS_2 | 19:cac3761a5d0b | 480 | return false;//Situation dégradée |
POTLESS_2 | 18:bfd78c05b589 | 481 | } |
POTLESS_2 | 18:bfd78c05b589 | 482 | |
POTLESS_2 | 18:bfd78c05b589 | 483 | //Calcul des OTU |
POTLESS_2 | 58:694d4d00407c | 484 | void Calcul_OTU() |
POTLESS_2 | 18:bfd78c05b589 | 485 | { |
POTLESS_2 | 18:bfd78c05b589 | 486 | /* |
POTLESS_2 | 18:bfd78c05b589 | 487 | La formule suivante permet de calculer la quantité d' OTU accumulée |
POTLESS_2 | 18:bfd78c05b589 | 488 | OTU = T * (2* PpO2 -1)0,83 |
POTLESS_2 | 18:bfd78c05b589 | 489 | avec : |
POTLESS_2 | 18:bfd78c05b589 | 490 | T = temps de plongée en minutes |
POTLESS_2 | 18:bfd78c05b589 | 491 | PpO2 = pression partielle d’ oxygène en bars |
POTLESS_2 | 18:bfd78c05b589 | 492 | */ |
POTLESS_2 | 18:bfd78c05b589 | 493 | |
POTLESS_2 | 19:cac3761a5d0b | 494 | if (ppO2 > 500) { |
POTLESS_2 | 18:bfd78c05b589 | 495 | float val = (2 * (float)ppO2/1000 - 1);//je divise par 1000 car la PP est en mb... |
POTLESS_2 | 58:694d4d00407c | 496 | OTU += pow(val, EXP_OTU);//T = 1 car le ticker est executé toutes les 60 secondes, 1 minute.... |
POTLESS_2 | 19:cac3761a5d0b | 497 | } |
POTLESS_2 | 18:bfd78c05b589 | 498 | } |
POTLESS_2 | 10:aca745a66d51 | 499 | |
POTLESS_2 | 17:bef8abc445f2 | 500 | //Thread d'intérogation des capteurs, positions servo |
POTLESS_2 | 34:26f6e3dbefb9 | 501 | void SENSORS_thread() |
POTLESS_2 | 6:ebed9093d661 | 502 | { |
POTLESS_2 | 7:ad15c386e960 | 503 | while (true) { |
POTLESS_2 | 36:1f5e2247b073 | 504 | //DEEP_DEBUG(" SENSORS_thread\r\n"); |
POTLESS_2 | 7:ad15c386e960 | 505 | |
POTLESS_2 | 7:ad15c386e960 | 506 | //CO2 sur Cozir |
POTLESS_2 | 7:ad15c386e960 | 507 | co2 = sensors.requestCO2(); |
POTLESS_2 | 7:ad15c386e960 | 508 | //P / T sur MS5837 |
POTLESS_2 | 7:ad15c386e960 | 509 | pression = sensors.requestPress(); |
POTLESS_2 | 9:04bfdfc029cb | 510 | Temp1 = sensors.requestTemp(); |
POTLESS_2 | 7:ad15c386e960 | 511 | //PPO2 sur ADS1015 |
POTLESS_2 | 33:f5d4bae05f16 | 512 | if (FLAG_O2) ppO2 = sensors.requestPpO2(); |
POTLESS_2 | 7:ad15c386e960 | 513 | //Cell O2 en mV |
POTLESS_2 | 33:f5d4bae05f16 | 514 | if (FLAG_O2) CellO2_1 = sensors.requestCellO2_1(); |
POTLESS_2 | 33:f5d4bae05f16 | 515 | if (FLAG_O2) CellO2_2 = sensors.requestCellO2_2(); |
POTLESS_2 | 9:04bfdfc029cb | 516 | |
POTLESS_2 | 8:a750d531b381 | 517 | //HTU21D |
POTLESS_2 | 9:04bfdfc029cb | 518 | Temp2 = temphumid.sample_ctemp(); |
POTLESS_2 | 9:04bfdfc029cb | 519 | Humid = temphumid.sample_humid(); |
POTLESS_2 | 9:04bfdfc029cb | 520 | |
POTLESS_2 | 10:aca745a66d51 | 521 | //Retour position des servos |
POTLESS_2 | 17:bef8abc445f2 | 522 | volet_poumon_Position = Servo_Poumon.Get_Position(); |
POTLESS_2 | 43:5ae8baf28e32 | 523 | volet_fuite_Position = Servo_Fuite.Get_Position(); |
POTLESS_2 | 43:5ae8baf28e32 | 524 | |
POTLESS_2 | 43:5ae8baf28e32 | 525 | //Calcul des OTU |
POTLESS_2 | 58:694d4d00407c | 526 | //Calcul_OTU(); |
POTLESS_2 | 34:26f6e3dbefb9 | 527 | |
POTLESS_2 | 19:cac3761a5d0b | 528 | } |
POTLESS_2 | 19:cac3761a5d0b | 529 | } |
POTLESS_2 | 12:7f3aadd79f89 | 530 | |
POTLESS_2 | 57:a0827fa46b03 | 531 | void GO_TO_thread_POUMON() |
POTLESS_2 | 19:cac3761a5d0b | 532 | { |
POTLESS_2 | 19:cac3761a5d0b | 533 | while (true) { |
POTLESS_2 | 57:a0827fa46b03 | 534 | //DEEP_DEBUG(" GO_TO_Thread_POUMON\r\n"); |
POTLESS_2 | 62:891379d80b1b | 535 | |
POTLESS_2 | 19:cac3761a5d0b | 536 | //Servo_Poumon.Go_To_Prop(Consigne_poumon); |
POTLESS_2 | 62:891379d80b1b | 537 | //Servo_Poumon.Go_To_PID(Consigne_poumon, Volet_DeadBand);//Nécessite de déclarer un dernier terme true dans l'init du moteur |
POTLESS_2 | 34:26f6e3dbefb9 | 538 | Servo_Poumon.Go_To(Consigne_poumon, Volets_Speed, Volet_DeadBand); |
POTLESS_2 | 62:891379d80b1b | 539 | |
POTLESS_2 | 57:a0827fa46b03 | 540 | } |
POTLESS_2 | 57:a0827fa46b03 | 541 | } |
POTLESS_2 | 57:a0827fa46b03 | 542 | |
POTLESS_2 | 57:a0827fa46b03 | 543 | void GO_TO_thread_FUITE() |
POTLESS_2 | 57:a0827fa46b03 | 544 | { |
POTLESS_2 | 57:a0827fa46b03 | 545 | while (true) { |
POTLESS_2 | 57:a0827fa46b03 | 546 | //DEEP_DEBUG(" GO_TO_Thread_FUITE\r\n"); |
POTLESS_2 | 34:26f6e3dbefb9 | 547 | |
POTLESS_2 | 19:cac3761a5d0b | 548 | //Servo_Fuite.Go_To_Prop(Consigne_fuite); |
POTLESS_2 | 43:5ae8baf28e32 | 549 | //Servo_Fuite.Go_To_PID(Consigne_fuite, Volet_DeadBand); |
POTLESS_2 | 57:a0827fa46b03 | 550 | Servo_Fuite.Go_To(Consigne_fuite, Volets_Speed, Volet_DeadBand); |
POTLESS_2 | 62:891379d80b1b | 551 | |
POTLESS_2 | 15:efd3b3bf3f37 | 552 | } |
potless | 2:4a8bf1d53439 | 553 | } |
POTLESS_2 | 4:d84250f67dec | 554 | |
POTLESS_2 | 20:5f79fb4565a7 | 555 | void SECU_thread() |
POTLESS_2 | 20:5f79fb4565a7 | 556 | { |
POTLESS_2 | 34:26f6e3dbefb9 | 557 | while (true) { |
POTLESS_2 | 58:694d4d00407c | 558 | //Mettre toutes les vérifs de sécu.... |
POTLESS_2 | 20:5f79fb4565a7 | 559 | } |
POTLESS_2 | 20:5f79fb4565a7 | 560 | } |
POTLESS_2 | 20:5f79fb4565a7 | 561 | |
POTLESS_2 | 57:a0827fa46b03 | 562 | //Callback de l'intérruption des envois de commandes depuis le terminal / WINDEV |
POTLESS_2 | 6:ebed9093d661 | 563 | void callbackParam() |
POTLESS_2 | 34:26f6e3dbefb9 | 564 | { |
POTLESS_2 | 40:32d89e04ead1 | 565 | |
POTLESS_2 | 34:26f6e3dbefb9 | 566 | while(serialMonit.readable()) { |
POTLESS_2 | 40:32d89e04ead1 | 567 | if ((indexParam == sizeParam) || newParamFlag == true) { //éviter la saturation du buffer |
POTLESS_2 | 29:5b822d18bce6 | 568 | char char_flush = serialMonit.getc(); |
POTLESS_2 | 40:32d89e04ead1 | 569 | } else { |
POTLESS_2 | 29:5b822d18bce6 | 570 | param [indexParam ++] = serialMonit.getc();//chargement du buffer dans le message |
POTLESS_2 | 40:32d89e04ead1 | 571 | if ((indexParam == sizeParam) || (param[indexParam - 1] == '\n')) {//le message est complet ou nouvelle ligne ou autre si on veut... |
POTLESS_2 | 40:32d89e04ead1 | 572 | param[indexParam] = 0; |
POTLESS_2 | 40:32d89e04ead1 | 573 | newParamFlag = true; |
POTLESS_2 | 40:32d89e04ead1 | 574 | } |
POTLESS_2 | 56:61b0f4d6a890 | 575 | } |
POTLESS_2 | 56:61b0f4d6a890 | 576 | } |
POTLESS_2 | 56:61b0f4d6a890 | 577 | } |
POTLESS_2 | 56:61b0f4d6a890 | 578 | |
POTLESS_2 | 56:61b0f4d6a890 | 579 | //Callback de l'intérruption des envois de commandes depuis l'IHM |
POTLESS_2 | 56:61b0f4d6a890 | 580 | void callbackIHM() |
POTLESS_2 | 56:61b0f4d6a890 | 581 | { |
POTLESS_2 | 56:61b0f4d6a890 | 582 | |
POTLESS_2 | 56:61b0f4d6a890 | 583 | while(display.readable()) { |
POTLESS_2 | 56:61b0f4d6a890 | 584 | if ((indexIHM == sizeIHM) || newIHMFlag == true) { //éviter la saturation du buffer |
POTLESS_2 | 58:694d4d00407c | 585 | NVIC_DisableIRQ(USART3_IRQn); |
POTLESS_2 | 56:61b0f4d6a890 | 586 | char char_flush = display.getc(); |
POTLESS_2 | 56:61b0f4d6a890 | 587 | NVIC_EnableIRQ(USART3_IRQn); |
POTLESS_2 | 56:61b0f4d6a890 | 588 | } else { |
POTLESS_2 | 56:61b0f4d6a890 | 589 | NVIC_DisableIRQ(USART3_IRQn); |
POTLESS_2 | 56:61b0f4d6a890 | 590 | IHM [indexIHM ++] = display.getc();//chargement du buffer dans le message |
POTLESS_2 | 56:61b0f4d6a890 | 591 | if ((indexIHM == sizeIHM) || (IHM[indexIHM - 1] == '\n')) {//le message est complet ou nouvelle ligne ou autre si on veut... |
POTLESS_2 | 56:61b0f4d6a890 | 592 | IHM[indexIHM] = 0; |
POTLESS_2 | 56:61b0f4d6a890 | 593 | newIHMFlag = true; |
POTLESS_2 | 56:61b0f4d6a890 | 594 | } |
POTLESS_2 | 56:61b0f4d6a890 | 595 | NVIC_EnableIRQ(USART3_IRQn); |
POTLESS_2 | 34:26f6e3dbefb9 | 596 | } |
POTLESS_2 | 34:26f6e3dbefb9 | 597 | } |
POTLESS_2 | 6:ebed9093d661 | 598 | } |
POTLESS_2 | 4:d84250f67dec | 599 | |
POTLESS_2 | 9:04bfdfc029cb | 600 | void Decoding_Message(char message []) |
POTLESS_2 | 9:04bfdfc029cb | 601 | { |
POTLESS_2 | 9:04bfdfc029cb | 602 | |
POTLESS_2 | 42:3591ec9903b4 | 603 | char com[20] = ""; |
POTLESS_2 | 42:3591ec9903b4 | 604 | char numb[30] = ""; |
POTLESS_2 | 36:1f5e2247b073 | 605 | |
POTLESS_2 | 34:26f6e3dbefb9 | 606 | sscanf(message,"%s %s",&com , &numb); |
POTLESS_2 | 36:1f5e2247b073 | 607 | |
POTLESS_2 | 56:61b0f4d6a890 | 608 | DEBUG("\r\n Commande = %s Valeur = %s \r\n\r\n", com, numb); |
POTLESS_2 | 36:1f5e2247b073 | 609 | |
POTLESS_2 | 43:5ae8baf28e32 | 610 | OUTPUT("?\r\n"); |
POTLESS_2 | 43:5ae8baf28e32 | 611 | |
POTLESS_2 | 30:7a16a66d76f3 | 612 | if (0 == strcmp(com, "secu")) { |
POTLESS_2 | 19:cac3761a5d0b | 613 | Mode_SECU(); |
POTLESS_2 | 42:3591ec9903b4 | 614 | } else if (0 == strcmp(com, "PING")) { |
POTLESS_2 | 56:61b0f4d6a890 | 615 | Commande_IHM = 1; |
POTLESS_2 | 56:61b0f4d6a890 | 616 | IHM("<0 0 ;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;%d>\r\n", Commande_IHM); |
POTLESS_2 | 57:a0827fa46b03 | 617 | FLAG_DISPLAY = false; |
POTLESS_2 | 59:fd64ca9dae27 | 618 | Commande_IHM = 0; |
POTLESS_2 | 34:26f6e3dbefb9 | 619 | } else if (0 == strcmp(com, "ARNSRS_ID")) { |
POTLESS_2 | 58:694d4d00407c | 620 | OUTPUT(" Changement de l'ID de l'appareil pour le N°: %s\r\n", numb); |
POTLESS_2 | 58:694d4d00407c | 621 | //UTILS::Store_A_Val(atoi(numb), "ARNSRS_ID"); |
POTLESS_2 | 58:694d4d00407c | 622 | UTILS::EffacePage(2, 30, 1); |
POTLESS_2 | 58:694d4d00407c | 623 | UTILS::Write(ID_ARNSRS_ADDR, (uint64_t) atoi(numb)); |
POTLESS_2 | 43:5ae8baf28e32 | 624 | } else if (0 == strcmp(com, "monit")) { |
POTLESS_2 | 43:5ae8baf28e32 | 625 | FLAG_AFF = false; |
POTLESS_2 | 43:5ae8baf28e32 | 626 | FLAG_WINDEV = true; |
POTLESS_2 | 43:5ae8baf28e32 | 627 | } else if (0 == strcmp(com, "debug")) { |
POTLESS_2 | 43:5ae8baf28e32 | 628 | FLAG_AFF = false; |
POTLESS_2 | 43:5ae8baf28e32 | 629 | FLAG_WINDEV = false; |
POTLESS_2 | 34:26f6e3dbefb9 | 630 | } else if (0 == strcmp(com, "Head_ID")) { |
POTLESS_2 | 34:26f6e3dbefb9 | 631 | //On l'enregistre dans l'eeprom |
POTLESS_2 | 43:5ae8baf28e32 | 632 | OUTPUT("Changement de l'ID de la tête capteur pour le N°: %s\r\n", numb); |
POTLESS_2 | 34:26f6e3dbefb9 | 633 | UTILS::write_EEPROM(numb, HEAD_ID); |
POTLESS_2 | 34:26f6e3dbefb9 | 634 | } else if (0 == strcmp(com, "O2_1_ID")) { |
POTLESS_2 | 34:26f6e3dbefb9 | 635 | //On l'enregistre dans l'eeprom |
POTLESS_2 | 34:26f6e3dbefb9 | 636 | UTILS::write_EEPROM(numb, CELL_O2_1_ID); |
POTLESS_2 | 34:26f6e3dbefb9 | 637 | } else if (0 == strcmp(com, "O2_2_ID")) { |
POTLESS_2 | 34:26f6e3dbefb9 | 638 | //On l'enregistre dans l'eeprom |
POTLESS_2 | 34:26f6e3dbefb9 | 639 | UTILS::write_EEPROM(numb, CELL_O2_2_ID); |
POTLESS_2 | 34:26f6e3dbefb9 | 640 | } else if (0 == strcmp(com, "CO2_ID")) { |
POTLESS_2 | 34:26f6e3dbefb9 | 641 | //On l'enregistre dans l'eeprom |
POTLESS_2 | 34:26f6e3dbefb9 | 642 | UTILS::write_EEPROM(numb, CO2_ID); |
POTLESS_2 | 34:26f6e3dbefb9 | 643 | } else if (0 == strcmp(com, "calib_O2")) { |
POTLESS_2 | 33:f5d4bae05f16 | 644 | FLAG_O2 = false; |
POTLESS_2 | 33:f5d4bae05f16 | 645 | wait_ms(100); |
POTLESS_2 | 42:3591ec9903b4 | 646 | float Val = sensors.Calibrate_O2(atoi(numb)); |
POTLESS_2 | 43:5ae8baf28e32 | 647 | OUTPUT(" Calibration O2 dans l'air = %f\r\n", Val); |
POTLESS_2 | 33:f5d4bae05f16 | 648 | wait_ms(100); |
POTLESS_2 | 33:f5d4bae05f16 | 649 | FLAG_O2 = true; |
POTLESS_2 | 41:51ba69648f9d | 650 | } else if (0 == strcmp(com, "calib_CO2_A")) { |
POTLESS_2 | 43:5ae8baf28e32 | 651 | int Val = sensors.Calibrate_CO2(); |
POTLESS_2 | 43:5ae8baf28e32 | 652 | OUTPUT(" Calibration CO2 dans l'air = %d\r\n", Val); |
POTLESS_2 | 34:26f6e3dbefb9 | 653 | } else if (0 == strcmp(com, "flash_i")) { |
POTLESS_2 | 42:3591ec9903b4 | 654 | UTILS::Flash_Infos(&serialMonit); |
POTLESS_2 | 36:1f5e2247b073 | 655 | } else if (0 == strcmp(com, "flash_u")) { |
POTLESS_2 | 43:5ae8baf28e32 | 656 | OUTPUT(" Démontage de la Flash.\r\n"); |
POTLESS_2 | 36:1f5e2247b073 | 657 | FLAG_REC = false; |
POTLESS_2 | 36:1f5e2247b073 | 658 | UTILS::UnMount_Flash(); |
POTLESS_2 | 36:1f5e2247b073 | 659 | } else if (0 == strcmp(com, "flash_m")) { |
POTLESS_2 | 43:5ae8baf28e32 | 660 | OUTPUT(" Montage de la Flash.\r\n"); |
POTLESS_2 | 40:32d89e04ead1 | 661 | UTILS::Mount_Flash(); |
POTLESS_2 | 35:a209a192f431 | 662 | } else if (0 == strcmp(com, "check_F")) { |
POTLESS_2 | 58:694d4d00407c | 663 | /* |
POTLESS_2 | 43:5ae8baf28e32 | 664 | OUTPUT(" ARNSRS_ID.sys = %d\r\n", (int)UTILS::Read_A_Val("ARNSRS_ID.sys")); |
POTLESS_2 | 43:5ae8baf28e32 | 665 | OUTPUT(" Servo_Poumon.sys = %d\r\n", (int)UTILS::Read_A_Val("Servo_Poumon.sys")); |
POTLESS_2 | 43:5ae8baf28e32 | 666 | OUTPUT(" Servo_Fuite.sys = %d\r\n", (int)UTILS::Read_A_Val("Servo_Fuite.sys")); |
POTLESS_2 | 58:694d4d00407c | 667 | */ |
POTLESS_2 | 58:694d4d00407c | 668 | OUTPUT(" ARNSRS ID = %d\r\n", (int) UTILS::Read(ID_ARNSRS_ADDR)); |
POTLESS_2 | 58:694d4d00407c | 669 | OUTPUT(" Dernière Position volet poumon enregistrée = %d\r\n", (int) UTILS::Read(VOLET_POUMON_ADDR)); |
POTLESS_2 | 58:694d4d00407c | 670 | OUTPUT(" Dernière Position volet fuite enregistrée = %d\r\n", (int) UTILS::Read(VOLET_FUITE_ADDR)); |
POTLESS_2 | 35:a209a192f431 | 671 | } else if (0 == strcmp(com, "check_E")) { |
POTLESS_2 | 42:3591ec9903b4 | 672 | sensors.Sensor_head_check(&serialMonit); |
POTLESS_2 | 34:26f6e3dbefb9 | 673 | } else if (0 == strcmp(com, "rec")) { |
POTLESS_2 | 34:26f6e3dbefb9 | 674 | if (FLAG_REC) { |
POTLESS_2 | 34:26f6e3dbefb9 | 675 | FLAG_REC = false; |
POTLESS_2 | 43:5ae8baf28e32 | 676 | OUTPUT(" Arrêt du Data Logging.\r\n"); |
POTLESS_2 | 34:26f6e3dbefb9 | 677 | } else { |
POTLESS_2 | 34:26f6e3dbefb9 | 678 | FLAG_REC = true; |
POTLESS_2 | 43:5ae8baf28e32 | 679 | OUTPUT(" Démarrage Data Logging dans %s\r\n", Log_File_Name); |
POTLESS_2 | 34:26f6e3dbefb9 | 680 | } |
POTLESS_2 | 34:26f6e3dbefb9 | 681 | } else if (0 == strcmp(com, "help")) { |
POTLESS_2 | 29:5b822d18bce6 | 682 | FLAG_AFF = false; |
POTLESS_2 | 42:3591ec9903b4 | 683 | UTILS::Help(&serialMonit); |
POTLESS_2 | 34:26f6e3dbefb9 | 684 | } else if (0 == strcmp(com, "start")) { |
POTLESS_2 | 29:5b822d18bce6 | 685 | FLAG_AFF = true; |
POTLESS_2 | 34:26f6e3dbefb9 | 686 | } else if (0 == strcmp(com, "stop")) { |
POTLESS_2 | 29:5b822d18bce6 | 687 | FLAG_AFF = false; |
POTLESS_2 | 40:32d89e04ead1 | 688 | //UTILS::Help(); |
POTLESS_2 | 36:1f5e2247b073 | 689 | } else if (0 == strcmp(com, "flash_c")) { |
POTLESS_2 | 29:5b822d18bce6 | 690 | FLAG_REC = false; |
POTLESS_2 | 29:5b822d18bce6 | 691 | UTILS::Clean_Flash(); |
POTLESS_2 | 42:3591ec9903b4 | 692 | } else if (0 == strcmp(com, "flash_f")) { |
POTLESS_2 | 34:26f6e3dbefb9 | 693 | FLAG_REC = false; |
POTLESS_2 | 43:5ae8baf28e32 | 694 | UTILS::Clean_Flash_All(); |
POTLESS_2 | 42:3591ec9903b4 | 695 | } else if (0 == strcmp(com, "dir")) { |
POTLESS_2 | 43:5ae8baf28e32 | 696 | FLAG_WINDEV = false; |
POTLESS_2 | 56:61b0f4d6a890 | 697 | wait(0.5); |
POTLESS_2 | 43:5ae8baf28e32 | 698 | OUTPUT("$\r\n"); |
POTLESS_2 | 43:5ae8baf28e32 | 699 | wait(0.5); |
POTLESS_2 | 42:3591ec9903b4 | 700 | UTILS::Dir_Flash(&serialMonit); |
POTLESS_2 | 42:3591ec9903b4 | 701 | } else if (0 == strcmp(com, "get")) { |
POTLESS_2 | 29:5b822d18bce6 | 702 | wait_ms(100); |
POTLESS_2 | 43:5ae8baf28e32 | 703 | char filename[20]; |
POTLESS_2 | 43:5ae8baf28e32 | 704 | UTILS::Read_Flash_File(&serialMonit, numb); |
POTLESS_2 | 43:5ae8baf28e32 | 705 | wait_ms(100); |
POTLESS_2 | 34:26f6e3dbefb9 | 706 | } else if (0 == strcmp(com, "del")) { |
POTLESS_2 | 29:5b822d18bce6 | 707 | FLAG_REC = false; |
POTLESS_2 | 29:5b822d18bce6 | 708 | char filename[20]; |
POTLESS_2 | 42:3591ec9903b4 | 709 | UTILS::Delete_Flash_File(numb); |
POTLESS_2 | 43:5ae8baf28e32 | 710 | OUTPUT("$\r\n"); |
POTLESS_2 | 43:5ae8baf28e32 | 711 | wait(0.5); |
POTLESS_2 | 43:5ae8baf28e32 | 712 | UTILS::Dir_Flash(&serialMonit); |
POTLESS_2 | 31:231a96d1d1c8 | 713 | FLAG_REC = true; |
POTLESS_2 | 34:26f6e3dbefb9 | 714 | } else if (0 == strcmp(com, "file_s")) { |
POTLESS_2 | 31:231a96d1d1c8 | 715 | char filename[20]; |
POTLESS_2 | 42:3591ec9903b4 | 716 | UTILS::Get_File_Size(&serialMonit, numb); |
POTLESS_2 | 29:5b822d18bce6 | 717 | } else if (0 == strcmp(com, "calib_p")) { |
POTLESS_2 | 59:fd64ca9dae27 | 718 | volet_poumon_Position = 0; |
POTLESS_2 | 59:fd64ca9dae27 | 719 | Servo_Poumon.reset(); |
POTLESS_2 | 58:694d4d00407c | 720 | Consigne_poumon = HOME_SERVO_POUMON; |
POTLESS_2 | 43:5ae8baf28e32 | 721 | OUTPUT(" Volet poumon Calibré.\r\n"); |
POTLESS_2 | 29:5b822d18bce6 | 722 | } else if (0 == strcmp(com, "calib_f")) { |
POTLESS_2 | 59:fd64ca9dae27 | 723 | volet_fuite_Position = 0; |
POTLESS_2 | 59:fd64ca9dae27 | 724 | Servo_Fuite.reset(); |
POTLESS_2 | 58:694d4d00407c | 725 | Consigne_fuite = HOME_SERVO_FUITE; |
POTLESS_2 | 43:5ae8baf28e32 | 726 | OUTPUT(" Volet fuite Calibré.\r\n"); |
POTLESS_2 | 29:5b822d18bce6 | 727 | } else if (0 == strcmp(com, "sleep")) { |
POTLESS_2 | 19:cac3761a5d0b | 728 | Stop_Sequence(); |
POTLESS_2 | 29:5b822d18bce6 | 729 | } else if (0 == strcmp(com, "time")) {//Depuis terminal MAC taper : " date +%s " |
POTLESS_2 | 34:26f6e3dbefb9 | 730 | set_time(atoi(numb)); |
POTLESS_2 | 43:5ae8baf28e32 | 731 | OUTPUT(" La RTC a été mise à l'heure.\r\n"); |
POTLESS_2 | 29:5b822d18bce6 | 732 | } else if (0 == strcmp(com, "c_pou")) { |
POTLESS_2 | 43:5ae8baf28e32 | 733 | Consigne_poumon = atof(numb); |
POTLESS_2 | 43:5ae8baf28e32 | 734 | DEBUG(" Servo Poumon = %f\r\n", Consigne_poumon); |
POTLESS_2 | 43:5ae8baf28e32 | 735 | } else if (0 == strcmp(com, "c_fui")) { |
POTLESS_2 | 43:5ae8baf28e32 | 736 | Consigne_fuite = atof(numb); |
POTLESS_2 | 43:5ae8baf28e32 | 737 | DEBUG(" Servo Fuite = %f\r\n", Consigne_fuite); |
POTLESS_2 | 43:5ae8baf28e32 | 738 | } else if (0 == strcmp(com, "mp_pou")) { |
POTLESS_2 | 41:51ba69648f9d | 739 | Consigne_poumon += atof(numb); |
POTLESS_2 | 33:f5d4bae05f16 | 740 | DEBUG(" Servo Poumon = %f\r\n", Consigne_poumon); |
POTLESS_2 | 43:5ae8baf28e32 | 741 | } else if (0 == strcmp(com, "mp_fui")) { |
POTLESS_2 | 41:51ba69648f9d | 742 | Consigne_fuite += atof(numb); |
POTLESS_2 | 33:f5d4bae05f16 | 743 | DEBUG(" Servo Fuite = %f\r\n", Consigne_fuite); |
POTLESS_2 | 29:5b822d18bce6 | 744 | } else if (0 == strcmp(com, "reset")) { |
POTLESS_2 | 43:5ae8baf28e32 | 745 | FLAG_REC = false; |
POTLESS_2 | 57:a0827fa46b03 | 746 | Mode_SECU(); |
POTLESS_2 | 36:1f5e2247b073 | 747 | UTILS::UnMount_Flash(); |
POTLESS_2 | 43:5ae8baf28e32 | 748 | OUTPUT(" Reset de l'appareil.\r\n"); |
POTLESS_2 | 43:5ae8baf28e32 | 749 | wait(1); |
POTLESS_2 | 10:aca745a66d51 | 750 | NVIC_SystemReset(); |
POTLESS_2 | 43:5ae8baf28e32 | 751 | } else if (0 == strcmp(com, "Kc")) { |
POTLESS_2 | 43:5ae8baf28e32 | 752 | Kc = atof(numb); |
POTLESS_2 | 43:5ae8baf28e32 | 753 | control_Servo.reset(); |
POTLESS_2 | 43:5ae8baf28e32 | 754 | control_Servo.setTunings(Kc, Ti, Td); |
POTLESS_2 | 56:61b0f4d6a890 | 755 | OUTPUT(" MAJ PID --> Kc = %f Ti = %f Td = %f\r\n", Kc, Ti, Td); |
POTLESS_2 | 43:5ae8baf28e32 | 756 | } else if (0 == strcmp(com, "Ti")) { |
POTLESS_2 | 43:5ae8baf28e32 | 757 | Ti = atof(numb); |
POTLESS_2 | 43:5ae8baf28e32 | 758 | control_Servo.reset(); |
POTLESS_2 | 43:5ae8baf28e32 | 759 | control_Servo.setTunings(Kc, Ti, Td); |
POTLESS_2 | 56:61b0f4d6a890 | 760 | OUTPUT(" MAJ PID --> Kc = %f Ti = %f Td = %f\r\n", Kc, Ti, Td); |
POTLESS_2 | 43:5ae8baf28e32 | 761 | } else if (0 == strcmp(com, "Td")) { |
POTLESS_2 | 43:5ae8baf28e32 | 762 | Td = atof(numb); |
POTLESS_2 | 43:5ae8baf28e32 | 763 | control_Servo.reset(); |
POTLESS_2 | 43:5ae8baf28e32 | 764 | control_Servo.setTunings(Kc, Ti, Td); |
POTLESS_2 | 56:61b0f4d6a890 | 765 | OUTPUT(" MAJ PID --> Kc = %f Ti = %f Td = %f\r\n", Kc, Ti, Td); |
POTLESS_2 | 43:5ae8baf28e32 | 766 | } else if (0 == strcmp(com, "Cons")) { |
POTLESS_2 | 43:5ae8baf28e32 | 767 | consigne = atoi(numb); |
POTLESS_2 | 43:5ae8baf28e32 | 768 | control_Servo.setSetPoint(consigne); |
POTLESS_2 | 56:61b0f4d6a890 | 769 | OUTPUT(" MAJ CONSIGNE PID --> Consigne = %d\r\n", consigne); |
potless | 49:a7432da60647 | 770 | } else if (0 == strcmp(com, "dfu")) { |
POTLESS_2 | 53:84571a5e2cda | 771 | OUTPUT(" Passage en DFU...\r\n"); |
POTLESS_2 | 58:694d4d00407c | 772 | FLAG_REC = false; |
POTLESS_2 | 58:694d4d00407c | 773 | Mode_SECU(); |
POTLESS_2 | 58:694d4d00407c | 774 | UTILS::UnMount_Flash(); |
POTLESS_2 | 59:fd64ca9dae27 | 775 | UTILS::EffacePage(2, 29, 1); |
POTLESS_2 | 59:fd64ca9dae27 | 776 | UTILS::Write(DFU_ADDR, 0xDEADBEEF); |
POTLESS_2 | 58:694d4d00407c | 777 | wait(1); |
POTLESS_2 | 58:694d4d00407c | 778 | NVIC_SystemReset(); |
POTLESS_2 | 43:5ae8baf28e32 | 779 | } else if (0 == strcmp(com, "PID")) { |
POTLESS_2 | 43:5ae8baf28e32 | 780 | if (FLAG_PID == 1) { |
POTLESS_2 | 56:61b0f4d6a890 | 781 | OUTPUT(" PID OFF\r\n"); |
POTLESS_2 | 43:5ae8baf28e32 | 782 | FLAG_PID = 0; |
POTLESS_2 | 43:5ae8baf28e32 | 783 | } else if (FLAG_PID == 0) { |
POTLESS_2 | 56:61b0f4d6a890 | 784 | OUTPUT(" PID ON\r\n"); |
POTLESS_2 | 43:5ae8baf28e32 | 785 | FLAG_PID = 1; |
POTLESS_2 | 43:5ae8baf28e32 | 786 | } |
POTLESS_2 | 12:7f3aadd79f89 | 787 | } else { |
POTLESS_2 | 43:5ae8baf28e32 | 788 | |
POTLESS_2 | 9:04bfdfc029cb | 789 | sensors.cozirSend(message); |
POTLESS_2 | 9:04bfdfc029cb | 790 | } |
POTLESS_2 | 34:26f6e3dbefb9 | 791 | |
POTLESS_2 | 9:04bfdfc029cb | 792 | strcpy(param," "); |
POTLESS_2 | 9:04bfdfc029cb | 793 | indexParam = 0; |
POTLESS_2 | 9:04bfdfc029cb | 794 | newParamFlag = false; |
POTLESS_2 | 9:04bfdfc029cb | 795 | } |
POTLESS_2 | 9:04bfdfc029cb | 796 | |
POTLESS_2 | 56:61b0f4d6a890 | 797 | void Decoding_IHM(char message []) |
POTLESS_2 | 56:61b0f4d6a890 | 798 | { |
POTLESS_2 | 56:61b0f4d6a890 | 799 | |
POTLESS_2 | 56:61b0f4d6a890 | 800 | char com[20] = ""; |
POTLESS_2 | 56:61b0f4d6a890 | 801 | char numb[30] = ""; |
POTLESS_2 | 56:61b0f4d6a890 | 802 | |
POTLESS_2 | 56:61b0f4d6a890 | 803 | sscanf(message,"%s %s",&com , &numb); |
POTLESS_2 | 56:61b0f4d6a890 | 804 | |
POTLESS_2 | 56:61b0f4d6a890 | 805 | DEEP_DEBUG("\r\n Commande = %s Valeur = %s \r\n\r\n", com, numb); |
POTLESS_2 | 56:61b0f4d6a890 | 806 | |
POTLESS_2 | 56:61b0f4d6a890 | 807 | OUTPUT("?\r\n"); |
POTLESS_2 | 56:61b0f4d6a890 | 808 | |
POTLESS_2 | 56:61b0f4d6a890 | 809 | if (0 == strcmp(com, "1")) { |
POTLESS_2 | 58:694d4d00407c | 810 | |
POTLESS_2 | 56:61b0f4d6a890 | 811 | } else if (0 == strcmp(com, "2")) { |
POTLESS_2 | 58:694d4d00407c | 812 | |
POTLESS_2 | 56:61b0f4d6a890 | 813 | } else if (0 == strcmp(com, "3")) { |
POTLESS_2 | 56:61b0f4d6a890 | 814 | |
POTLESS_2 | 56:61b0f4d6a890 | 815 | } else { |
POTLESS_2 | 58:694d4d00407c | 816 | |
POTLESS_2 | 56:61b0f4d6a890 | 817 | } |
POTLESS_2 | 56:61b0f4d6a890 | 818 | |
POTLESS_2 | 56:61b0f4d6a890 | 819 | strcpy(IHM," "); |
POTLESS_2 | 56:61b0f4d6a890 | 820 | indexIHM = 0; |
POTLESS_2 | 56:61b0f4d6a890 | 821 | newIHMFlag = false; |
POTLESS_2 | 56:61b0f4d6a890 | 822 | } |
POTLESS_2 | 56:61b0f4d6a890 | 823 | |
POTLESS_2 | 26:a2fe19341f92 | 824 | void Create_File_Name_Date() |
POTLESS_2 | 25:322ef9488e65 | 825 | { |
POTLESS_2 | 25:322ef9488e65 | 826 | //Du nom du fichier Date / heure |
POTLESS_2 | 25:322ef9488e65 | 827 | seconds = time(NULL); |
POTLESS_2 | 25:322ef9488e65 | 828 | char Time[40]; |
POTLESS_2 | 25:322ef9488e65 | 829 | strftime(Time, 40, "%a_%d_%m_%Y_%H%M", localtime(&seconds)); |
POTLESS_2 | 42:3591ec9903b4 | 830 | sprintf(Log_File_Name, "%s_LOG.csv", Time); |
POTLESS_2 | 42:3591ec9903b4 | 831 | DEBUG(" Nouveau fichier LOG = %s \r\n", Log_File_Name); |
POTLESS_2 | 34:26f6e3dbefb9 | 832 | } |
POTLESS_2 | 34:26f6e3dbefb9 | 833 | |
POTLESS_2 | 26:a2fe19341f92 | 834 | void Create_File_Name_Index() |
POTLESS_2 | 26:a2fe19341f92 | 835 | { |
POTLESS_2 | 26:a2fe19341f92 | 836 | //Du nom du fichier par Index |
POTLESS_2 | 42:3591ec9903b4 | 837 | sprintf(Log_File_Name, "LOG_%d.csv", UTILS::File_Index()); |
POTLESS_2 | 34:26f6e3dbefb9 | 838 | DEBUG(" Nouveau fichier LOG = %s \r\n", Log_File_Name); |
POTLESS_2 | 34:26f6e3dbefb9 | 839 | } |
POTLESS_2 | 34:26f6e3dbefb9 | 840 | |
potless | 48:9ceb095f397a | 841 | |
POTLESS_2 | 4:d84250f67dec | 842 | int main() |
POTLESS_2 | 12:7f3aadd79f89 | 843 | { |
POTLESS_2 | 62:891379d80b1b | 844 | flagSleep(); // on vérifie si la demande de sleep n'est pas active (permet de redémarrer sur un front haut) |
POTLESS_2 | 58:694d4d00407c | 845 | |
POTLESS_2 | 40:32d89e04ead1 | 846 | HAL_Init(); |
POTLESS_2 | 40:32d89e04ead1 | 847 | __HAL_RCC_PWR_CLK_ENABLE(); |
potless | 37:f9461c6592f2 | 848 | HAL_PWR_EnableBkUpAccess(); |
POTLESS_2 | 53:84571a5e2cda | 849 | |
POTLESS_2 | 58:694d4d00407c | 850 | UTILS::DFU(); |
POTLESS_2 | 62:891379d80b1b | 851 | |
potless | 60:e2922f9e309c | 852 | flagSleep(); // on vérifie si la demande de sleep n'est pas active (permet de redémarrer sur un front haut) |
POTLESS_2 | 58:694d4d00407c | 853 | |
POTLESS_2 | 56:61b0f4d6a890 | 854 | E5V = 1; |
POTLESS_2 | 57:a0827fa46b03 | 855 | E3V = 1; |
POTLESS_2 | 40:32d89e04ead1 | 856 | |
POTLESS_2 | 58:694d4d00407c | 857 | if (PIN_V_USB_DIGI) flag_USB = true; |
POTLESS_2 | 59:fd64ca9dae27 | 858 | if (PIN_V_PILES_DIGI) flag_Piles = true; |
POTLESS_2 | 58:694d4d00407c | 859 | |
POTLESS_2 | 58:694d4d00407c | 860 | UTILS::PVD_Config(); |
POTLESS_2 | 58:694d4d00407c | 861 | |
POTLESS_2 | 56:61b0f4d6a890 | 862 | buzzer.beep(1000,0.5); |
POTLESS_2 | 58:694d4d00407c | 863 | |
POTLESS_2 | 43:5ae8baf28e32 | 864 | //Ci-dessous commande pour formater une nouvelle carte |
POTLESS_2 | 58:694d4d00407c | 865 | //UTILS::Format_Flash(); |
POTLESS_2 | 43:5ae8baf28e32 | 866 | |
POTLESS_2 | 43:5ae8baf28e32 | 867 | //Montage Flash |
POTLESS_2 | 43:5ae8baf28e32 | 868 | UTILS::Mount_Flash(); |
POTLESS_2 | 62:891379d80b1b | 869 | |
POTLESS_2 | 58:694d4d00407c | 870 | /* |
POTLESS_2 | 58:694d4d00407c | 871 | if (UTILS::File_Exist("ARNSRS_ID.sys") == false) { |
POTLESS_2 | 58:694d4d00407c | 872 | UTILS::Store_A_Val(000, "ARNSRS_ID.sys"); |
POTLESS_2 | 58:694d4d00407c | 873 | DEBUG("ARNSRS ID forcée à 000\r\n"); |
POTLESS_2 | 58:694d4d00407c | 874 | } |
POTLESS_2 | 58:694d4d00407c | 875 | */ |
POTLESS_2 | 62:891379d80b1b | 876 | |
POTLESS_2 | 58:694d4d00407c | 877 | //pour le premier lancement quand l'appareil n'a pas d'ID. |
POTLESS_2 | 58:694d4d00407c | 878 | //int ID = 0; |
POTLESS_2 | 58:694d4d00407c | 879 | //UTILS::Write(ADRESSE_ID, ID); |
POTLESS_2 | 12:7f3aadd79f89 | 880 | |
POTLESS_2 | 57:a0827fa46b03 | 881 | DEBUG("\r\n\r\n Démarrage de l'appareil, veuillez patienter...\r\n\r\n"); |
POTLESS_2 | 58:694d4d00407c | 882 | |
POTLESS_2 | 34:26f6e3dbefb9 | 883 | |
POTLESS_2 | 43:5ae8baf28e32 | 884 | //Vérification RTC, si on est le 01/01/70, c'est qu'il y a un problème... |
POTLESS_2 | 43:5ae8baf28e32 | 885 | seconds = time(NULL); |
POTLESS_2 | 43:5ae8baf28e32 | 886 | char YEAR[10]; |
POTLESS_2 | 43:5ae8baf28e32 | 887 | strftime(YEAR, 10, "%D", localtime(&seconds)); |
POTLESS_2 | 58:694d4d00407c | 888 | if (0 == strcmp(YEAR, "01/01/70")); |
POTLESS_2 | 58:694d4d00407c | 889 | DEBUG(" Vous devez régler la RTC...\r\n\r\n"); |
POTLESS_2 | 18:bfd78c05b589 | 890 | |
POTLESS_2 | 43:5ae8baf28e32 | 891 | bool calib_O2 = false; |
POTLESS_2 | 43:5ae8baf28e32 | 892 | bool calib_CO2 = false; |
POTLESS_2 | 18:bfd78c05b589 | 893 | |
POTLESS_2 | 62:891379d80b1b | 894 | sensors.Sensors_INIT(calib_O2, calib_CO2); |
POTLESS_2 | 43:5ae8baf28e32 | 895 | |
POTLESS_2 | 43:5ae8baf28e32 | 896 | wait(1); |
POTLESS_2 | 43:5ae8baf28e32 | 897 | |
POTLESS_2 | 43:5ae8baf28e32 | 898 | //Création du nouveau fichier LOG par index / par date. |
POTLESS_2 | 43:5ae8baf28e32 | 899 | //Create_File_Name_Index(); |
POTLESS_2 | 43:5ae8baf28e32 | 900 | Create_File_Name_Date(); |
POTLESS_2 | 43:5ae8baf28e32 | 901 | |
POTLESS_2 | 43:5ae8baf28e32 | 902 | //Création et écriture du header du fichier LOG |
POTLESS_2 | 43:5ae8baf28e32 | 903 | sensors.Create_Header(Log_File_Name); |
POTLESS_2 | 42:3591ec9903b4 | 904 | |
POTLESS_2 | 58:694d4d00407c | 905 | /* |
POTLESS_2 | 43:5ae8baf28e32 | 906 | Servo_Poumon.Init("Servo_Poumon.sys"); |
POTLESS_2 | 43:5ae8baf28e32 | 907 | Servo_Fuite.Init("Servo_Fuite.sys"); |
POTLESS_2 | 15:efd3b3bf3f37 | 908 | |
POTLESS_2 | 58:694d4d00407c | 909 | Servo_Poumon.Init(VOLET_POUMON_ADDR); |
POTLESS_2 | 58:694d4d00407c | 910 | Servo_Fuite.Init(VOLET_FUITE_ADDR); |
POTLESS_2 | 58:694d4d00407c | 911 | */ |
POTLESS_2 | 58:694d4d00407c | 912 | |
POTLESS_2 | 57:a0827fa46b03 | 913 | DEBUG(" Demarrage des threads...\r\n\r\n"); |
POTLESS_2 | 62:891379d80b1b | 914 | |
POTLESS_2 | 62:891379d80b1b | 915 | /* |
POTLESS_2 | 62:891379d80b1b | 916 | |
POTLESS_2 | 62:891379d80b1b | 917 | Pour mémoire, les réglage de priorité des thread |
POTLESS_2 | 62:891379d80b1b | 918 | |
POTLESS_2 | 62:891379d80b1b | 919 | osPriorityIdle = -3, ///< priority: idle (lowest) |
POTLESS_2 | 62:891379d80b1b | 920 | osPriorityLow = -2, ///< priority: low |
POTLESS_2 | 62:891379d80b1b | 921 | osPriorityBelowNormal = -1, ///< priority: below normal |
POTLESS_2 | 62:891379d80b1b | 922 | osPriorityNormal = 0, ///< priority: normal (default) |
POTLESS_2 | 62:891379d80b1b | 923 | osPriorityAboveNormal = +1, ///< priority: above normal |
POTLESS_2 | 62:891379d80b1b | 924 | osPriorityHigh = +2, ///< priority: high |
POTLESS_2 | 62:891379d80b1b | 925 | osPriorityRealtime = +3, ///< priority: realtime (highest) |
POTLESS_2 | 62:891379d80b1b | 926 | osPriorityError = 0x84 ///< system cannot determine priority or thread has illegal priority |
POTLESS_2 | 62:891379d80b1b | 927 | */ |
POTLESS_2 | 62:891379d80b1b | 928 | |
POTLESS_2 | 62:891379d80b1b | 929 | thread_Volets_POUMON.set_priority(osPriorityHigh); |
POTLESS_2 | 62:891379d80b1b | 930 | |
POTLESS_2 | 62:891379d80b1b | 931 | thread_Volets_POUMON.start(callback(GO_TO_thread_POUMON)); |
POTLESS_2 | 62:891379d80b1b | 932 | |
POTLESS_2 | 62:891379d80b1b | 933 | DEBUG(" Contrôle volet Poumon démarré\r\n\r\n"); |
POTLESS_2 | 62:891379d80b1b | 934 | |
POTLESS_2 | 43:5ae8baf28e32 | 935 | wait(1); |
potless | 60:e2922f9e309c | 936 | |
POTLESS_2 | 62:891379d80b1b | 937 | thread_Volets_FUITE.set_priority(osPriorityHigh); |
POTLESS_2 | 62:891379d80b1b | 938 | |
POTLESS_2 | 62:891379d80b1b | 939 | thread_Volets_FUITE.start(callback(GO_TO_thread_FUITE)); |
POTLESS_2 | 62:891379d80b1b | 940 | |
POTLESS_2 | 62:891379d80b1b | 941 | DEBUG(" Contrôle volet Fuite démarré\r\n\r\n"); |
POTLESS_2 | 62:891379d80b1b | 942 | |
POTLESS_2 | 62:891379d80b1b | 943 | wait(1); |
POTLESS_2 | 62:891379d80b1b | 944 | |
POTLESS_2 | 62:891379d80b1b | 945 | thread_Secu.set_priority(osPriorityNormal); |
POTLESS_2 | 62:891379d80b1b | 946 | |
POTLESS_2 | 62:891379d80b1b | 947 | thread_Secu.start(callback(SECU_thread)); |
POTLESS_2 | 62:891379d80b1b | 948 | |
POTLESS_2 | 62:891379d80b1b | 949 | DEBUG(" Contrôle des paramètres de sécu démarré\r\n\r\n"); |
POTLESS_2 | 62:891379d80b1b | 950 | |
POTLESS_2 | 62:891379d80b1b | 951 | wait(1); |
POTLESS_2 | 62:891379d80b1b | 952 | |
POTLESS_2 | 62:891379d80b1b | 953 | thread_Head.set_priority(osPriorityNormal); |
POTLESS_2 | 62:891379d80b1b | 954 | |
POTLESS_2 | 43:5ae8baf28e32 | 955 | thread_Head.start(callback(SENSORS_thread)); |
POTLESS_2 | 62:891379d80b1b | 956 | |
POTLESS_2 | 56:61b0f4d6a890 | 957 | DEBUG(" Tête capteurs démarrée\r\n\r\n"); |
POTLESS_2 | 62:891379d80b1b | 958 | |
POTLESS_2 | 43:5ae8baf28e32 | 959 | wait(1); |
POTLESS_2 | 9:04bfdfc029cb | 960 | |
POTLESS_2 | 56:61b0f4d6a890 | 961 | |
POTLESS_2 | 43:5ae8baf28e32 | 962 | //Init PID |
POTLESS_2 | 43:5ae8baf28e32 | 963 | //Entrée PPO2 entre 100 et 1000 mb |
POTLESS_2 | 43:5ae8baf28e32 | 964 | control_Servo.setInputLimits(Min_Input, Max_Input); |
POTLESS_2 | 43:5ae8baf28e32 | 965 | //Sortie servo entre 0 et 100 % |
POTLESS_2 | 43:5ae8baf28e32 | 966 | control_Servo.setOutputLimits(Min_Output, Max_Output); |
POTLESS_2 | 57:a0827fa46b03 | 967 | //Reglage de l'interval du PID |
POTLESS_2 | 57:a0827fa46b03 | 968 | control_Servo.setInterval(RATE_PID); |
POTLESS_2 | 43:5ae8baf28e32 | 969 | //Consigne à x mb |
POTLESS_2 | 43:5ae8baf28e32 | 970 | control_Servo.setSetPoint(consigne); |
POTLESS_2 | 57:a0827fa46b03 | 971 | //Mode auto au démarrage |
POTLESS_2 | 58:694d4d00407c | 972 | control_Servo.setMode(AUTO_MODE); |
POTLESS_2 | 34:26f6e3dbefb9 | 973 | |
POTLESS_2 | 56:61b0f4d6a890 | 974 | DEBUG(" Cliquez sur le bouton help pour voir la liste des \r\n commandes administrateur disponibles.\r\n"); |
POTLESS_2 | 7:ad15c386e960 | 975 | |
POTLESS_2 | 46:28298df0ac55 | 976 | OUTPUT("$\r\n"); |
POTLESS_2 | 43:5ae8baf28e32 | 977 | wait(0.5); |
POTLESS_2 | 43:5ae8baf28e32 | 978 | UTILS::Dir_Flash(&serialMonit); |
POTLESS_2 | 43:5ae8baf28e32 | 979 | |
POTLESS_2 | 47:89a088bc8866 | 980 | serialMonit.attach(&callbackParam); |
POTLESS_2 | 58:694d4d00407c | 981 | |
POTLESS_2 | 56:61b0f4d6a890 | 982 | display.attach(&callbackIHM); |
POTLESS_2 | 58:694d4d00407c | 983 | |
POTLESS_2 | 58:694d4d00407c | 984 | OTU_Ticker.attach(&Calcul_OTU, 60); |
POTLESS_2 | 58:694d4d00407c | 985 | |
potless | 60:e2922f9e309c | 986 | vusb_off_on.fall(&USB_unplugged); |
POTLESS_2 | 59:fd64ca9dae27 | 987 | |
POTLESS_2 | 59:fd64ca9dae27 | 988 | vpiles_off_on.fall(&PILES_unpluged); |
POTLESS_2 | 53:84571a5e2cda | 989 | |
POTLESS_2 | 56:61b0f4d6a890 | 990 | buzzer.beep(1000,0.3); |
POTLESS_2 | 56:61b0f4d6a890 | 991 | wait_ms(500); |
POTLESS_2 | 56:61b0f4d6a890 | 992 | buzzer.beep(1000,0.3); |
POTLESS_2 | 58:694d4d00407c | 993 | |
POTLESS_2 | 43:5ae8baf28e32 | 994 | while (true) { |
POTLESS_2 | 36:1f5e2247b073 | 995 | |
POTLESS_2 | 43:5ae8baf28e32 | 996 | //Démarrage du Timer mesurant le temps d'éxecution du code |
POTLESS_2 | 43:5ae8baf28e32 | 997 | REAL_RATE.start(); |
POTLESS_2 | 36:1f5e2247b073 | 998 | |
POTLESS_2 | 43:5ae8baf28e32 | 999 | if (newParamFlag) { |
POTLESS_2 | 43:5ae8baf28e32 | 1000 | DEEP_DEBUG(" From PC = %s\r\n", param); |
POTLESS_2 | 43:5ae8baf28e32 | 1001 | Decoding_Message(param); |
POTLESS_2 | 43:5ae8baf28e32 | 1002 | } |
POTLESS_2 | 58:694d4d00407c | 1003 | |
POTLESS_2 | 56:61b0f4d6a890 | 1004 | if (newIHMFlag) { |
POTLESS_2 | 56:61b0f4d6a890 | 1005 | DEEP_DEBUG(" From IHM = %s\r\n", IHM); |
POTLESS_2 | 56:61b0f4d6a890 | 1006 | Decoding_IHM(IHM); |
POTLESS_2 | 56:61b0f4d6a890 | 1007 | } |
POTLESS_2 | 34:26f6e3dbefb9 | 1008 | |
POTLESS_2 | 43:5ae8baf28e32 | 1009 | //Fabrication de la chaine Date / heure |
POTLESS_2 | 43:5ae8baf28e32 | 1010 | seconds = time(NULL); |
POTLESS_2 | 43:5ae8baf28e32 | 1011 | char Time_buf[32]; |
POTLESS_2 | 43:5ae8baf28e32 | 1012 | strftime(Time_buf, 32, "%D %I-%M-%S ", localtime(&seconds)); |
POTLESS_2 | 19:cac3761a5d0b | 1013 | |
POTLESS_2 | 56:61b0f4d6a890 | 1014 | //Fabrication de la chaine de com |
POTLESS_2 | 56:61b0f4d6a890 | 1015 | sprintf(to_store,"<%s;%d;%d;%.2f;%d;%.2f;%.2f;%d;%d;%d;%.2f;%.2f;%d;%.3f;%.3f;%.3f;%d;%d>", |
POTLESS_2 | 43:5ae8baf28e32 | 1016 | Time_buf, |
POTLESS_2 | 43:5ae8baf28e32 | 1017 | co2, |
POTLESS_2 | 43:5ae8baf28e32 | 1018 | ppO2, |
POTLESS_2 | 43:5ae8baf28e32 | 1019 | pression, |
POTLESS_2 | 43:5ae8baf28e32 | 1020 | (int)OTU, |
POTLESS_2 | 43:5ae8baf28e32 | 1021 | Temp1, |
POTLESS_2 | 43:5ae8baf28e32 | 1022 | Temp2, |
POTLESS_2 | 43:5ae8baf28e32 | 1023 | Humid, |
POTLESS_2 | 43:5ae8baf28e32 | 1024 | CellO2_1, |
POTLESS_2 | 43:5ae8baf28e32 | 1025 | CellO2_2, |
POTLESS_2 | 43:5ae8baf28e32 | 1026 | volet_poumon_Position, |
POTLESS_2 | 43:5ae8baf28e32 | 1027 | volet_fuite_Position, |
POTLESS_2 | 43:5ae8baf28e32 | 1028 | FLAG_PID, |
POTLESS_2 | 43:5ae8baf28e32 | 1029 | Kc, |
POTLESS_2 | 43:5ae8baf28e32 | 1030 | Ti, |
POTLESS_2 | 43:5ae8baf28e32 | 1031 | Td, |
POTLESS_2 | 56:61b0f4d6a890 | 1032 | consigne, |
POTLESS_2 | 56:61b0f4d6a890 | 1033 | Commande_IHM |
POTLESS_2 | 58:694d4d00407c | 1034 | ); |
POTLESS_2 | 15:efd3b3bf3f37 | 1035 | |
POTLESS_2 | 15:efd3b3bf3f37 | 1036 | |
POTLESS_2 | 43:5ae8baf28e32 | 1037 | //Pour windev |
POTLESS_2 | 43:5ae8baf28e32 | 1038 | if (FLAG_WINDEV) { |
POTLESS_2 | 43:5ae8baf28e32 | 1039 | OUTPUT("%s\r\n", to_store); |
POTLESS_2 | 43:5ae8baf28e32 | 1040 | } |
POTLESS_2 | 53:84571a5e2cda | 1041 | |
POTLESS_2 | 43:5ae8baf28e32 | 1042 | //Pour l'IHM |
POTLESS_2 | 46:28298df0ac55 | 1043 | if (FLAG_DISPLAY) { |
POTLESS_2 | 46:28298df0ac55 | 1044 | IHM("%s\r\n", to_store); |
POTLESS_2 | 46:28298df0ac55 | 1045 | } |
POTLESS_2 | 53:84571a5e2cda | 1046 | |
POTLESS_2 | 43:5ae8baf28e32 | 1047 | //Vers le moniteur série |
POTLESS_2 | 43:5ae8baf28e32 | 1048 | if (FLAG_AFF) { |
POTLESS_2 | 43:5ae8baf28e32 | 1049 | Affichage(); |
POTLESS_2 | 43:5ae8baf28e32 | 1050 | } |
POTLESS_2 | 12:7f3aadd79f89 | 1051 | |
POTLESS_2 | 43:5ae8baf28e32 | 1052 | //Enregistrement de la chaine |
POTLESS_2 | 43:5ae8baf28e32 | 1053 | if (FLAG_REC) { |
POTLESS_2 | 43:5ae8baf28e32 | 1054 | UTILS::Write_Flash_File(to_store, Log_File_Name); |
POTLESS_2 | 43:5ae8baf28e32 | 1055 | count ++; |
POTLESS_2 | 43:5ae8baf28e32 | 1056 | if (count > Max_Log_Size) { |
POTLESS_2 | 43:5ae8baf28e32 | 1057 | Create_File_Name_Date(); |
POTLESS_2 | 43:5ae8baf28e32 | 1058 | sensors.Create_Header(Log_File_Name); |
POTLESS_2 | 43:5ae8baf28e32 | 1059 | count = 0; |
POTLESS_2 | 43:5ae8baf28e32 | 1060 | OUTPUT("$\r\n"); |
POTLESS_2 | 43:5ae8baf28e32 | 1061 | wait(0.5); |
POTLESS_2 | 43:5ae8baf28e32 | 1062 | UTILS::Dir_Flash(&serialMonit); |
POTLESS_2 | 34:26f6e3dbefb9 | 1063 | } |
POTLESS_2 | 34:26f6e3dbefb9 | 1064 | } |
POTLESS_2 | 43:5ae8baf28e32 | 1065 | |
POTLESS_2 | 56:61b0f4d6a890 | 1066 | |
POTLESS_2 | 43:5ae8baf28e32 | 1067 | //Update du PID |
POTLESS_2 | 58:694d4d00407c | 1068 | if (FLAG_PID == 1 && EN_MODE_SECU == false) { |
POTLESS_2 | 58:694d4d00407c | 1069 | control_Servo.setProcessValue(ppO2); |
POTLESS_2 | 58:694d4d00407c | 1070 | //Nouvelle sortie servo fuite si on est pas en mode SECU |
POTLESS_2 | 58:694d4d00407c | 1071 | Consigne_fuite = control_Servo.compute(); |
POTLESS_2 | 58:694d4d00407c | 1072 | } |
POTLESS_2 | 43:5ae8baf28e32 | 1073 | |
POTLESS_2 | 43:5ae8baf28e32 | 1074 | //Arrêt du Timer mesurant le temps d'éxecution du code |
POTLESS_2 | 43:5ae8baf28e32 | 1075 | REAL_RATE.stop(); |
POTLESS_2 | 43:5ae8baf28e32 | 1076 | //Définition de la nouvelle valeur du temps d'échantillonage du PID. |
POTLESS_2 | 43:5ae8baf28e32 | 1077 | RATE = REAL_RATE.read(); |
POTLESS_2 | 43:5ae8baf28e32 | 1078 | //Reset du Timer |
POTLESS_2 | 43:5ae8baf28e32 | 1079 | REAL_RATE.reset(); |
POTLESS_2 | 43:5ae8baf28e32 | 1080 | |
POTLESS_2 | 43:5ae8baf28e32 | 1081 | //Pour ralentir le code à Ref_Time seconde fixe quelque soit les intéruptions du loop.... |
POTLESS_2 | 43:5ae8baf28e32 | 1082 | if (Ref_Time > RATE) { |
POTLESS_2 | 43:5ae8baf28e32 | 1083 | RATE_TRUE = (Ref_Time - RATE) * 1000; |
POTLESS_2 | 43:5ae8baf28e32 | 1084 | } else { |
POTLESS_2 | 43:5ae8baf28e32 | 1085 | RATE_TRUE = 0; |
POTLESS_2 | 43:5ae8baf28e32 | 1086 | |
POTLESS_2 | 43:5ae8baf28e32 | 1087 | DEEP_DEBUG("Pour ralentir le code, Ref_Time doit être supérieur à %f seconde(s)\r\n\n", RATE); |
POTLESS_2 | 43:5ae8baf28e32 | 1088 | } |
POTLESS_2 | 43:5ae8baf28e32 | 1089 | |
POTLESS_2 | 43:5ae8baf28e32 | 1090 | wait_ms(RATE_TRUE); |
POTLESS_2 | 34:26f6e3dbefb9 | 1091 | } |
POTLESS_2 | 4:d84250f67dec | 1092 | } |
POTLESS_2 | 43:5ae8baf28e32 | 1093 | |
POTLESS_2 | 43:5ae8baf28e32 | 1094 |