ttt2/my_src/timer.c
2017-06-20 15:00:18 +02:00

61 lines
1.1 KiB
C

/*
* timer.c
*
* Created on: May 31, 2017
* Author: wn
*/
#include "hmi.h"
#include "timer.h"
#include "alarm.h"
#include <PontCoopScheduler.h>
#include "eeprom.h"
const uint8_t OPTIME_UPDATE_CYCLE = 10;
extern tDisplay display;
void startTimer() {
display.timerState = TT_STARTED;
}
void stopTimer() {
display.timerState = TT_IDLE;
}
void secondTick(void *handle) {
tDisplay *lDisplay = (tDisplay*) handle;
lDisplay->operatingTime += 1;
if (lDisplay->operatingTime % OPTIME_UPDATE_CYCLE == 0) {
eepromWriteStorage();
}
switch (lDisplay->timerState) {
case TT_STARTED:
lDisplay->currentTime = lDisplay->targetTime;
lDisplay->overrunTime = 0;
lDisplay->timerState = TT_RUNNING;
break;
case TT_RUNNING:
lDisplay->currentTime -= 1;
if (lDisplay->currentTime == 0) {
enableAlarm(TIME_ALARM);
lDisplay->timerState = TT_OVERRUN;
}
break;
case TT_OVERRUN:
lDisplay->overrunTime += 1;
break;
case TT_IDLE:
;
break;
default:
;
}
}
void timerInit() {
schAdd(secondTick, &display, 0, 1000);
}