Modification du chronomètre
- 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.
This commit is contained in:
parent
a417a487bf
commit
281ac81a98
@ -1,6 +1,11 @@
|
|||||||
#ifndef TIMER_H
|
#ifndef TIMER_H
|
||||||
#define 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
|
#endif
|
41
src/timer.c
41
src/timer.c
@ -1,24 +1,33 @@
|
|||||||
#include<stdio.h>
|
#include<stdio.h>
|
||||||
#include<stdlib.h>
|
#include<stdlib.h>
|
||||||
#include<graph.h>
|
#include<graph.h>
|
||||||
#define delta 1000000L
|
#define DELTA 1000000L
|
||||||
|
|
||||||
void start_timer(void) {
|
|
||||||
unsigned long int start = Microsecondes();
|
|
||||||
unsigned int minute = 0;
|
|
||||||
unsigned int a = 0;
|
|
||||||
|
|
||||||
|
void update_timer(unsigned long int start) {
|
||||||
|
unsigned int secondes = ((Microsecondes() - start) / DELTA);
|
||||||
|
unsigned int minutes = 0;
|
||||||
char buf[100];
|
char buf[100];
|
||||||
while(1){
|
|
||||||
unsigned long int seconde = ((Microsecondes() - start) / 1000000)-a;
|
|
||||||
|
|
||||||
if (seconde>=60) {
|
while (secondes >= 60) {
|
||||||
minute +=1;
|
minutes += 1;
|
||||||
a += 60;
|
secondes -= 60;
|
||||||
}
|
|
||||||
|
|
||||||
snprintf(buf, 100, "temps : %02d:%02d", minute, seconde);
|
|
||||||
|
|
||||||
EcrireTexte(20,20, buf, 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user