mbed-os github
Dependencies: ADS1015 Faulhaber HTU21D_mod MS5837_potless Sensor_Head_RevB_3 USBDevice_dfu Utilsdfu beep
Fork of ARNSRS_testDFU by
Diff: main.cpp
- Revision:
- 33:f5d4bae05f16
- Parent:
- 31:231a96d1d1c8
- Child:
- 34:26f6e3dbefb9
diff -r 4bbf57bcd41a -r f5d4bae05f16 main.cpp --- a/main.cpp Fri Feb 23 19:06:44 2018 +0000 +++ b/main.cpp Sat Feb 24 16:56:19 2018 +0000 @@ -23,9 +23,6 @@ #define Channel_B_SERVO_FUITE PB_9 #define HOME_SERVO_FUITE 90 -//Un peu plus ou un peu moins de sortie moniteurs pour du debug.... -#define DEBUG_MAIN 0 - //Ecrit dans le moniteur série de la tablette à 115200 bds si sur 1, penser à mettre NEED_CONSOLE_OUTPUT à 0 #define NEED_ANDROID_OUTPUT 1 @@ -47,10 +44,10 @@ #define ANDROID(...) #endif -#if DEBUG_MAIN -#define DEBUG_M(...) { serialMonit.printf(__VA_ARGS__); fflush(stdout);} +#if DEBUG_MODE +#define DEBUG(...) { serialMonit.printf(__VA_ARGS__); fflush(stdout);} #else -#define DEBUG_M(...) +#define DEBUG(...) #endif @@ -86,6 +83,9 @@ //Flag pour interrompre l'enregistrement si on veut... bool FLAG_REC = true; +//Flag pour interrompre les demandes O2 en cours ed calibration... +bool FLAG_O2 = true; + //Variables de stockage des infos capteurs int co2 = 0; float pression = 0; @@ -211,7 +211,7 @@ if (Servo_Poumon.Pos_OK() == true) break; //if (Servo_Poumon.Pos_OK() == true && Servo_Fuite.Pos_OK() == true) break; } - DEBUG_M("-------------- Appareil en mode SECU ---------------\r\n"); + DEBUG("-------------- Appareil en mode SECU ---------------\r\n"); wait_ms(100); @@ -219,10 +219,10 @@ wait_ms(100); int Pos = Servo_Poumon.getPulses(); UTILS::Store_A_Val((float)Pos, "Servo_Poumon"); - DEBUG_M(" position volet poumon sauvegardée = %d pulse(s)\r\n", Pos); + DEBUG(" position volet poumon sauvegardée = %d pulse(s)\r\n", Pos); //Pos = Servo_Fuite.getPulses(); //UTILS::Store_A_Val((float)Pos, "Servo_Fuite"); - //DEBUG_M(" position volet fuite sauvegardée = %d pulse(s)\r\n", Pos); + //DEBUG(" position volet fuite sauvegardée = %d pulse(s)\r\n", Pos); UTILS::UnMount_Flash(); Servo_Poumon.Sleep(); } @@ -231,9 +231,9 @@ void Stop_Sequence() { Mode_SECU(); - DEBUG_M("----------------ARRET DE L'APPAREIL--------------------\r\n"); + DEBUG("----------------ARRET DE L'APPAREIL--------------------\r\n"); - DEBUG_M(" Deep sleep autorisé : %i\r\n", sleep_manager_can_deep_sleep()); + DEBUG(" Deep sleep autorisé : %i\r\n", sleep_manager_can_deep_sleep()); wait(1.0); sleep_manager_sleep_auto(); } @@ -295,10 +295,10 @@ pression = sensors.requestPress(); Temp1 = sensors.requestTemp(); //PPO2 sur ADS1015 - ppO2 = sensors.requestPpO2(); + if (FLAG_O2) ppO2 = sensors.requestPpO2(); //Cell O2 en mV - CellO2_1 = sensors.requestCellO2_1(); - CellO2_2 = sensors.requestCellO2_2(); + if (FLAG_O2) CellO2_1 = sensors.requestCellO2_1(); + if (FLAG_O2) CellO2_2 = sensors.requestCellO2_2(); //HTU21D Temp2 = temphumid.sample_ctemp(); @@ -328,8 +328,8 @@ { while (true) { //Alim USB - Vusb = Power_Test(V_USB); - VPiles = Power_Test(V_PILES); + //Vusb = Power_Test(V_USB); + //VPiles = Power_Test(V_PILES); //Divers problèmes à implémenter //if(!Check()) Mode_SECU(); } @@ -375,12 +375,16 @@ sscanf(message,"%s %f",&com , &val); - DEBUG_M("\r\n Commande = %s Valeur = %f \r\n\r\n", com, val); + DEBUG("\r\n Commande = %s Valeur = %f \r\n\r\n", com, val); if (0 == strcmp(com, "secu")) { Mode_SECU(); }else if (0 == strcmp(com, "calib_O2")) { - sensors.Calibrate_O2(true, (int)val); + FLAG_O2 = false; + wait_ms(100); + sensors.Calibrate_O2(true, (int)val); + wait_ms(100); + FLAG_O2 = true; }else if (0 == strcmp(com, "flash_i")) { FLAG_REC = false; UTILS::Flash_Infos(); @@ -454,10 +458,10 @@ set_time(val); } else if (0 == strcmp(com, "c_pou")) { Consigne_poumon = (float)val; - DEBUG_M(" Servo Poumon = %f\r\n", Consigne_poumon); + DEBUG(" Servo Poumon = %f\r\n", Consigne_poumon); } else if (0 == strcmp(com, "c_fui")) { Consigne_fuite = (float)val; - DEBUG_M(" Servo Fuite = %f\r\n", Consigne_fuite); + DEBUG(" Servo Fuite = %f\r\n", Consigne_fuite); } else if (0 == strcmp(com, "reset")) { NVIC_SystemReset(); ///////////////////////////////////////// @@ -486,10 +490,10 @@ set_time(valeur); } else if ((char)commande == 'I') { Consigne_poumon = (float)valeur; - DEBUG_M(" Servo Poumon = %f\r\n", Consigne_poumon); + DEBUG(" Servo Poumon = %f\r\n", Consigne_poumon); } else if ((char)commande == 'O') { Consigne_fuite = (float)valeur; - DEBUG_M(" Servo Fuite = %f\r\n", Consigne_fuite); + DEBUG(" Servo Fuite = %f\r\n", Consigne_fuite); ///////////////////////////////////////// //Pour rajouter une commande //} else if ((char)commande == 'X') { @@ -504,21 +508,21 @@ Kc = (float)valeur; control_Servo.reset(); control_Servo.setTunings(Kc, Ti, Td); - DEBUG_M" UPDATE PID --> Kc = %f Ti = %f Td = %f\r\n\n", Kc, Ti, Td); + DEBUG" UPDATE PID --> Kc = %f Ti = %f Td = %f\r\n\n", Kc, Ti, Td); } else if ((char)commande == 'i') { Ti = (float)valeur; control_Servo.reset(); control_Servo.setTunings(Kc, Ti, Td); - DEBUG_M(" UPDATE PID --> Kc = %f Ti = %f Td = %f\r\n\n", Kc, Ti, Td); + DEBUG(" UPDATE PID --> Kc = %f Ti = %f Td = %f\r\n\n", Kc, Ti, Td); } else if ((char)commande == 'd') { Td = (float)valeur; control_Servo.reset(); control_Servo.setTunings(Kc, Ti, Td); - DEBUG_M(" UPDATE PID --> Kc = %f Ti = %f Td = %f\r\n\n", Kc, Ti, Td); + DEBUG(" UPDATE PID --> Kc = %f Ti = %f Td = %f\r\n\n", Kc, Ti, Td); } else if ((char)commande == 'c') { consigne = valeur; control_Servo.setSetPoint(consigne); - DEBUG_M(" UPDATE CONSIGNE PID --> Consigne = %d\r\n\n", consigne); + DEBUG(" UPDATE CONSIGNE PID --> Consigne = %d\r\n\n", consigne); } #endif @@ -534,14 +538,14 @@ char Time[40]; strftime(Time, 40, "%a_%d_%m_%Y_%H%M", localtime(&seconds)); sprintf(Log_File_Name, "%s_LOG.txt", Time); - DEBUG_M("Nouveau fichier LOG = %s \r\n", Log_File_Name); + DEBUG("Nouveau fichier LOG = %s \r\n", Log_File_Name); } void Create_File_Name_Index() { //Du nom du fichier par Index sprintf(Log_File_Name, "LOG_%d.txt", UTILS::File_Index()); - DEBUG_M(" Nouveau fichier LOG = %s \r\n", Log_File_Name); + DEBUG(" Nouveau fichier LOG = %s \r\n", Log_File_Name); } int main() @@ -574,7 +578,7 @@ //Liste des fichiers sur la Flash UTILS::Dir_Flash(); - bool calib_O2 = false; + bool calib_O2 = true; bool calib_CO2 = false; /* @@ -608,7 +612,7 @@ Create_File_Name_Index(); //Create_File_Name_Date() - DEBUG_M(" Demarrage des threads...\r\n\r\n"); + DEBUG(" Demarrage des threads...\r\n\r\n"); /* @@ -654,7 +658,7 @@ control_Servo.setSetPoint(consigne); #endif - DEBUG_M(" Threads démmarés.....\r\n\r\n Tapez help pour voir la liste des commandes disponibles.\r\n "); + DEBUG(" Threads démmarés.....\r\n\r\n Tapez help pour voir la liste des commandes disponibles.\r\n "); while (true) { @@ -662,12 +666,12 @@ REAL_RATE.start(); if (newParamFlag) { - DEBUG_M(" From PC = %s\r\n", param); + DEBUG(" From PC = %s\r\n", param); Decoding_Message(param); } if (newAndroidFlag) { - DEBUG_M(" From Android = %s\r\n", Android); + DEBUG(" From Android = %s\r\n", Android); Decoding_Message_Android(Android); } @@ -771,7 +775,7 @@ #ifdef PID_MODE control_Servo.setInterval(RATE); #endif - DEBUG_M("Pour ralentir le code, Ref_Time doit être supérieur à %f seconde(s)\r\n\n", RATE); + DEBUG("Pour ralentir le code, Ref_Time doit être supérieur à %f seconde(s)\r\n\n", RATE); } wait_ms(RATE_TRUE);