|
@@ -23,7 +23,6 @@
|
|
|
#include "timer.h"
|
|
|
#include "database.h"
|
|
|
|
|
|
-
|
|
|
coffee_status_t state;
|
|
|
coffee_menuPage_t page;
|
|
|
coffee_mode_t mode;
|
|
@@ -37,10 +36,10 @@ uint16_t brewCounter;
|
|
|
bool initalHeating;
|
|
|
bool descaling; //flag to indicate descaling and cleaning
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-const char* PageName[] = {"SoftOff", "Kill", "Stats", "Temp", "Clean", "Demo", "Exit"};
|
|
|
-const char* StateName[] = {"OFF", "HEATING", "INITHEAT", "IDLE", "BREW", "BREWMAN", "CLEAN", "ERROR", "WAITOFF"};
|
|
|
+const char* PageName[] = { "SoftOff", "Kill", "Stats", "Temp", "Clean", "Demo",
|
|
|
+ "Exit" };
|
|
|
+const char* StateName[] = { "OFF", "HEATING", "INITHEAT", "IDLE", "BREW",
|
|
|
+ "BREWMAN", "CLEAN", "ERROR", "WAITOFF" };
|
|
|
|
|
|
/**
|
|
|
* Thread for the finite state machine
|
|
@@ -69,13 +68,15 @@ void *coffeeThread(void *threadid) {
|
|
|
descaling = false;
|
|
|
|
|
|
//read the database values
|
|
|
- if(!(totalHeatingTime = sqlGetConf(CFGHeatingTime))){
|
|
|
- logger_error("coffee.cpp: Couldn't read the heating time from the database");
|
|
|
+ if (!(totalHeatingTime = sqlGetConf(CFGHeatingTime))) {
|
|
|
+ logger_error(
|
|
|
+ "coffee.cpp: Couldn't read the heating time from the database");
|
|
|
//pthread_exit(EXIT_SUCCESS);
|
|
|
exit(EXIT_FAILURE);
|
|
|
}
|
|
|
- if(!(brewCounter = sqlGetConf(CFGbrewcounter))){
|
|
|
- logger_error("coffee.cpp: Couldn't read the brew counter from the database");
|
|
|
+ if (!(brewCounter = sqlGetConf(CFGbrewcounter))) {
|
|
|
+ logger_error(
|
|
|
+ "coffee.cpp: Couldn't read the brew counter from the database");
|
|
|
//pthread_exit(EXIT_SUCCESS);
|
|
|
exit(EXIT_FAILURE);
|
|
|
}
|
|
@@ -131,7 +132,7 @@ void *coffeeThread(void *threadid) {
|
|
|
|
|
|
switch (getSigValue(MODE_MENU)) {
|
|
|
case SigInt0Psh:
|
|
|
- if(halIsHeating()){
|
|
|
+ if (halIsHeating()) {
|
|
|
coffeeIncreaseHeatingTime(halgetHeatingTime());
|
|
|
}
|
|
|
changeState(STATE_OFF);
|
|
@@ -139,10 +140,9 @@ void *coffeeThread(void *threadid) {
|
|
|
break;
|
|
|
|
|
|
case SigInt1Psh:
|
|
|
- if(state == STATE_IDLE || state == STATE_HEATING){
|
|
|
+ if (state == STATE_IDLE || state == STATE_HEATING) {
|
|
|
changePage(PAGE_CLEAN);
|
|
|
- }
|
|
|
- else {
|
|
|
+ } else {
|
|
|
changePage(PAGE_DEMO);
|
|
|
}
|
|
|
break;
|
|
@@ -156,11 +156,10 @@ void *coffeeThread(void *threadid) {
|
|
|
switch (getSigValue(MODE_MENU)) {
|
|
|
case SigInt0Psh:
|
|
|
changeMode(MODE_STATE);
|
|
|
- if(!halProxSensorCovered()){
|
|
|
+ if (!halProxSensorCovered()) {
|
|
|
changeState(STATE_CLEANING);
|
|
|
leaveMenu();
|
|
|
- }
|
|
|
- else {
|
|
|
+ } else {
|
|
|
changeState(STATE_FULLTANK);
|
|
|
leaveMenu();
|
|
|
}
|
|
@@ -215,10 +214,11 @@ void *coffeeThread(void *threadid) {
|
|
|
break;
|
|
|
|
|
|
case SigInt1Psh:
|
|
|
- if(state == STATE_HEATING || state == STATE_ERROR || state == STATE_IDLE || state == STATE_INITALHEATING){
|
|
|
+ if (state == STATE_HEATING || state == STATE_ERROR
|
|
|
+ || state == STATE_IDLE
|
|
|
+ || state == STATE_INITALHEATING) {
|
|
|
changePage(PAGE_SOFTOFF);
|
|
|
- }
|
|
|
- else {
|
|
|
+ } else {
|
|
|
changePage(PAGE_DEMO);
|
|
|
}
|
|
|
break;
|
|
@@ -226,6 +226,9 @@ void *coffeeThread(void *threadid) {
|
|
|
break;
|
|
|
} //end switch (page)
|
|
|
|
|
|
+ /* FIXME: Display events are reacting on Psh signal, leads to instant
|
|
|
+ * machine turn on when leave menu is pressed */
|
|
|
+
|
|
|
/*
|
|
|
* Hardware FSM
|
|
|
*/
|
|
@@ -234,12 +237,13 @@ void *coffeeThread(void *threadid) {
|
|
|
*
|
|
|
*/
|
|
|
case STATE_OFF:
|
|
|
- halMachineOff();
|
|
|
- writeBackCache();
|
|
|
- page = PAGE_DEMO; //machine is off, the menu starts with the demo page
|
|
|
+ if (mode == MODE_STATE) {
|
|
|
+ halMachineOff();
|
|
|
+ writeBackCache();
|
|
|
+ if (SigValueEmpty())
|
|
|
+ pause();
|
|
|
+ }
|
|
|
|
|
|
- if (SigValueEmpty() && mode == MODE_STATE)
|
|
|
- pause();
|
|
|
switch (getSigValue(MODE_STATE)) {
|
|
|
case SigInt0Rls:
|
|
|
//Check waterlevel in gray water tank
|
|
@@ -248,18 +252,20 @@ void *coffeeThread(void *threadid) {
|
|
|
sleep(1);
|
|
|
if (halIsHeating() && !halProxSensorCovered()) { //check if System starts to heat when turned on
|
|
|
changeState(STATE_INITALHEATING);
|
|
|
- } else if (!halIsHeating() && !halProxSensorCovered()){
|
|
|
+ } else if (!halIsHeating() && !halProxSensorCovered()) {
|
|
|
changeState(STATE_IDLE);
|
|
|
- }
|
|
|
- else if (halProxSensorCovered()) {
|
|
|
+ } else if (halProxSensorCovered()) {
|
|
|
logger_error("Empty Tank please!\n");
|
|
|
changeState(STATE_FULLTANK);
|
|
|
}
|
|
|
- page = PAGE_SOFTOFF; //the machine is on, the menu starts with the turning off page
|
|
|
+ if (page != PAGE_SOFTOFF)
|
|
|
+ changePage(PAGE_SOFTOFF); //the machine is on, the menu starts with the turning off page
|
|
|
break;
|
|
|
|
|
|
case SigInt1Psh:
|
|
|
//Enter the menu
|
|
|
+ if (page != PAGE_DEMO)
|
|
|
+ changePage(PAGE_DEMO); //machine is off, the menu starts with the demo page
|
|
|
changeMode(MODE_MENU);
|
|
|
break;
|
|
|
}
|
|
@@ -267,13 +273,13 @@ void *coffeeThread(void *threadid) {
|
|
|
|
|
|
/*
|
|
|
*
|
|
|
- */
|
|
|
+ */
|
|
|
case STATE_WAIT_OFF:
|
|
|
if (SigValueEmpty() && mode == MODE_STATE)
|
|
|
pause();
|
|
|
switch (getSigValue(MODE_STATE)) {
|
|
|
case SigPressOpn:
|
|
|
- usleep(100000);//wait so no load will be switched
|
|
|
+ usleep(100000); //wait so no load will be switched
|
|
|
coffeeIncreaseHeatingTime(halgetHeatingTime());
|
|
|
changeState(STATE_OFF);
|
|
|
break;
|
|
@@ -471,9 +477,9 @@ void *coffeeThread(void *threadid) {
|
|
|
switch (getSigValue(MODE_STATE)) {
|
|
|
case SigInt1Psh:
|
|
|
case SigInt0Psh:
|
|
|
- if(halIsHeating() && initalHeating){
|
|
|
+ if (halIsHeating() && initalHeating) {
|
|
|
changeState(STATE_INITALHEATING);
|
|
|
- } else if (halIsHeating() && !initalHeating){
|
|
|
+ } else if (halIsHeating() && !initalHeating) {
|
|
|
changeState(STATE_HEATING);
|
|
|
} else {
|
|
|
changeState(STATE_IDLE);
|
|
@@ -488,15 +494,15 @@ void *coffeeThread(void *threadid) {
|
|
|
case STATE_ERROR:
|
|
|
if (SigValueEmpty() && mode == MODE_STATE)
|
|
|
pause();
|
|
|
- switch (getSigValue(MODE_STATE)) {
|
|
|
- case SigInt1RlsLong:
|
|
|
- case SigInt0RlsLong:
|
|
|
- if(halIsHeating()){
|
|
|
- coffeeIncreaseHeatingTime(halgetHeatingTime());
|
|
|
+ switch (getSigValue(MODE_STATE)) {
|
|
|
+ case SigInt1RlsLong:
|
|
|
+ case SigInt0RlsLong:
|
|
|
+ if (halIsHeating()) {
|
|
|
+ coffeeIncreaseHeatingTime(halgetHeatingTime());
|
|
|
+ }
|
|
|
+ changeState(STATE_OFF);
|
|
|
+ break;
|
|
|
}
|
|
|
- changeState(STATE_OFF);
|
|
|
- break;
|
|
|
- }
|
|
|
}
|
|
|
}
|
|
|
pthread_exit(EXIT_SUCCESS);
|
|
@@ -512,7 +518,8 @@ void *coffeeThread(void *threadid) {
|
|
|
void coffeeHandler(int signum, siginfo_t *siginfo, void *context) {
|
|
|
sigval_t sigVal = (siginfo->si_value);
|
|
|
sigValue = sigVal.sival_int;
|
|
|
- logger(V_BREW, "coffee.cpp: CoffeeHandler called with Signal %d\n", sigValue);
|
|
|
+ logger(V_BREW, "coffee.cpp: CoffeeHandler called with Signal %d\n",
|
|
|
+ sigValue);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -520,28 +527,29 @@ void coffeeHandler(int signum, siginfo_t *siginfo, void *context) {
|
|
|
* @return value sent with the last signal
|
|
|
*/
|
|
|
int getSigValue(coffee_mode_t mode) {
|
|
|
- if(mode == MODE_MENU) {
|
|
|
- switch (sigValue){
|
|
|
+ int tmp = sigValue;
|
|
|
+ if (mode == MODE_MENU) {
|
|
|
+ switch (sigValue) {
|
|
|
case SigInt0Psh:
|
|
|
case SigInt0Rls:
|
|
|
case SigInt0RlsLong:
|
|
|
case SigInt1Psh:
|
|
|
case SigInt1Rls:
|
|
|
case SigInt1RlsLong:
|
|
|
- int tmp = sigValue;
|
|
|
sigValue = 0;
|
|
|
return tmp;
|
|
|
+
|
|
|
+ default:
|
|
|
break;
|
|
|
}
|
|
|
- }
|
|
|
- else { //State Mode
|
|
|
- int tmp = sigValue;
|
|
|
+ } else { //State Mode
|
|
|
sigValue = 0;
|
|
|
return tmp;
|
|
|
}
|
|
|
- int tmp = sigValue;
|
|
|
- sigValue = 0;
|
|
|
- return tmp;
|
|
|
+ //int tmp = sigValue;
|
|
|
+ //sigValue = 0;
|
|
|
+ //return tmp;
|
|
|
+ return 0;
|
|
|
}
|
|
|
|
|
|
bool SigValueEmpty(void) {
|
|
@@ -565,27 +573,29 @@ void changeState(coffee_status_t newState) {
|
|
|
/*
|
|
|
* Change Page to new menu page
|
|
|
*/
|
|
|
-void changePage(coffee_menuPage_t newPage){
|
|
|
- logger(V_BREW, "Change Page to %s", PageName[newPage]);
|
|
|
+void changePage(coffee_menuPage_t newPage) {
|
|
|
+ logger(V_BREW, "Change Page to %s\n", PageName[newPage]);
|
|
|
+ event_trigger("pagechange", &newPage, sizeof(newPage));
|
|
|
page = newPage;
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
* Changes the mode of the machine to the given mode
|
|
|
*/
|
|
|
-void changeMode(coffee_mode_t newmode){
|
|
|
- if(mode == MODE_MENU)
|
|
|
+void changeMode(coffee_mode_t newMode) {
|
|
|
+ if (newMode == MODE_MENU)
|
|
|
logger(V_BREW, "Changing to menu mode\n");
|
|
|
else
|
|
|
logger(V_BREW, "Changing to state mode\n");
|
|
|
|
|
|
- mode = newmode;
|
|
|
+ event_trigger("modechange", &newMode, sizeof(newMode));
|
|
|
+ mode = newMode;
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
* leaving the menu
|
|
|
*/
|
|
|
-void leaveMenu(){
|
|
|
+void leaveMenu() {
|
|
|
logger(V_BREW, "Leaving the menu again...\n");
|
|
|
//leave the menu again
|
|
|
changeMode(MODE_STATE);
|
|
@@ -623,7 +633,7 @@ void coffeeTerminate(event_t *event) {
|
|
|
* brewCounter and totalHeatingTime
|
|
|
*
|
|
|
*/
|
|
|
-void writeBackCache(void){
|
|
|
+void writeBackCache(void) {
|
|
|
if (sqlSetConf(CFGbrewcounter, brewCounter)) {
|
|
|
logger_error("coffee.cpp: Couldn't write brewcounter to database");
|
|
|
return;
|
|
@@ -637,9 +647,9 @@ void writeBackCache(void){
|
|
|
/*
|
|
|
* Procedure for cleaning the machine
|
|
|
*/
|
|
|
-void coffeeClean(void){
|
|
|
+void coffeeClean(void) {
|
|
|
logger(V_BREW, "Cleaning...\n");
|
|
|
- for(int i = 0; i < 20; i++){
|
|
|
+ for (int i = 0; i < 20; i++) {
|
|
|
halRelaisOn(RELAIS_PUMP);
|
|
|
sleep(3);
|
|
|
halRelaisOff(RELAIS_PUMP);
|
|
@@ -665,7 +675,7 @@ void coffeeBrew(void) {
|
|
|
usleep(50000);
|
|
|
if (getSigValue(MODE_STATE) == SigInt0Psh)
|
|
|
stopBrewing();
|
|
|
- return;
|
|
|
+ return;
|
|
|
}
|
|
|
stopBrewing();
|
|
|
|
|
@@ -675,9 +685,10 @@ void coffeeBrew(void) {
|
|
|
brewTimer.start();
|
|
|
while (brewTime < TIME_SOAK) {
|
|
|
usleep(100000);
|
|
|
- if (getSigValue(MODE_STATE) == SigInt0Psh)
|
|
|
+ if (getSigValue(MODE_STATE) == SigInt0Psh) {
|
|
|
stopBrewing();
|
|
|
return;
|
|
|
+ }
|
|
|
}
|
|
|
stopBrewing();
|
|
|
|
|
@@ -690,8 +701,7 @@ void coffeeBrew(void) {
|
|
|
while (brewTime < TIME_INFUSION && halGetFlow() < AMOUNT_DBLESPRESSO) {
|
|
|
usleep(100000);
|
|
|
if (getSigValue(MODE_STATE) == SigInt0Psh)
|
|
|
- stopBrewing();
|
|
|
- return;
|
|
|
+ break;
|
|
|
}
|
|
|
stopBrewing();
|
|
|
return;
|
|
@@ -701,7 +711,7 @@ void coffeeBrew(void) {
|
|
|
* Wrapper function for the end of a brewing process
|
|
|
* this function stops the pump, brewtimer and resets the flow and brew time to zero
|
|
|
*/
|
|
|
-void stopBrewing(){
|
|
|
+void stopBrewing() {
|
|
|
halRelaisOff(RELAIS_PUMP);
|
|
|
brewTimer.stop();
|
|
|
brewTime = 0;
|
|
@@ -713,11 +723,10 @@ void stopBrewing(){
|
|
|
*/
|
|
|
void coffeeIncreaseBrewCounter(void) {
|
|
|
brewCounter++;
|
|
|
- if((brewCounter % DIRTY_ESPRESSO) == 0)
|
|
|
+ if ((brewCounter % DIRTY_ESPRESSO) == 0)
|
|
|
descaling = true;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
*
|
|
|
*/
|