From 281ac81a9897bff93c9a0136a0409d75786420b8 Mon Sep 17 00:00:00 2001 From: Lyanis Souidi Date: Fri, 25 Nov 2022 12:55:52 +0100 Subject: [PATCH] =?UTF-8?q?Modification=20du=20chronom=C3=A8tre?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Division de la fonction `start_timer()` : l'ancienne fonction bloquait l'execution des autres instructions à cause d'une boucle while, une nouvelle fonction `update_timer()` sera appelée à interval régulier pour afficher à l'écran le chronomètre. - Création d'une fonction `stop_timer()`. - Ajout d'un argument à la fonction `start_timer()` afin de lancer le chronomètre à une valeur autre que 0. --- include/timer.h | 7 ++++++- src/timer.c | 41 +++++++++++++++++++++++++---------------- 2 files changed, 31 insertions(+), 17 deletions(-) diff --git a/include/timer.h b/include/timer.h index 1ac7d5c..2a5b7c9 100644 --- a/include/timer.h +++ b/include/timer.h @@ -1,6 +1,11 @@ #ifndef TIMER_H #define TIMER_H +#define DELTA 1000000L -void start_timer(void); +void update_timer(unsigned long int start); + +unsigned long int start_timer(unsigned long int start); + +unsigned long int stop_timer(unsigned long int start); #endif \ No newline at end of file diff --git a/src/timer.c b/src/timer.c index 8125b2c..10449e3 100644 --- a/src/timer.c +++ b/src/timer.c @@ -1,24 +1,33 @@ #include #include #include -#define delta 1000000L - -void start_timer(void) { - unsigned long int start = Microsecondes(); - unsigned int minute = 0; - unsigned int a = 0; +#define DELTA 1000000L +void update_timer(unsigned long int start) { + unsigned int secondes = ((Microsecondes() - start) / DELTA); + unsigned int minutes = 0; char buf[100]; - while(1){ - unsigned long int seconde = ((Microsecondes() - start) / 1000000)-a; - if (seconde>=60) { - minute +=1; - a += 60; - } - - snprintf(buf, 100, "temps : %02d:%02d", minute, seconde); - - EcrireTexte(20,20, buf, 1); + while (secondes >= 60) { + minutes += 1; + secondes -= 60; } + + ChoisirEcran(3); + EffacerEcran(CouleurParComposante(54, 57, 63)); + ChoisirCouleurDessin(CouleurParNom("white")); + snprintf(buf, 100, "Temps : %02d:%02d", minutes, secondes); + EcrireTexte(20, 20, buf, 1); + CopierZone(3, 0, 0, 0, 150, 30, 0, 0); + ChoisirEcran(0); +} + +unsigned long int start_timer(unsigned long int start) { + start = Microsecondes() - start; + update_timer(start); + return start; +} + +unsigned long int stop_timer(unsigned long int start) { + return Microsecondes()-start; } \ No newline at end of file