Переглянути джерело

added a soft turn off function

Sebastian 7 роки тому
батько
коміт
65eaa7881b
4 змінених файлів з 54 додано та 5 видалено
  1. 39 4
      CoffeeCode/coffee.cpp
  2. 2 1
      CoffeeCode/coffee.h
  3. 6 0
      CoffeeCode/display.cpp
  4. 7 0
      CoffeeCode/display.h

+ 39 - 4
CoffeeCode/coffee.cpp

@@ -33,7 +33,7 @@ uint64_t totalHeatingTime; //local copies of the corresponding database entries
 uint16_t brewCounter;
 
 
-const char* StateName[] = {"OFF", "HEATING", "INITHEAT", "IDLE", "BREW", "BREWMAN", "CLEAN", "ERROR"};
+const char* StateName[] = {"OFF", "HEATING", "INITHEAT", "IDLE", "BREW", "BREWMAN", "CLEAN", "ERROR", "WAITOFF"};
 
 /**
  * Thread for the finite state machine
@@ -112,7 +112,26 @@ void *coffeeThread(void *threadid) {
 				break;
 			}
 			break;
+			/*
+			 *
+			*/
+		case STATE_WAIT_OFF:
+			if (SigValueEmpty())
+				pause();
+			switch (getSigValue()) {
+			case SigPressOpn:
+				halMachineOff();
+				coffeeIncreaseHeatingTime(halgetHeatingTime());
+				writeBackCache();
+				changeState(STATE_OFF);
+				break;
 
+			case SigInt0Psh:
+			case SigInt1Psh:
+				changeState(STATE_INITALHEATING);
+				break;
+			}
+			break;
 			/*
 			 *
 			 */
@@ -127,6 +146,11 @@ void *coffeeThread(void *threadid) {
 				writeBackCache();
 				changeState(STATE_OFF);
 				break;
+
+			case SigInt1Rls:
+				changeState(STATE_WAIT_OFF);
+				break;
+
 			case SigPressOpn:
 				//Inital heating finished
 				coffeeIncreaseHeatingTime(halgetHeatingTime());
@@ -143,20 +167,28 @@ void *coffeeThread(void *threadid) {
 				pause();
 			switch (getSigValue()) {
 			case SigInt1RlsLong:
-				//Turn machine off again
+				//Turn machine _immediately_ off again
 				halMachineOff();
 				coffeeIncreaseHeatingTime(halgetHeatingTime());
 				writeBackCache();
 				changeState(STATE_OFF);
 				break;
+
+			case SigInt1Rls:
+				//turn machine off when heating is finished
+				changeState(STATE_WAIT_OFF);
+			break;
+
 			case SigPressOpn:
 				coffeeIncreaseHeatingTime(halgetHeatingTime());
 				changeState(STATE_IDLE);
 				break;
+
 			case SigInt0Psh:
 				//start to brew a delicious coffee
 				changeState(STATE_BREW);
 				break;
+
 			case SigBrewOn:
 				//someone brews manually
 				changeState(STATE_BREWMANUAL);
@@ -171,18 +203,21 @@ void *coffeeThread(void *threadid) {
 				pause();
 			switch (getSigValue()) {
 			case SigInt1RlsLong:
-				//Turn machine off again
+				//turn machine _immediately_ off
 				halMachineOff();
 				writeBackCache();
 				changeState(STATE_OFF);
 				break;
+
 			case SigPressCls:
 				changeState(STATE_HEATING);
 				break;
+
 			case SigInt0Psh:
 				//start to brew a delicious coffee
 				changeState(STATE_BREW);
 				break;
+
 			case SigBrewOn:
 				//someone brews manually
 				changeState(STATE_BREWMANUAL);
@@ -291,7 +326,7 @@ void coffeeTerminate(event_t *event) {
 		logger_error("Invalid use of event %s\n", event->event);
 		return;
 	}
-	logger(V_BREW, "Coffee.cpp thread terminating");
+	logger(V_BREW, "Coffee.cpp: Thread terminating");
 	//stop brewing
 	halRelaisOff(RELAIS_PUMP);
 	brewTimer.stop();

+ 2 - 1
CoffeeCode/coffee.h

@@ -20,7 +20,8 @@ typedef enum {
 	STATE_BREW,
 	STATE_BREWMANUAL,
 	STATE_CLEANING,
-	STATE_ERROR
+	STATE_ERROR,
+	STATE_WAIT_OFF
 } coffee_status_t;
 
 extern const char* StateName[];

+ 6 - 0
CoffeeCode/display.cpp

@@ -169,6 +169,7 @@ void* displayTimerHandler(void* threadid) {
 		case STATE_IDLE:
 		case STATE_CLEANING:
 		case STATE_ERROR:
+		case STATE_WAIT_OFF:
 			displayRefresh();
 			break;
 		default:
@@ -266,6 +267,11 @@ void displayRefresh(void) {
 		displayPrintLn(1, displayGetString(str_error), true);
 		break;
 
+	case STATE_WAIT_OFF:
+		displayPrintLn(0, "CoffeePi", true);
+		displayPrintLn(1, displayGetString(str_waitoff), true);
+		break;
+
 	case STATE_OFF:
 	default:
 		displayPrintLn(0, "CoffeePi", true);

+ 7 - 0
CoffeeCode/display.h

@@ -25,6 +25,7 @@ typedef enum {
 	str_error,
 	str_flow,
 	str_bye,
+	str_waitoff,
 	str_last
 } display_strings_t;
 
@@ -81,6 +82,12 @@ static const display_string_t display_strings[str_last] =
 						"Auf wiedersehen",
 						"Good bye"
 				}
+		},
+		{
+				{
+						"Ausschalten...",
+						"Turning off..."
+				}
 		}
 };