mbed-os github

Dependencies:   ADS1015 Faulhaber HTU21D_mod MS5837_potless Sensor_Head_RevB_3 USBDevice_dfu Utilsdfu beep

Fork of ARNSRS_testDFU by POTLESS

Committer:
potless
Date:
Thu May 24 23:17:16 2018 +0000
Revision:
49:a7432da60647
Parent:
48:9ceb095f397a
Child:
51:16a055fd287c
avec tentative infructueuse de dfu

Who changed what in which revision?

UserRevisionLine numberNew 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 45:61ba3cc4fc55 13
potless 45:61ba3cc4fc55 14 DigitalOut E5V (PA_4);
POTLESS_2 19:cac3761a5d0b 15 #define PWM_SERVO_POUMON PB_15
POTLESS_2 19:cac3761a5d0b 16 #define nSleep_SERVO_POUMON PC_6
POTLESS_2 19:cac3761a5d0b 17 #define FWD_SERVO_POUMON PB_14
POTLESS_2 19:cac3761a5d0b 18 #define REV_SERVO_POUMON PB_13
POTLESS_2 43:5ae8baf28e32 19 #define Channel_A_SERVO_POUMON PB_2
POTLESS_2 43:5ae8baf28e32 20 #define Channel_B_SERVO_POUMON PB_1
POTLESS_2 19:cac3761a5d0b 21 #define HOME_SERVO_POUMON 0
POTLESS_2 17:bef8abc445f2 22
POTLESS_2 19:cac3761a5d0b 23 #define PWM_SERVO_FUITE PB_10
POTLESS_2 43:5ae8baf28e32 24 #define nSleep_SERVO_FUITE PB_0
POTLESS_2 19:cac3761a5d0b 25 #define FWD_SERVO_FUITE PB_4
POTLESS_2 19:cac3761a5d0b 26 #define REV_SERVO_FUITE PB_5
POTLESS_2 43:5ae8baf28e32 27 #define Channel_A_SERVO_FUITE PC_9
POTLESS_2 43:5ae8baf28e32 28 #define Channel_B_SERVO_FUITE PA_8
POTLESS_2 19:cac3761a5d0b 29 #define HOME_SERVO_FUITE 90
POTLESS_2 17:bef8abc445f2 30
POTLESS_2 43:5ae8baf28e32 31 //Pin de test des alims
POTLESS_2 43:5ae8baf28e32 32 #define PIN_V_PILES_ANALOG PA_1
POTLESS_2 43:5ae8baf28e32 33 #define PIN_V_PILES_DIGI PC_3
POTLESS_2 43:5ae8baf28e32 34 #define PIN_V_USB_DIGI PA_0
POTLESS_2 11:b2feed92584a 35
potless 44:5cd6f84a62ec 36 //#define OUTPUT(...) { NVIC_DisableIRQ(USART3_IRQn); serialMonit.printf(__VA_ARGS__); fflush(stdout);NVIC_EnableIRQ(USART3_IRQn);}
potless 44:5cd6f84a62ec 37 #define OUTPUT(...) { NVIC_DisableIRQ(USART2_IRQn); serialMonit.printf(__VA_ARGS__); fflush(stdout);NVIC_EnableIRQ(USART2_IRQn);}
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 25:322ef9488e65 40 //PinName pwm, PinName nSleep, PinName fwd, PinName rev, PinName channelA, PinName channelB, int pulsesPerRev, int Rapport, Encoding encoding = X2_ENCODING
POTLESS_2 25:322ef9488e65 41 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 43:5ae8baf28e32 42 Faulhaber Servo_Fuite("Servo_Fuite", PWM_SERVO_FUITE, nSleep_SERVO_FUITE, FWD_SERVO_FUITE, REV_SERVO_FUITE, Channel_A_SERVO_FUITE, Channel_B_SERVO_FUITE, 16, 207, Faulhaber::X2_ENCODING);
POTLESS_2 17:bef8abc445f2 43
POTLESS_2 17:bef8abc445f2 44 //Moniteur série, Serial 2
potless 45:61ba3cc4fc55 45 //Serial serialMonit(PC_10, PC_11, 115200); // UART 3 pour windev nucleo - version définitive sur uart3 pour carte ARNSRS
POTLESS_2 47:89a088bc8866 46 //Serial serialMonit(PA_2, PA_3,115200); // UART2 à décommenter pour carte ARNSRS
POTLESS_2 47:89a088bc8866 47
potless 49:a7432da60647 48
POTLESS_2 10:aca745a66d51 49
POTLESS_2 43:5ae8baf28e32 50 //Communication avec l'IHM
POTLESS_2 46:28298df0ac55 51 Serial display(PC_4, PC_5, 115200);
POTLESS_2 43:5ae8baf28e32 52
POTLESS_2 43:5ae8baf28e32 53 //Moniteur pour le debug avec une nucleo, a commenter avec la carte definitive
potless 44:5cd6f84a62ec 54 //Serial serial(USBTX, USBRX, 115200);
POTLESS_2 4:d84250f67dec 55
POTLESS_2 7:ad15c386e960 56 //Init de la lib ARNSRS;
POTLESS_2 7:ad15c386e960 57 SENSOR_HEAD_REV_B sensors;
potless 2:4a8bf1d53439 58
POTLESS_2 34:26f6e3dbefb9 59 //pour Param Venant du PV
POTLESS_2 42:3591ec9903b4 60 const int sizeParam = 50;
POTLESS_2 11:b2feed92584a 61 char param[sizeParam];
POTLESS_2 11:b2feed92584a 62 volatile int indexParam = 0;
POTLESS_2 6:ebed9093d661 63 bool newParamFlag = false;
potless 2:4a8bf1d53439 64
POTLESS_2 43:5ae8baf28e32 65 //Flag PID ON / OFF
POTLESS_2 43:5ae8baf28e32 66 int FLAG_PID = 0;
POTLESS_2 42:3591ec9903b4 67
POTLESS_2 42:3591ec9903b4 68 //Flag pour interrompre l'affichage si on veut...
POTLESS_2 42:3591ec9903b4 69 bool FLAG_AFF = false;
POTLESS_2 25:322ef9488e65 70
POTLESS_2 40:32d89e04ead1 71 //Flag pour envoyer à l'app windev...
POTLESS_2 40:32d89e04ead1 72 bool FLAG_WINDEV = false;
POTLESS_2 40:32d89e04ead1 73
POTLESS_2 43:5ae8baf28e32 74 //Flag pour envoyer à l'IHM...
POTLESS_2 46:28298df0ac55 75 bool FLAG_DISPLAY = true;
POTLESS_2 43:5ae8baf28e32 76
POTLESS_2 29:5b822d18bce6 77 //Flag pour interrompre l'enregistrement si on veut...
POTLESS_2 29:5b822d18bce6 78 bool FLAG_REC = true;
POTLESS_2 29:5b822d18bce6 79
POTLESS_2 33:f5d4bae05f16 80 //Flag pour interrompre les demandes O2 en cours ed calibration...
POTLESS_2 33:f5d4bae05f16 81 bool FLAG_O2 = true;
POTLESS_2 33:f5d4bae05f16 82
POTLESS_2 7:ad15c386e960 83 //Variables de stockage des infos capteurs
POTLESS_2 7:ad15c386e960 84 int co2 = 0;
POTLESS_2 7:ad15c386e960 85 float pression = 0;
POTLESS_2 9:04bfdfc029cb 86 float Temp1 = 0;
POTLESS_2 7:ad15c386e960 87 int ppO2 = 0;
POTLESS_2 7:ad15c386e960 88 int CellO2_1 = 0;
POTLESS_2 7:ad15c386e960 89 int CellO2_2 = 0;
POTLESS_2 36:1f5e2247b073 90
POTLESS_2 18:bfd78c05b589 91 //Variables et constantes OTU
POTLESS_2 18:bfd78c05b589 92 float OTU = 0;
POTLESS_2 18:bfd78c05b589 93 float COEF_OTU = 0.83;
POTLESS_2 18:bfd78c05b589 94
POTLESS_2 17:bef8abc445f2 95 //Mesure du temps d'éxecution du loop
POTLESS_2 7:ad15c386e960 96 Timer REAL_RATE;
POTLESS_2 7:ad15c386e960 97 float RATE = 0;
POTLESS_2 11:b2feed92584a 98 float RATE_TRUE = 0;
POTLESS_2 29:5b822d18bce6 99 float Ref_Time = 2.0; //La durée de la boucle désirée...
POTLESS_2 7:ad15c386e960 100
POTLESS_2 17:bef8abc445f2 101 //HTU21D sur l'I2C
POTLESS_2 8:a750d531b381 102 HTU21D temphumid(PB_9, PB_8); //Temp humid sensor || SDA, SCL
POTLESS_2 9:04bfdfc029cb 103 float Temp2;
POTLESS_2 9:04bfdfc029cb 104 int Humid;
POTLESS_2 9:04bfdfc029cb 105
POTLESS_2 9:04bfdfc029cb 106 //Data LOG
POTLESS_2 9:04bfdfc029cb 107 char to_store[50];
POTLESS_2 9:04bfdfc029cb 108 time_t seconds;
POTLESS_2 25:322ef9488e65 109 char Log_File_Name[] = " ";
POTLESS_2 42:3591ec9903b4 110 int count = 0;
POTLESS_2 42:3591ec9903b4 111 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 112
POTLESS_2 10:aca745a66d51 113 //Contrôle des servos
POTLESS_2 19:cac3761a5d0b 114 float Consigne_poumon = 0;
POTLESS_2 19:cac3761a5d0b 115 float volet_poumon_Position = 0;
POTLESS_2 19:cac3761a5d0b 116 float Consigne_fuite = 0;
POTLESS_2 19:cac3761a5d0b 117 float volet_fuite_Position = 0;
potless 45:61ba3cc4fc55 118 float Volets_Speed = 1;
POTLESS_2 26:a2fe19341f92 119 float Volet_DeadBand = 5;
POTLESS_2 10:aca745a66d51 120
POTLESS_2 12:7f3aadd79f89 121 //Paramètre du PID
POTLESS_2 12:7f3aadd79f89 122 float Kc = 40;
POTLESS_2 12:7f3aadd79f89 123 float Ti = 0;
POTLESS_2 12:7f3aadd79f89 124 float Td = 0;
POTLESS_2 12:7f3aadd79f89 125 float RATE_PID = Ref_Time;
POTLESS_2 12:7f3aadd79f89 126 float Commande_PID;
POTLESS_2 43:5ae8baf28e32 127 int consigne = 210;
POTLESS_2 15:efd3b3bf3f37 128 float Max_Input = 1000;
POTLESS_2 15:efd3b3bf3f37 129 float Min_Input = 80;
POTLESS_2 19:cac3761a5d0b 130 float Max_Output = 85;//Vérifier la valeur pour angle à laisser ouvert...
POTLESS_2 19:cac3761a5d0b 131 float Min_Output = 5;
POTLESS_2 10:aca745a66d51 132
POTLESS_2 12:7f3aadd79f89 133 //Init PID
POTLESS_2 17:bef8abc445f2 134 PID control_Servo(Kc, Ti, Td, RATE_PID);
POTLESS_2 10:aca745a66d51 135
POTLESS_2 19:cac3761a5d0b 136 //Boolean du status de l'appareil, en mode SECU ou nominal
POTLESS_2 19:cac3761a5d0b 137 bool EN_MODE_SECU = false;
POTLESS_2 31:231a96d1d1c8 138
POTLESS_2 31:231a96d1d1c8 139 //Test des alim
POTLESS_2 46:28298df0ac55 140 //DigitalIn V_PILES_DIGI(PIN_V_PILES_DIGI);
POTLESS_2 39:65ff3c4f9675 141
POTLESS_2 43:5ae8baf28e32 142 //Test voltage piles
POTLESS_2 43:5ae8baf28e32 143 AnalogIn V_PILES_ANALOG(PIN_V_PILES_ANALOG);
POTLESS_2 31:231a96d1d1c8 144
POTLESS_2 31:231a96d1d1c8 145 int Vusb = 1;
POTLESS_2 31:231a96d1d1c8 146 int VPiles = 1;
POTLESS_2 43:5ae8baf28e32 147 float VPiles_val = 1;
POTLESS_2 18:bfd78c05b589 148
potless 48:9ceb095f397a 149
POTLESS_2 43:5ae8baf28e32 150 //Interruption pin
POTLESS_2 43:5ae8baf28e32 151 InterruptIn vpile_off_on(PIN_V_PILES_DIGI);
POTLESS_2 43:5ae8baf28e32 152 InterruptIn vusb_off_on(PIN_V_USB_DIGI);
POTLESS_2 21:b8900130ca05 153
POTLESS_2 47:89a088bc8866 154 //Buzzer
POTLESS_2 47:89a088bc8866 155 Beep buzzer(PC_8);
POTLESS_2 47:89a088bc8866 156
potless 49:a7432da60647 157 void __initialize_hardware_early(void){
potless 49:a7432da60647 158 if ( *((unsigned long *) 0x10007FF0) = 0xDEADBEEF ){
potless 49:a7432da60647 159 *((unsigned long *) 0x10007FF0) = 0xCAFEFEED;
potless 49:a7432da60647 160 UTILS::DFU();
potless 49:a7432da60647 161 while(1);
potless 49:a7432da60647 162 } else {
potless 49:a7432da60647 163 USBSerial serialMonit;//( 0x0483 , 0x5740 , 0x0001 , true ) ; A declarer en dur dans la lib
potless 49:a7432da60647 164 SystemInit();}
potless 49:a7432da60647 165 }
potless 49:a7432da60647 166
potless 49:a7432da60647 167
POTLESS_2 47:89a088bc8866 168
POTLESS_2 29:5b822d18bce6 169 void Affichage()
potless 49:a7432da60647 170 {
POTLESS_2 42:3591ec9903b4 171 //serialMonit.printf("\r\n");
POTLESS_2 29:5b822d18bce6 172 serialMonit.printf(" CO2 = %d ppm\r\n" , co2);
POTLESS_2 29:5b822d18bce6 173 serialMonit.printf(" PPO2 = %d mb\r\n", ppO2);
POTLESS_2 31:231a96d1d1c8 174 serialMonit.printf(" OTU = %d \r\n", (int)OTU);
POTLESS_2 29:5b822d18bce6 175 serialMonit.printf(" Pression = %f msw\r\n", pression);
POTLESS_2 29:5b822d18bce6 176 serialMonit.printf(" Temp MS5837 = %f C\r\n", Temp1);
POTLESS_2 29:5b822d18bce6 177 serialMonit.printf(" Temp HTU21D = %f C\n\r", Temp2);
POTLESS_2 29:5b822d18bce6 178 serialMonit.printf(" Humidity = %d %%\n\r", Humid);
POTLESS_2 42:3591ec9903b4 179 //serialMonit.printf("\n\r");
POTLESS_2 29:5b822d18bce6 180 serialMonit.printf(" Cell O2 n 1 = %d\r\n" , CellO2_1);
POTLESS_2 29:5b822d18bce6 181 serialMonit.printf(" Cell O2 n 2 = %d\r\n" , CellO2_2);
POTLESS_2 42:3591ec9903b4 182 //serialMonit.printf("\r\n");
POTLESS_2 29:5b822d18bce6 183 serialMonit.printf(" Volet Poumon = %f\r\n" , volet_poumon_Position);
POTLESS_2 29:5b822d18bce6 184 serialMonit.printf(" Volet Fuite = %f\r\n" , volet_fuite_Position);
POTLESS_2 42:3591ec9903b4 185 //serialMonit.printf("\r\n");
POTLESS_2 42:3591ec9903b4 186 serialMonit.printf(" Temps d execution de la boucle = %f seconde(s)\r\n", (RATE + RATE_TRUE / 1000));
POTLESS_2 42:3591ec9903b4 187 //serialMonit.printf("\r\n");
POTLESS_2 42:3591ec9903b4 188 if (FLAG_REC) serialMonit.printf(" Chaine enregistrée = %s\r\n", to_store);
POTLESS_2 30:7a16a66d76f3 189 else serialMonit.printf(" Pas d'enregistrement en cours.");
POTLESS_2 42:3591ec9903b4 190 //serialMonit.printf("\r\n");
POTLESS_2 42:3591ec9903b4 191 serialMonit.printf(" V_USB = %f\r\n", Vusb);
POTLESS_2 42:3591ec9903b4 192 //serialMonit.printf("\r\n\r\n");
POTLESS_2 29:5b822d18bce6 193 fflush(stdout);
POTLESS_2 29:5b822d18bce6 194 }
POTLESS_2 29:5b822d18bce6 195
potless 38:fe77b68eec37 196
POTLESS_2 19:cac3761a5d0b 197 //Passage en mode SECU
POTLESS_2 19:cac3761a5d0b 198 void Mode_SECU()
POTLESS_2 18:bfd78c05b589 199 {
POTLESS_2 43:5ae8baf28e32 200
POTLESS_2 18:bfd78c05b589 201 //Mise du PID en mode manuel (desactivation...)
POTLESS_2 18:bfd78c05b589 202 control_Servo.setMode(MANUAL_MODE);
POTLESS_2 43:5ae8baf28e32 203
POTLESS_2 19:cac3761a5d0b 204 Consigne_poumon = HOME_SERVO_POUMON;
POTLESS_2 19:cac3761a5d0b 205 Consigne_fuite = HOME_SERVO_FUITE;
POTLESS_2 34:26f6e3dbefb9 206
POTLESS_2 25:322ef9488e65 207 Volets_Speed = 0.1;
POTLESS_2 25:322ef9488e65 208 Volet_DeadBand = 10;
POTLESS_2 25:322ef9488e65 209
POTLESS_2 47:89a088bc8866 210 /*
POTLESS_2 19:cac3761a5d0b 211 while(1) {
POTLESS_2 25:322ef9488e65 212 wait_ms(100);
POTLESS_2 19:cac3761a5d0b 213 if (Servo_Poumon.Pos_OK() == true) break;
POTLESS_2 43:5ae8baf28e32 214 if (Servo_Fuite.Pos_OK() == true) break;
POTLESS_2 19:cac3761a5d0b 215 }
POTLESS_2 47:89a088bc8866 216 */
POTLESS_2 43:5ae8baf28e32 217
POTLESS_2 43:5ae8baf28e32 218 OUTPUT(" Appareil en mode SECU\r\n");
POTLESS_2 34:26f6e3dbefb9 219
POTLESS_2 25:322ef9488e65 220 wait_ms(100);
POTLESS_2 34:26f6e3dbefb9 221
POTLESS_2 19:cac3761a5d0b 222 EN_MODE_SECU = true;
POTLESS_2 43:5ae8baf28e32 223
POTLESS_2 25:322ef9488e65 224 wait_ms(100);
POTLESS_2 43:5ae8baf28e32 225 int Pos_P = Servo_Poumon.getPulses();
POTLESS_2 43:5ae8baf28e32 226 UTILS::Store_A_Val((float)Pos_P, "Servo_Poumon.sys");
POTLESS_2 43:5ae8baf28e32 227 DEBUG(" position volet poumon sauvegardée = %d pulse(s)\r\n", Pos_P);
POTLESS_2 47:89a088bc8866 228 OUTPUT(" Volet poumon en sécu\r\n");
POTLESS_2 47:89a088bc8866 229
POTLESS_2 43:5ae8baf28e32 230 int Pos_F = Servo_Fuite.getPulses();
POTLESS_2 43:5ae8baf28e32 231 UTILS::Store_A_Val((float)Pos_F, "Servo_Fuite.sys");
POTLESS_2 43:5ae8baf28e32 232 DEBUG(" position volet fuite sauvegardée = %d pulse(s)\r\n", Pos_F);
POTLESS_2 47:89a088bc8866 233 OUTPUT(" Volet fuite en sécu\r\n");
POTLESS_2 47:89a088bc8866 234
POTLESS_2 23:7477dc855fad 235 Servo_Poumon.Sleep();
POTLESS_2 43:5ae8baf28e32 236 Servo_Fuite.Sleep();
POTLESS_2 19:cac3761a5d0b 237 }
POTLESS_2 19:cac3761a5d0b 238
POTLESS_2 19:cac3761a5d0b 239 //Sequence d'arrêt
POTLESS_2 19:cac3761a5d0b 240 void Stop_Sequence()
POTLESS_2 34:26f6e3dbefb9 241 {
POTLESS_2 43:5ae8baf28e32 242 OUTPUT(" Mise en veille de l'appareil.\r\n");
POTLESS_2 43:5ae8baf28e32 243
POTLESS_2 43:5ae8baf28e32 244 wait(1);
POTLESS_2 43:5ae8baf28e32 245
POTLESS_2 34:26f6e3dbefb9 246 Mode_SECU();
POTLESS_2 47:89a088bc8866 247
POTLESS_2 47:89a088bc8866 248 wait(1);
POTLESS_2 39:65ff3c4f9675 249 //ejection de la flash pour pas crasher le system de fichiers
POTLESS_2 39:65ff3c4f9675 250 UTILS::UnMount_Flash();
POTLESS_2 47:89a088bc8866 251
POTLESS_2 47:89a088bc8866 252 OUTPUT(" Ejection de la Flash\r\n");
POTLESS_2 47:89a088bc8866 253 wait(1);
POTLESS_2 47:89a088bc8866 254 buzzer.beep(1000,0.5);
POTLESS_2 47:89a088bc8866 255 wait(1);
potless 37:f9461c6592f2 256 // préparation deepsleep
POTLESS_2 40:32d89e04ead1 257
potless 37:f9461c6592f2 258 /*
potless 37:f9461c6592f2 259 //première méthode mais je ne sais pas ce que ça consomme et il faut normalement reduire le frequence d'horloge avant
potless 37:f9461c6592f2 260 //il est possible que ça génère un plantage et la rtc ne fonctionnera pas?
potless 37:f9461c6592f2 261 HAL_PWREx_EnableLowPowerRunMode();
potless 37:f9461c6592f2 262 DEBUG("----------------LOW POWER RUN MODE--------------------\r\n");
POTLESS_2 40:32d89e04ead1 263
potless 37:f9461c6592f2 264 bool isDSallowed;
potless 37:f9461c6592f2 265 isDSallowed = sleep_manager_can_deep_sleep();
potless 37:f9461c6592f2 266 DEBUG(" Deep sleep autorisé ? %i\r\n", isDSallowed);
potless 37:f9461c6592f2 267 wait(1.0);
POTLESS_2 34:26f6e3dbefb9 268
potless 37:f9461c6592f2 269 DEBUG("\n\r Deepsleep tentative normale !(bouton bleu pour ressortir)\n");
potless 37:f9461c6592f2 270 wait(0.1);
POTLESS_2 40:32d89e04ead1 271
potless 37:f9461c6592f2 272 sleep_manager_sleep_auto(); // ne marche pas, je ne sais pas pk
potless 37:f9461c6592f2 273 */
POTLESS_2 47:89a088bc8866 274
POTLESS_2 39:65ff3c4f9675 275 /*
potless 38:fe77b68eec37 276 HAL_PWR_DisableWakeUpPin(PWR_WAKEUP_PIN2); // pour PC_13
POTLESS_2 40:32d89e04ead1 277 // Clear wake up Flag
POTLESS_2 40:32d89e04ead1 278 __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WUF2);
POTLESS_2 40:32d89e04ead1 279 // Enable wakeup pin WKUP2
potless 38:fe77b68eec37 280 HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN2_LOW); // low parce qu'on veut que ça redémarre avec le user button TODO à passer sur High pour que ça redémarrage avec l'arrivée du hus sur l'USB
POTLESS_2 39:65ff3c4f9675 281 */
POTLESS_2 47:89a088bc8866 282
POTLESS_2 43:5ae8baf28e32 283 HAL_PWREx_EnablePullUpPullDownConfig() ;
POTLESS_2 46:28298df0ac55 284 HAL_PWREx_EnableGPIOPullDown(PWR_GPIO_A, PWR_GPIO_BIT_0);
POTLESS_2 40:32d89e04ead1 285
potless 38:fe77b68eec37 286 HAL_PWR_DisableWakeUpPin(PWR_WAKEUP_PIN1); // pour PA_0
POTLESS_2 40:32d89e04ead1 287 // Clear wake up Flag
POTLESS_2 40:32d89e04ead1 288 __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WUF1);
POTLESS_2 40:32d89e04ead1 289 // Enable wakeup pin WKUP2
POTLESS_2 39:65ff3c4f9675 290 HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN1); // high est la valeur par défaut
POTLESS_2 40:32d89e04ead1 291
POTLESS_2 40:32d89e04ead1 292 // Set RTC back-up register RTC_BKP31R to indicate
POTLESS_2 40:32d89e04ead1 293 //later on that system has entered shutdown mode
potless 37:f9461c6592f2 294 WRITE_REG( RTC->BKP31R, 0x1 );
POTLESS_2 40:32d89e04ead1 295 //Enter shutdown mode
potless 37:f9461c6592f2 296 DEBUG("\n\r Attention c'est du brutal ! bouton bleu pour ressort.... ZZZZZZZ ZZZZZ !!!\n");
POTLESS_2 40:32d89e04ead1 297
potless 37:f9461c6592f2 298 HAL_PWREx_EnterSHUTDOWNMode();
POTLESS_2 18:bfd78c05b589 299 }
POTLESS_2 18:bfd78c05b589 300
POTLESS_2 31:231a96d1d1c8 301 //Fonction test de valeur d'entrée digitale
POTLESS_2 29:5b822d18bce6 302 int Power_Test(DigitalIn& pin)
POTLESS_2 20:5f79fb4565a7 303 {
POTLESS_2 29:5b822d18bce6 304 pin.mode(PullDown);
POTLESS_2 34:26f6e3dbefb9 305
POTLESS_2 34:26f6e3dbefb9 306 if(!pin) {
POTLESS_2 34:26f6e3dbefb9 307 Stop_Sequence();
POTLESS_2 34:26f6e3dbefb9 308 return 0;
POTLESS_2 34:26f6e3dbefb9 309 } else {
POTLESS_2 34:26f6e3dbefb9 310 return 1;
POTLESS_2 34:26f6e3dbefb9 311 }
POTLESS_2 20:5f79fb4565a7 312 }
POTLESS_2 20:5f79fb4565a7 313
POTLESS_2 31:231a96d1d1c8 314 //Fonction test de valeur d'entrée analogique
POTLESS_2 31:231a96d1d1c8 315 float Power_Test(AnalogIn& pin)
POTLESS_2 31:231a96d1d1c8 316 {
POTLESS_2 31:231a96d1d1c8 317 float Val = pin.read();
POTLESS_2 31:231a96d1d1c8 318 return Val;
POTLESS_2 31:231a96d1d1c8 319 }
POTLESS_2 31:231a96d1d1c8 320
POTLESS_2 18:bfd78c05b589 321 //Contrôle du status de l'appareil / des constantes
POTLESS_2 18:bfd78c05b589 322 bool Check()
POTLESS_2 18:bfd78c05b589 323 {
POTLESS_2 18:bfd78c05b589 324 if (ppO2 > 100)
POTLESS_2 19:cac3761a5d0b 325 return true;//Situation OK
POTLESS_2 18:bfd78c05b589 326 else
POTLESS_2 19:cac3761a5d0b 327 return false;//Situation dégradée
POTLESS_2 18:bfd78c05b589 328 }
POTLESS_2 18:bfd78c05b589 329
POTLESS_2 18:bfd78c05b589 330 //Calcul des OTU
POTLESS_2 18:bfd78c05b589 331 float Calcul_OTU()
POTLESS_2 18:bfd78c05b589 332 {
POTLESS_2 18:bfd78c05b589 333 /*
POTLESS_2 18:bfd78c05b589 334 La formule suivante permet de calculer la quantité d' OTU accumulée
POTLESS_2 18:bfd78c05b589 335 OTU = T * (2* PpO2 -1)0,83
POTLESS_2 18:bfd78c05b589 336 avec :
POTLESS_2 18:bfd78c05b589 337 T = temps de plongée en minutes
POTLESS_2 18:bfd78c05b589 338 PpO2 = pression partielle d’ oxygène en bars
POTLESS_2 18:bfd78c05b589 339 */
POTLESS_2 18:bfd78c05b589 340
POTLESS_2 19:cac3761a5d0b 341 if (ppO2 > 500) {
POTLESS_2 18:bfd78c05b589 342 float val = (2 * (float)ppO2/1000 - 1);//je divise par 1000 car la PP est en mb...
POTLESS_2 18:bfd78c05b589 343 OTU += Ref_Time * pow(val, COEF_OTU);
POTLESS_2 19:cac3761a5d0b 344 }
POTLESS_2 18:bfd78c05b589 345 }
POTLESS_2 10:aca745a66d51 346
POTLESS_2 17:bef8abc445f2 347 //Thread d'intérogation des capteurs, positions servo
POTLESS_2 34:26f6e3dbefb9 348 void SENSORS_thread()
POTLESS_2 6:ebed9093d661 349 {
POTLESS_2 7:ad15c386e960 350 while (true) {
POTLESS_2 36:1f5e2247b073 351 //DEEP_DEBUG(" SENSORS_thread\r\n");
POTLESS_2 7:ad15c386e960 352
POTLESS_2 7:ad15c386e960 353 //CO2 sur Cozir
POTLESS_2 7:ad15c386e960 354 co2 = sensors.requestCO2();
POTLESS_2 7:ad15c386e960 355 //P / T sur MS5837
POTLESS_2 7:ad15c386e960 356 pression = sensors.requestPress();
POTLESS_2 9:04bfdfc029cb 357 Temp1 = sensors.requestTemp();
POTLESS_2 7:ad15c386e960 358 //PPO2 sur ADS1015
POTLESS_2 33:f5d4bae05f16 359 if (FLAG_O2) ppO2 = sensors.requestPpO2();
POTLESS_2 7:ad15c386e960 360 //Cell O2 en mV
POTLESS_2 33:f5d4bae05f16 361 if (FLAG_O2) CellO2_1 = sensors.requestCellO2_1();
POTLESS_2 33:f5d4bae05f16 362 if (FLAG_O2) CellO2_2 = sensors.requestCellO2_2();
POTLESS_2 9:04bfdfc029cb 363
POTLESS_2 8:a750d531b381 364 //HTU21D
POTLESS_2 9:04bfdfc029cb 365 Temp2 = temphumid.sample_ctemp();
POTLESS_2 9:04bfdfc029cb 366 Humid = temphumid.sample_humid();
POTLESS_2 9:04bfdfc029cb 367
POTLESS_2 10:aca745a66d51 368 //Retour position des servos
POTLESS_2 17:bef8abc445f2 369 volet_poumon_Position = Servo_Poumon.Get_Position();
POTLESS_2 43:5ae8baf28e32 370 volet_fuite_Position = Servo_Fuite.Get_Position();
POTLESS_2 43:5ae8baf28e32 371
POTLESS_2 43:5ae8baf28e32 372 //Calcul des OTU
POTLESS_2 43:5ae8baf28e32 373 Calcul_OTU();
POTLESS_2 34:26f6e3dbefb9 374
POTLESS_2 19:cac3761a5d0b 375 }
POTLESS_2 19:cac3761a5d0b 376 }
POTLESS_2 12:7f3aadd79f89 377
POTLESS_2 19:cac3761a5d0b 378 void GO_TO_thread()
POTLESS_2 19:cac3761a5d0b 379 {
POTLESS_2 19:cac3761a5d0b 380 while (true) {
POTLESS_2 36:1f5e2247b073 381 //DEEP_DEBUG(" GO_TO_Thread\r\n");
POTLESS_2 34:26f6e3dbefb9 382
POTLESS_2 19:cac3761a5d0b 383 //Servo_Poumon.Go_To_Prop(Consigne_poumon);
POTLESS_2 26:a2fe19341f92 384 //Servo_Poumon.Go_To_PID(Consigne_poumon, Volet_DeadBand);
POTLESS_2 34:26f6e3dbefb9 385 Servo_Poumon.Go_To(Consigne_poumon, Volets_Speed, Volet_DeadBand);
POTLESS_2 34:26f6e3dbefb9 386
POTLESS_2 19:cac3761a5d0b 387 //Servo_Fuite.Go_To_Prop(Consigne_fuite);
POTLESS_2 43:5ae8baf28e32 388 //Servo_Fuite.Go_To_PID(Consigne_fuite, Volet_DeadBand);
POTLESS_2 43:5ae8baf28e32 389 Servo_Fuite.Go_To(Consigne_fuite, Volets_Speed, Volet_DeadBand );
POTLESS_2 15:efd3b3bf3f37 390 }
potless 2:4a8bf1d53439 391 }
POTLESS_2 4:d84250f67dec 392
POTLESS_2 20:5f79fb4565a7 393 void SECU_thread()
POTLESS_2 20:5f79fb4565a7 394 {
POTLESS_2 34:26f6e3dbefb9 395 while (true) {
POTLESS_2 34:26f6e3dbefb9 396
POTLESS_2 20:5f79fb4565a7 397 }
POTLESS_2 20:5f79fb4565a7 398 }
POTLESS_2 20:5f79fb4565a7 399
POTLESS_2 11:b2feed92584a 400 //Callback de l'intérruption des envois de commandes depuis le terminal
POTLESS_2 6:ebed9093d661 401 void callbackParam()
POTLESS_2 34:26f6e3dbefb9 402 {
POTLESS_2 40:32d89e04ead1 403
POTLESS_2 40:32d89e04ead1 404
POTLESS_2 34:26f6e3dbefb9 405 while(serialMonit.readable()) {
POTLESS_2 40:32d89e04ead1 406 if ((indexParam == sizeParam) || newParamFlag == true) { //éviter la saturation du buffer
potless 44:5cd6f84a62ec 407 NVIC_DisableIRQ(USART2_IRQn); // USART 2 pour carte ARNSRS
POTLESS_2 29:5b822d18bce6 408 char char_flush = serialMonit.getc();
potless 44:5cd6f84a62ec 409 NVIC_EnableIRQ(USART2_IRQn); // USART 2 pour carte ARNSRS
POTLESS_2 40:32d89e04ead1 410 } else {
potless 44:5cd6f84a62ec 411 NVIC_DisableIRQ(USART2_IRQn); // USART 2 pour carte ARNSRS
POTLESS_2 29:5b822d18bce6 412 param [indexParam ++] = serialMonit.getc();//chargement du buffer dans le message
POTLESS_2 40:32d89e04ead1 413 if ((indexParam == sizeParam) || (param[indexParam - 1] == '\n')) {//le message est complet ou nouvelle ligne ou autre si on veut...
POTLESS_2 40:32d89e04ead1 414 param[indexParam] = 0;
POTLESS_2 40:32d89e04ead1 415 newParamFlag = true;
POTLESS_2 40:32d89e04ead1 416 }
potless 44:5cd6f84a62ec 417 NVIC_EnableIRQ(USART2_IRQn); // USART 2 pour carte ARNSRS
POTLESS_2 34:26f6e3dbefb9 418 }
POTLESS_2 34:26f6e3dbefb9 419 }
POTLESS_2 6:ebed9093d661 420 }
POTLESS_2 4:d84250f67dec 421
POTLESS_2 9:04bfdfc029cb 422 void Decoding_Message(char message [])
POTLESS_2 9:04bfdfc029cb 423 {
POTLESS_2 9:04bfdfc029cb 424
POTLESS_2 42:3591ec9903b4 425 char com[20] = "";
POTLESS_2 42:3591ec9903b4 426 char numb[30] = "";
POTLESS_2 36:1f5e2247b073 427
POTLESS_2 34:26f6e3dbefb9 428 sscanf(message,"%s %s",&com , &numb);
POTLESS_2 36:1f5e2247b073 429
POTLESS_2 35:a209a192f431 430 DEEP_DEBUG("\r\n Commande = %s Valeur = %s \r\n\r\n", com, numb);
POTLESS_2 42:3591ec9903b4 431 //serialMonit.printf("\r\n Commande = %s Valeur = %s \r\n\r\n", com, numb);
POTLESS_2 36:1f5e2247b073 432
POTLESS_2 43:5ae8baf28e32 433 OUTPUT("?\r\n");
POTLESS_2 43:5ae8baf28e32 434
POTLESS_2 30:7a16a66d76f3 435 if (0 == strcmp(com, "secu")) {
POTLESS_2 19:cac3761a5d0b 436 Mode_SECU();
POTLESS_2 42:3591ec9903b4 437 } else if (0 == strcmp(com, "PING")) {
POTLESS_2 43:5ae8baf28e32 438 FLAG_PID = 0;
POTLESS_2 43:5ae8baf28e32 439 FLAG_AFF = false;
POTLESS_2 43:5ae8baf28e32 440 FLAG_WINDEV = false;
POTLESS_2 43:5ae8baf28e32 441 control_Servo.setMode(MANUAL_MODE);
POTLESS_2 34:26f6e3dbefb9 442 } else if (0 == strcmp(com, "ARNSRS_ID")) {
POTLESS_2 43:5ae8baf28e32 443 OUTPUT("Changement de l'ID de l'appareil pour le N°: %s?\r\n", numb);
POTLESS_2 34:26f6e3dbefb9 444 UTILS::Store_A_Val(atoi(numb), "ARNSRS_ID");
POTLESS_2 43:5ae8baf28e32 445 } else if (0 == strcmp(com, "monit")) {
POTLESS_2 43:5ae8baf28e32 446 FLAG_AFF = false;
POTLESS_2 43:5ae8baf28e32 447 FLAG_WINDEV = true;
POTLESS_2 43:5ae8baf28e32 448 } else if (0 == strcmp(com, "debug")) {
POTLESS_2 43:5ae8baf28e32 449 FLAG_AFF = false;
POTLESS_2 43:5ae8baf28e32 450 FLAG_WINDEV = false;
POTLESS_2 34:26f6e3dbefb9 451 } else if (0 == strcmp(com, "Head_ID")) {
POTLESS_2 34:26f6e3dbefb9 452 //On l'enregistre dans l'eeprom
POTLESS_2 43:5ae8baf28e32 453 OUTPUT("Changement de l'ID de la tête capteur pour le N°: %s\r\n", numb);
POTLESS_2 34:26f6e3dbefb9 454 UTILS::write_EEPROM(numb, HEAD_ID);
POTLESS_2 34:26f6e3dbefb9 455 } else if (0 == strcmp(com, "O2_1_ID")) {
POTLESS_2 34:26f6e3dbefb9 456 //On l'enregistre dans l'eeprom
POTLESS_2 34:26f6e3dbefb9 457 UTILS::write_EEPROM(numb, CELL_O2_1_ID);
POTLESS_2 34:26f6e3dbefb9 458 } else if (0 == strcmp(com, "O2_2_ID")) {
POTLESS_2 34:26f6e3dbefb9 459 //On l'enregistre dans l'eeprom
POTLESS_2 34:26f6e3dbefb9 460 UTILS::write_EEPROM(numb, CELL_O2_2_ID);
POTLESS_2 34:26f6e3dbefb9 461 } else if (0 == strcmp(com, "CO2_ID")) {
POTLESS_2 34:26f6e3dbefb9 462 //On l'enregistre dans l'eeprom
POTLESS_2 34:26f6e3dbefb9 463 UTILS::write_EEPROM(numb, CO2_ID);
POTLESS_2 34:26f6e3dbefb9 464 } else if (0 == strcmp(com, "calib_O2")) {
POTLESS_2 33:f5d4bae05f16 465 FLAG_O2 = false;
POTLESS_2 33:f5d4bae05f16 466 wait_ms(100);
POTLESS_2 42:3591ec9903b4 467 float Val = sensors.Calibrate_O2(atoi(numb));
POTLESS_2 43:5ae8baf28e32 468 OUTPUT(" Calibration O2 dans l'air = %f\r\n", Val);
POTLESS_2 33:f5d4bae05f16 469 wait_ms(100);
POTLESS_2 33:f5d4bae05f16 470 FLAG_O2 = true;
POTLESS_2 41:51ba69648f9d 471 } else if (0 == strcmp(com, "calib_CO2_A")) {
POTLESS_2 43:5ae8baf28e32 472 int Val = sensors.Calibrate_CO2();
POTLESS_2 43:5ae8baf28e32 473 OUTPUT(" Calibration CO2 dans l'air = %d\r\n", Val);
POTLESS_2 34:26f6e3dbefb9 474 } else if (0 == strcmp(com, "flash_i")) {
POTLESS_2 42:3591ec9903b4 475 UTILS::Flash_Infos(&serialMonit);
POTLESS_2 36:1f5e2247b073 476 } else if (0 == strcmp(com, "flash_u")) {
POTLESS_2 43:5ae8baf28e32 477 OUTPUT(" Démontage de la Flash.\r\n");
POTLESS_2 36:1f5e2247b073 478 FLAG_REC = false;
POTLESS_2 36:1f5e2247b073 479 UTILS::UnMount_Flash();
POTLESS_2 36:1f5e2247b073 480 } else if (0 == strcmp(com, "flash_m")) {
POTLESS_2 43:5ae8baf28e32 481 OUTPUT(" Montage de la Flash.\r\n");
POTLESS_2 40:32d89e04ead1 482 UTILS::Mount_Flash();
POTLESS_2 35:a209a192f431 483 } else if (0 == strcmp(com, "check_F")) {
POTLESS_2 43:5ae8baf28e32 484 OUTPUT(" ARNSRS_ID.sys = %d\r\n", (int)UTILS::Read_A_Val("ARNSRS_ID.sys"));
POTLESS_2 43:5ae8baf28e32 485 OUTPUT(" Servo_Poumon.sys = %d\r\n", (int)UTILS::Read_A_Val("Servo_Poumon.sys"));
POTLESS_2 43:5ae8baf28e32 486 OUTPUT(" Servo_Fuite.sys = %d\r\n", (int)UTILS::Read_A_Val("Servo_Fuite.sys"));
POTLESS_2 35:a209a192f431 487 } else if (0 == strcmp(com, "check_E")) {
POTLESS_2 42:3591ec9903b4 488 sensors.Sensor_head_check(&serialMonit);
POTLESS_2 34:26f6e3dbefb9 489 } else if (0 == strcmp(com, "rec")) {
POTLESS_2 34:26f6e3dbefb9 490 if (FLAG_REC) {
POTLESS_2 34:26f6e3dbefb9 491 FLAG_REC = false;
POTLESS_2 43:5ae8baf28e32 492 OUTPUT(" Arrêt du Data Logging.\r\n");
POTLESS_2 34:26f6e3dbefb9 493 } else {
POTLESS_2 34:26f6e3dbefb9 494 FLAG_REC = true;
POTLESS_2 43:5ae8baf28e32 495 OUTPUT(" Démarrage Data Logging dans %s\r\n", Log_File_Name);
POTLESS_2 34:26f6e3dbefb9 496 }
POTLESS_2 34:26f6e3dbefb9 497 } else if (0 == strcmp(com, "help")) {
POTLESS_2 29:5b822d18bce6 498 FLAG_AFF = false;
POTLESS_2 42:3591ec9903b4 499 UTILS::Help(&serialMonit);
POTLESS_2 34:26f6e3dbefb9 500 } else if (0 == strcmp(com, "start")) {
POTLESS_2 29:5b822d18bce6 501 FLAG_AFF = true;
POTLESS_2 34:26f6e3dbefb9 502 } else if (0 == strcmp(com, "stop")) {
POTLESS_2 29:5b822d18bce6 503 FLAG_AFF = false;
POTLESS_2 40:32d89e04ead1 504 //UTILS::Help();
POTLESS_2 36:1f5e2247b073 505 } else if (0 == strcmp(com, "flash_c")) {
POTLESS_2 29:5b822d18bce6 506 FLAG_REC = false;
POTLESS_2 29:5b822d18bce6 507 UTILS::Clean_Flash();
POTLESS_2 42:3591ec9903b4 508 } else if (0 == strcmp(com, "flash_f")) {
POTLESS_2 34:26f6e3dbefb9 509 FLAG_REC = false;
POTLESS_2 43:5ae8baf28e32 510 UTILS::Clean_Flash_All();
POTLESS_2 42:3591ec9903b4 511 } else if (0 == strcmp(com, "dir")) {
POTLESS_2 43:5ae8baf28e32 512 FLAG_WINDEV = false;
POTLESS_2 43:5ae8baf28e32 513 OUTPUT("$\r\n");
POTLESS_2 43:5ae8baf28e32 514 wait(0.5);
POTLESS_2 42:3591ec9903b4 515 UTILS::Dir_Flash(&serialMonit);
POTLESS_2 42:3591ec9903b4 516 } else if (0 == strcmp(com, "get")) {
POTLESS_2 29:5b822d18bce6 517 wait_ms(100);
POTLESS_2 43:5ae8baf28e32 518 char filename[20];
POTLESS_2 43:5ae8baf28e32 519 UTILS::Read_Flash_File(&serialMonit, numb);
POTLESS_2 43:5ae8baf28e32 520 wait_ms(100);
POTLESS_2 34:26f6e3dbefb9 521 } else if (0 == strcmp(com, "del")) {
POTLESS_2 29:5b822d18bce6 522 FLAG_REC = false;
POTLESS_2 29:5b822d18bce6 523 char filename[20];
POTLESS_2 42:3591ec9903b4 524 UTILS::Delete_Flash_File(numb);
POTLESS_2 43:5ae8baf28e32 525 OUTPUT("$\r\n");
POTLESS_2 43:5ae8baf28e32 526 wait(0.5);
POTLESS_2 43:5ae8baf28e32 527 UTILS::Dir_Flash(&serialMonit);
POTLESS_2 31:231a96d1d1c8 528 FLAG_REC = true;
POTLESS_2 34:26f6e3dbefb9 529 } else if (0 == strcmp(com, "file_s")) {
POTLESS_2 31:231a96d1d1c8 530 char filename[20];
POTLESS_2 42:3591ec9903b4 531 UTILS::Get_File_Size(&serialMonit, numb);
POTLESS_2 29:5b822d18bce6 532 } else if (0 == strcmp(com, "calib_p")) {
POTLESS_2 20:5f79fb4565a7 533 Consigne_poumon = 0;
POTLESS_2 20:5f79fb4565a7 534 volet_poumon_Position = 0;
POTLESS_2 19:cac3761a5d0b 535 Servo_Poumon.reset();
POTLESS_2 43:5ae8baf28e32 536 OUTPUT(" Volet poumon Calibré.\r\n");
POTLESS_2 29:5b822d18bce6 537 } else if (0 == strcmp(com, "calib_f")) {
POTLESS_2 29:5b822d18bce6 538 Consigne_fuite = 0;
POTLESS_2 29:5b822d18bce6 539 volet_fuite_Position = 0;
POTLESS_2 43:5ae8baf28e32 540 Servo_Fuite.reset();
POTLESS_2 43:5ae8baf28e32 541 OUTPUT(" Volet fuite Calibré.\r\n");
POTLESS_2 29:5b822d18bce6 542 } else if (0 == strcmp(com, "sleep")) {
POTLESS_2 19:cac3761a5d0b 543 Stop_Sequence();
POTLESS_2 29:5b822d18bce6 544 } else if (0 == strcmp(com, "time")) {//Depuis terminal MAC taper : " date +%s "
POTLESS_2 34:26f6e3dbefb9 545 set_time(atoi(numb));
POTLESS_2 43:5ae8baf28e32 546 OUTPUT(" La RTC a été mise à l'heure.\r\n");
POTLESS_2 29:5b822d18bce6 547 } else if (0 == strcmp(com, "c_pou")) {
POTLESS_2 43:5ae8baf28e32 548 Consigne_poumon = atof(numb);
POTLESS_2 43:5ae8baf28e32 549 DEBUG(" Servo Poumon = %f\r\n", Consigne_poumon);
POTLESS_2 43:5ae8baf28e32 550 } else if (0 == strcmp(com, "c_fui")) {
POTLESS_2 43:5ae8baf28e32 551 Consigne_fuite = atof(numb);
POTLESS_2 43:5ae8baf28e32 552 DEBUG(" Servo Fuite = %f\r\n", Consigne_fuite);
POTLESS_2 43:5ae8baf28e32 553 } else if (0 == strcmp(com, "mp_pou")) {
POTLESS_2 41:51ba69648f9d 554 Consigne_poumon += atof(numb);
POTLESS_2 33:f5d4bae05f16 555 DEBUG(" Servo Poumon = %f\r\n", Consigne_poumon);
POTLESS_2 43:5ae8baf28e32 556 } else if (0 == strcmp(com, "mp_fui")) {
POTLESS_2 41:51ba69648f9d 557 Consigne_fuite += atof(numb);
POTLESS_2 33:f5d4bae05f16 558 DEBUG(" Servo Fuite = %f\r\n", Consigne_fuite);
POTLESS_2 29:5b822d18bce6 559 } else if (0 == strcmp(com, "reset")) {
POTLESS_2 43:5ae8baf28e32 560 FLAG_REC = false;
POTLESS_2 36:1f5e2247b073 561 UTILS::UnMount_Flash();
POTLESS_2 43:5ae8baf28e32 562 OUTPUT(" Reset de l'appareil.\r\n");
POTLESS_2 43:5ae8baf28e32 563 wait(1);
POTLESS_2 10:aca745a66d51 564 NVIC_SystemReset();
POTLESS_2 43:5ae8baf28e32 565 } else if (0 == strcmp(com, "Kc")) {
POTLESS_2 43:5ae8baf28e32 566 Kc = atof(numb);
POTLESS_2 43:5ae8baf28e32 567 control_Servo.reset();
POTLESS_2 43:5ae8baf28e32 568 control_Servo.setTunings(Kc, Ti, Td);
POTLESS_2 43:5ae8baf28e32 569 OUTPUT(" MAJ PID --> Kc = %f Ti = %f Td = %f?\r\n", Kc, Ti, Td);
POTLESS_2 43:5ae8baf28e32 570 } else if (0 == strcmp(com, "Ti")) {
POTLESS_2 43:5ae8baf28e32 571 Ti = atof(numb);
POTLESS_2 43:5ae8baf28e32 572 control_Servo.reset();
POTLESS_2 43:5ae8baf28e32 573 control_Servo.setTunings(Kc, Ti, Td);
POTLESS_2 43:5ae8baf28e32 574 OUTPUT(" MAJ PID --> Kc = %f Ti = %f Td = %f?\r\n", Kc, Ti, Td);
POTLESS_2 43:5ae8baf28e32 575 } else if (0 == strcmp(com, "Td")) {
POTLESS_2 43:5ae8baf28e32 576 Td = atof(numb);
POTLESS_2 43:5ae8baf28e32 577 control_Servo.reset();
POTLESS_2 43:5ae8baf28e32 578 control_Servo.setTunings(Kc, Ti, Td);
POTLESS_2 43:5ae8baf28e32 579 OUTPUT(" MAJ PID --> Kc = %f Ti = %f Td = %f?\r\n", Kc, Ti, Td);
POTLESS_2 43:5ae8baf28e32 580 } else if (0 == strcmp(com, "Cons")) {
POTLESS_2 43:5ae8baf28e32 581 consigne = atoi(numb);
POTLESS_2 43:5ae8baf28e32 582 control_Servo.setSetPoint(consigne);
POTLESS_2 43:5ae8baf28e32 583 OUTPUT(" MAJ CONSIGNE PID --> Consigne = %d?\r\n", consigne);
potless 49:a7432da60647 584
potless 49:a7432da60647 585 } else if (0 == strcmp(com, "dfu")) {
potless 49:a7432da60647 586 OUTPUT(" Mode DFU main \r\n");
potless 49:a7432da60647 587 *((unsigned long *) 0x10007FF0) = 0xDEADBEEF;
potless 49:a7432da60647 588 wait(1);
potless 49:a7432da60647 589 NVIC_SystemReset();
potless 49:a7432da60647 590
potless 49:a7432da60647 591
POTLESS_2 43:5ae8baf28e32 592 } else if (0 == strcmp(com, "PID")) {
POTLESS_2 43:5ae8baf28e32 593 if (FLAG_PID == 1) {
POTLESS_2 43:5ae8baf28e32 594 control_Servo.setMode(MANUAL_MODE);
POTLESS_2 43:5ae8baf28e32 595 OUTPUT(" PID OFF?\r\n");
POTLESS_2 43:5ae8baf28e32 596 FLAG_PID = 0;
POTLESS_2 43:5ae8baf28e32 597 } else if (FLAG_PID == 0) {
POTLESS_2 43:5ae8baf28e32 598 control_Servo.setMode(AUTO_MODE);
POTLESS_2 43:5ae8baf28e32 599 OUTPUT(" PID ON?\r\n");
POTLESS_2 43:5ae8baf28e32 600 FLAG_PID = 1;
POTLESS_2 43:5ae8baf28e32 601 }
POTLESS_2 12:7f3aadd79f89 602 } else {
POTLESS_2 43:5ae8baf28e32 603
POTLESS_2 9:04bfdfc029cb 604 sensors.cozirSend(message);
POTLESS_2 9:04bfdfc029cb 605 }
POTLESS_2 34:26f6e3dbefb9 606
POTLESS_2 9:04bfdfc029cb 607 strcpy(param," ");
POTLESS_2 9:04bfdfc029cb 608 indexParam = 0;
POTLESS_2 9:04bfdfc029cb 609 newParamFlag = false;
POTLESS_2 9:04bfdfc029cb 610 }
POTLESS_2 9:04bfdfc029cb 611
POTLESS_2 26:a2fe19341f92 612 void Create_File_Name_Date()
POTLESS_2 25:322ef9488e65 613 {
POTLESS_2 25:322ef9488e65 614 //Du nom du fichier Date / heure
POTLESS_2 25:322ef9488e65 615 seconds = time(NULL);
POTLESS_2 25:322ef9488e65 616 char Time[40];
POTLESS_2 25:322ef9488e65 617 strftime(Time, 40, "%a_%d_%m_%Y_%H%M", localtime(&seconds));
POTLESS_2 42:3591ec9903b4 618 sprintf(Log_File_Name, "%s_LOG.csv", Time);
POTLESS_2 42:3591ec9903b4 619 DEBUG(" Nouveau fichier LOG = %s \r\n", Log_File_Name);
POTLESS_2 34:26f6e3dbefb9 620 }
POTLESS_2 34:26f6e3dbefb9 621
POTLESS_2 26:a2fe19341f92 622 void Create_File_Name_Index()
POTLESS_2 26:a2fe19341f92 623 {
POTLESS_2 26:a2fe19341f92 624 //Du nom du fichier par Index
POTLESS_2 42:3591ec9903b4 625 sprintf(Log_File_Name, "LOG_%d.csv", UTILS::File_Index());
POTLESS_2 34:26f6e3dbefb9 626 DEBUG(" Nouveau fichier LOG = %s \r\n", Log_File_Name);
POTLESS_2 34:26f6e3dbefb9 627 }
POTLESS_2 34:26f6e3dbefb9 628
potless 48:9ceb095f397a 629
potless 48:9ceb095f397a 630
potless 48:9ceb095f397a 631
potless 48:9ceb095f397a 632
potless 48:9ceb095f397a 633
potless 48:9ceb095f397a 634
POTLESS_2 4:d84250f67dec 635 int main()
POTLESS_2 12:7f3aadd79f89 636 {
POTLESS_2 47:89a088bc8866 637
POTLESS_2 40:32d89e04ead1 638 HAL_Init();
potless 48:9ceb095f397a 639
POTLESS_2 40:32d89e04ead1 640
POTLESS_2 40:32d89e04ead1 641 __HAL_RCC_PWR_CLK_ENABLE();
potless 37:f9461c6592f2 642 HAL_PWR_EnableBkUpAccess();
potless 48:9ceb095f397a 643
potless 48:9ceb095f397a 644
potless 48:9ceb095f397a 645
POTLESS_2 40:32d89e04ead1 646
POTLESS_2 43:5ae8baf28e32 647 //Ci-dessous commande pour formater une nouvelle carte
POTLESS_2 43:5ae8baf28e32 648 //UTILS::Format_Flash();
POTLESS_2 43:5ae8baf28e32 649
POTLESS_2 43:5ae8baf28e32 650 //Montage Flash
POTLESS_2 43:5ae8baf28e32 651 UTILS::Mount_Flash();
POTLESS_2 12:7f3aadd79f89 652
POTLESS_2 43:5ae8baf28e32 653 //Liste des fichiers sur la Flash
POTLESS_2 43:5ae8baf28e32 654 //UTILS::Dir_Flash(&serialMonit);
POTLESS_2 26:a2fe19341f92 655
POTLESS_2 43:5ae8baf28e32 656 if (UTILS::File_Exist("ARNSRS_ID.sys") == false) {
POTLESS_2 43:5ae8baf28e32 657 UTILS::Store_A_Val(000, "ARNSRS_ID.sys");
POTLESS_2 43:5ae8baf28e32 658 DEBUG("ARNSRS ID forcée à 000\r\n");
POTLESS_2 43:5ae8baf28e32 659 }
potless 45:61ba3cc4fc55 660 /*
potless 45:61ba3cc4fc55 661 while(1){
potless 45:61ba3cc4fc55 662 OUTPUT("\r\n\r\n Démarrage de l'appareil, veuillez patienter...\r\n\r\n");}
potless 45:61ba3cc4fc55 663 */
POTLESS_2 34:26f6e3dbefb9 664
POTLESS_2 43:5ae8baf28e32 665 //Vérification RTC, si on est le 01/01/70, c'est qu'il y a un problème...
POTLESS_2 43:5ae8baf28e32 666 seconds = time(NULL);
POTLESS_2 43:5ae8baf28e32 667 char YEAR[10];
POTLESS_2 43:5ae8baf28e32 668 strftime(YEAR, 10, "%D", localtime(&seconds));
POTLESS_2 43:5ae8baf28e32 669 if (0 == strcmp(YEAR, "01/01/70")); //OUTPUT(" Vous devez régler la RTC...\r\n\r\n");
POTLESS_2 18:bfd78c05b589 670
POTLESS_2 43:5ae8baf28e32 671 bool calib_O2 = false;
POTLESS_2 43:5ae8baf28e32 672 bool calib_CO2 = false;
POTLESS_2 18:bfd78c05b589 673
POTLESS_2 43:5ae8baf28e32 674 /*
POTLESS_2 43:5ae8baf28e32 675 Par défaut les valeur en cas de calibration sur true sont les suivant
POTLESS_2 18:bfd78c05b589 676
POTLESS_2 43:5ae8baf28e32 677 nbCalibO2 = 5
POTLESS_2 43:5ae8baf28e32 678 Mode = SPOOLING
POTLESS_2 43:5ae8baf28e32 679 Filtre = DIGI_FILTER32
POTLESS_2 43:5ae8baf28e32 680 CalibrationCO2 = "CALIB_AIR"
POTLESS_2 18:bfd78c05b589 681
POTLESS_2 43:5ae8baf28e32 682 Parfois la calibration du Cozir coince...faire reset et relancer...
POTLESS_2 43:5ae8baf28e32 683
POTLESS_2 43:5ae8baf28e32 684 Pour calibrer avec ces paramètres :
POTLESS_2 18:bfd78c05b589 685
POTLESS_2 43:5ae8baf28e32 686 sensors.Sensors_INIT(true, true);
POTLESS_2 43:5ae8baf28e32 687
POTLESS_2 43:5ae8baf28e32 688 Pour changer utiliser la syntaxe suivante :
POTLESS_2 43:5ae8baf28e32 689
POTLESS_2 43:5ae8baf28e32 690 sensors.Sensors_INIT(true, true, true, 5, SPOOLING, DIGI_FILTER32, CALIB_AIR);
POTLESS_2 43:5ae8baf28e32 691
POTLESS_2 43:5ae8baf28e32 692 */
POTLESS_2 43:5ae8baf28e32 693
POTLESS_2 43:5ae8baf28e32 694 sensors.Sensors_INIT(calib_O2, calib_CO2);
POTLESS_2 43:5ae8baf28e32 695
POTLESS_2 43:5ae8baf28e32 696 wait(1);
POTLESS_2 43:5ae8baf28e32 697
POTLESS_2 43:5ae8baf28e32 698 //Création du nouveau fichier LOG par index / par date.
POTLESS_2 43:5ae8baf28e32 699 //Create_File_Name_Index();
POTLESS_2 43:5ae8baf28e32 700 Create_File_Name_Date();
POTLESS_2 43:5ae8baf28e32 701
POTLESS_2 43:5ae8baf28e32 702 //Création et écriture du header du fichier LOG
POTLESS_2 43:5ae8baf28e32 703 sensors.Create_Header(Log_File_Name);
POTLESS_2 42:3591ec9903b4 704
POTLESS_2 43:5ae8baf28e32 705 Servo_Poumon.Init("Servo_Poumon.sys");
POTLESS_2 43:5ae8baf28e32 706 Servo_Fuite.Init("Servo_Fuite.sys");
POTLESS_2 15:efd3b3bf3f37 707
POTLESS_2 43:5ae8baf28e32 708 //OUTPUT(" Demarrage des threads...\r\n\r\n");
POTLESS_2 43:5ae8baf28e32 709
POTLESS_2 43:5ae8baf28e32 710 /*
POTLESS_2 43:5ae8baf28e32 711
POTLESS_2 43:5ae8baf28e32 712 Pour mémoire, les réglage de priorité des thread
POTLESS_2 15:efd3b3bf3f37 713
POTLESS_2 43:5ae8baf28e32 714 osPriorityIdle = -3, ///< priority: idle (lowest)
POTLESS_2 43:5ae8baf28e32 715 osPriorityLow = -2, ///< priority: low
POTLESS_2 43:5ae8baf28e32 716 osPriorityBelowNormal = -1, ///< priority: below normal
POTLESS_2 43:5ae8baf28e32 717 osPriorityNormal = 0, ///< priority: normal (default)
POTLESS_2 43:5ae8baf28e32 718 osPriorityAboveNormal = +1, ///< priority: above normal
POTLESS_2 43:5ae8baf28e32 719 osPriorityHigh = +2, ///< priority: high
POTLESS_2 43:5ae8baf28e32 720 osPriorityRealtime = +3, ///< priority: realtime (highest)
POTLESS_2 43:5ae8baf28e32 721 osPriorityError = 0x84 ///< system cannot determine priority or thread has illegal priority
POTLESS_2 43:5ae8baf28e32 722 */
POTLESS_2 18:bfd78c05b589 723
POTLESS_2 43:5ae8baf28e32 724 wait(1);
POTLESS_2 20:5f79fb4565a7 725
POTLESS_2 43:5ae8baf28e32 726 Thread thread_Volets(osPriorityNormal);
POTLESS_2 43:5ae8baf28e32 727
POTLESS_2 43:5ae8baf28e32 728 thread_Volets.start(callback(GO_TO_thread));
POTLESS_2 12:7f3aadd79f89 729
POTLESS_2 43:5ae8baf28e32 730 //OUTPUT(" Contrôle des volets démarré\r\n\r\n");
POTLESS_2 43:5ae8baf28e32 731
POTLESS_2 43:5ae8baf28e32 732 wait(1);
POTLESS_2 34:26f6e3dbefb9 733
POTLESS_2 43:5ae8baf28e32 734 Thread thread_Secu(osPriorityNormal);
POTLESS_2 43:5ae8baf28e32 735
POTLESS_2 43:5ae8baf28e32 736 thread_Secu.start(callback(SECU_thread));
POTLESS_2 34:26f6e3dbefb9 737
POTLESS_2 43:5ae8baf28e32 738 //OUTPUT(" Contrôle des paramètres de sécu démarré\r\n\r\n");
POTLESS_2 43:5ae8baf28e32 739
POTLESS_2 43:5ae8baf28e32 740 wait(1);
POTLESS_2 43:5ae8baf28e32 741
POTLESS_2 43:5ae8baf28e32 742 Thread thread_Head(osPriorityNormal);
POTLESS_2 36:1f5e2247b073 743
POTLESS_2 43:5ae8baf28e32 744 thread_Head.start(callback(SENSORS_thread));
POTLESS_2 36:1f5e2247b073 745
POTLESS_2 43:5ae8baf28e32 746 //OUTPUT(" Tête capteurs démarrée\r\n\r\n");
POTLESS_2 43:5ae8baf28e32 747
POTLESS_2 43:5ae8baf28e32 748 wait(1);
POTLESS_2 9:04bfdfc029cb 749
POTLESS_2 43:5ae8baf28e32 750 //Init PID
POTLESS_2 43:5ae8baf28e32 751 //Entrée PPO2 entre 100 et 1000 mb
POTLESS_2 43:5ae8baf28e32 752 control_Servo.setInputLimits(Min_Input, Max_Input);
POTLESS_2 43:5ae8baf28e32 753 //Sortie servo entre 0 et 100 %
POTLESS_2 43:5ae8baf28e32 754 control_Servo.setOutputLimits(Min_Output, Max_Output);
POTLESS_2 43:5ae8baf28e32 755 //Mode auto au démarrage
POTLESS_2 43:5ae8baf28e32 756 control_Servo.setMode(MANUAL_MODE);
POTLESS_2 43:5ae8baf28e32 757 //Consigne à x mb
POTLESS_2 43:5ae8baf28e32 758 control_Servo.setSetPoint(consigne);
POTLESS_2 34:26f6e3dbefb9 759
POTLESS_2 43:5ae8baf28e32 760 //OUTPUT(" Cliquez sur le bouton help pour voir la liste des \r\n commandes administrateur disponibles.\r\n");
POTLESS_2 7:ad15c386e960 761
POTLESS_2 43:5ae8baf28e32 762
POTLESS_2 46:28298df0ac55 763 OUTPUT("$\r\n");
POTLESS_2 43:5ae8baf28e32 764 wait(0.5);
POTLESS_2 43:5ae8baf28e32 765 UTILS::Dir_Flash(&serialMonit);
POTLESS_2 43:5ae8baf28e32 766
POTLESS_2 47:89a088bc8866 767 serialMonit.attach(&callbackParam);
potless 45:61ba3cc4fc55 768
POTLESS_2 46:28298df0ac55 769 vusb_off_on.fall(&Stop_Sequence);
POTLESS_2 46:28298df0ac55 770
POTLESS_2 46:28298df0ac55 771 E5V = 1;
POTLESS_2 36:1f5e2247b073 772
POTLESS_2 47:89a088bc8866 773 buzzer.beep(1000,0.5);
POTLESS_2 47:89a088bc8866 774
POTLESS_2 43:5ae8baf28e32 775 while (true) {
POTLESS_2 36:1f5e2247b073 776
POTLESS_2 43:5ae8baf28e32 777 //Démarrage du Timer mesurant le temps d'éxecution du code
POTLESS_2 43:5ae8baf28e32 778 REAL_RATE.start();
POTLESS_2 36:1f5e2247b073 779
POTLESS_2 43:5ae8baf28e32 780 if (newParamFlag) {
POTLESS_2 43:5ae8baf28e32 781 DEEP_DEBUG(" From PC = %s\r\n", param);
POTLESS_2 43:5ae8baf28e32 782 Decoding_Message(param);
POTLESS_2 43:5ae8baf28e32 783 }
POTLESS_2 34:26f6e3dbefb9 784
POTLESS_2 43:5ae8baf28e32 785 //Fabrication de la chaine Date / heure
POTLESS_2 43:5ae8baf28e32 786 seconds = time(NULL);
POTLESS_2 43:5ae8baf28e32 787 char Time_buf[32];
POTLESS_2 43:5ae8baf28e32 788 strftime(Time_buf, 32, "%D %I-%M-%S ", localtime(&seconds));
POTLESS_2 19:cac3761a5d0b 789
POTLESS_2 43:5ae8baf28e32 790 //Fabrication de la chaine à enregistrer
POTLESS_2 43:5ae8baf28e32 791 sprintf(to_store,"<%s;%d;%d;%.2f;%d;%.2f;%.2f;%d;%d;%d;%.2f;%.2f;%d;%.3f;%.3f;%.3f;%d>",
POTLESS_2 43:5ae8baf28e32 792 Time_buf,
POTLESS_2 43:5ae8baf28e32 793 co2,
POTLESS_2 43:5ae8baf28e32 794 ppO2,
POTLESS_2 43:5ae8baf28e32 795 pression,
POTLESS_2 43:5ae8baf28e32 796 (int)OTU,
POTLESS_2 43:5ae8baf28e32 797 Temp1,
POTLESS_2 43:5ae8baf28e32 798 Temp2,
POTLESS_2 43:5ae8baf28e32 799 Humid,
POTLESS_2 43:5ae8baf28e32 800 CellO2_1,
POTLESS_2 43:5ae8baf28e32 801 CellO2_2,
POTLESS_2 43:5ae8baf28e32 802 volet_poumon_Position,
POTLESS_2 43:5ae8baf28e32 803 volet_fuite_Position,
POTLESS_2 43:5ae8baf28e32 804 FLAG_PID,
POTLESS_2 43:5ae8baf28e32 805 Kc,
POTLESS_2 43:5ae8baf28e32 806 Ti,
POTLESS_2 43:5ae8baf28e32 807 Td,
POTLESS_2 43:5ae8baf28e32 808 consigne
POTLESS_2 43:5ae8baf28e32 809 );
POTLESS_2 15:efd3b3bf3f37 810
POTLESS_2 15:efd3b3bf3f37 811
POTLESS_2 43:5ae8baf28e32 812 //Pour windev
POTLESS_2 43:5ae8baf28e32 813 if (FLAG_WINDEV) {
POTLESS_2 43:5ae8baf28e32 814 OUTPUT("%s\r\n", to_store);
POTLESS_2 43:5ae8baf28e32 815 }
POTLESS_2 43:5ae8baf28e32 816
POTLESS_2 43:5ae8baf28e32 817 //Pour l'IHM
POTLESS_2 46:28298df0ac55 818 if (FLAG_DISPLAY) {
POTLESS_2 46:28298df0ac55 819 IHM("%s\r\n", to_store);
POTLESS_2 46:28298df0ac55 820 }
POTLESS_2 43:5ae8baf28e32 821
POTLESS_2 43:5ae8baf28e32 822 //Vers le moniteur série
POTLESS_2 43:5ae8baf28e32 823 if (FLAG_AFF) {
potless 44:5cd6f84a62ec 824 NVIC_DisableIRQ(USART3_IRQn); // USART 2 si ARNSRS mais plus utilisé
POTLESS_2 43:5ae8baf28e32 825 Affichage();
potless 44:5cd6f84a62ec 826 NVIC_EnableIRQ(USART3_IRQn); // USART 2 si ARNSRS mais plus utilisé
POTLESS_2 43:5ae8baf28e32 827 }
POTLESS_2 12:7f3aadd79f89 828
POTLESS_2 43:5ae8baf28e32 829 //Enregistrement de la chaine
POTLESS_2 43:5ae8baf28e32 830 if (FLAG_REC) {
POTLESS_2 43:5ae8baf28e32 831 UTILS::Write_Flash_File(to_store, Log_File_Name);
POTLESS_2 43:5ae8baf28e32 832 count ++;
POTLESS_2 43:5ae8baf28e32 833 if (count > Max_Log_Size) {
POTLESS_2 43:5ae8baf28e32 834 Create_File_Name_Date();
POTLESS_2 43:5ae8baf28e32 835 sensors.Create_Header(Log_File_Name);
POTLESS_2 43:5ae8baf28e32 836 count = 0;
POTLESS_2 43:5ae8baf28e32 837 OUTPUT("$\r\n");
POTLESS_2 43:5ae8baf28e32 838 wait(0.5);
POTLESS_2 43:5ae8baf28e32 839 UTILS::Dir_Flash(&serialMonit);
POTLESS_2 34:26f6e3dbefb9 840 }
POTLESS_2 34:26f6e3dbefb9 841 }
POTLESS_2 43:5ae8baf28e32 842
POTLESS_2 43:5ae8baf28e32 843 //Update du PID
POTLESS_2 43:5ae8baf28e32 844 control_Servo.setProcessValue(ppO2);
POTLESS_2 43:5ae8baf28e32 845 //Nouvelle sortie servo fuite si on est pas en mode SECU
potless 45:61ba3cc4fc55 846 //if(!EN_MODE_SECU) Consigne_fuite = control_Servo.compute();
POTLESS_2 43:5ae8baf28e32 847
POTLESS_2 43:5ae8baf28e32 848 //Arrêt du Timer mesurant le temps d'éxecution du code
POTLESS_2 43:5ae8baf28e32 849 REAL_RATE.stop();
POTLESS_2 43:5ae8baf28e32 850 //Définition de la nouvelle valeur du temps d'échantillonage du PID.
POTLESS_2 43:5ae8baf28e32 851 RATE = REAL_RATE.read();
POTLESS_2 43:5ae8baf28e32 852 //Reset du Timer
POTLESS_2 43:5ae8baf28e32 853 REAL_RATE.reset();
POTLESS_2 43:5ae8baf28e32 854
POTLESS_2 43:5ae8baf28e32 855 //Pour ralentir le code à Ref_Time seconde fixe quelque soit les intéruptions du loop....
POTLESS_2 43:5ae8baf28e32 856 if (Ref_Time > RATE) {
POTLESS_2 43:5ae8baf28e32 857 RATE_TRUE = (Ref_Time - RATE) * 1000;
POTLESS_2 43:5ae8baf28e32 858 } else {
POTLESS_2 43:5ae8baf28e32 859 RATE_TRUE = 0;
POTLESS_2 43:5ae8baf28e32 860
POTLESS_2 43:5ae8baf28e32 861 //control_Servo.setInterval(RATE);
POTLESS_2 43:5ae8baf28e32 862
POTLESS_2 43:5ae8baf28e32 863 DEEP_DEBUG("Pour ralentir le code, Ref_Time doit être supérieur à %f seconde(s)\r\n\n", RATE);
POTLESS_2 43:5ae8baf28e32 864 }
POTLESS_2 43:5ae8baf28e32 865
POTLESS_2 43:5ae8baf28e32 866 wait_ms(RATE_TRUE);
POTLESS_2 34:26f6e3dbefb9 867 }
POTLESS_2 4:d84250f67dec 868 }
POTLESS_2 43:5ae8baf28e32 869
POTLESS_2 43:5ae8baf28e32 870