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