|
@@ -35,7 +35,7 @@ timer brewTimer(&brewTimeHandler);
|
|
|
*/
|
|
|
|
|
|
void *coffeeThread(void *threadid) {
|
|
|
- logger(V_BREW, "Initializing coffee thread...\n");
|
|
|
+ logger(V_BASIC, "Initializing coffee thread...\n");
|
|
|
|
|
|
//installing new Signal handler for coffeethread
|
|
|
struct sigaction action;
|
|
@@ -55,15 +55,13 @@ void *coffeeThread(void *threadid) {
|
|
|
//wait for heat relais to switch
|
|
|
sleep(1);
|
|
|
if (halIsHeating()) { //Heating is on
|
|
|
- logger(V_BREW, "Change state: INITALHEATING\n");
|
|
|
- state = STATE_INITALHEATING;
|
|
|
+ changeState(STATE_INITALHEATING);
|
|
|
} else {
|
|
|
- logger(V_BREW, "Change state: IDLE\n");
|
|
|
- state = STATE_IDLE;
|
|
|
+ changeState(STATE_IDLE);
|
|
|
}
|
|
|
} else if (halGetRelaisState(RELAIS_PUMP)) {
|
|
|
logger_error("Whoops, why is the pump running...\n");
|
|
|
- state = STATE_ERROR;
|
|
|
+ changeState(STATE_ERROR);
|
|
|
}
|
|
|
|
|
|
logger(V_BREW, "Start Coffee FSM\n");
|
|
@@ -81,15 +79,12 @@ void *coffeeThread(void *threadid) {
|
|
|
halRelaisOn(RELAIS_POWER);
|
|
|
sleep(1);
|
|
|
if (halIsHeating()) { //check if System starts to heat when turned on
|
|
|
- logger(V_BREW, "Change state: INITALHEATING\n");
|
|
|
- state = STATE_INITALHEATING;
|
|
|
+ changeState(STATE_INITALHEATING);
|
|
|
} else {
|
|
|
- logger(V_BREW, "Change state: IDLE\n");
|
|
|
- state = STATE_IDLE;
|
|
|
+ changeState(STATE_IDLE);
|
|
|
}
|
|
|
} else {
|
|
|
- logger(V_BREW, "Change state: ERROR\n");
|
|
|
- state = STATE_ERROR;
|
|
|
+ changeState(STATE_ERROR);
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
@@ -99,16 +94,15 @@ void *coffeeThread(void *threadid) {
|
|
|
switch (getSigValue()) {
|
|
|
case SigInt1Rls:
|
|
|
//Turn machine off again
|
|
|
+ logger(V_BREW, "Turn machine off\n");
|
|
|
halRelaisOff(RELAIS_HEAT);
|
|
|
halRelaisOff(RELAIS_PUMP);
|
|
|
halRelaisOff(RELAIS_POWER);
|
|
|
- logger(V_BREW, "Change state: OFF\n");
|
|
|
- state = STATE_OFF;
|
|
|
+ changeState(STATE_OFF);
|
|
|
break;
|
|
|
case SigPressOpn:
|
|
|
//Inital heating finished
|
|
|
- logger(V_BREW, "Change state: IDLE\n");
|
|
|
- state = STATE_IDLE;
|
|
|
+ changeState(STATE_IDLE);
|
|
|
break;
|
|
|
}
|
|
|
break;
|
|
@@ -117,25 +111,23 @@ void *coffeeThread(void *threadid) {
|
|
|
switch(getSigValue()){
|
|
|
case SigInt1Rls:
|
|
|
//Turn machine off again
|
|
|
+ logger(V_BREW, "Turn machine off\n");
|
|
|
halRelaisOff(RELAIS_HEAT);
|
|
|
halRelaisOff(RELAIS_PUMP);
|
|
|
halRelaisOff(RELAIS_POWER);
|
|
|
- logger(V_BREW, "Change state: OFF\n");
|
|
|
- state = STATE_OFF;
|
|
|
+ changeState(STATE_OFF);
|
|
|
break;
|
|
|
case SigPressOpn:
|
|
|
logger(V_BREW, "Change state: IDLE\n");
|
|
|
- state = STATE_IDLE;
|
|
|
+ changeState(STATE_IDLE);
|
|
|
break;
|
|
|
case SigInt0Psh:
|
|
|
//start to brew a delicious coffee
|
|
|
- logger(V_BREW, "Change state: BREW\n");
|
|
|
- state = STATE_BREW;
|
|
|
+ changeState(STATE_BREW);
|
|
|
break;
|
|
|
case SigBrewOn:
|
|
|
//someone brews manually
|
|
|
- logger(V_BREW, "Change state: BREWMANUAL\n");
|
|
|
- state = STATE_BREWMANUAL;
|
|
|
+ changeState(STATE_BREWMANUAL);
|
|
|
break;
|
|
|
}
|
|
|
break;
|
|
@@ -144,25 +136,22 @@ void *coffeeThread(void *threadid) {
|
|
|
switch(getSigValue()){
|
|
|
case SigInt1Rls:
|
|
|
//Turn machine off again
|
|
|
+ logger(V_BREW, "Turn machine off\n");
|
|
|
halRelaisOff(RELAIS_HEAT);
|
|
|
halRelaisOff(RELAIS_PUMP);
|
|
|
halRelaisOff(RELAIS_POWER);
|
|
|
- logger(V_BREW, "Change state: OFF\n");
|
|
|
- state = STATE_OFF;
|
|
|
+ changeState(STATE_OFF);
|
|
|
break;
|
|
|
case SigPressCls:
|
|
|
- logger(V_BREW, "Change state: HEATING\n");
|
|
|
- state = STATE_HEATING;
|
|
|
+ changeState(STATE_HEATING);
|
|
|
break;
|
|
|
case SigInt0Psh:
|
|
|
//start to brew a delicious coffee
|
|
|
- logger(V_BREW, "Change state: BREW\n");
|
|
|
- state = STATE_BREW;
|
|
|
+ changeState(STATE_BREW);
|
|
|
break;
|
|
|
case SigBrewOn:
|
|
|
//someone brews manually
|
|
|
- logger(V_BREW, "Change state: BREWMANUAL\n");
|
|
|
- state = STATE_BREWMANUAL;
|
|
|
+ changeState(STATE_BREWMANUAL);
|
|
|
break;
|
|
|
}
|
|
|
break;
|
|
@@ -190,8 +179,7 @@ void *coffeeThread(void *threadid) {
|
|
|
brewTimer.stop();
|
|
|
brewTime = 0;
|
|
|
logger(V_BREW, "Finish brewing\n");
|
|
|
- logger(V_BREW, "Change state: IDLE\n");
|
|
|
- state = STATE_IDLE;
|
|
|
+ changeState(STATE_IDLE);
|
|
|
break;
|
|
|
case STATE_BREWMANUAL:
|
|
|
pause();
|
|
@@ -228,6 +216,18 @@ int getSigValue(void){
|
|
|
sigValue = 0;
|
|
|
return tmp;
|
|
|
}
|
|
|
+
|
|
|
+/**
|
|
|
+ * Changes the state of the machine to newState
|
|
|
+ * prints the change to the logger
|
|
|
+ * @param newState
|
|
|
+ */
|
|
|
+void changeState(int newState){
|
|
|
+ logger(V_BREW, "Change state to %d\n", newState);
|
|
|
+ state = newState;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* Counter for the brew time
|
|
|
* refresh every 200ms
|