diff --git a/src/main.cpp b/src/main.cpp index c7f7d6c..7ec1f81 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -35,7 +35,7 @@ int pptr = 2; //nombre de pulsations par tour d'hélice ///////////////////////////////// /*NUMÉRO DE SÉRIE DE L'APPAREIL*/ ///////////////////////////////// -char numero_capteur[] = "0001"; +char numero_capteur[5] = "0001"; /////////////////////////// /* DÉFINITIONS DE LA RTC */ @@ -51,7 +51,7 @@ DateTime now{rtc.now()}; //////////////////////////////// /* DÉFINITIONS DE LA CARTE SD */ //////////////////////////////// -unsigned long inter_ecriture = 60000; // durée entre deux écritures sur la carte SD en millisecondes +unsigned long inter_ecriture; // durée entre deux écritures sur la carte SD en millisecondes char horodatage[12]; //création du tableau pour contenir l'horodatage char fichier[] = "/"; //tableau pour le nom de fichier @@ -124,8 +124,8 @@ void gaz_moteur() { pos --; } moteur.write(pos); - Serial.println("gaz ="); - Serial.println(pos); + //Serial.println("gaz ="); + //Serial.println(pos); } void stop_moteur() { @@ -188,12 +188,12 @@ void compte_tour() { int diff_count = count - old_count; vRotReel = (60000*diff_count/(pptr*offset)); //vitesse en tours par min (4 pulsations /tour, 2 montantes, 2 descendantes) old_count = count; - Serial.println("count ="); - Serial.println(count); + //Serial.println("count ="); + //Serial.println(count); //Serial.println("chrono_compte_tour="); //Serial.println(chrono_compte_tour); - Serial.println("vRrotReel="); - Serial.println(vRotReel); + //Serial.println("vRrotReel="); + //Serial.println(vRotReel); gaz_moteur();// ajustement des gaz en fonction de la vitesse mesurée sema_compte_tour = false; } @@ -331,18 +331,13 @@ void sd_init() { } void scribe_sd (){ - if ( sem_scribe == false ) { - sem_scribe = true; - pcnt_counter_pause(PCNT_TEST_UNIT); - pcnt_counter_clear(PCNT_TEST_UNIT); - pcnt_counter_resume(PCNT_TEST_UNIT); - start_chrono_scribe = millis(); - } + chrono_scribe = millis() - start_chrono_scribe; - Serial.println("sem_scribe="); - Serial.println(sem_scribe); + //Serial.println(chrono_scribe); + //Serial.println(inter_ecriture); + //Serial.println(sem_scribe); - if (chrono_scribe >= inter_ecriture ){ + if ( sem_scribe == true && chrono_scribe >= inter_ecriture ){ //Serial.println("balise scribe"); char timestamp[] = "YY-MM-DD-hh:mm:ss"; char *horodatage = now.toString(timestamp); @@ -356,6 +351,17 @@ void scribe_sd (){ Serial.println("ECRITURE SUR SD"); sem_scribe = false; } + + if ( sem_scribe == false ) { + sem_scribe = true; + pcnt_counter_pause(PCNT_TEST_UNIT); + pcnt_counter_clear(PCNT_TEST_UNIT); + pcnt_counter_resume(PCNT_TEST_UNIT); + start_chrono_scribe = millis(); + } + + + } @@ -488,6 +494,7 @@ void setup() { pinMode(bouton_wifi, INPUT); // bouton wifi //Serial.println("balise 0"); rtc_init(); // RTC + inter_ecriture = 60000; sd_init (); // initialisation de la carte SD sem_wifi = false; // initialisation du sémaphore /* compteur de pulsations */