mbed-os github

Dependencies:   ADS1015 Faulhaber HTU21D_mod MS5837_potless Sensor_Head_RevB_3 USBDevice_dfu Utilsdfu beep

Fork of ARNSRS_testDFU by POTLESS

Revision:
40:32d89e04ead1
Parent:
39:65ff3c4f9675
Child:
41:51ba69648f9d
diff -r 65ff3c4f9675 -r 32d89e04ead1 main.cpp
--- a/main.cpp	Wed Mar 21 07:07:50 2018 +0000
+++ b/main.cpp	Thu Mar 29 16:03:01 2018 +0000
@@ -80,6 +80,9 @@
 //Flag pour interrompre l'affichage si on veut...
 bool FLAG_AFF = true;
 
+//Flag pour envoyer à l'app windev...
+bool FLAG_WINDEV = false;
+
 //Flag pour interrompre l'enregistrement si on veut...
 bool FLAG_REC = true;
 
@@ -159,7 +162,7 @@
 
 void Affichage()
 {
-
+    //NVIC_DisableIRQ(USART2_IRQn);
     serialMonit.printf("\r\n");
     serialMonit.printf("  CO2             = %d ppm\r\n"  , co2);
     serialMonit.printf("  PPO2            = %d mb\r\n", ppO2);
@@ -183,6 +186,7 @@
     serialMonit.printf("  V_USB = %f", Vusb);
     serialMonit.printf("\r\n\r\n");
     fflush(stdout);
+    //NVIC_EnableIRQ(USART2_IRQn);
 }
 
 void pressed()
@@ -240,17 +244,17 @@
     Mode_SECU();
     //ejection de la flash pour pas crasher le system de fichiers
     UTILS::UnMount_Flash();
-    
+
     DEBUG("----------------ARRET DE L'APPAREIL--------------------\r\n");
-    
+
     // préparation deepsleep
-    
+
     /*
     //première méthode mais je ne sais pas ce que ça consomme et il faut normalement reduire le frequence d'horloge avant
     //il est possible que ça génère un plantage et la rtc ne fonctionnera pas?
     HAL_PWREx_EnableLowPowerRunMode();
     DEBUG("----------------LOW POWER RUN MODE--------------------\r\n");
-    
+
     bool isDSallowed;
     isDSallowed =  sleep_manager_can_deep_sleep();
     DEBUG("  Deep sleep autorisé ? %i\r\n", isDSallowed);
@@ -258,33 +262,33 @@
 
     DEBUG("\n\r Deepsleep tentative normale !(bouton bleu pour ressortir)\n");
     wait(0.1);
-           
+
     sleep_manager_sleep_auto(); // ne marche pas, je ne sais pas pk
     */
-    
-    
+
+
     DEBUG("\n\r Deepsleep méthode offensive !\n");
-    
+
     /*
     HAL_PWR_DisableWakeUpPin(PWR_WAKEUP_PIN2); // pour PC_13
-    // Clear wake up Flag 
-    __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WUF2);  
-    // Enable wakeup pin WKUP2 
+    // Clear wake up Flag
+    __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WUF2);
+    // Enable wakeup pin WKUP2
     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
     */
-    
+
     HAL_PWR_DisableWakeUpPin(PWR_WAKEUP_PIN1); // pour PA_0
-    // Clear wake up Flag 
-    __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WUF1);  
-    // Enable wakeup pin WKUP2 
+    // Clear wake up Flag
+    __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WUF1);
+    // Enable wakeup pin WKUP2
     HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN1); // high est la valeur par défaut
-    
-    // Set RTC back-up register RTC_BKP31R to indicate 
-    //later on that system has entered shutdown mode  
+
+    // Set RTC back-up register RTC_BKP31R to indicate
+    //later on that system has entered shutdown mode
     WRITE_REG( RTC->BKP31R, 0x1 );
-    //Enter shutdown mode 
+    //Enter shutdown mode
     DEBUG("\n\r Attention c'est du brutal !  bouton bleu pour ressort.... ZZZZZZZ ZZZZZ !!!\n");
-    
+
     HAL_PWREx_EnterSHUTDOWNMode();
 }
 
