39 lines
639 B
C
39 lines
639 B
C
![]() |
/*
|
||
|
* timer.c
|
||
|
*
|
||
|
* Created on: May 31, 2017
|
||
|
* Author: wn
|
||
|
*/
|
||
|
|
||
|
#include "timer.h"
|
||
|
#include "display.h"
|
||
|
|
||
|
|
||
|
extern tDisplay display;
|
||
|
|
||
|
void startTimer() {
|
||
|
display.timerState = STARTED;
|
||
|
}
|
||
|
|
||
|
void secondTick(void *handle) {
|
||
|
tDisplay *lDisplay = (tDisplay*) handle;
|
||
|
|
||
|
switch (lDisplay->timerState) {
|
||
|
case STARTED:
|
||
|
lDisplay->currentTime = lDisplay->targetTime;
|
||
|
lDisplay->timerState = RUNNING;
|
||
|
break;
|
||
|
case RUNNING:
|
||
|
lDisplay->currentTime -= 1;
|
||
|
if (lDisplay->currentTime == 0) {
|
||
|
lDisplay->timerState = OVERRUN;
|
||
|
}
|
||
|
break;
|
||
|
case OVERRUN:
|
||
|
lDisplay->overrunTime += 1;
|
||
|
break;
|
||
|
default:
|
||
|
;
|
||
|
}
|
||
|
}
|