![](/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@33:f5d4bae05f16, 2018-02-24 (annotated)
- Committer:
- POTLESS_2
- Date:
- Sat Feb 24 16:56:19 2018 +0000
- Revision:
- 33:f5d4bae05f16
- Parent:
- 31:231a96d1d1c8
- Child:
- 34:26f6e3dbefb9
Avec O2 qui marche
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 | 4:d84250f67dec | 8 | |
POTLESS_2 | 17:bef8abc445f2 | 9 | //Commandes des servos |
POTLESS_2 | 19:cac3761a5d0b | 10 | #define PWM_SERVO_POUMON PB_15 |
POTLESS_2 | 19:cac3761a5d0b | 11 | #define nSleep_SERVO_POUMON PC_6 |
POTLESS_2 | 19:cac3761a5d0b | 12 | #define FWD_SERVO_POUMON PB_14 |
POTLESS_2 | 19:cac3761a5d0b | 13 | #define REV_SERVO_POUMON PB_13 |
POTLESS_2 | 19:cac3761a5d0b | 14 | #define Channel_A_SERVO_POUMON PB_1 |
POTLESS_2 | 19:cac3761a5d0b | 15 | #define Channel_B_SERVO_POUMON PB_2 |
POTLESS_2 | 19:cac3761a5d0b | 16 | #define HOME_SERVO_POUMON 0 |
POTLESS_2 | 17:bef8abc445f2 | 17 | |
POTLESS_2 | 19:cac3761a5d0b | 18 | #define PWM_SERVO_FUITE PB_10 |
POTLESS_2 | 19:cac3761a5d0b | 19 | #define nSleep_SERVO_FUITE PC_5 |
POTLESS_2 | 19:cac3761a5d0b | 20 | #define FWD_SERVO_FUITE PB_4 |
POTLESS_2 | 19:cac3761a5d0b | 21 | #define REV_SERVO_FUITE PB_5 |
POTLESS_2 | 19:cac3761a5d0b | 22 | #define Channel_A_SERVO_FUITE PB_8 |
POTLESS_2 | 19:cac3761a5d0b | 23 | #define Channel_B_SERVO_FUITE PB_9 |
POTLESS_2 | 19:cac3761a5d0b | 24 | #define HOME_SERVO_FUITE 90 |
POTLESS_2 | 17:bef8abc445f2 | 25 | |
POTLESS_2 | 17:bef8abc445f2 | 26 | //Ecrit dans le moniteur série de la tablette à 115200 bds si sur 1, penser à mettre NEED_CONSOLE_OUTPUT à 0 |
POTLESS_2 | 9:04bfdfc029cb | 27 | #define NEED_ANDROID_OUTPUT 1 |
POTLESS_2 | 9:04bfdfc029cb | 28 | |
POTLESS_2 | 17:bef8abc445f2 | 29 | //Mode PID, STD à commenter / décommenter |
POTLESS_2 | 17:bef8abc445f2 | 30 | #define STD_MODE |
POTLESS_2 | 17:bef8abc445f2 | 31 | //#define PID_MODE |
POTLESS_2 | 11:b2feed92584a | 32 | |
POTLESS_2 | 12:7f3aadd79f89 | 33 | #ifdef STD_MODE |
POTLESS_2 | 12:7f3aadd79f89 | 34 | int MODE_FLAG = 0; |
POTLESS_2 | 11:b2feed92584a | 35 | #endif |
POTLESS_2 | 11:b2feed92584a | 36 | |
POTLESS_2 | 12:7f3aadd79f89 | 37 | #ifdef PID_MODE |
POTLESS_2 | 12:7f3aadd79f89 | 38 | int MODE_FLAG = 2; |
POTLESS_2 | 11:b2feed92584a | 39 | #endif |
POTLESS_2 | 11:b2feed92584a | 40 | |
POTLESS_2 | 9:04bfdfc029cb | 41 | #if NEED_ANDROID_OUTPUT |
POTLESS_2 | 9:04bfdfc029cb | 42 | #define ANDROID(...) { android.printf(__VA_ARGS__); } |
POTLESS_2 | 9:04bfdfc029cb | 43 | #else |
POTLESS_2 | 9:04bfdfc029cb | 44 | #define ANDROID(...) |
POTLESS_2 | 9:04bfdfc029cb | 45 | #endif |
POTLESS_2 | 9:04bfdfc029cb | 46 | |
POTLESS_2 | 33:f5d4bae05f16 | 47 | #if DEBUG_MODE |
POTLESS_2 | 33:f5d4bae05f16 | 48 | #define DEBUG(...) { serialMonit.printf(__VA_ARGS__); fflush(stdout);} |
POTLESS_2 | 29:5b822d18bce6 | 49 | #else |
POTLESS_2 | 33:f5d4bae05f16 | 50 | #define DEBUG(...) |
POTLESS_2 | 29:5b822d18bce6 | 51 | #endif |
POTLESS_2 | 29:5b822d18bce6 | 52 | |
POTLESS_2 | 29:5b822d18bce6 | 53 | |
POTLESS_2 | 25:322ef9488e65 | 54 | //PinName pwm, PinName nSleep, PinName fwd, PinName rev, PinName channelA, PinName channelB, int pulsesPerRev, int Rapport, Encoding encoding = X2_ENCODING |
POTLESS_2 | 25:322ef9488e65 | 55 | Faulhaber Servo_Poumon("Servo_Poumon", PWM_SERVO_POUMON, nSleep_SERVO_POUMON, FWD_SERVO_POUMON, REV_SERVO_POUMON, Channel_A_SERVO_POUMON, Channel_B_SERVO_POUMON, 16, 207, Faulhaber::X2_ENCODING); |
POTLESS_2 | 22:555c2930e8e0 | 56 | //Faulhaber Servo_Fuite("Servo_Fuite", PWM_SERVO_FUITE, nSleep_SERVO_FUITE, FWD_SERVO_FUITE, REV_SERVO_FUITE, 1, Channel_A_SERVO_FUITE, Channel_B_SERVO_FUITE, 16, 207, Faulhaber::X2_ENCODING); |
POTLESS_2 | 17:bef8abc445f2 | 57 | |
POTLESS_2 | 17:bef8abc445f2 | 58 | //Moniteur série, Serial 2 |
POTLESS_2 | 17:bef8abc445f2 | 59 | Serial serialMonit(USBTX,USBRX,115200); |
POTLESS_2 | 10:aca745a66d51 | 60 | |
POTLESS_2 | 9:04bfdfc029cb | 61 | //COM Série vers Android, Serial 3 |
POTLESS_2 | 17:bef8abc445f2 | 62 | Serial android(PC_10,PC_11,115200); |
POTLESS_2 | 4:d84250f67dec | 63 | |
POTLESS_2 | 7:ad15c386e960 | 64 | //Init de la lib ARNSRS; |
POTLESS_2 | 7:ad15c386e960 | 65 | SENSOR_HEAD_REV_B sensors; |
potless | 2:4a8bf1d53439 | 66 | |
POTLESS_2 | 6:ebed9093d661 | 67 | //pour Param Cozir |
POTLESS_2 | 9:04bfdfc029cb | 68 | const int sizeParam = 20; |
POTLESS_2 | 11:b2feed92584a | 69 | char param[sizeParam]; |
POTLESS_2 | 11:b2feed92584a | 70 | volatile int indexParam = 0; |
POTLESS_2 | 6:ebed9093d661 | 71 | bool newParamFlag = false; |
potless | 2:4a8bf1d53439 | 72 | |
POTLESS_2 | 9:04bfdfc029cb | 73 | //pour Commandes Android |
POTLESS_2 | 9:04bfdfc029cb | 74 | const int sizeAndroid = 20; |
POTLESS_2 | 11:b2feed92584a | 75 | char Android[sizeAndroid]; |
POTLESS_2 | 11:b2feed92584a | 76 | volatile int indexAndroid = 0; |
POTLESS_2 | 9:04bfdfc029cb | 77 | bool newAndroidFlag = false; |
POTLESS_2 | 12:7f3aadd79f89 | 78 | char to_android[100]; |
POTLESS_2 | 9:04bfdfc029cb | 79 | |
POTLESS_2 | 25:322ef9488e65 | 80 | //Flag pour interrompre l'affichage si on veut... |
POTLESS_2 | 25:322ef9488e65 | 81 | bool FLAG_AFF = true; |
POTLESS_2 | 25:322ef9488e65 | 82 | |
POTLESS_2 | 29:5b822d18bce6 | 83 | //Flag pour interrompre l'enregistrement si on veut... |
POTLESS_2 | 29:5b822d18bce6 | 84 | bool FLAG_REC = true; |
POTLESS_2 | 29:5b822d18bce6 | 85 | |
POTLESS_2 | 33:f5d4bae05f16 | 86 | //Flag pour interrompre les demandes O2 en cours ed calibration... |
POTLESS_2 | 33:f5d4bae05f16 | 87 | bool FLAG_O2 = true; |
POTLESS_2 | 33:f5d4bae05f16 | 88 | |
POTLESS_2 | 7:ad15c386e960 | 89 | //Variables de stockage des infos capteurs |
POTLESS_2 | 7:ad15c386e960 | 90 | int co2 = 0; |
POTLESS_2 | 7:ad15c386e960 | 91 | float pression = 0; |
POTLESS_2 | 9:04bfdfc029cb | 92 | float Temp1 = 0; |
POTLESS_2 | 7:ad15c386e960 | 93 | int ppO2 = 0; |
POTLESS_2 | 7:ad15c386e960 | 94 | int CellO2_1 = 0; |
POTLESS_2 | 7:ad15c386e960 | 95 | int CellO2_2 = 0; |
POTLESS_2 | 7:ad15c386e960 | 96 | |
POTLESS_2 | 18:bfd78c05b589 | 97 | //Variables et constantes OTU |
POTLESS_2 | 18:bfd78c05b589 | 98 | float OTU = 0; |
POTLESS_2 | 18:bfd78c05b589 | 99 | float COEF_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 | 8:a750d531b381 | 116 | |
POTLESS_2 | 17:bef8abc445f2 | 117 | //Thread d'intérogation des capteurs et de positionnement des volets |
POTLESS_2 | 19:cac3761a5d0b | 118 | Thread thread_Sensors; |
POTLESS_2 | 19:cac3761a5d0b | 119 | Thread thread_Volets; |
POTLESS_2 | 20:5f79fb4565a7 | 120 | Thread thread_Secu; |
POTLESS_2 | 7:ad15c386e960 | 121 | |
POTLESS_2 | 10:aca745a66d51 | 122 | //Contrôle des servos |
POTLESS_2 | 19:cac3761a5d0b | 123 | float Consigne_poumon = 0; |
POTLESS_2 | 19:cac3761a5d0b | 124 | float volet_poumon_Position = 0; |
POTLESS_2 | 19:cac3761a5d0b | 125 | float Consigne_fuite = 0; |
POTLESS_2 | 19:cac3761a5d0b | 126 | float volet_fuite_Position = 0; |
POTLESS_2 | 25:322ef9488e65 | 127 | float Volets_Speed = 0.1; |
POTLESS_2 | 26:a2fe19341f92 | 128 | float Volet_DeadBand = 5; |
POTLESS_2 | 10:aca745a66d51 | 129 | |
POTLESS_2 | 12:7f3aadd79f89 | 130 | #ifdef PID_MODE |
POTLESS_2 | 12:7f3aadd79f89 | 131 | //Paramètre du PID |
POTLESS_2 | 12:7f3aadd79f89 | 132 | float Kc = 40; |
POTLESS_2 | 12:7f3aadd79f89 | 133 | float Ti = 0; |
POTLESS_2 | 12:7f3aadd79f89 | 134 | float Td = 0; |
POTLESS_2 | 12:7f3aadd79f89 | 135 | float RATE_PID = Ref_Time; |
POTLESS_2 | 12:7f3aadd79f89 | 136 | float Commande_PID; |
POTLESS_2 | 15:efd3b3bf3f37 | 137 | float consigne = 210; |
POTLESS_2 | 15:efd3b3bf3f37 | 138 | float Max_Input = 1000; |
POTLESS_2 | 15:efd3b3bf3f37 | 139 | float Min_Input = 80; |
POTLESS_2 | 19:cac3761a5d0b | 140 | float Max_Output = 85;//Vérifier la valeur pour angle à laisser ouvert... |
POTLESS_2 | 19:cac3761a5d0b | 141 | float Min_Output = 5; |
POTLESS_2 | 10:aca745a66d51 | 142 | |
POTLESS_2 | 12:7f3aadd79f89 | 143 | //Init PID |
POTLESS_2 | 17:bef8abc445f2 | 144 | PID control_Servo(Kc, Ti, Td, RATE_PID); |
POTLESS_2 | 12:7f3aadd79f89 | 145 | #endif |
POTLESS_2 | 10:aca745a66d51 | 146 | |
POTLESS_2 | 19:cac3761a5d0b | 147 | //Boolean du status de l'appareil, en mode SECU ou nominal |
POTLESS_2 | 19:cac3761a5d0b | 148 | bool EN_MODE_SECU = false; |
POTLESS_2 | 31:231a96d1d1c8 | 149 | |
POTLESS_2 | 31:231a96d1d1c8 | 150 | //Test des alim |
POTLESS_2 | 29:5b822d18bce6 | 151 | DigitalIn V_USB(PA_0); |
POTLESS_2 | 31:231a96d1d1c8 | 152 | DigitalIn V_PILES_2(PC_3); |
POTLESS_2 | 31:231a96d1d1c8 | 153 | AnalogIn V_PILES(PA_1); |
POTLESS_2 | 31:231a96d1d1c8 | 154 | |
POTLESS_2 | 31:231a96d1d1c8 | 155 | int Vusb = 1; |
POTLESS_2 | 31:231a96d1d1c8 | 156 | int VPiles = 1; |
POTLESS_2 | 31:231a96d1d1c8 | 157 | float VPiles_2 = 1; |
POTLESS_2 | 18:bfd78c05b589 | 158 | |
POTLESS_2 | 21:b8900130ca05 | 159 | //Interruption user button |
POTLESS_2 | 21:b8900130ca05 | 160 | InterruptIn button(USER_BUTTON); |
POTLESS_2 | 23:7477dc855fad | 161 | volatile int GO = 0; |
POTLESS_2 | 21:b8900130ca05 | 162 | |
POTLESS_2 | 29:5b822d18bce6 | 163 | void Affichage() |
POTLESS_2 | 29:5b822d18bce6 | 164 | { |
POTLESS_2 | 29:5b822d18bce6 | 165 | |
POTLESS_2 | 29:5b822d18bce6 | 166 | serialMonit.printf("\r\n"); |
POTLESS_2 | 29:5b822d18bce6 | 167 | serialMonit.printf(" CO2 = %d ppm\r\n" , co2); |
POTLESS_2 | 29:5b822d18bce6 | 168 | serialMonit.printf(" PPO2 = %d mb\r\n", ppO2); |
POTLESS_2 | 31:231a96d1d1c8 | 169 | serialMonit.printf(" OTU = %d \r\n", (int)OTU); |
POTLESS_2 | 29:5b822d18bce6 | 170 | serialMonit.printf(" Pression = %f msw\r\n", pression); |
POTLESS_2 | 29:5b822d18bce6 | 171 | serialMonit.printf(" Temp MS5837 = %f C\r\n", Temp1); |
POTLESS_2 | 29:5b822d18bce6 | 172 | serialMonit.printf(" Temp HTU21D = %f C\n\r", Temp2); |
POTLESS_2 | 29:5b822d18bce6 | 173 | serialMonit.printf(" Humidity = %d %%\n\r", Humid); |
POTLESS_2 | 29:5b822d18bce6 | 174 | serialMonit.printf("\n\r"); |
POTLESS_2 | 29:5b822d18bce6 | 175 | serialMonit.printf(" Cell O2 n 1 = %d\r\n" , CellO2_1); |
POTLESS_2 | 29:5b822d18bce6 | 176 | serialMonit.printf(" Cell O2 n 2 = %d\r\n" , CellO2_2); |
POTLESS_2 | 29:5b822d18bce6 | 177 | serialMonit.printf("\r\n"); |
POTLESS_2 | 29:5b822d18bce6 | 178 | serialMonit.printf(" Volet Poumon = %f\r\n" , volet_poumon_Position); |
POTLESS_2 | 29:5b822d18bce6 | 179 | serialMonit.printf(" Volet Fuite = %f\r\n" , volet_fuite_Position); |
POTLESS_2 | 29:5b822d18bce6 | 180 | serialMonit.printf("\r\n"); |
POTLESS_2 | 29:5b822d18bce6 | 181 | serialMonit.printf(" Temps d execution de la boucle = %f seconde(s)\n", (RATE + RATE_TRUE / 1000)); |
POTLESS_2 | 29:5b822d18bce6 | 182 | serialMonit.printf("\r\n"); |
POTLESS_2 | 30:7a16a66d76f3 | 183 | if (FLAG_REC) serialMonit.printf(" Chaine enregistrée = %s\n", to_store); |
POTLESS_2 | 30:7a16a66d76f3 | 184 | else serialMonit.printf(" Pas d'enregistrement en cours."); |
POTLESS_2 | 29:5b822d18bce6 | 185 | serialMonit.printf("\r\n"); |
POTLESS_2 | 29:5b822d18bce6 | 186 | serialMonit.printf(" V_USB = %f", Vusb); |
POTLESS_2 | 29:5b822d18bce6 | 187 | serialMonit.printf("\r\n\r\n"); |
POTLESS_2 | 29:5b822d18bce6 | 188 | fflush(stdout); |
POTLESS_2 | 29:5b822d18bce6 | 189 | } |
POTLESS_2 | 29:5b822d18bce6 | 190 | |
POTLESS_2 | 21:b8900130ca05 | 191 | void pressed() { |
POTLESS_2 | 23:7477dc855fad | 192 | GO = GO + 1; |
POTLESS_2 | 24:44ef919899c1 | 193 | if (GO > 1) NVIC_SystemReset(); |
POTLESS_2 | 21:b8900130ca05 | 194 | } |
POTLESS_2 | 21:b8900130ca05 | 195 | |
POTLESS_2 | 19:cac3761a5d0b | 196 | //Passage en mode SECU |
POTLESS_2 | 19:cac3761a5d0b | 197 | void Mode_SECU() |
POTLESS_2 | 18:bfd78c05b589 | 198 | { |
POTLESS_2 | 19:cac3761a5d0b | 199 | #ifdef PID_MODE |
POTLESS_2 | 18:bfd78c05b589 | 200 | //Mise du PID en mode manuel (desactivation...) |
POTLESS_2 | 18:bfd78c05b589 | 201 | control_Servo.setMode(MANUAL_MODE); |
POTLESS_2 | 18:bfd78c05b589 | 202 | #endif |
POTLESS_2 | 19:cac3761a5d0b | 203 | Consigne_poumon = HOME_SERVO_POUMON; |
POTLESS_2 | 19:cac3761a5d0b | 204 | Consigne_fuite = HOME_SERVO_FUITE; |
POTLESS_2 | 25:322ef9488e65 | 205 | |
POTLESS_2 | 25:322ef9488e65 | 206 | Volets_Speed = 0.1; |
POTLESS_2 | 25:322ef9488e65 | 207 | Volet_DeadBand = 10; |
POTLESS_2 | 25:322ef9488e65 | 208 | |
POTLESS_2 | 19:cac3761a5d0b | 209 | while(1) { |
POTLESS_2 | 25:322ef9488e65 | 210 | wait_ms(100); |
POTLESS_2 | 19:cac3761a5d0b | 211 | if (Servo_Poumon.Pos_OK() == true) break; |
POTLESS_2 | 19:cac3761a5d0b | 212 | //if (Servo_Poumon.Pos_OK() == true && Servo_Fuite.Pos_OK() == true) break; |
POTLESS_2 | 19:cac3761a5d0b | 213 | } |
POTLESS_2 | 33:f5d4bae05f16 | 214 | DEBUG("-------------- Appareil en mode SECU ---------------\r\n"); |
POTLESS_2 | 25:322ef9488e65 | 215 | |
POTLESS_2 | 25:322ef9488e65 | 216 | wait_ms(100); |
POTLESS_2 | 25:322ef9488e65 | 217 | |
POTLESS_2 | 19:cac3761a5d0b | 218 | EN_MODE_SECU = true; |
POTLESS_2 | 25:322ef9488e65 | 219 | wait_ms(100); |
POTLESS_2 | 19:cac3761a5d0b | 220 | int Pos = Servo_Poumon.getPulses(); |
POTLESS_2 | 19:cac3761a5d0b | 221 | UTILS::Store_A_Val((float)Pos, "Servo_Poumon"); |
POTLESS_2 | 33:f5d4bae05f16 | 222 | DEBUG(" position volet poumon sauvegardée = %d pulse(s)\r\n", Pos); |
POTLESS_2 | 19:cac3761a5d0b | 223 | //Pos = Servo_Fuite.getPulses(); |
POTLESS_2 | 19:cac3761a5d0b | 224 | //UTILS::Store_A_Val((float)Pos, "Servo_Fuite"); |
POTLESS_2 | 33:f5d4bae05f16 | 225 | //DEBUG(" position volet fuite sauvegardée = %d pulse(s)\r\n", Pos); |
POTLESS_2 | 29:5b822d18bce6 | 226 | UTILS::UnMount_Flash(); |
POTLESS_2 | 23:7477dc855fad | 227 | Servo_Poumon.Sleep(); |
POTLESS_2 | 19:cac3761a5d0b | 228 | } |
POTLESS_2 | 19:cac3761a5d0b | 229 | |
POTLESS_2 | 19:cac3761a5d0b | 230 | //Sequence d'arrêt |
POTLESS_2 | 19:cac3761a5d0b | 231 | void Stop_Sequence() |
POTLESS_2 | 29:5b822d18bce6 | 232 | { |
POTLESS_2 | 26:a2fe19341f92 | 233 | Mode_SECU(); |
POTLESS_2 | 33:f5d4bae05f16 | 234 | DEBUG("----------------ARRET DE L'APPAREIL--------------------\r\n"); |
POTLESS_2 | 29:5b822d18bce6 | 235 | |
POTLESS_2 | 33:f5d4bae05f16 | 236 | DEBUG(" Deep sleep autorisé : %i\r\n", sleep_manager_can_deep_sleep()); |
POTLESS_2 | 29:5b822d18bce6 | 237 | wait(1.0); |
POTLESS_2 | 29:5b822d18bce6 | 238 | sleep_manager_sleep_auto(); |
POTLESS_2 | 18:bfd78c05b589 | 239 | } |
POTLESS_2 | 18:bfd78c05b589 | 240 | |
POTLESS_2 | 31:231a96d1d1c8 | 241 | //Fonction test de valeur d'entrée digitale |
POTLESS_2 | 29:5b822d18bce6 | 242 | int Power_Test(DigitalIn& pin) |
POTLESS_2 | 20:5f79fb4565a7 | 243 | { |
POTLESS_2 | 29:5b822d18bce6 | 244 | pin.mode(PullDown); |
POTLESS_2 | 29:5b822d18bce6 | 245 | |
POTLESS_2 | 29:5b822d18bce6 | 246 | if(!pin){ |
POTLESS_2 | 29:5b822d18bce6 | 247 | Stop_Sequence(); |
POTLESS_2 | 29:5b822d18bce6 | 248 | return 0; |
POTLESS_2 | 29:5b822d18bce6 | 249 | }else{ |
POTLESS_2 | 29:5b822d18bce6 | 250 | return 1; |
POTLESS_2 | 29:5b822d18bce6 | 251 | } |
POTLESS_2 | 20:5f79fb4565a7 | 252 | } |
POTLESS_2 | 20:5f79fb4565a7 | 253 | |
POTLESS_2 | 31:231a96d1d1c8 | 254 | //Fonction test de valeur d'entrée analogique |
POTLESS_2 | 31:231a96d1d1c8 | 255 | float Power_Test(AnalogIn& pin) |
POTLESS_2 | 31:231a96d1d1c8 | 256 | { |
POTLESS_2 | 31:231a96d1d1c8 | 257 | float Val = pin.read(); |
POTLESS_2 | 31:231a96d1d1c8 | 258 | return Val; |
POTLESS_2 | 31:231a96d1d1c8 | 259 | } |
POTLESS_2 | 31:231a96d1d1c8 | 260 | |
POTLESS_2 | 18:bfd78c05b589 | 261 | //Contrôle du status de l'appareil / des constantes |
POTLESS_2 | 18:bfd78c05b589 | 262 | bool Check() |
POTLESS_2 | 18:bfd78c05b589 | 263 | { |
POTLESS_2 | 18:bfd78c05b589 | 264 | if (ppO2 > 100) |
POTLESS_2 | 19:cac3761a5d0b | 265 | return true;//Situation OK |
POTLESS_2 | 18:bfd78c05b589 | 266 | else |
POTLESS_2 | 19:cac3761a5d0b | 267 | return false;//Situation dégradée |
POTLESS_2 | 18:bfd78c05b589 | 268 | } |
POTLESS_2 | 18:bfd78c05b589 | 269 | |
POTLESS_2 | 18:bfd78c05b589 | 270 | //Calcul des OTU |
POTLESS_2 | 18:bfd78c05b589 | 271 | float Calcul_OTU() |
POTLESS_2 | 18:bfd78c05b589 | 272 | { |
POTLESS_2 | 18:bfd78c05b589 | 273 | /* |
POTLESS_2 | 18:bfd78c05b589 | 274 | La formule suivante permet de calculer la quantité d' OTU accumulée |
POTLESS_2 | 18:bfd78c05b589 | 275 | OTU = T * (2* PpO2 -1)0,83 |
POTLESS_2 | 18:bfd78c05b589 | 276 | avec : |
POTLESS_2 | 18:bfd78c05b589 | 277 | T = temps de plongée en minutes |
POTLESS_2 | 18:bfd78c05b589 | 278 | PpO2 = pression partielle d’ oxygène en bars |
POTLESS_2 | 18:bfd78c05b589 | 279 | */ |
POTLESS_2 | 18:bfd78c05b589 | 280 | |
POTLESS_2 | 19:cac3761a5d0b | 281 | if (ppO2 > 500) { |
POTLESS_2 | 18:bfd78c05b589 | 282 | float val = (2 * (float)ppO2/1000 - 1);//je divise par 1000 car la PP est en mb... |
POTLESS_2 | 18:bfd78c05b589 | 283 | OTU += Ref_Time * pow(val, COEF_OTU); |
POTLESS_2 | 19:cac3761a5d0b | 284 | } |
POTLESS_2 | 18:bfd78c05b589 | 285 | } |
POTLESS_2 | 10:aca745a66d51 | 286 | |
POTLESS_2 | 17:bef8abc445f2 | 287 | //Thread d'intérogation des capteurs, positions servo |
POTLESS_2 | 10:aca745a66d51 | 288 | void Get_Info_thread() |
POTLESS_2 | 6:ebed9093d661 | 289 | { |
POTLESS_2 | 7:ad15c386e960 | 290 | while (true) { |
POTLESS_2 | 7:ad15c386e960 | 291 | |
POTLESS_2 | 7:ad15c386e960 | 292 | //CO2 sur Cozir |
POTLESS_2 | 7:ad15c386e960 | 293 | co2 = sensors.requestCO2(); |
POTLESS_2 | 7:ad15c386e960 | 294 | //P / T sur MS5837 |
POTLESS_2 | 7:ad15c386e960 | 295 | pression = sensors.requestPress(); |
POTLESS_2 | 9:04bfdfc029cb | 296 | Temp1 = sensors.requestTemp(); |
POTLESS_2 | 7:ad15c386e960 | 297 | //PPO2 sur ADS1015 |
POTLESS_2 | 33:f5d4bae05f16 | 298 | if (FLAG_O2) ppO2 = sensors.requestPpO2(); |
POTLESS_2 | 7:ad15c386e960 | 299 | //Cell O2 en mV |
POTLESS_2 | 33:f5d4bae05f16 | 300 | if (FLAG_O2) CellO2_1 = sensors.requestCellO2_1(); |
POTLESS_2 | 33:f5d4bae05f16 | 301 | if (FLAG_O2) CellO2_2 = sensors.requestCellO2_2(); |
POTLESS_2 | 9:04bfdfc029cb | 302 | |
POTLESS_2 | 8:a750d531b381 | 303 | //HTU21D |
POTLESS_2 | 9:04bfdfc029cb | 304 | Temp2 = temphumid.sample_ctemp(); |
POTLESS_2 | 9:04bfdfc029cb | 305 | Humid = temphumid.sample_humid(); |
POTLESS_2 | 9:04bfdfc029cb | 306 | |
POTLESS_2 | 10:aca745a66d51 | 307 | //Retour position des servos |
POTLESS_2 | 17:bef8abc445f2 | 308 | volet_poumon_Position = Servo_Poumon.Get_Position(); |
POTLESS_2 | 20:5f79fb4565a7 | 309 | //volet_fuite_Position = Servo_Fuite.Get_Position(); |
POTLESS_2 | 22:555c2930e8e0 | 310 | |
POTLESS_2 | 19:cac3761a5d0b | 311 | } |
POTLESS_2 | 19:cac3761a5d0b | 312 | } |
POTLESS_2 | 12:7f3aadd79f89 | 313 | |
POTLESS_2 | 19:cac3761a5d0b | 314 | void GO_TO_thread() |
POTLESS_2 | 19:cac3761a5d0b | 315 | { |
POTLESS_2 | 19:cac3761a5d0b | 316 | while (true) { |
POTLESS_2 | 19:cac3761a5d0b | 317 | //Servo_Poumon.Go_To_Prop(Consigne_poumon); |
POTLESS_2 | 26:a2fe19341f92 | 318 | //Servo_Poumon.Go_To_PID(Consigne_poumon, Volet_DeadBand); |
POTLESS_2 | 25:322ef9488e65 | 319 | Servo_Poumon.Go_To(Consigne_poumon, Volets_Speed, Volet_DeadBand ); |
POTLESS_2 | 20:5f79fb4565a7 | 320 | |
POTLESS_2 | 19:cac3761a5d0b | 321 | //Servo_Fuite.Go_To_Prop(Consigne_fuite); |
POTLESS_2 | 19:cac3761a5d0b | 322 | //Servo_Fuite.Go_To_PID(Consigne_fuite); |
POTLESS_2 | 29:5b822d18bce6 | 323 | //Servo_Fuite.Go_To(Consigne_fuite, Volets_Speed, Volet_DeadBand ); |
POTLESS_2 | 15:efd3b3bf3f37 | 324 | } |
potless | 2:4a8bf1d53439 | 325 | } |
POTLESS_2 | 4:d84250f67dec | 326 | |
POTLESS_2 | 20:5f79fb4565a7 | 327 | void SECU_thread() |
POTLESS_2 | 20:5f79fb4565a7 | 328 | { |
POTLESS_2 | 20:5f79fb4565a7 | 329 | while (true) { |
POTLESS_2 | 20:5f79fb4565a7 | 330 | //Alim USB |
POTLESS_2 | 33:f5d4bae05f16 | 331 | //Vusb = Power_Test(V_USB); |
POTLESS_2 | 33:f5d4bae05f16 | 332 | //VPiles = Power_Test(V_PILES); |
POTLESS_2 | 20:5f79fb4565a7 | 333 | //Divers problèmes à implémenter |
POTLESS_2 | 20:5f79fb4565a7 | 334 | //if(!Check()) Mode_SECU(); |
POTLESS_2 | 20:5f79fb4565a7 | 335 | } |
POTLESS_2 | 20:5f79fb4565a7 | 336 | } |
POTLESS_2 | 20:5f79fb4565a7 | 337 | |
POTLESS_2 | 11:b2feed92584a | 338 | //Callback de l'intérruption des envois de commandes depuis le terminal |
POTLESS_2 | 6:ebed9093d661 | 339 | void callbackParam() |
POTLESS_2 | 29:5b822d18bce6 | 340 | { |
POTLESS_2 | 29:5b822d18bce6 | 341 | while(serialMonit.readable()) |
POTLESS_2 | 29:5b822d18bce6 | 342 | { |
POTLESS_2 | 29:5b822d18bce6 | 343 | if ((indexParam == sizeParam) || newParamFlag == true) //éviter la saturation du buffer |
POTLESS_2 | 29:5b822d18bce6 | 344 | char char_flush = serialMonit.getc(); |
POTLESS_2 | 29:5b822d18bce6 | 345 | else |
POTLESS_2 | 29:5b822d18bce6 | 346 | param [indexParam ++] = serialMonit.getc();//chargement du buffer dans le message |
POTLESS_2 | 29:5b822d18bce6 | 347 | |
POTLESS_2 | 29:5b822d18bce6 | 348 | if ((indexParam == sizeParam) || (param[indexParam - 1] == '\n')) {//le message est complet ou nouvelle ligne ou autre si on veut... |
POTLESS_2 | 29:5b822d18bce6 | 349 | param[indexParam] = 0; |
POTLESS_2 | 29:5b822d18bce6 | 350 | newParamFlag = true; |
POTLESS_2 | 29:5b822d18bce6 | 351 | } |
POTLESS_2 | 29:5b822d18bce6 | 352 | } |
POTLESS_2 | 6:ebed9093d661 | 353 | } |
POTLESS_2 | 4:d84250f67dec | 354 | |
POTLESS_2 | 9:04bfdfc029cb | 355 | //Callback de l'intérruption des envois de commandes depuis Android |
POTLESS_2 | 9:04bfdfc029cb | 356 | void callbackAndroid() |
POTLESS_2 | 9:04bfdfc029cb | 357 | { |
POTLESS_2 | 9:04bfdfc029cb | 358 | while(android.readable()) { |
POTLESS_2 | 9:04bfdfc029cb | 359 | if (indexAndroid == sizeAndroid) //éviter la saturation du buffer |
POTLESS_2 | 9:04bfdfc029cb | 360 | android.getc(); |
POTLESS_2 | 9:04bfdfc029cb | 361 | else |
POTLESS_2 | 9:04bfdfc029cb | 362 | Android [indexAndroid++] = android.getc();//chargement du buffer dans le message |
POTLESS_2 | 9:04bfdfc029cb | 363 | if ((indexAndroid == sizeAndroid) || (Android[indexAndroid -1] == '\n')) {//le message est complet ou nouvelle ligne ou autre si on veut... |
POTLESS_2 | 9:04bfdfc029cb | 364 | Android[indexAndroid] = 0; |
POTLESS_2 | 9:04bfdfc029cb | 365 | newAndroidFlag = true; |
POTLESS_2 | 9:04bfdfc029cb | 366 | } |
POTLESS_2 | 9:04bfdfc029cb | 367 | } |
POTLESS_2 | 9:04bfdfc029cb | 368 | } |
POTLESS_2 | 11:b2feed92584a | 369 | |
POTLESS_2 | 9:04bfdfc029cb | 370 | void Decoding_Message(char message []) |
POTLESS_2 | 9:04bfdfc029cb | 371 | { |
POTLESS_2 | 9:04bfdfc029cb | 372 | |
POTLESS_2 | 29:5b822d18bce6 | 373 | char com[sizeParam] = ""; |
POTLESS_2 | 29:5b822d18bce6 | 374 | float val = 0.0; |
POTLESS_2 | 29:5b822d18bce6 | 375 | |
POTLESS_2 | 29:5b822d18bce6 | 376 | sscanf(message,"%s %f",&com , &val); |
POTLESS_2 | 29:5b822d18bce6 | 377 | |
POTLESS_2 | 33:f5d4bae05f16 | 378 | DEBUG("\r\n Commande = %s Valeur = %f \r\n\r\n", com, val); |
POTLESS_2 | 9:04bfdfc029cb | 379 | |
POTLESS_2 | 30:7a16a66d76f3 | 380 | if (0 == strcmp(com, "secu")) { |
POTLESS_2 | 19:cac3761a5d0b | 381 | Mode_SECU(); |
POTLESS_2 | 30:7a16a66d76f3 | 382 | }else if (0 == strcmp(com, "calib_O2")) { |
POTLESS_2 | 33:f5d4bae05f16 | 383 | FLAG_O2 = false; |
POTLESS_2 | 33:f5d4bae05f16 | 384 | wait_ms(100); |
POTLESS_2 | 33:f5d4bae05f16 | 385 | sensors.Calibrate_O2(true, (int)val); |
POTLESS_2 | 33:f5d4bae05f16 | 386 | wait_ms(100); |
POTLESS_2 | 33:f5d4bae05f16 | 387 | FLAG_O2 = true; |
POTLESS_2 | 31:231a96d1d1c8 | 388 | }else if (0 == strcmp(com, "flash_i")) { |
POTLESS_2 | 31:231a96d1d1c8 | 389 | FLAG_REC = false; |
POTLESS_2 | 31:231a96d1d1c8 | 390 | UTILS::Flash_Infos(); |
POTLESS_2 | 31:231a96d1d1c8 | 391 | FLAG_REC = true; |
POTLESS_2 | 30:7a16a66d76f3 | 392 | }else if (0 == strcmp(com, "check")) { |
POTLESS_2 | 30:7a16a66d76f3 | 393 | FLAG_REC = false; |
POTLESS_2 | 30:7a16a66d76f3 | 394 | serialMonit.printf(" Calibration_O2.txt = %f\r\n", UTILS::Read_A_Val("Calibration_O2")); |
POTLESS_2 | 30:7a16a66d76f3 | 395 | serialMonit.printf(" Servo_Poumon.txt = %d\r\n", (int)UTILS::Read_A_Val("Servo_Poumon")); |
POTLESS_2 | 30:7a16a66d76f3 | 396 | //serialMonit.printf("Servo_Fuite.txt = %d\r\n", (int)UTILS::Read_A_Val("Servo_Fuite"); |
POTLESS_2 | 30:7a16a66d76f3 | 397 | FLAG_REC = true; |
POTLESS_2 | 30:7a16a66d76f3 | 398 | }else if (0 == strcmp(com, "rec")) { |
POTLESS_2 | 30:7a16a66d76f3 | 399 | if (FLAG_REC){ |
POTLESS_2 | 30:7a16a66d76f3 | 400 | FLAG_REC = false; |
POTLESS_2 | 30:7a16a66d76f3 | 401 | serialMonit.printf("Arrêt du Data Logging."); |
POTLESS_2 | 30:7a16a66d76f3 | 402 | }else { |
POTLESS_2 | 30:7a16a66d76f3 | 403 | FLAG_REC = true; |
POTLESS_2 | 30:7a16a66d76f3 | 404 | serialMonit.printf("Démarrage Data Logging dans %s", Log_File_Name);} |
POTLESS_2 | 29:5b822d18bce6 | 405 | }else if (0 == strcmp(com, "help")) { |
POTLESS_2 | 29:5b822d18bce6 | 406 | FLAG_AFF = false; |
POTLESS_2 | 29:5b822d18bce6 | 407 | UTILS::Help(); |
POTLESS_2 | 29:5b822d18bce6 | 408 | }else if (0 == strcmp(com, "start")) { |
POTLESS_2 | 29:5b822d18bce6 | 409 | FLAG_AFF = true; |
POTLESS_2 | 29:5b822d18bce6 | 410 | }else if (0 == strcmp(com, "stop")) { |
POTLESS_2 | 29:5b822d18bce6 | 411 | FLAG_AFF = false; |
POTLESS_2 | 29:5b822d18bce6 | 412 | UTILS::Help(); |
POTLESS_2 | 29:5b822d18bce6 | 413 | }else if (0 == strcmp(com, "clean")) { |
POTLESS_2 | 29:5b822d18bce6 | 414 | FLAG_REC = false; |
POTLESS_2 | 29:5b822d18bce6 | 415 | UTILS::Clean_Flash(); |
POTLESS_2 | 29:5b822d18bce6 | 416 | }else if (0 == strcmp(com, "dir")) { |
POTLESS_2 | 29:5b822d18bce6 | 417 | FLAG_REC = false; |
POTLESS_2 | 29:5b822d18bce6 | 418 | UTILS::Dir_Flash(); |
POTLESS_2 | 29:5b822d18bce6 | 419 | FLAG_REC = true; |
POTLESS_2 | 29:5b822d18bce6 | 420 | }else if (0 == strcmp(com, "get")) { |
POTLESS_2 | 29:5b822d18bce6 | 421 | FLAG_REC = false; |
POTLESS_2 | 29:5b822d18bce6 | 422 | wait_ms(100); |
POTLESS_2 | 26:a2fe19341f92 | 423 | char filename[20]; |
POTLESS_2 | 29:5b822d18bce6 | 424 | sprintf(filename, "LOG_%d.txt", (int)val); |
POTLESS_2 | 29:5b822d18bce6 | 425 | UTILS::Read_Flash_File(filename); |
POTLESS_2 | 29:5b822d18bce6 | 426 | wait_ms(100); |
POTLESS_2 | 29:5b822d18bce6 | 427 | FLAG_REC = true; |
POTLESS_2 | 29:5b822d18bce6 | 428 | }else if (0 == strcmp(com, "del")) { |
POTLESS_2 | 29:5b822d18bce6 | 429 | FLAG_REC = false; |
POTLESS_2 | 29:5b822d18bce6 | 430 | char filename[20]; |
POTLESS_2 | 29:5b822d18bce6 | 431 | sprintf(filename, "LOG_%d.txt", (int)val); |
POTLESS_2 | 29:5b822d18bce6 | 432 | UTILS::Delete_Flash_File(filename); |
POTLESS_2 | 29:5b822d18bce6 | 433 | UTILS::Dir_Flash(); |
POTLESS_2 | 31:231a96d1d1c8 | 434 | FLAG_REC = true; |
POTLESS_2 | 31:231a96d1d1c8 | 435 | }else if (0 == strcmp(com, "file_s")) { |
POTLESS_2 | 31:231a96d1d1c8 | 436 | FLAG_REC = false; |
POTLESS_2 | 31:231a96d1d1c8 | 437 | char filename[20]; |
POTLESS_2 | 31:231a96d1d1c8 | 438 | sprintf(filename, "LOG_%d.txt", (int)val); |
POTLESS_2 | 31:231a96d1d1c8 | 439 | UTILS::Get_File_Size(filename); |
POTLESS_2 | 31:231a96d1d1c8 | 440 | FLAG_REC = true; |
POTLESS_2 | 31:231a96d1d1c8 | 441 | //}else if (0 == strcmp(com, "file_i")) { |
POTLESS_2 | 31:231a96d1d1c8 | 442 | // FLAG_REC = false; |
POTLESS_2 | 31:231a96d1d1c8 | 443 | // char filename[20]; |
POTLESS_2 | 31:231a96d1d1c8 | 444 | // sprintf(filename, "LOG_%d.txt", (int)val); |
POTLESS_2 | 31:231a96d1d1c8 | 445 | // UTILS::Get_File_Infos_bis(filename); |
POTLESS_2 | 31:231a96d1d1c8 | 446 | // FLAG_REC = true; |
POTLESS_2 | 29:5b822d18bce6 | 447 | } else if (0 == strcmp(com, "calib_p")) { |
POTLESS_2 | 20:5f79fb4565a7 | 448 | Consigne_poumon = 0; |
POTLESS_2 | 20:5f79fb4565a7 | 449 | volet_poumon_Position = 0; |
POTLESS_2 | 19:cac3761a5d0b | 450 | Servo_Poumon.reset(); |
POTLESS_2 | 29:5b822d18bce6 | 451 | } else if (0 == strcmp(com, "calib_f")) { |
POTLESS_2 | 29:5b822d18bce6 | 452 | Consigne_fuite = 0; |
POTLESS_2 | 29:5b822d18bce6 | 453 | volet_fuite_Position = 0; |
POTLESS_2 | 29:5b822d18bce6 | 454 | //Servo_Fuite.reset(); |
POTLESS_2 | 29:5b822d18bce6 | 455 | } else if (0 == strcmp(com, "sleep")) { |
POTLESS_2 | 19:cac3761a5d0b | 456 | Stop_Sequence(); |
POTLESS_2 | 29:5b822d18bce6 | 457 | } else if (0 == strcmp(com, "time")) {//Depuis terminal MAC taper : " date +%s " |
POTLESS_2 | 29:5b822d18bce6 | 458 | set_time(val); |
POTLESS_2 | 29:5b822d18bce6 | 459 | } else if (0 == strcmp(com, "c_pou")) { |
POTLESS_2 | 29:5b822d18bce6 | 460 | Consigne_poumon = (float)val; |
POTLESS_2 | 33:f5d4bae05f16 | 461 | DEBUG(" Servo Poumon = %f\r\n", Consigne_poumon); |
POTLESS_2 | 29:5b822d18bce6 | 462 | } else if (0 == strcmp(com, "c_fui")) { |
POTLESS_2 | 29:5b822d18bce6 | 463 | Consigne_fuite = (float)val; |
POTLESS_2 | 33:f5d4bae05f16 | 464 | DEBUG(" Servo Fuite = %f\r\n", Consigne_fuite); |
POTLESS_2 | 29:5b822d18bce6 | 465 | } else if (0 == strcmp(com, "reset")) { |
POTLESS_2 | 10:aca745a66d51 | 466 | NVIC_SystemReset(); |
POTLESS_2 | 12:7f3aadd79f89 | 467 | ///////////////////////////////////////// |
POTLESS_2 | 12:7f3aadd79f89 | 468 | //Pour rajouter une commande |
POTLESS_2 | 12:7f3aadd79f89 | 469 | //} else if ((char)commande == 'X') { |
POTLESS_2 | 12:7f3aadd79f89 | 470 | // attribuer à une VARIABLE = valeur; |
POTLESS_2 | 12:7f3aadd79f89 | 471 | // ou une action, avec ou sans valeur |
POTLESS_2 | 12:7f3aadd79f89 | 472 | ///////////////////////////////////////// |
POTLESS_2 | 12:7f3aadd79f89 | 473 | } else { |
POTLESS_2 | 9:04bfdfc029cb | 474 | sensors.cozirSend(message); |
POTLESS_2 | 9:04bfdfc029cb | 475 | } |
POTLESS_2 | 29:5b822d18bce6 | 476 | |
POTLESS_2 | 9:04bfdfc029cb | 477 | strcpy(param," "); |
POTLESS_2 | 9:04bfdfc029cb | 478 | indexParam = 0; |
POTLESS_2 | 9:04bfdfc029cb | 479 | newParamFlag = false; |
POTLESS_2 | 9:04bfdfc029cb | 480 | } |
POTLESS_2 | 9:04bfdfc029cb | 481 | |
POTLESS_2 | 9:04bfdfc029cb | 482 | void Decoding_Message_Android(char message []) |
POTLESS_2 | 9:04bfdfc029cb | 483 | { |
POTLESS_2 | 9:04bfdfc029cb | 484 | char *commande = 0; |
POTLESS_2 | 14:b5e0e882205e | 485 | float valeur = 0; |
POTLESS_2 | 9:04bfdfc029cb | 486 | |
POTLESS_2 | 14:b5e0e882205e | 487 | sscanf(message,"%s %f",&commande , &valeur); |
POTLESS_2 | 9:04bfdfc029cb | 488 | |
POTLESS_2 | 9:04bfdfc029cb | 489 | if ((char)commande == 'T') { |
POTLESS_2 | 9:04bfdfc029cb | 490 | set_time(valeur); |
POTLESS_2 | 12:7f3aadd79f89 | 491 | } else if ((char)commande == 'I') { |
POTLESS_2 | 17:bef8abc445f2 | 492 | Consigne_poumon = (float)valeur; |
POTLESS_2 | 33:f5d4bae05f16 | 493 | DEBUG(" Servo Poumon = %f\r\n", Consigne_poumon); |
POTLESS_2 | 12:7f3aadd79f89 | 494 | } else if ((char)commande == 'O') { |
POTLESS_2 | 17:bef8abc445f2 | 495 | Consigne_fuite = (float)valeur; |
POTLESS_2 | 33:f5d4bae05f16 | 496 | DEBUG(" Servo Fuite = %f\r\n", Consigne_fuite); |
POTLESS_2 | 12:7f3aadd79f89 | 497 | ///////////////////////////////////////// |
POTLESS_2 | 12:7f3aadd79f89 | 498 | //Pour rajouter une commande |
POTLESS_2 | 12:7f3aadd79f89 | 499 | //} else if ((char)commande == 'X') { |
POTLESS_2 | 12:7f3aadd79f89 | 500 | // attribuer à une VARIABLE = valeur; |
POTLESS_2 | 12:7f3aadd79f89 | 501 | // ou une action, avec ou sans valeur |
POTLESS_2 | 12:7f3aadd79f89 | 502 | ///////////////////////////////////////// |
POTLESS_2 | 9:04bfdfc029cb | 503 | } else if ((char)commande == 'R') { |
POTLESS_2 | 9:04bfdfc029cb | 504 | NVIC_SystemReset(); |
POTLESS_2 | 9:04bfdfc029cb | 505 | } |
POTLESS_2 | 12:7f3aadd79f89 | 506 | #ifdef PID_MODE |
POTLESS_2 | 12:7f3aadd79f89 | 507 | else if ((char)commande == 'p') { |
POTLESS_2 | 12:7f3aadd79f89 | 508 | Kc = (float)valeur; |
POTLESS_2 | 16:917656586772 | 509 | control_Servo.reset(); |
POTLESS_2 | 12:7f3aadd79f89 | 510 | control_Servo.setTunings(Kc, Ti, Td); |
POTLESS_2 | 33:f5d4bae05f16 | 511 | DEBUG" UPDATE PID --> Kc = %f Ti = %f Td = %f\r\n\n", Kc, Ti, Td); |
POTLESS_2 | 15:efd3b3bf3f37 | 512 | } else if ((char)commande == 'i') { |
POTLESS_2 | 12:7f3aadd79f89 | 513 | Ti = (float)valeur; |
POTLESS_2 | 16:917656586772 | 514 | control_Servo.reset(); |
POTLESS_2 | 12:7f3aadd79f89 | 515 | control_Servo.setTunings(Kc, Ti, Td); |
POTLESS_2 | 33:f5d4bae05f16 | 516 | DEBUG(" UPDATE PID --> Kc = %f Ti = %f Td = %f\r\n\n", Kc, Ti, Td); |
POTLESS_2 | 15:efd3b3bf3f37 | 517 | } else if ((char)commande == 'd') { |
POTLESS_2 | 12:7f3aadd79f89 | 518 | Td = (float)valeur; |
POTLESS_2 | 16:917656586772 | 519 | control_Servo.reset(); |
POTLESS_2 | 12:7f3aadd79f89 | 520 | control_Servo.setTunings(Kc, Ti, Td); |
POTLESS_2 | 33:f5d4bae05f16 | 521 | DEBUG(" UPDATE PID --> Kc = %f Ti = %f Td = %f\r\n\n", Kc, Ti, Td); |
POTLESS_2 | 15:efd3b3bf3f37 | 522 | } else if ((char)commande == 'c') { |
POTLESS_2 | 12:7f3aadd79f89 | 523 | consigne = valeur; |
POTLESS_2 | 15:efd3b3bf3f37 | 524 | control_Servo.setSetPoint(consigne); |
POTLESS_2 | 33:f5d4bae05f16 | 525 | DEBUG(" UPDATE CONSIGNE PID --> Consigne = %d\r\n\n", consigne); |
POTLESS_2 | 12:7f3aadd79f89 | 526 | } |
POTLESS_2 | 15:efd3b3bf3f37 | 527 | #endif |
POTLESS_2 | 18:bfd78c05b589 | 528 | |
POTLESS_2 | 9:04bfdfc029cb | 529 | strcpy(Android," "); |
POTLESS_2 | 9:04bfdfc029cb | 530 | indexAndroid = 0; |
POTLESS_2 | 9:04bfdfc029cb | 531 | newAndroidFlag = false; |
POTLESS_2 | 9:04bfdfc029cb | 532 | } |
POTLESS_2 | 9:04bfdfc029cb | 533 | |
POTLESS_2 | 26:a2fe19341f92 | 534 | void Create_File_Name_Date() |
POTLESS_2 | 25:322ef9488e65 | 535 | { |
POTLESS_2 | 25:322ef9488e65 | 536 | //Du nom du fichier Date / heure |
POTLESS_2 | 25:322ef9488e65 | 537 | seconds = time(NULL); |
POTLESS_2 | 25:322ef9488e65 | 538 | char Time[40]; |
POTLESS_2 | 25:322ef9488e65 | 539 | strftime(Time, 40, "%a_%d_%m_%Y_%H%M", localtime(&seconds)); |
POTLESS_2 | 25:322ef9488e65 | 540 | sprintf(Log_File_Name, "%s_LOG.txt", Time); |
POTLESS_2 | 33:f5d4bae05f16 | 541 | DEBUG("Nouveau fichier LOG = %s \r\n", Log_File_Name); |
POTLESS_2 | 25:322ef9488e65 | 542 | } |
POTLESS_2 | 25:322ef9488e65 | 543 | |
POTLESS_2 | 26:a2fe19341f92 | 544 | void Create_File_Name_Index() |
POTLESS_2 | 26:a2fe19341f92 | 545 | { |
POTLESS_2 | 26:a2fe19341f92 | 546 | //Du nom du fichier par Index |
POTLESS_2 | 26:a2fe19341f92 | 547 | sprintf(Log_File_Name, "LOG_%d.txt", UTILS::File_Index()); |
POTLESS_2 | 33:f5d4bae05f16 | 548 | DEBUG(" Nouveau fichier LOG = %s \r\n", Log_File_Name); |
POTLESS_2 | 26:a2fe19341f92 | 549 | } |
POTLESS_2 | 26:a2fe19341f92 | 550 | |
POTLESS_2 | 4:d84250f67dec | 551 | int main() |
POTLESS_2 | 12:7f3aadd79f89 | 552 | { |
POTLESS_2 | 29:5b822d18bce6 | 553 | |
POTLESS_2 | 21:b8900130ca05 | 554 | button.fall(&pressed); |
POTLESS_2 | 29:5b822d18bce6 | 555 | |
POTLESS_2 | 21:b8900130ca05 | 556 | int count = 0; |
POTLESS_2 | 25:322ef9488e65 | 557 | |
POTLESS_2 | 21:b8900130ca05 | 558 | while (1) { |
POTLESS_2 | 21:b8900130ca05 | 559 | |
POTLESS_2 | 29:5b822d18bce6 | 560 | if (count == 0) serialMonit.printf("\r\nAppuyez sur le User Button pour commencer...\r\n\r\n"); |
POTLESS_2 | 21:b8900130ca05 | 561 | |
POTLESS_2 | 21:b8900130ca05 | 562 | count = 1; |
POTLESS_2 | 21:b8900130ca05 | 563 | |
POTLESS_2 | 24:44ef919899c1 | 564 | if (GO == 1) { |
POTLESS_2 | 21:b8900130ca05 | 565 | |
POTLESS_2 | 21:b8900130ca05 | 566 | wait(1); |
POTLESS_2 | 21:b8900130ca05 | 567 | |
POTLESS_2 | 19:cac3761a5d0b | 568 | serialMonit.attach(&callbackParam, Serial::RxIrq); |
POTLESS_2 | 12:7f3aadd79f89 | 569 | |
POTLESS_2 | 19:cac3761a5d0b | 570 | android.attach(&callbackAndroid, Serial::RxIrq); |
POTLESS_2 | 12:7f3aadd79f89 | 571 | |
POTLESS_2 | 26:a2fe19341f92 | 572 | //Ci-dessous commande pour formater une nouvelle carte |
POTLESS_2 | 29:5b822d18bce6 | 573 | //UTILS::Format_Flash(); |
POTLESS_2 | 26:a2fe19341f92 | 574 | |
POTLESS_2 | 29:5b822d18bce6 | 575 | //Montage Flash |
POTLESS_2 | 29:5b822d18bce6 | 576 | UTILS::Mount_Flash(); |
POTLESS_2 | 26:a2fe19341f92 | 577 | |
POTLESS_2 | 29:5b822d18bce6 | 578 | //Liste des fichiers sur la Flash |
POTLESS_2 | 29:5b822d18bce6 | 579 | UTILS::Dir_Flash(); |
POTLESS_2 | 26:a2fe19341f92 | 580 | |
POTLESS_2 | 33:f5d4bae05f16 | 581 | bool calib_O2 = true; |
POTLESS_2 | 26:a2fe19341f92 | 582 | bool calib_CO2 = false; |
POTLESS_2 | 26:a2fe19341f92 | 583 | |
POTLESS_2 | 18:bfd78c05b589 | 584 | /* |
POTLESS_2 | 18:bfd78c05b589 | 585 | Par défaut les valeur en cas de calibration sur true sont les suivant |
POTLESS_2 | 18:bfd78c05b589 | 586 | |
POTLESS_2 | 19:cac3761a5d0b | 587 | nbCalibO2 = 5 |
POTLESS_2 | 19:cac3761a5d0b | 588 | Mode = SPOOLING |
POTLESS_2 | 19:cac3761a5d0b | 589 | Filtre = DIGI_FILTER32 |
POTLESS_2 | 19:cac3761a5d0b | 590 | CalibrationCO2 = "CALIB_AIR" |
POTLESS_2 | 18:bfd78c05b589 | 591 | |
POTLESS_2 | 19:cac3761a5d0b | 592 | Parfois la calibration du Cozir coince...faire reset et relancer... |
POTLESS_2 | 6:ebed9093d661 | 593 | |
POTLESS_2 | 19:cac3761a5d0b | 594 | Pour calibrer avec ces paramètres : |
POTLESS_2 | 18:bfd78c05b589 | 595 | |
POTLESS_2 | 19:cac3761a5d0b | 596 | sensors.Sensors_INIT(true, true); |
POTLESS_2 | 18:bfd78c05b589 | 597 | |
POTLESS_2 | 19:cac3761a5d0b | 598 | Pour changer utiliser la syntaxe suivante : |
POTLESS_2 | 18:bfd78c05b589 | 599 | |
POTLESS_2 | 19:cac3761a5d0b | 600 | sensors.Sensors_INIT(true, true, true, 5, SPOOLING, DIGI_FILTER32, CALIB_AIR); |
POTLESS_2 | 18:bfd78c05b589 | 601 | |
POTLESS_2 | 19:cac3761a5d0b | 602 | */ |
POTLESS_2 | 26:a2fe19341f92 | 603 | |
POTLESS_2 | 26:a2fe19341f92 | 604 | sensors.Sensors_INIT(calib_O2, calib_CO2); |
POTLESS_2 | 18:bfd78c05b589 | 605 | |
POTLESS_2 | 19:cac3761a5d0b | 606 | wait(1); |
POTLESS_2 | 25:322ef9488e65 | 607 | |
POTLESS_2 | 27:1b1fd20a2793 | 608 | Servo_Poumon.Init("Servo_Poumon"); |
POTLESS_2 | 29:5b822d18bce6 | 609 | //Servo_Fuite.Init("Servo_Fuite"); |
POTLESS_2 | 27:1b1fd20a2793 | 610 | |
POTLESS_2 | 26:a2fe19341f92 | 611 | //Création du nouveau fichier LOG par index / par date. |
POTLESS_2 | 26:a2fe19341f92 | 612 | Create_File_Name_Index(); |
POTLESS_2 | 26:a2fe19341f92 | 613 | //Create_File_Name_Date() |
POTLESS_2 | 26:a2fe19341f92 | 614 | |
POTLESS_2 | 33:f5d4bae05f16 | 615 | DEBUG(" Demarrage des threads...\r\n\r\n"); |
POTLESS_2 | 6:ebed9093d661 | 616 | |
POTLESS_2 | 18:bfd78c05b589 | 617 | /* |
POTLESS_2 | 15:efd3b3bf3f37 | 618 | |
POTLESS_2 | 18:bfd78c05b589 | 619 | Pour mémoire, les réglage de priorité des thread |
POTLESS_2 | 15:efd3b3bf3f37 | 620 | |
POTLESS_2 | 18:bfd78c05b589 | 621 | osPriorityIdle = -3, ///< priority: idle (lowest) |
POTLESS_2 | 18:bfd78c05b589 | 622 | osPriorityLow = -2, ///< priority: low |
POTLESS_2 | 18:bfd78c05b589 | 623 | osPriorityBelowNormal = -1, ///< priority: below normal |
POTLESS_2 | 18:bfd78c05b589 | 624 | osPriorityNormal = 0, ///< priority: normal (default) |
POTLESS_2 | 18:bfd78c05b589 | 625 | osPriorityAboveNormal = +1, ///< priority: above normal |
POTLESS_2 | 18:bfd78c05b589 | 626 | osPriorityHigh = +2, ///< priority: high |
POTLESS_2 | 18:bfd78c05b589 | 627 | osPriorityRealtime = +3, ///< priority: realtime (highest) |
POTLESS_2 | 18:bfd78c05b589 | 628 | osPriorityError = 0x84 ///< system cannot determine priority or thread has illegal priority |
POTLESS_2 | 18:bfd78c05b589 | 629 | */ |
POTLESS_2 | 18:bfd78c05b589 | 630 | |
POTLESS_2 | 19:cac3761a5d0b | 631 | thread_Sensors.start(Get_Info_thread); |
POTLESS_2 | 19:cac3761a5d0b | 632 | |
POTLESS_2 | 19:cac3761a5d0b | 633 | thread_Sensors.set_priority(osPriorityNormal); |
POTLESS_2 | 21:b8900130ca05 | 634 | |
POTLESS_2 | 21:b8900130ca05 | 635 | wait_ms(300); |
POTLESS_2 | 9:04bfdfc029cb | 636 | |
POTLESS_2 | 19:cac3761a5d0b | 637 | thread_Volets.start(GO_TO_thread); |
POTLESS_2 | 19:cac3761a5d0b | 638 | |
POTLESS_2 | 19:cac3761a5d0b | 639 | thread_Volets.set_priority(osPriorityNormal); |
POTLESS_2 | 20:5f79fb4565a7 | 640 | |
POTLESS_2 | 21:b8900130ca05 | 641 | wait_ms(300); |
POTLESS_2 | 21:b8900130ca05 | 642 | |
POTLESS_2 | 20:5f79fb4565a7 | 643 | thread_Secu.start(SECU_thread); |
POTLESS_2 | 20:5f79fb4565a7 | 644 | |
POTLESS_2 | 20:5f79fb4565a7 | 645 | thread_Secu.set_priority(osPriorityNormal); |
POTLESS_2 | 21:b8900130ca05 | 646 | |
POTLESS_2 | 21:b8900130ca05 | 647 | wait_ms(300); |
POTLESS_2 | 12:7f3aadd79f89 | 648 | |
POTLESS_2 | 12:7f3aadd79f89 | 649 | #ifdef PID_MODE |
POTLESS_2 | 12:7f3aadd79f89 | 650 | //Init PID |
POTLESS_2 | 12:7f3aadd79f89 | 651 | //Entrée PPO2 entre 100 et 1000 mb |
POTLESS_2 | 12:7f3aadd79f89 | 652 | control_Servo.setInputLimits(Min_Input, Max_Input); |
POTLESS_2 | 12:7f3aadd79f89 | 653 | //Sortie servo entre 0 et 100 % |
POTLESS_2 | 12:7f3aadd79f89 | 654 | control_Servo.setOutputLimits(Min_Output, Max_Output); |
POTLESS_2 | 15:efd3b3bf3f37 | 655 | //Mode auto au démarrage |
POTLESS_2 | 12:7f3aadd79f89 | 656 | control_Servo.setMode(AUTO_MODE); |
POTLESS_2 | 12:7f3aadd79f89 | 657 | //Consigne à x mb |
POTLESS_2 | 12:7f3aadd79f89 | 658 | control_Servo.setSetPoint(consigne); |
POTLESS_2 | 15:efd3b3bf3f37 | 659 | #endif |
POTLESS_2 | 25:322ef9488e65 | 660 | |
POTLESS_2 | 33:f5d4bae05f16 | 661 | DEBUG(" Threads démmarés.....\r\n\r\n Tapez help pour voir la liste des commandes disponibles.\r\n "); |
POTLESS_2 | 29:5b822d18bce6 | 662 | |
POTLESS_2 | 7:ad15c386e960 | 663 | while (true) { |
POTLESS_2 | 25:322ef9488e65 | 664 | |
POTLESS_2 | 7:ad15c386e960 | 665 | //Démarrage du Timer mesurant le temps d'éxecution du code |
POTLESS_2 | 7:ad15c386e960 | 666 | REAL_RATE.start(); |
POTLESS_2 | 7:ad15c386e960 | 667 | |
POTLESS_2 | 6:ebed9093d661 | 668 | if (newParamFlag) { |
POTLESS_2 | 33:f5d4bae05f16 | 669 | DEBUG(" From PC = %s\r\n", param); |
POTLESS_2 | 9:04bfdfc029cb | 670 | Decoding_Message(param); |
POTLESS_2 | 9:04bfdfc029cb | 671 | } |
POTLESS_2 | 9:04bfdfc029cb | 672 | |
POTLESS_2 | 9:04bfdfc029cb | 673 | if (newAndroidFlag) { |
POTLESS_2 | 33:f5d4bae05f16 | 674 | DEBUG(" From Android = %s\r\n", Android); |
POTLESS_2 | 9:04bfdfc029cb | 675 | Decoding_Message_Android(Android); |
POTLESS_2 | 6:ebed9093d661 | 676 | } |
POTLESS_2 | 7:ad15c386e960 | 677 | |
POTLESS_2 | 15:efd3b3bf3f37 | 678 | //Fabrication de la chaine Date / heure |
POTLESS_2 | 15:efd3b3bf3f37 | 679 | seconds = time(NULL); |
POTLESS_2 | 15:efd3b3bf3f37 | 680 | char Time_buf[32]; |
POTLESS_2 | 15:efd3b3bf3f37 | 681 | strftime(Time_buf, 32, "%D %I-%M-%S ", localtime(&seconds)); |
POTLESS_2 | 25:322ef9488e65 | 682 | |
POTLESS_2 | 17:bef8abc445f2 | 683 | #ifdef PID_MODE |
POTLESS_2 | 15:efd3b3bf3f37 | 684 | //Fabrication de la chaine à enregistrer |
POTLESS_2 | 17:bef8abc445f2 | 685 | sprintf(to_store,"%s:%d:%d:%.2f:%.2f:%.2f:%d:%d:%d:%.2f:%.2f:%d:%.3f:%.3f:%.3f:%d", |
POTLESS_2 | 15:efd3b3bf3f37 | 686 | Time_buf, |
POTLESS_2 | 15:efd3b3bf3f37 | 687 | co2, |
POTLESS_2 | 15:efd3b3bf3f37 | 688 | ppO2, |
POTLESS_2 | 15:efd3b3bf3f37 | 689 | pression, |
POTLESS_2 | 15:efd3b3bf3f37 | 690 | Temp1, |
POTLESS_2 | 15:efd3b3bf3f37 | 691 | Temp2, |
POTLESS_2 | 15:efd3b3bf3f37 | 692 | Humid, |
POTLESS_2 | 15:efd3b3bf3f37 | 693 | CellO2_1, |
POTLESS_2 | 15:efd3b3bf3f37 | 694 | CellO2_2, |
POTLESS_2 | 15:efd3b3bf3f37 | 695 | volet_poumon_Position, |
POTLESS_2 | 15:efd3b3bf3f37 | 696 | volet_fuite_Position, |
POTLESS_2 | 15:efd3b3bf3f37 | 697 | MODE_FLAG, |
POTLESS_2 | 15:efd3b3bf3f37 | 698 | Kc, |
POTLESS_2 | 15:efd3b3bf3f37 | 699 | Ti, |
POTLESS_2 | 18:bfd78c05b589 | 700 | Td, |
POTLESS_2 | 17:bef8abc445f2 | 701 | (int)consigne |
POTLESS_2 | 18:bfd78c05b589 | 702 | ); |
POTLESS_2 | 17:bef8abc445f2 | 703 | #endif |
POTLESS_2 | 17:bef8abc445f2 | 704 | #ifndef PID_MODE |
POTLESS_2 | 17:bef8abc445f2 | 705 | //Fabrication de la chaine à enregistrer sans les variables du PID |
POTLESS_2 | 17:bef8abc445f2 | 706 | sprintf(to_store,"%s:%d:%d:%.2f:%.2f:%.2f:%d:%d:%d:%.2f:%.2f:%d:%.3f:%.3f:%.3f:%d", |
POTLESS_2 | 17:bef8abc445f2 | 707 | Time_buf, |
POTLESS_2 | 17:bef8abc445f2 | 708 | co2, |
POTLESS_2 | 17:bef8abc445f2 | 709 | ppO2, |
POTLESS_2 | 17:bef8abc445f2 | 710 | pression, |
POTLESS_2 | 17:bef8abc445f2 | 711 | Temp1, |
POTLESS_2 | 17:bef8abc445f2 | 712 | Temp2, |
POTLESS_2 | 17:bef8abc445f2 | 713 | Humid, |
POTLESS_2 | 17:bef8abc445f2 | 714 | CellO2_1, |
POTLESS_2 | 17:bef8abc445f2 | 715 | CellO2_2, |
POTLESS_2 | 17:bef8abc445f2 | 716 | volet_poumon_Position, |
POTLESS_2 | 17:bef8abc445f2 | 717 | volet_fuite_Position, |
POTLESS_2 | 17:bef8abc445f2 | 718 | MODE_FLAG, |
POTLESS_2 | 20:5f79fb4565a7 | 719 | 0.0, |
POTLESS_2 | 20:5f79fb4565a7 | 720 | 0.0, |
POTLESS_2 | 20:5f79fb4565a7 | 721 | 0.0, |
POTLESS_2 | 17:bef8abc445f2 | 722 | 0 |
POTLESS_2 | 18:bfd78c05b589 | 723 | ); |
POTLESS_2 | 17:bef8abc445f2 | 724 | #endif |
POTLESS_2 | 31:231a96d1d1c8 | 725 | char to_slave[50]; |
POTLESS_2 | 31:231a96d1d1c8 | 726 | //Fabrication de la chaine pour l'IHM |
POTLESS_2 | 31:231a96d1d1c8 | 727 | sprintf(to_slave,"%d:%d:%d:%.2f:%.2f:%.2f:%d:%d:%d:%.2f:%.2f\r\n", |
POTLESS_2 | 31:231a96d1d1c8 | 728 | co2, |
POTLESS_2 | 31:231a96d1d1c8 | 729 | ppO2, |
POTLESS_2 | 31:231a96d1d1c8 | 730 | (int)OTU, |
POTLESS_2 | 31:231a96d1d1c8 | 731 | pression, |
POTLESS_2 | 31:231a96d1d1c8 | 732 | Temp1, |
POTLESS_2 | 31:231a96d1d1c8 | 733 | Temp2, |
POTLESS_2 | 31:231a96d1d1c8 | 734 | Humid, |
POTLESS_2 | 31:231a96d1d1c8 | 735 | CellO2_1, |
POTLESS_2 | 31:231a96d1d1c8 | 736 | CellO2_2, |
POTLESS_2 | 31:231a96d1d1c8 | 737 | volet_poumon_Position, |
POTLESS_2 | 31:231a96d1d1c8 | 738 | volet_fuite_Position); |
POTLESS_2 | 31:231a96d1d1c8 | 739 | |
POTLESS_2 | 15:efd3b3bf3f37 | 740 | //Pour Android on ajoute < et > pour décoder l'arrivée du message |
POTLESS_2 | 9:04bfdfc029cb | 741 | if (NEED_ANDROID_OUTPUT == 1) { |
POTLESS_2 | 31:231a96d1d1c8 | 742 | //sprintf(to_android,"<%s>",to_store); |
POTLESS_2 | 31:231a96d1d1c8 | 743 | ANDROID(to_slave); |
POTLESS_2 | 9:04bfdfc029cb | 744 | } |
POTLESS_2 | 15:efd3b3bf3f37 | 745 | |
POTLESS_2 | 18:bfd78c05b589 | 746 | //Calcul des OTU |
POTLESS_2 | 18:bfd78c05b589 | 747 | Calcul_OTU(); |
POTLESS_2 | 19:cac3761a5d0b | 748 | |
POTLESS_2 | 20:5f79fb4565a7 | 749 | //Vers le moniteur série |
POTLESS_2 | 29:5b822d18bce6 | 750 | if (FLAG_AFF) Affichage(); |
POTLESS_2 | 29:5b822d18bce6 | 751 | |
POTLESS_2 | 29:5b822d18bce6 | 752 | //Enregistrement de la chaine |
POTLESS_2 | 29:5b822d18bce6 | 753 | if (FLAG_REC) UTILS::Write_Flash_File(to_store, Log_File_Name); |
POTLESS_2 | 15:efd3b3bf3f37 | 754 | |
POTLESS_2 | 15:efd3b3bf3f37 | 755 | |
POTLESS_2 | 15:efd3b3bf3f37 | 756 | #ifdef PID_MODE |
POTLESS_2 | 15:efd3b3bf3f37 | 757 | //Update du PID |
POTLESS_2 | 15:efd3b3bf3f37 | 758 | control_Servo.setProcessValue(ppO2); |
POTLESS_2 | 19:cac3761a5d0b | 759 | //Nouvelle sortie servo fuite si on est pas en mode SECU |
POTLESS_2 | 19:cac3761a5d0b | 760 | if(!EN_MODE_SECU) Consigne_fuite = control_Servo.compute(); |
POTLESS_2 | 12:7f3aadd79f89 | 761 | #endif |
POTLESS_2 | 15:efd3b3bf3f37 | 762 | |
POTLESS_2 | 7:ad15c386e960 | 763 | //Arrêt du Timer mesurant le temps d'éxecution du code |
POTLESS_2 | 7:ad15c386e960 | 764 | REAL_RATE.stop(); |
POTLESS_2 | 7:ad15c386e960 | 765 | //Définition de la nouvelle valeur du temps d'échantillonage du PID. |
POTLESS_2 | 7:ad15c386e960 | 766 | RATE = REAL_RATE.read(); |
POTLESS_2 | 7:ad15c386e960 | 767 | //Reset du Timer |
POTLESS_2 | 7:ad15c386e960 | 768 | REAL_RATE.reset(); |
POTLESS_2 | 12:7f3aadd79f89 | 769 | |
POTLESS_2 | 16:917656586772 | 770 | //Pour ralentir le code à Ref_Time seconde fixe quelque soit les intéruptions du loop.... |
POTLESS_2 | 18:bfd78c05b589 | 771 | if (Ref_Time > RATE) { |
POTLESS_2 | 18:bfd78c05b589 | 772 | RATE_TRUE = (Ref_Time - RATE) * 1000; |
POTLESS_2 | 18:bfd78c05b589 | 773 | } else { |
POTLESS_2 | 18:bfd78c05b589 | 774 | RATE_TRUE = 0; |
POTLESS_2 | 16:917656586772 | 775 | #ifdef PID_MODE |
POTLESS_2 | 18:bfd78c05b589 | 776 | control_Servo.setInterval(RATE); |
POTLESS_2 | 18:bfd78c05b589 | 777 | #endif |
POTLESS_2 | 33:f5d4bae05f16 | 778 | DEBUG("Pour ralentir le code, Ref_Time doit être supérieur à %f seconde(s)\r\n\n", RATE); |
POTLESS_2 | 16:917656586772 | 779 | } |
POTLESS_2 | 18:bfd78c05b589 | 780 | |
POTLESS_2 | 11:b2feed92584a | 781 | wait_ms(RATE_TRUE); |
POTLESS_2 | 21:b8900130ca05 | 782 | } |
POTLESS_2 | 27:1b1fd20a2793 | 783 | } |
POTLESS_2 | 21:b8900130ca05 | 784 | } |
POTLESS_2 | 4:d84250f67dec | 785 | } |