/*
 * coffee.h
 *
 *  Created on: Sep 25, 2017
 *      Author: Sebastian
 */

#ifndef COFFEE_H_
#define COFFEE_H_

#include <csignal>
#include "events.h"

//define status
typedef enum {
	STATE_OFF,
	STATE_HEATING,
	STATE_INITALHEATING,
	STATE_IDLE,
	STATE_BREW,
	STATE_BREWMANUAL,
	STATE_CLEANING,
	STATE_ERROR,
	STATE_WAIT_OFF,
	RETURN_STATE
} coffee_status_t;

extern const char* StateName[];

#define AMOUNT_PREINFUSION	25 //Preinfusion amount in ml
#define TIME_SOAK			5000 //Time between preinfusion and infusion in ms
#define TIME_INFUSION 		25000	//Infusion time in ms
#define AMOUNT_DBLESPRESSO	59.0	//Size of a double espresso in ml
void *coffeeThread(void *threadid);

void coffeeHandler(int signum, siginfo_t *siginfo, void *context);
int getSigValue(void);
bool SigValueEmpty(void);
void changeState(coffee_status_t newState);
coffee_status_t getState(void);
void brewTimeHandler(void);
void writeBackCache(void);
void coffeeTerminate(event_t *event);
void coffeeBrew(void);
void coffeeIncreaseBrewCounter(void);
void coffeeIncreaseHeatingTime(uint64_t heatingTime);

#endif /* COFFEE_H_ */
