|
@@ -31,7 +31,7 @@ timer brewTimer(&brewTimeHandler);
|
|
|
|
|
|
uint64_t totalHeatingTime; //local copies of the corresponding database entries
|
|
|
uint16_t brewCounter;
|
|
|
-coffee_status_t lastState;
|
|
|
+bool initalHeating;
|
|
|
|
|
|
|
|
|
const char* StateName[] = {"OFF", "HEATING", "INITHEAT", "IDLE", "BREW", "BREWMAN", "CLEAN", "ERROR", "WAITOFF"};
|
|
@@ -58,6 +58,7 @@ void *coffeeThread(void *threadid) {
|
|
|
brewTime = 0;
|
|
|
|
|
|
lastState = STATE_OFF;
|
|
|
+ initalHeating = true;
|
|
|
|
|
|
//read the database values
|
|
|
if(!(totalHeatingTime = sqlGetConf(CFGHeatingTime))){
|
|
@@ -82,6 +83,7 @@ void *coffeeThread(void *threadid) {
|
|
|
if (halIsHeating()) { //Heating is on
|
|
|
changeState(STATE_INITALHEATING);
|
|
|
} else {
|
|
|
+ initalHeating = false;
|
|
|
changeState(STATE_IDLE);
|
|
|
}
|
|
|
} else if (halGetRelaisState(RELAIS_PUMP)) {
|
|
@@ -99,21 +101,25 @@ void *coffeeThread(void *threadid) {
|
|
|
*
|
|
|
*/
|
|
|
case STATE_OFF:
|
|
|
+ halMachineOff();
|
|
|
+ writeBackCache();
|
|
|
+
|
|
|
if (SigValueEmpty())
|
|
|
pause();
|
|
|
if (getSigValue() == SigInt0Rls) {
|
|
|
- if (!halProxSensorCovered()) { //Check waterlevel in gray water tank
|
|
|
- //turn machine on
|
|
|
- halMachineOn();
|
|
|
- sleep(1);
|
|
|
- if (halIsHeating()) { //check if System starts to heat when turned on
|
|
|
- changeState(STATE_INITALHEATING);
|
|
|
- } else {
|
|
|
- changeState(STATE_IDLE);
|
|
|
- }
|
|
|
+ //Check waterlevel in gray water tank
|
|
|
+ //turn machine on
|
|
|
+ halMachineOn();
|
|
|
+ sleep(1);
|
|
|
+ if (halIsHeating()) { //check if System starts to heat when turned on
|
|
|
+ initalHeating = true;
|
|
|
+ changeState(STATE_INITALHEATING);
|
|
|
} else {
|
|
|
- logger_error("Empty Tank please!\n");
|
|
|
- changeState(STATE_ERROR);
|
|
|
+ changeState(STATE_IDLE);
|
|
|
+ }
|
|
|
+ if (halProxSensorCovered()) {
|
|
|
+ logger_error("Empty Tank please!\n");//change the state again to go back to the last state afterwards
|
|
|
+ changeState(STATE_FULLTANK);
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
@@ -122,25 +128,24 @@ void *coffeeThread(void *threadid) {
|
|
|
*
|
|
|
*/
|
|
|
case STATE_WAIT_OFF:
|
|
|
- if (halIsHeating()) {
|
|
|
- halMachineOff();
|
|
|
- coffeeIncreaseHeatingTime(halgetHeatingTime());
|
|
|
- writeBackCache();
|
|
|
- changeState(STATE_OFF);
|
|
|
- }
|
|
|
if (SigValueEmpty())
|
|
|
pause();
|
|
|
switch (getSigValue()) {
|
|
|
case SigPressOpn:
|
|
|
- halMachineOff();
|
|
|
+ usleep(100000);//wait so no load will be switched
|
|
|
coffeeIncreaseHeatingTime(halgetHeatingTime());
|
|
|
- writeBackCache();
|
|
|
changeState(STATE_OFF);
|
|
|
break;
|
|
|
|
|
|
case SigInt0Psh:
|
|
|
case SigInt1Psh:
|
|
|
- changeState(STATE_INITALHEATING);
|
|
|
+ if (halProxSensorCovered()) {
|
|
|
+ changeState(STATE_FULLTANK);
|
|
|
+ } else if (initalHeating) {
|
|
|
+ changeState(STATE_INITALHEATING);
|
|
|
+ } else {
|
|
|
+ changeState(STATE_HEATING);
|
|
|
+ }
|
|
|
break;
|
|
|
}
|
|
|
break;
|
|
@@ -148,14 +153,14 @@ void *coffeeThread(void *threadid) {
|
|
|
*
|
|
|
*/
|
|
|
case STATE_INITALHEATING:
|
|
|
+ initalHeating = true;
|
|
|
+
|
|
|
if (SigValueEmpty())
|
|
|
pause();
|
|
|
switch (getSigValue()) {
|
|
|
case SigInt1RlsLong:
|
|
|
//Turn machine off again
|
|
|
- halMachineOff();
|
|
|
coffeeIncreaseHeatingTime(halgetHeatingTime());
|
|
|
- writeBackCache();
|
|
|
changeState(STATE_OFF);
|
|
|
break;
|
|
|
|
|
@@ -163,8 +168,13 @@ void *coffeeThread(void *threadid) {
|
|
|
changeState(STATE_WAIT_OFF);
|
|
|
break;
|
|
|
|
|
|
+ case SigProxCvrd:
|
|
|
+ changeState(STATE_FULLTANK);
|
|
|
+ break;
|
|
|
+
|
|
|
case SigPressOpn:
|
|
|
//Inital heating finished
|
|
|
+ initalHeating = false;
|
|
|
coffeeIncreaseHeatingTime(halgetHeatingTime());
|
|
|
changeState(STATE_IDLE);
|
|
|
break;
|
|
@@ -180,9 +190,7 @@ void *coffeeThread(void *threadid) {
|
|
|
switch (getSigValue()) {
|
|
|
case SigInt1RlsLong:
|
|
|
//Turn machine _immediately_ off again
|
|
|
- halMachineOff();
|
|
|
coffeeIncreaseHeatingTime(halgetHeatingTime());
|
|
|
- writeBackCache();
|
|
|
changeState(STATE_OFF);
|
|
|
break;
|
|
|
|
|
@@ -201,6 +209,10 @@ void *coffeeThread(void *threadid) {
|
|
|
changeState(STATE_BREW);
|
|
|
break;
|
|
|
|
|
|
+ case SigProxCvrd:
|
|
|
+ changeState(STATE_FULLTANK);
|
|
|
+ break;
|
|
|
+
|
|
|
case SigBrewOn:
|
|
|
//someone brews manually
|
|
|
changeState(STATE_BREWMANUAL);
|
|
@@ -216,14 +228,11 @@ void *coffeeThread(void *threadid) {
|
|
|
switch (getSigValue()) {
|
|
|
case SigInt1RlsLong:
|
|
|
//turn machine _immediately_ off
|
|
|
- halMachineOff();
|
|
|
- writeBackCache();
|
|
|
changeState(STATE_OFF);
|
|
|
break;
|
|
|
|
|
|
case SigInt1Rls:
|
|
|
- //turn machine off when heating is finished
|
|
|
- changeState(STATE_WAIT_OFF);
|
|
|
+ changeState(STATE_OFF);
|
|
|
break;
|
|
|
|
|
|
case SigPressCls:
|
|
@@ -231,13 +240,11 @@ void *coffeeThread(void *threadid) {
|
|
|
break;
|
|
|
|
|
|
case SigInt0Psh:
|
|
|
- //start to brew a delicious coffee
|
|
|
- if(!halProxSensorCovered()){
|
|
|
- changeState(STATE_BREW);
|
|
|
- }
|
|
|
- else {
|
|
|
- changeState(STATE_ERROR);
|
|
|
- }
|
|
|
+ changeState(STATE_BREW);
|
|
|
+ break;
|
|
|
+
|
|
|
+ case SigProxCvrd:
|
|
|
+ changeState(STATE_FULLTANK);
|
|
|
break;
|
|
|
|
|
|
case SigBrewOn:
|
|
@@ -250,13 +257,22 @@ void *coffeeThread(void *threadid) {
|
|
|
*
|
|
|
*/
|
|
|
case STATE_BREW:
|
|
|
- coffeeBrew();
|
|
|
- logger(V_BREW, "Finishing brewing\n");
|
|
|
- if(!halProxSensorCovered()){
|
|
|
- changeState(STATE_IDLE);
|
|
|
- }
|
|
|
- else {
|
|
|
- changeState(STATE_ERROR);
|
|
|
+ //make sure the tank is not full
|
|
|
+ if (halProxSensorCovered()) {
|
|
|
+ changeState(STATE_FULLTANK);
|
|
|
+ logger_error("coffee.cpp: Full tank detection failed..\n");
|
|
|
+ } else {
|
|
|
+ coffeeBrew();
|
|
|
+ logger(V_BREW, "Finishing brewing\n");
|
|
|
+ if (!halProxSensorCovered()) {
|
|
|
+ if (halIsHeating()) {
|
|
|
+ changeState(STATE_HEATING);
|
|
|
+ } else {
|
|
|
+ changeState(STATE_IDLE);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ changeState(STATE_FULLTANK);
|
|
|
+ }
|
|
|
}
|
|
|
break;
|
|
|
|
|
@@ -276,6 +292,27 @@ void *coffeeThread(void *threadid) {
|
|
|
pause();
|
|
|
break;
|
|
|
|
|
|
+ /*
|
|
|
+ * Full tank is detected at the beginning and the end of a brewing process, during
|
|
|
+ * idle times, initial heating and heating
|
|
|
+ */
|
|
|
+ case STATE_FULLTANK:
|
|
|
+ if (SigValueEmpty())
|
|
|
+ pause();
|
|
|
+ switch (getSigValue()) {
|
|
|
+ case SigInt1Psh:
|
|
|
+ case SigInt0Psh:
|
|
|
+ if(halIsHeating() && initalHeating){
|
|
|
+ changeState(STATE_INITALHEATING);
|
|
|
+ } else if (halIsHeating() && !initalHeating){
|
|
|
+ changeState(STATE_HEATING);
|
|
|
+ } else {
|
|
|
+ changeState(STATE_IDLE);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+
|
|
|
/*
|
|
|
*
|
|
|
*/
|
|
@@ -283,9 +320,12 @@ void *coffeeThread(void *threadid) {
|
|
|
if (SigValueEmpty())
|
|
|
pause();
|
|
|
switch (getSigValue()) {
|
|
|
- case SigInt1Psh:
|
|
|
- case SigInt0Psh:
|
|
|
- changeState(RETURN_STATE);
|
|
|
+ case SigInt1RlsLong:
|
|
|
+ case SigInt0RlsLong:
|
|
|
+ if(halIsHeating()){
|
|
|
+ coffeeIncreaseHeatingTime(halgetHeatingTime());
|
|
|
+ }
|
|
|
+ changeState(STATE_OFF);
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
@@ -329,11 +369,7 @@ bool SigValueEmpty(void) {
|
|
|
* @param newState
|
|
|
*/
|
|
|
void changeState(coffee_status_t newState) {
|
|
|
- if(newState == RETURN_STATE)
|
|
|
- newState = lastState;
|
|
|
-
|
|
|
logger(V_BREW, "Changing state to %s\n", StateName[newState]);
|
|
|
- lastState = state;
|
|
|
state = newState;
|
|
|
event_trigger("statechange", &state, sizeof(state));
|
|
|
}
|
|
@@ -385,7 +421,6 @@ void writeBackCache(void){
|
|
|
*/
|
|
|
void coffeeBrew(void) {
|
|
|
coffeeIncreaseBrewCounter();
|
|
|
-
|
|
|
/*
|
|
|
* Preinfusion
|
|
|
*/
|