teathermotimerng/src/eggTimer.c
2016-09-11 20:33:38 +02:00

69 lines
1.3 KiB
C

/*
* eggTimer.c
*
* Created on: 08.09.2016
* Author: dehottgw
*/
#include <stdint.h>
#include <stdbool.h>
#include <stdlib.h>
#include <msp430g2553.h>
#include "eggTimer.h"
#include "displayMuxer.h"
#include "button.h"
#include "gpio.h"
#include "PontCoopScheduler.h"
#include "powerDown.h"
const uint32_t EGG_TIMER_CYCLE = 1000;
const uint32_t LED_CYCLE = 250;
const uint32_t MY_POWER_DOWN_DELAY = 120000;
const uint8_t COOKING_TIME = 120;
uint8_t restCookingTime;
bool timerRunning;
bool timerStarted;
void eggTimerStart(void *handleArg) {
if (! timerStarted) {
timerRunning = true;
timerStarted = true;
}
}
void eggTimerAlarm(void *handleArg) {
gpioTogglePin(LED_1);
}
void eggTimerInit(void *handleArg) {
restCookingTime = COOKING_TIME;
timerRunning = false;
timerStarted = false;
buttonRegister(eggTimerStart, NULL, BUTTON_START_TIMER);
}
void eggTimerExec(void *handleArg) {
if (timerRunning) {
restCookingTime--;
displayMuxerSetValue(restCookingTime, true, TIMER_MUX);
if (restCookingTime == 0) {
// activate alarm
schAdd(eggTimerAlarm, NULL, 0, LED_CYCLE);
schDel(powerDown, NULL);
schAdd(powerDown, NULL, MY_POWER_DOWN_DELAY, 0);
timerRunning = false;
}
}
}