|
@@ -38,16 +38,18 @@ bool initalHeating;
|
|
|
bool descaling; //flag to indicate descaling and cleaning
|
|
|
uint16_t descBrewcount;
|
|
|
time_t descRawTimestamp;
|
|
|
+uint16_t oldCoffeeCFGVal; //temporary variable to save any old config value to restore when aborting the config change
|
|
|
|
|
|
const char* PageName[] = {
|
|
|
"SOFTOFF",
|
|
|
"KILL",
|
|
|
+ "SINGLEESPRESSO"
|
|
|
"STATS",
|
|
|
"STATS2",
|
|
|
"DESCALING",
|
|
|
"TEMP",
|
|
|
"CLEAN",
|
|
|
- "RESTART",
|
|
|
+ "REBOOT",
|
|
|
"SETTINGS",
|
|
|
"RESETKWH",
|
|
|
"RESETKWH_VAL",
|
|
@@ -59,6 +61,8 @@ const char* PageName[] = {
|
|
|
"CHANGEBREWML_VAL",
|
|
|
"CHANGESOAKTIME",
|
|
|
"CHANGESOAKTIME_VAL",
|
|
|
+ "CHANGEAUTORESET",
|
|
|
+ "CHANGEAUTORESET_VAL",
|
|
|
"LEAVESETTINGS",
|
|
|
"Exit",
|
|
|
"PAGE_NULL"
|
|
@@ -78,7 +82,9 @@ const char* StateName[] = {
|
|
|
"STATE_NULL",
|
|
|
};
|
|
|
|
|
|
-struct coffeeConfig coffeeCFG = {AMOUNT_PREINFUSION, TIME_SOAK, TIME_INFUSION, AMOUNT_DBLESPRESSO};
|
|
|
+//the reference configuration for brewing coffees
|
|
|
+coffeeConfig coffeeCFG = {AMOUNT_PREINFUSION, TIME_SOAK, TIME_INFUSION, AMOUNT_DBLESPRESSO};
|
|
|
+bool brewSingleEspresso = false; //flag to brew a single espresso only
|
|
|
|
|
|
/**
|
|
|
* Thread for the finite state machine
|
|
@@ -88,7 +94,7 @@ struct coffeeConfig coffeeCFG = {AMOUNT_PREINFUSION, TIME_SOAK, TIME_INFUSION, A
|
|
|
*/
|
|
|
|
|
|
void *coffeeThread(void *threadid) {
|
|
|
- logger(V_BASIC, "Initializing coffee thread...\n");
|
|
|
+ logger(V_BASIC, "coffee.cpp: Initializing coffee thread...\n");
|
|
|
|
|
|
//installing new Signal handler for coffeethread
|
|
|
struct sigaction action;
|
|
@@ -127,16 +133,20 @@ void *coffeeThread(void *threadid) {
|
|
|
//pthread_exit(EXIT_SUCCESS);
|
|
|
exit(EXIT_FAILURE);
|
|
|
}
|
|
|
- if (!(coffeeCFG.amount_dblespresso = sqlGetConf(CFGAmountDblEspresso))) {
|
|
|
+ if (!(coffeeCFG.amount_espresso = sqlGetConf(CFGAmountDblEspresso))) {
|
|
|
+ coffeeCFG.amount_espresso = AMOUNT_DBLESPRESSO;
|
|
|
logger_error("coffee.cpp: Couldn't read config CFGAmountDblEspresso from database\nFalling back to default!\n");
|
|
|
}
|
|
|
if (!(coffeeCFG.amount_preinfusion = sqlGetConf(CFGAmountPreinfusion))) {
|
|
|
+ coffeeCFG.amount_preinfusion = AMOUNT_PREINFUSION;
|
|
|
logger_error("coffee.cpp: Couldn't read config CFGAmountPreinfusion from database\nFalling back to default!\n");
|
|
|
}
|
|
|
if (!(coffeeCFG.time_infusion = sqlGetConf(CFGTimeInfusion))) {
|
|
|
+ coffeeCFG.time_infusion = TIME_INFUSION;
|
|
|
logger_error("coffee.cpp: Couldn't read config CFGTimeInfusion from database\nFalling back to default!\n");
|
|
|
}
|
|
|
if (!(coffeeCFG.time_soak = sqlGetConf(CFGTimeSoak))) {
|
|
|
+ coffeeCFG.time_soak = TIME_SOAK;
|
|
|
logger_error("coffee.cpp: Couldn't read config CFGTimeSoak from database\nFalling back to default!\n");
|
|
|
}
|
|
|
|
|
@@ -157,7 +167,7 @@ void *coffeeThread(void *threadid) {
|
|
|
changeState(STATE_IDLE);
|
|
|
}
|
|
|
} else if (halGetRelaisState(RELAIS_PUMP)) {
|
|
|
- logger_error("Whoops, why is the pump running...\n");
|
|
|
+ logger_error("coffee.cpp: Whoops, why is the pump running...\n");
|
|
|
changeState(STATE_ERROR);
|
|
|
} else {
|
|
|
changeState(STATE_OFF);
|
|
@@ -197,7 +207,6 @@ void *coffeeThread(void *threadid) {
|
|
|
break;
|
|
|
}
|
|
|
break;
|
|
|
-
|
|
|
case PAGE_KILL: //this page is only available when the machine is on
|
|
|
if (SigValueEmpty() && mode == MODE_MENU)
|
|
|
pause();
|
|
@@ -209,10 +218,10 @@ void *coffeeThread(void *threadid) {
|
|
|
break;
|
|
|
|
|
|
case SigRotCW:
|
|
|
- if (state == STATE_IDLE || state == STATE_HEATING) {
|
|
|
- changePage(PAGE_CLEAN);
|
|
|
+ if (state == STATE_HEATING || state == STATE_IDLE) {
|
|
|
+ changePage(PAGE_SINGLEESPRESSO);
|
|
|
} else {
|
|
|
- changePage(PAGE_RESTART);
|
|
|
+ changePage(PAGE_REBOOT);
|
|
|
}
|
|
|
break;
|
|
|
|
|
@@ -221,25 +230,20 @@ void *coffeeThread(void *threadid) {
|
|
|
break;
|
|
|
}
|
|
|
break;
|
|
|
-
|
|
|
- case PAGE_CLEAN: //this page is only be available when the machine is hot
|
|
|
+ case PAGE_SINGLEESPRESSO: //this page is only available when the machine is hot
|
|
|
if (SigValueEmpty() && mode == MODE_MENU)
|
|
|
pause();
|
|
|
|
|
|
switch (getSigValue(MODE_MENU)) {
|
|
|
case SigInt0Rls:
|
|
|
+ brewSingleEspresso = true;
|
|
|
changeMode(MODE_STATE);
|
|
|
- if (!halProxSensorCovered()) {
|
|
|
- changeState(STATE_CLEANING);
|
|
|
- leaveMenu();
|
|
|
- } else {
|
|
|
- changeState(STATE_FULLTANK);
|
|
|
- leaveMenu();
|
|
|
- }
|
|
|
+ changeState(STATE_BREW);
|
|
|
+ leaveMenu();
|
|
|
break;
|
|
|
|
|
|
case SigRotCW:
|
|
|
- changePage(PAGE_RESTART);
|
|
|
+ changePage(PAGE_CLEAN);
|
|
|
break;
|
|
|
|
|
|
case SigRotCCW:
|
|
@@ -247,8 +251,27 @@ void *coffeeThread(void *threadid) {
|
|
|
break;
|
|
|
}
|
|
|
break;
|
|
|
+ case PAGE_CLEAN: //this page is only be available when the machine is hot
|
|
|
+ if (SigValueEmpty() && mode == MODE_MENU)
|
|
|
+ pause();
|
|
|
|
|
|
- case PAGE_RESTART:
|
|
|
+ switch (getSigValue(MODE_MENU)) {
|
|
|
+ case SigInt0Rls:
|
|
|
+ changeMode(MODE_STATE);
|
|
|
+ changeState(STATE_CLEANING);
|
|
|
+ leaveMenu();
|
|
|
+ break;
|
|
|
+
|
|
|
+ case SigRotCW:
|
|
|
+ changePage(PAGE_REBOOT);
|
|
|
+ break;
|
|
|
+
|
|
|
+ case SigRotCCW:
|
|
|
+ changePage(PAGE_SINGLEESPRESSO);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case PAGE_REBOOT:
|
|
|
if (SigValueEmpty() && mode == MODE_MENU)
|
|
|
pause();
|
|
|
|
|
@@ -256,7 +279,9 @@ void *coffeeThread(void *threadid) {
|
|
|
case SigInt0Rls:
|
|
|
event_trigger("terminate");
|
|
|
coffeeNap(4, 0);
|
|
|
- exit(EXIT_SUCCESS);
|
|
|
+ system("reboot");
|
|
|
+ //prevent any further user action
|
|
|
+ coffeeNap(30, 0);
|
|
|
break;
|
|
|
case SigRotCW:
|
|
|
changePage(PAGE_TEMP);
|
|
@@ -273,7 +298,6 @@ void *coffeeThread(void *threadid) {
|
|
|
break;
|
|
|
}
|
|
|
break;
|
|
|
-
|
|
|
case PAGE_TEMP:
|
|
|
if (SigValueEmpty() && mode == MODE_MENU)
|
|
|
pause();
|
|
@@ -284,7 +308,7 @@ void *coffeeThread(void *threadid) {
|
|
|
break;
|
|
|
|
|
|
case SigRotCCW:
|
|
|
- changePage(PAGE_RESTART);
|
|
|
+ changePage(PAGE_REBOOT);
|
|
|
break;
|
|
|
}
|
|
|
break;
|
|
@@ -370,7 +394,8 @@ void *coffeeThread(void *threadid) {
|
|
|
switch (getSigValue(MODE_MENU)) {
|
|
|
case SigInt0Rls:
|
|
|
//Reset the KWH counter
|
|
|
-
|
|
|
+ halSetTotalHeatingTime(0);
|
|
|
+ halWriteBackCache();
|
|
|
changePage(PAGE_RESETKWH);
|
|
|
break;
|
|
|
case SigInt1Rls:
|
|
@@ -378,10 +403,8 @@ void *coffeeThread(void *threadid) {
|
|
|
changePage(PAGE_RESETKWH);
|
|
|
break;
|
|
|
case SigRotCW:
|
|
|
-
|
|
|
break;
|
|
|
case SigRotCCW:
|
|
|
-
|
|
|
break;
|
|
|
}
|
|
|
break;
|
|
@@ -391,7 +414,9 @@ void *coffeeThread(void *threadid) {
|
|
|
|
|
|
switch (getSigValue(MODE_MENU)) {
|
|
|
case SigInt0Rls:
|
|
|
-
|
|
|
+ //temporary store the old value of the config to restore when the change process is aborted
|
|
|
+ oldCoffeeCFGVal = coffeeCFG.amount_preinfusion;
|
|
|
+ changePage(PAGE_CHANGEPREINF_VAL);
|
|
|
break;
|
|
|
case SigRotCW:
|
|
|
changePage(PAGE_CHANGEBREWTIME);
|
|
@@ -407,13 +432,22 @@ void *coffeeThread(void *threadid) {
|
|
|
|
|
|
switch (getSigValue(MODE_MENU)) {
|
|
|
case SigInt0Rls:
|
|
|
+ writeBackCache();
|
|
|
+ oldCoffeeCFGVal = 0;
|
|
|
+ changePage(PAGE_CHANGEPREINF);
|
|
|
+ break;
|
|
|
+ case SigInt1Rls:
|
|
|
+ //Abort the change of the preinfusion
|
|
|
+ //restore the previous value
|
|
|
+ coffeeCFG.amount_preinfusion = oldCoffeeCFGVal;
|
|
|
+ oldCoffeeCFGVal = 0;
|
|
|
changePage(PAGE_CHANGEPREINF);
|
|
|
break;
|
|
|
case SigRotCW:
|
|
|
-
|
|
|
+ coffeeCFG.amount_preinfusion += 1;
|
|
|
break;
|
|
|
case SigRotCCW:
|
|
|
-
|
|
|
+ if (coffeeCFG.amount_preinfusion >= 1) coffeeCFG.amount_preinfusion -= 1;
|
|
|
break;
|
|
|
}
|
|
|
break;
|
|
@@ -423,7 +457,8 @@ void *coffeeThread(void *threadid) {
|
|
|
|
|
|
switch (getSigValue(MODE_MENU)) {
|
|
|
case SigInt0Rls:
|
|
|
-
|
|
|
+ oldCoffeeCFGVal = coffeeCFG.time_infusion;
|
|
|
+ changePage(PAGE_CHANGEBREWTIME_VAL);
|
|
|
break;
|
|
|
case SigRotCW:
|
|
|
changePage(PAGE_CHANGEBREWML);
|
|
@@ -439,13 +474,21 @@ void *coffeeThread(void *threadid) {
|
|
|
|
|
|
switch (getSigValue(MODE_MENU)) {
|
|
|
case SigInt0Rls:
|
|
|
+ writeBackCache();
|
|
|
+ oldCoffeeCFGVal = 0;
|
|
|
+ changePage(PAGE_CHANGEBREWTIME);
|
|
|
+ break;
|
|
|
+ case SigInt1Rls:
|
|
|
+ //abort the change of the brew time
|
|
|
+ coffeeCFG.time_infusion = oldCoffeeCFGVal;
|
|
|
+ oldCoffeeCFGVal = 0;
|
|
|
changePage(PAGE_CHANGEBREWTIME);
|
|
|
break;
|
|
|
case SigRotCW:
|
|
|
-
|
|
|
+ coffeeCFG.time_infusion += 1000;
|
|
|
break;
|
|
|
case SigRotCCW:
|
|
|
-
|
|
|
+ if (coffeeCFG.time_infusion >= 1000) coffeeCFG.time_infusion -= 1000;
|
|
|
break;
|
|
|
}
|
|
|
break;
|
|
@@ -455,7 +498,8 @@ void *coffeeThread(void *threadid) {
|
|
|
|
|
|
switch (getSigValue(MODE_MENU)) {
|
|
|
case SigInt0Rls:
|
|
|
-
|
|
|
+ oldCoffeeCFGVal = coffeeCFG.amount_espresso;
|
|
|
+ changePage(PAGE_CHANGEBREWML_VAL);
|
|
|
break;
|
|
|
case SigRotCW:
|
|
|
changePage(PAGE_CHANGESOAKTIME);
|
|
@@ -471,13 +515,21 @@ void *coffeeThread(void *threadid) {
|
|
|
|
|
|
switch (getSigValue(MODE_MENU)) {
|
|
|
case SigInt0Rls:
|
|
|
+ writeBackCache();
|
|
|
+ oldCoffeeCFGVal = 0;
|
|
|
+ changePage(PAGE_CHANGEBREWML);
|
|
|
+ break;
|
|
|
+ case SigInt1Rls:
|
|
|
+ //abort the change of the brew amout
|
|
|
+ coffeeCFG.amount_espresso = oldCoffeeCFGVal;
|
|
|
+ oldCoffeeCFGVal = 0;
|
|
|
changePage(PAGE_CHANGEBREWML);
|
|
|
break;
|
|
|
case SigRotCW:
|
|
|
-
|
|
|
+ coffeeCFG.amount_espresso += 1;
|
|
|
break;
|
|
|
case SigRotCCW:
|
|
|
-
|
|
|
+ if (coffeeCFG.amount_espresso >= 1) coffeeCFG.amount_espresso -= 1;
|
|
|
break;
|
|
|
}
|
|
|
break;
|
|
@@ -487,10 +539,11 @@ void *coffeeThread(void *threadid) {
|
|
|
|
|
|
switch (getSigValue(MODE_MENU)) {
|
|
|
case SigInt0Rls:
|
|
|
-
|
|
|
+ oldCoffeeCFGVal = coffeeCFG.time_soak;
|
|
|
+ changePage(PAGE_CHANGESOAKTIME_VAL);
|
|
|
break;
|
|
|
case SigRotCW:
|
|
|
- changePage(PAGE_LEAVESETTINGS);
|
|
|
+ changePage(PAGE_CHANGEAUTORESET);
|
|
|
break;
|
|
|
case SigRotCCW:
|
|
|
changePage(PAGE_CHANGEBREWML);
|
|
@@ -503,13 +556,62 @@ void *coffeeThread(void *threadid) {
|
|
|
|
|
|
switch (getSigValue(MODE_MENU)) {
|
|
|
case SigInt0Rls:
|
|
|
+ writeBackCache();
|
|
|
+ oldCoffeeCFGVal = 0;
|
|
|
+ changePage(PAGE_CHANGESOAKTIME);
|
|
|
+ break;
|
|
|
+ case SigInt1Rls:
|
|
|
+ //abort the change of the soak time
|
|
|
+ coffeeCFG.time_soak = oldCoffeeCFGVal;
|
|
|
+ oldCoffeeCFGVal = 0;
|
|
|
changePage(PAGE_CHANGESOAKTIME);
|
|
|
break;
|
|
|
case SigRotCW:
|
|
|
+ coffeeCFG.time_soak += 100;
|
|
|
+ break;
|
|
|
+ case SigRotCCW:
|
|
|
+ if (coffeeCFG.time_soak >= 100) coffeeCFG.time_soak -= 100;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case PAGE_CHANGEAUTORESET:
|
|
|
+ if (SigValueEmpty() && mode == MODE_MENU)
|
|
|
+ pause();
|
|
|
|
|
|
+ switch (getSigValue(MODE_MENU)) {
|
|
|
+ case SigInt0Rls:
|
|
|
+ oldCoffeeCFGVal = halGetFlowResetTime();
|
|
|
+ changePage(PAGE_CHANGEAUTORESET_VAL);
|
|
|
+ break;
|
|
|
+ case SigRotCW:
|
|
|
+ changePage(PAGE_LEAVESETTINGS);
|
|
|
break;
|
|
|
case SigRotCCW:
|
|
|
+ changePage(PAGE_CHANGESOAKTIME);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case PAGE_CHANGEAUTORESET_VAL:
|
|
|
+ if (SigValueEmpty() && mode == MODE_MENU)
|
|
|
+ pause();
|
|
|
|
|
|
+ switch (getSigValue(MODE_MENU)) {
|
|
|
+ case SigInt0Rls:
|
|
|
+ halWriteBackCache();
|
|
|
+ oldCoffeeCFGVal = 0;
|
|
|
+ changePage(PAGE_CHANGEAUTORESET);
|
|
|
+ break;
|
|
|
+ case SigInt1Rls:
|
|
|
+ //abort the change of the auto reset
|
|
|
+ halSetFlowResetTime(oldCoffeeCFGVal);
|
|
|
+ oldCoffeeCFGVal = 0;
|
|
|
+ changePage(PAGE_CHANGEAUTORESET);
|
|
|
+ break;
|
|
|
+ case SigRotCW:
|
|
|
+ halSetFlowResetTime(halGetFlowResetTime() + 100);
|
|
|
+ break;
|
|
|
+ case SigRotCCW:
|
|
|
+ if (halGetFlowResetTime() >= 100) halSetFlowResetTime(halGetFlowResetTime() - 100);
|
|
|
break;
|
|
|
}
|
|
|
break;
|
|
@@ -544,7 +646,7 @@ void *coffeeThread(void *threadid) {
|
|
|
|| state == STATE_INITALHEATING) {
|
|
|
changePage(PAGE_SOFTOFF);
|
|
|
} else {
|
|
|
- changePage(PAGE_RESTART);
|
|
|
+ changePage(PAGE_REBOOT);
|
|
|
}
|
|
|
break;
|
|
|
|
|
@@ -569,7 +671,7 @@ void *coffeeThread(void *threadid) {
|
|
|
halMachineOff();
|
|
|
writeBackCache();
|
|
|
// his might be a bit confusing to change the page here even if the menu isn't actually displayed
|
|
|
- changePage(PAGE_RESTART);
|
|
|
+ changePage(PAGE_REBOOT);
|
|
|
if (SigValueEmpty())
|
|
|
pause();
|
|
|
}
|
|
@@ -580,13 +682,13 @@ void *coffeeThread(void *threadid) {
|
|
|
//Check waterlevel in gray water tank
|
|
|
//turn machine on
|
|
|
halMachineOn();
|
|
|
- coffeeNap(1,0);
|
|
|
+ coffeeNap(1,500000000);
|
|
|
if (halIsHeating() && !halProxSensorCovered()) { //check if System starts to heat when turned on
|
|
|
changeState(STATE_INITALHEATING);
|
|
|
} else if (!halIsHeating() && !halProxSensorCovered()) {
|
|
|
changeState(STATE_IDLE);
|
|
|
} else if (halProxSensorCovered()) {
|
|
|
- logger_error("Empty Tank please!\n");
|
|
|
+ logger_error("coffee.cpp: Full graywater tank detected\n");
|
|
|
changeState(STATE_FULLTANK);
|
|
|
}
|
|
|
if (page != PAGE_SOFTOFF)
|
|
@@ -597,9 +699,6 @@ void *coffeeThread(void *threadid) {
|
|
|
case SigRotCW:
|
|
|
case SigInt1Rls:
|
|
|
//Enter the menu
|
|
|
- /* This should be not necessary!
|
|
|
- * if (page != PAGE_DEMO)
|
|
|
- changePage(PAGE_DEMO); //machine is off, the menu starts with the demo page*/
|
|
|
enterMenu();
|
|
|
break;
|
|
|
}
|
|
@@ -640,20 +739,6 @@ void *coffeeThread(void *threadid) {
|
|
|
if (SigValueEmpty() && mode == MODE_STATE)
|
|
|
pause();
|
|
|
switch (getSigValue(MODE_STATE)) {
|
|
|
-// case SigInt0RlsLong:
|
|
|
-// //Turn machine off again
|
|
|
-// coffeeIncreaseHeatingTime(halgetHeatingTime());
|
|
|
-// changeState(STATE_OFF);
|
|
|
-// break;
|
|
|
-//
|
|
|
-// case SigInt0Rls:
|
|
|
-// changeState(STATE_WAIT_OFF);
|
|
|
-// break;
|
|
|
-
|
|
|
- case SigProxCvrd:
|
|
|
- changeState(STATE_FULLTANK);
|
|
|
- break;
|
|
|
-
|
|
|
case SigPressOpn:
|
|
|
//Inital heating finished
|
|
|
initalHeating = false;
|
|
@@ -679,17 +764,6 @@ void *coffeeThread(void *threadid) {
|
|
|
if (SigValueEmpty() && mode == MODE_STATE)
|
|
|
pause();
|
|
|
switch (getSigValue(MODE_STATE)) {
|
|
|
-// case SigInt1RlsLong:
|
|
|
-// //Turn machine _immediately_ off again
|
|
|
-// coffeeIncreaseHeatingTime(halgetHeatingTime());
|
|
|
-// changeState(STATE_OFF);
|
|
|
-// break;
|
|
|
-//
|
|
|
-// case SigInt1Rls:
|
|
|
-// //turn machine off when heating is finished
|
|
|
-// changeState(STATE_WAIT_OFF);
|
|
|
-// break;
|
|
|
-
|
|
|
case SigPressOpn:
|
|
|
changeState(STATE_IDLE);
|
|
|
break;
|
|
@@ -699,10 +773,6 @@ void *coffeeThread(void *threadid) {
|
|
|
changeState(STATE_BREW);
|
|
|
break;
|
|
|
|
|
|
- case SigProxCvrd:
|
|
|
- changeState(STATE_FULLTANK);
|
|
|
- break;
|
|
|
-
|
|
|
case SigBrewOn:
|
|
|
//someone brews manually
|
|
|
coffeeManualBrewStart();
|
|
@@ -729,15 +799,6 @@ void *coffeeThread(void *threadid) {
|
|
|
if (SigValueEmpty() && mode == MODE_STATE)
|
|
|
pause();
|
|
|
switch (getSigValue(MODE_STATE)) {
|
|
|
-// case SigInt1RlsLong:
|
|
|
-// //turn machine _immediately_ off
|
|
|
-// changeState(STATE_OFF);
|
|
|
-// break;
|
|
|
-//
|
|
|
-// case SigInt1Rls:
|
|
|
-// changeState(STATE_OFF);
|
|
|
-// break;
|
|
|
-
|
|
|
case SigPressCls:
|
|
|
changeState(STATE_HEATING);
|
|
|
break;
|
|
@@ -746,10 +807,6 @@ void *coffeeThread(void *threadid) {
|
|
|
changeState(STATE_BREW);
|
|
|
break;
|
|
|
|
|
|
- case SigProxCvrd:
|
|
|
- changeState(STATE_FULLTANK);
|
|
|
- break;
|
|
|
-
|
|
|
case SigBrewOn:
|
|
|
//someone brews manually
|
|
|
coffeeManualBrewStart();
|
|
@@ -776,19 +833,22 @@ void *coffeeThread(void *threadid) {
|
|
|
//make sure the tank is not full
|
|
|
if (halProxSensorCovered()) {
|
|
|
changeState(STATE_FULLTANK);
|
|
|
- logger_error("coffee.cpp: Full tank detection failed..\n");
|
|
|
} else {
|
|
|
- coffeeBrew();
|
|
|
+ if (brewSingleEspresso) {
|
|
|
+ coffeeBrew(coffeeCFG.amount_preinfusion, coffeeCFG.time_soak, coffeeCFG.time_infusion, coffeeCFG.amount_espresso / 2);
|
|
|
+ brewSingleEspresso = false;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ coffeeBrew(coffeeCFG.amount_preinfusion, coffeeCFG.time_soak, coffeeCFG.time_infusion, coffeeCFG.amount_espresso);
|
|
|
+ }
|
|
|
checkDescaling();
|
|
|
- logger(V_BREW, "Finishing brewing\n");
|
|
|
- if (!halProxSensorCovered()) {
|
|
|
- if (halIsHeating()) {
|
|
|
- changeState(STATE_HEATING);
|
|
|
- } else {
|
|
|
- changeState(STATE_IDLE);
|
|
|
- }
|
|
|
- } else {
|
|
|
+ logger(V_BREW, "coffee.cpp: Finished brewing\n");
|
|
|
+ if (halProxSensorCovered()) {
|
|
|
changeState(STATE_FULLTANK);
|
|
|
+ } else if (halIsHeating()) {
|
|
|
+ changeState(STATE_HEATING);
|
|
|
+ } else {
|
|
|
+ changeState(STATE_IDLE);
|
|
|
}
|
|
|
}
|
|
|
break;
|
|
@@ -800,13 +860,15 @@ void *coffeeThread(void *threadid) {
|
|
|
if (SigValueEmpty() && mode == MODE_STATE)
|
|
|
pause();
|
|
|
switch (getSigValue(MODE_STATE)) {
|
|
|
- case SigBrewOff:
|
|
|
- if (halIsHeating()) {
|
|
|
- changeState(STATE_HEATING);
|
|
|
- } else {
|
|
|
- changeState(STATE_IDLE);
|
|
|
- }
|
|
|
- break;
|
|
|
+ case SigBrewOff:
|
|
|
+ if (halProxSensorCovered()) {
|
|
|
+ changeState(STATE_FULLTANK);
|
|
|
+ } else if (halIsHeating()) {
|
|
|
+ changeState(STATE_HEATING);
|
|
|
+ } else {
|
|
|
+ changeState(STATE_IDLE);
|
|
|
+ }
|
|
|
+ break;
|
|
|
}
|
|
|
break;
|
|
|
|
|
@@ -817,7 +879,9 @@ void *coffeeThread(void *threadid) {
|
|
|
if (!halProxSensorCovered()) {
|
|
|
//execute the cleaning procedure
|
|
|
coffeeClean();
|
|
|
- if (halIsHeating()) {
|
|
|
+ if (halProxSensorCovered()) {
|
|
|
+ changeState(STATE_FULLTANK);
|
|
|
+ } else if (halIsHeating()) {
|
|
|
changeState(STATE_HEATING);
|
|
|
} else {
|
|
|
changeState(STATE_IDLE);
|
|
@@ -835,14 +899,16 @@ void *coffeeThread(void *threadid) {
|
|
|
if (SigValueEmpty() && mode == MODE_STATE)
|
|
|
pause();
|
|
|
switch (getSigValue(MODE_STATE)) {
|
|
|
- case SigInt1Rls:
|
|
|
- case SigInt0Rls:
|
|
|
- if (halIsHeating() && initalHeating) {
|
|
|
- changeState(STATE_INITALHEATING);
|
|
|
- } else if (halIsHeating() && !initalHeating) {
|
|
|
- changeState(STATE_HEATING);
|
|
|
- } else {
|
|
|
- changeState(STATE_IDLE);
|
|
|
+ case SigInt1RlsLong:
|
|
|
+ case SigInt0RlsLong:
|
|
|
+ if (!halProxSensorCovered()) {
|
|
|
+ if (halIsHeating() && initalHeating) {
|
|
|
+ changeState(STATE_INITALHEATING);
|
|
|
+ } else if (halIsHeating() && !initalHeating) {
|
|
|
+ changeState(STATE_HEATING);
|
|
|
+ } else {
|
|
|
+ changeState(STATE_IDLE);
|
|
|
+ }
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
@@ -924,7 +990,7 @@ bool SigValueEmpty(void) {
|
|
|
* @param newState
|
|
|
*/
|
|
|
void changeState(coffee_status_t newState) {
|
|
|
- logger(V_BREW, "Changing state to %s\n", StateName[newState]);
|
|
|
+ logger(V_BREW, "coffee.cpp: Changing state to %s\n", StateName[newState]);
|
|
|
state = newState;
|
|
|
event_trigger("statechange", &state, sizeof(state));
|
|
|
}
|
|
@@ -933,7 +999,7 @@ 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\n", PageName[newPage]);
|
|
|
+ logger(V_BREW, "coffee.cpp: Change Page to %s\n", PageName[newPage]);
|
|
|
event_trigger("pagechange", &newPage, sizeof(newPage));
|
|
|
page = newPage;
|
|
|
}
|
|
@@ -943,9 +1009,9 @@ void changePage(coffee_menuPage_t newPage) {
|
|
|
*/
|
|
|
void changeMode(coffee_mode_t newMode) {
|
|
|
if (newMode == MODE_MENU)
|
|
|
- logger(V_BREW, "Changing to menu mode\n");
|
|
|
+ logger(V_BREW, "coffee.cpp: Changing to menu mode\n");
|
|
|
else
|
|
|
- logger(V_BREW, "Changing to state mode\n");
|
|
|
+ logger(V_BREW, "coffee.cpp: Changing to state mode\n");
|
|
|
|
|
|
event_trigger("modechange", &newMode, sizeof(newMode));
|
|
|
mode = newMode;
|
|
@@ -956,7 +1022,7 @@ void changeMode(coffee_mode_t newMode) {
|
|
|
* sets the start page for the next menu call to softoff
|
|
|
*/
|
|
|
void leaveMenu(void) {
|
|
|
- logger(V_BREW, "Leaving the menu again\n");
|
|
|
+ logger(V_BREW, "coffee.cpp: Leaving the menu again\n");
|
|
|
//leave the menu again
|
|
|
changeMode(MODE_STATE);
|
|
|
//change page to initial page
|
|
@@ -972,7 +1038,7 @@ void leaveMenu(void) {
|
|
|
* starts the timeoutcounter and changes the mode to the Menu Mode
|
|
|
*/
|
|
|
void enterMenu(void) {
|
|
|
- logger(V_BREW, "Entering the menu\n");
|
|
|
+ logger(V_BREW, "coffee.cpp: Entering the menu\n");
|
|
|
changeMode(MODE_MENU);
|
|
|
menuTimeout = 0;
|
|
|
menuTimer.start();
|
|
@@ -1014,10 +1080,10 @@ time_t * getDescTimestamp (void) {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Returns the preinfusion amount in ml of the coffee config
|
|
|
+ * Returns a pointer to the current coffee config
|
|
|
*/
|
|
|
-uint16_t getAmountPreinfusion (void) {
|
|
|
- return coffeeCFG.amount_preinfusion;
|
|
|
+coffeeConfig* getCoffeeCfg (void) {
|
|
|
+ return &coffeeCFG;
|
|
|
}
|
|
|
|
|
|
|
|
@@ -1062,7 +1128,7 @@ void coffeeNap (uint64_t sec, uint64_t nanosec){
|
|
|
errval = clock_nanosleep(CLOCK_REALTIME, TIMER_ABSTIME, &sleepTime, NULL);
|
|
|
}
|
|
|
while(errval == EINTR);
|
|
|
- if(errval) logger_error("coffee.cpp: suspending thread failed with error %d\n", errval);
|
|
|
+ if(errval) logger_error("coffee.cpp: Suspending thread failed with error %d\n", errval);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -1072,11 +1138,11 @@ void coffeeNap (uint64_t sec, uint64_t nanosec){
|
|
|
*/
|
|
|
void writeBackCache(void) {
|
|
|
logger(V_BREW, "Writing back cache...\n");
|
|
|
- logger(V_BREW, "Writing back brewCounter with %d\n", brewCounter);
|
|
|
+ logger(V_BREW, "Writing back brewCounter: %d\n", brewCounter);
|
|
|
if (sqlSetConf(CFGbrewcounter, brewCounter)) {
|
|
|
logger_error("coffee.cpp: Couldn't write brewcounter to database!\n");
|
|
|
}
|
|
|
- logger(V_BREW, "Writing back descaling brew counter %d\n", descBrewcount);
|
|
|
+ logger(V_BREW, "Writing back descaling brew counter: %d\n", descBrewcount);
|
|
|
if (sqlSetConf(CFGDescBrewCount, descBrewcount)) {
|
|
|
logger_error("coffee.cpp: Couldn't write descaling brewcount to database!\n");
|
|
|
}
|
|
@@ -1086,20 +1152,20 @@ void writeBackCache(void) {
|
|
|
if (sqlSetConf(CFGDescTimestamp, (uint64_t)descRawTimestamp)) {
|
|
|
logger_error("coffee.cpp: Couldn't write descaling timestamp to database!\n");
|
|
|
}
|
|
|
- logger(V_BREW, "Writing back CFGAmountPreinfusion with %d", coffeeCFG.amount_preinfusion);
|
|
|
+ logger(V_BREW, "Writing back CFGAmountPreinfusion: %d\n", coffeeCFG.amount_preinfusion);
|
|
|
if (sqlSetConf(CFGAmountPreinfusion, coffeeCFG.amount_preinfusion)) {
|
|
|
logger_error("coffee.cpp: Couldn't write CFGAmountPreinfusion to database!\n");
|
|
|
}
|
|
|
- logger(V_BREW, "Writing back CFGTimeSoak with %d", coffeeCFG.time_soak);
|
|
|
+ logger(V_BREW, "Writing back CFGTimeSoak: %d\n", coffeeCFG.time_soak);
|
|
|
if (sqlSetConf(CFGTimeSoak, coffeeCFG.time_soak)) {
|
|
|
logger_error("coffee.cpp: Couldn't write CFGTimeSoak to database!\n");
|
|
|
}
|
|
|
- logger(V_BREW, "Writing back CFGTimeInfusion with %d", coffeeCFG.time_infusion);
|
|
|
+ logger(V_BREW, "Writing back CFGTimeInfusion: %d\n", coffeeCFG.time_infusion);
|
|
|
if (sqlSetConf(CFGTimeInfusion, coffeeCFG.time_infusion)) {
|
|
|
logger_error("coffee.cpp: Couldn't write CFGTimeInfusion to database!\n");
|
|
|
}
|
|
|
- logger(V_BREW, "Writing back CFGAmountDblEspresso with %d", coffeeCFG.amount_dblespresso);
|
|
|
- if (sqlSetConf(CFGAmountDblEspresso, coffeeCFG.amount_dblespresso)) {
|
|
|
+ logger(V_BREW, "Writing back CFGAmountDblEspresso: %d\n", coffeeCFG.amount_espresso);
|
|
|
+ if (sqlSetConf(CFGAmountDblEspresso, coffeeCFG.amount_espresso)) {
|
|
|
logger_error("coffee.cpp: Couldn't write CFGAmountDblEspresso to database!\n");
|
|
|
}
|
|
|
}
|
|
@@ -1108,7 +1174,7 @@ void writeBackCache(void) {
|
|
|
* Procedure for cleaning the machine
|
|
|
*/
|
|
|
void coffeeClean(void) {
|
|
|
- logger(V_BREW, "Cleaning...\n");
|
|
|
+ logger(V_BREW, "coffee.cpp: Cleaning...\n");
|
|
|
for (int i = 0; i < CLEANING_CYCLES; i++) {
|
|
|
currentCleanCycle++;
|
|
|
halPumpOn();
|
|
@@ -1126,22 +1192,22 @@ void coffeeClean(void) {
|
|
|
*
|
|
|
*/
|
|
|
void coffeeManualBrewStart (void) {
|
|
|
- logger(V_BREW, "Starting manual brewing...\n");
|
|
|
+ logger(V_BREW, "coffee.cpp: Starting manual brewing...\n");
|
|
|
coffeeIncreaseBrewCounter();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Brewing process
|
|
|
*/
|
|
|
-void coffeeBrew(void) {
|
|
|
+void coffeeBrew(uint16_t amount_preinfusion, uint16_t time_soak, uint16_t time_infusion, uint16_t amount_espresso) {
|
|
|
coffeeIncreaseBrewCounter();
|
|
|
/*
|
|
|
* Preinfusion
|
|
|
*/
|
|
|
- logger(V_BREW, "Starting preinfusion...\n");
|
|
|
+ logger(V_BREW, "coffee.cpp: Starting preinfusion...\n");
|
|
|
halPumpOn();
|
|
|
- while (halGetFlow() < AMOUNT_PREINFUSION && halGetFlowTime() < TIME_PREINFUSION) {
|
|
|
- //TODO-Done don't use coffeeNap here since we don't want to resume to sleep after a signal got caught...
|
|
|
+ while (halGetFlow() < amount_preinfusion && halGetFlowTime() < TIME_PREINFUSION) {
|
|
|
+ //Don't use coffeeNap here since we don't want to resume to sleep after a signal got caught...
|
|
|
//coffeeNap(0, 50000000);
|
|
|
usleep(50000);
|
|
|
if (getSigValue(MODE_STATE) == SigInt0Rls) {
|
|
@@ -1155,7 +1221,7 @@ void coffeeBrew(void) {
|
|
|
* Wait for coffee to soak in infused water
|
|
|
*/
|
|
|
brewTimer.start();
|
|
|
- while (brewTime < TIME_SOAK) {
|
|
|
+ while (brewTime < time_soak) {
|
|
|
//coffeeNap(1, 100000000);
|
|
|
usleep(100000);
|
|
|
if (getSigValue(MODE_STATE) == SigInt0Rls) {
|
|
@@ -1170,9 +1236,9 @@ void coffeeBrew(void) {
|
|
|
/*
|
|
|
* Brewing the actual espresso
|
|
|
*/
|
|
|
- logger(V_BREW, "Starting infusion...\n");
|
|
|
+ logger(V_BREW, "coffee.cpp: Starting infusion...\n");
|
|
|
halPumpOn();
|
|
|
- while (brewTime < TIME_INFUSION && halGetFlow() < AMOUNT_DBLESPRESSO) {
|
|
|
+ while (brewTime < time_infusion && halGetFlow() < amount_espresso) {
|
|
|
//coffeeNap(1, 100000000);
|
|
|
usleep(100000);
|
|
|
if (getSigValue(MODE_STATE) == SigInt0Rls){
|
|
@@ -1205,13 +1271,13 @@ void checkDescaling(){
|
|
|
int16_t dirtyTime = checkDirtyTime ();
|
|
|
|
|
|
if(dirtyEspresso <= 0) {
|
|
|
- logger(V_BREW, "Descaling necessary due to quantity: %d\n", dirtyEspresso);
|
|
|
+ logger(V_BREW, "coffee.cpp: Descaling necessary due to quantity: %d\n", dirtyEspresso);
|
|
|
descaling = true;
|
|
|
event_trigger("descaling", &descaling, sizeof(bool));
|
|
|
|
|
|
}
|
|
|
if(dirtyTime <= 0) {
|
|
|
- logger(V_BREW, "Descaling necessary due to time in days: %d\n", dirtyTime);
|
|
|
+ logger(V_BREW, "coffee.cpp: Descaling necessary due to time in days: %d\n", dirtyTime);
|
|
|
descaling = true;
|
|
|
event_trigger("descaling", &descaling, sizeof(bool));
|
|
|
}
|
|
@@ -1247,7 +1313,7 @@ void updateDescaling(){
|
|
|
time_t newDesTimestamp;
|
|
|
time(&newDesTimestamp);
|
|
|
if(newDesTimestamp == -1){
|
|
|
- logger(V_BREW, "Whoops, couldn't retrieve new descaling timestamp\n");
|
|
|
+ logger(V_BREW, "coffee.cpp: Whoops, couldn't retrieve new descaling timestamp\n");
|
|
|
}
|
|
|
else {
|
|
|
descRawTimestamp = newDesTimestamp;
|