@@ -393,15 +397,21 @@
 //Callback de l'intérruption des envois de commandes depuis le terminal
 void callbackParam()
 {
+
+
     while(serialMonit.readable()) {
-        if ((indexParam  == sizeParam) || newParamFlag  == true) //éviter la saturation du buffer
+        if ((indexParam  == sizeParam) || newParamFlag  == true) { //éviter la saturation du buffer
+            //NVIC_DisableIRQ(USART2_IRQn);
             char char_flush = serialMonit.getc();
-        else
+            //NVIC_EnableIRQ(USART2_IRQn);
+        } else {
+            //NVIC_DisableIRQ(USART2_IRQn);
             param [indexParam ++] = serialMonit.getc();//chargement du buffer dans le message
-
-        if ((indexParam == sizeParam) || (param[indexParam - 1] == '\n')) {//le message est complet ou nouvelle ligne ou autre si on veut...
-            param[indexParam] = 0;
-            newParamFlag  = true;
+            if ((indexParam == sizeParam) || (param[indexParam - 1] == '\n')) {//le message est complet ou nouvelle ligne ou autre si on veut...
+                param[indexParam] = 0;
+                newParamFlag  = true;
+            }
+            //NVIC_EnableIRQ(USART2_IRQn);
         }
     }
 }
@@ -435,6 +445,12 @@
         Mode_SECU();
     } else if (0 == strcmp(com, "ARNSRS_ID")) {
         UTILS::Store_A_Val(atoi(numb), "ARNSRS_ID");
+    } else if (0 == strcmp(com, "monit")) {        
+            FLAG_AFF = false;
+            FLAG_WINDEV = true;
+    } else if (0 == strcmp(com, "debug")) {        
+            FLAG_AFF = true;
+            FLAG_WINDEV = false;           
     } else if (0 == strcmp(com, "Head_ID")) {
         //On l'enregistre dans l'eeprom
         UTILS::write_EEPROM(numb, HEAD_ID);
@@ -461,7 +477,7 @@
         FLAG_REC = false;
         UTILS::UnMount_Flash();
     } else if (0 == strcmp(com, "flash_m")) {
-        UTILS::Mount_Flash();        
+        UTILS::Mount_Flash();
     } else if (0 == strcmp(com, "check_F")) {
         FLAG_REC = false;
         serialMonit.printf("  ARNSRS_ID.txt   = %d\r\n", (int)UTILS::Read_A_Val("ARNSRS_ID"));
@@ -486,7 +502,7 @@
         FLAG_AFF = true;
     } else if (0 == strcmp(com, "stop")) {
         FLAG_AFF = false;
-        UTILS::Help();
+        //UTILS::Help();
     } else if (0 == strcmp(com, "flash_c")) {
         FLAG_REC = false;
         UTILS::Clean_Flash();
@@ -616,17 +632,17 @@
 
 int main()
 {
-    
-    HAL_Init();  
-    
+
+    HAL_Init();
+
     //V_USB.mode(PullDown); // on force à zero tant que l'alim par les piles n'est pas en place
 
     button.fall(&pressed);
     //vpile_off_on.rise (&retour_alim);
-    
-    __HAL_RCC_PWR_CLK_ENABLE(); 
+
+    __HAL_RCC_PWR_CLK_ENABLE();
     HAL_PWR_EnableBkUpAccess();
-    
+
     int count = 0;
 
     while (1) {
@@ -657,7 +673,7 @@
             char YEAR[10];
             strftime(YEAR, 10, "%D", localtime(&seconds));
             if (0 == strcmp(YEAR, "01/01/70")) serialMonit.printf("  Vous devez régler la RTC...\r\n");
-             
+
             if (UTILS::File_Exist("ARNSRS_ID") == false) {
                 UTILS::Store_A_Val(000, "ARNSRS_ID");
                 DEBUG("ARNSRS ID forcée à 000\r\n");
@@ -820,7 +836,7 @@
 #endif
                 char to_slave[50];
                 //Fabrication de la chaine pour l'IHM
-                sprintf(to_slave,"%d:%d:%d:%.2f:%.2f:%.2f:%d:%d:%d:%.2f:%.2f\r\n",
+                sprintf(to_slave,"<%d:%d:%d:%.2f:%.2f:%.2f:%d:%d:%d:%.2f:%.2f>",
                         co2,
                         ppO2,
                         (int)OTU,
@@ -836,7 +852,14 @@
                 //Pour Android on ajoute < et > pour décoder l'arrivée du message
                 if (NEED_ANDROID_OUTPUT == 1) {
                     //sprintf(to_android,"<%s>",to_store);
-                    ANDROID(to_slave);
+                    //ANDROID(to_slave);
+                }
+
+                //Pour windev la même chose que pour l'écran
+                if (FLAG_WINDEV) {
+                    //NVIC_DisableIRQ(USART2_IRQn);
+                    serialMonit.printf(to_slave);
+                    //NVIC_EnableIRQ(USART2_IRQn);
                 }
 
                 //Calcul des OTU
@@ -871,7 +894,7 @@
 #ifdef PID_MODE
                     control_Servo.setInterval(RATE);
 #endif
-                    DEBUG("Pour ralentir le code, Ref_Time doit être supérieur à %f seconde(s)\r\n\n", RATE);
+                    DEEP_DEBUG("Pour ralentir le code, Ref_Time doit être supérieur à %f seconde(s)\r\n\n", RATE);
                 }
 
                 wait_ms(RATE_TRUE);