Przeglądaj źródła

More menu pages added, improved handling of full graywater tank

Sebastian Vendt 3 lat temu
rodzic
commit
83e3d94fcf
7 zmienionych plików z 308 dodań i 212 usunięć
  1. 1 1
      CoffeeCode/buildno
  2. 207 141
      CoffeeCode/coffee.cpp
  3. 8 6
      CoffeeCode/coffee.h
  4. 49 32
      CoffeeCode/display2.cpp
  5. 10 10
      CoffeeCode/display2.h
  6. 31 21
      CoffeeCode/hal.cpp
  7. 2 1
      CoffeeCode/hal.h

+ 1 - 1
CoffeeCode/buildno

@@ -1 +1 @@
-369
+377

+ 207 - 141
CoffeeCode/coffee.cpp

@@ -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;

+ 8 - 6
CoffeeCode/coffee.h

@@ -37,12 +37,13 @@ typedef enum {
 typedef enum {
 	PAGE_SOFTOFF,
 	PAGE_KILL,
+	PAGE_SINGLEESPRESSO,
 	PAGE_STATS,
 	PAGE_STATS2,
 	PAGE_DESCALING,
 	PAGE_TEMP,
 	PAGE_CLEAN,
-	PAGE_RESTART,
+	PAGE_REBOOT,
 	PAGE_SETTINGS,
 	PAGE_RESETKWH,
 	PAGE_RESETKWH_VAL,
@@ -62,17 +63,17 @@ typedef enum {
 	//Entering new PAGES? Don't forget to update pagenames in coffee.cpp!
 } coffee_menuPage_t;
 
-struct coffeeConfig{
+typedef struct coffeeConfig{
 	uint16_t amount_preinfusion;
 	uint16_t time_soak;
 	uint16_t time_infusion;
-	uint16_t amount_dblespresso;
-};
+	uint16_t amount_espresso;
+}coffeeConfig;
 
 #define AMOUNT_PREINFUSION	24 		//Preinfusion amount in ml
+#define TIME_PREINFUSION	2500	//Time for the preinfusion in ms
 #define TIME_SOAK			5000 	//Time between preinfusion and infusion in ms
 #define TIME_INFUSION 		25000	//Infusion time in ms
-#define TIME_PREINFUSION	2500
 #define AMOUNT_DBLESPRESSO	59		//Size of a double espresso in ml
 #define DIRTY_ESPRESSO		35		//Number of espressi until the next cleaning
 #define DIRTY_TIME			90		//Number of days until the next cleaning
@@ -99,6 +100,7 @@ uint16_t getCurrentCleanCycle(void);
 uint16_t getBrewCounter(void);
 uint16_t getDescBrewCounter (void);
 time_t * getDescTimestamp (void);
+coffeeConfig* getCoffeeCfg (void);
 void brewTimerHandler(void);
 void menuTimerHandler(void);
 void writeBackCache(void);
@@ -106,7 +108,7 @@ void coffeeTerminate(event_t *event);
 void coffeeNap (uint64_t sec, uint64_t nanosec);
 void coffeeManualBrewStart (void);
 void coffeeManualBrewStop (void);
-void coffeeBrew(void);
+void coffeeBrew(uint16_t amount_preinfusion, uint16_t time_soak, uint16_t time_infusion, uint16_t amount_espresso);
 void coffeeClean(void);
 void stopBrewing(void);
 void coffeeIncreaseBrewCounter(void);

+ 49 - 32
CoffeeCode/display2.cpp

@@ -63,13 +63,14 @@ void displayPrintNextDesc(int line);
 void displayPrintPostBrew(int line);
 void displayPrintBrewManual(int line);
 void displayPrintFlow(int line);
-void displayPrintAutoResetVal(int line);
 void displayPrintCleanCycle(int line);
 void displayStateUpdated(event_t *event);
 void displayModeUpdated(event_t *event);
 void displayPageUpdated(event_t *event);
 void displayDescaling(event_t *event);
 void displayPrintLogo(void);
+void displayPrintNum(int line, uint16_t num, char* unitstr);
+void displayClearLine(int line);
 void displayTerminate(event_t *e);
 void track(idx_t idx);
 
@@ -127,7 +128,7 @@ void displayPrintStats2(int line) {
 	if (line > DISPLAY_ROWS)
 		line = 0;
 
-	uint64_t totalkWh = 2 * getTotalHeatingTime()/(60*60);
+	uint64_t totalkWh = 2 * halGetTotalHeatingTime()/(60*60);
 	sprintf(buffer, "%lld kWh", totalkWh);
 	displayPrintLn(line, buffer, true);
 }
@@ -176,15 +177,6 @@ void displayPrintFlow(int line) {
 	lcdPrintf(lcd, "%s: %.0f ml    ", displayGetString(str_flow), flow);
 }
 
-/**
- *
- */
-void displayPrintAutoResetVal(int line) {
-	uint16_t restFlowTime = halGetFlowResetTime();
-	lcdPosition(lcd, 0, line);
-	lcdPrintf(lcd, "%.0f ms", restFlowTime);
-}
-
 /**
  * Prints the current cycle of the cleaning process
  */
@@ -235,7 +227,6 @@ void displayPrintLn(int line, const char* str, bool centered) {
 	lcdPosition(lcd, 0, line);
 	buf[DISPLAY_COLS] = '\0';
 	lcdPrintf(lcd, buf);
-	//logger(V_HAL, "Printed out on display: \"%s\"\n", buf);
 }
 
 /**
@@ -244,7 +235,7 @@ void displayPrintLn(int line, const char* str, bool centered) {
  */
 void displayStateUpdated(event_t *event) {
 	if (event->len != sizeof(coffee_status_t)) {
-		logger_error("Invalid use of event %s\n", event->event);
+		logger_error("display2.cpp: Invalid use of event %s\n", event->event);
 		return;
 	}
 	coffee_status_t state = *(coffee_status_t*) event->data;
@@ -259,7 +250,7 @@ void displayStateUpdated(event_t *event) {
 
 void displayModeUpdated(event_t *event) {
 	if (event->len != sizeof(coffee_mode_t)) {
-		logger_error("Invalid use of event %s\n", event->event);
+		logger_error("display2.cpp: Invalid use of event %s\n", event->event);
 		return;
 	}
 	coffee_mode_t mode = *(coffee_mode_t*) event->data;
@@ -278,7 +269,7 @@ void displayModeUpdated(event_t *event) {
 
 void displayPageUpdated(event_t *event) {
 	if (event->len != sizeof(coffee_menuPage_t)) {
-		logger_error("Invalid use of event %s\n", event->event);
+		logger_error("display2.cpp: Invalid use of event %s\n", event->event);
 		return;
 	}
 	coffee_menuPage_t page = *(coffee_menuPage_t*) event->data;
@@ -291,7 +282,7 @@ void displayPageUpdated(event_t *event) {
  */
 void displayDescaling(event_t *event) {
 	if (event->len != sizeof(bool)) {
-		logger_error("Invalid use of event %s\n", event->event);
+		logger_error("display2.cpp: Invalid use of event %s\n", event->event);
 		return;
 	}
 	coffeeDescaling = *(bool*) event->data;
@@ -315,6 +306,27 @@ void displayPrintLogo(void) {
 	displayPrintLn(0, buffer, true);
 }
 
+/**
+ * Prints a integer number on the display
+ * @param line: The line number where the number shall be printed
+ * @param num: The number to be printed
+ * @param unitstr: The unit string, e.g. ms
+ */
+void displayPrintNum(int line, uint16_t num, const char* unitstr) {
+	displayClearLine(line);
+	lcdPosition(lcd, 0, line);
+	lcdPrintf(lcd, " %d %s", num, unitstr);
+}
+
+/**
+ * Write spaces to the display line to clear previous content
+ * @param num: The line number
+ */
+void displayClearLine(int line) {
+	lcdPosition(lcd, 0, line);
+	lcdPrintf(lcd, "                ");
+}
+
 /**
  * Handles cleanup before program termination
  */
@@ -332,7 +344,7 @@ void displayTerminate(event_t *e) {
 void* displayThread(void* threadid) {
 	//sleep(1); // Wait for other components to initialize
 	displayTimer.start();
-	logger(V_BASIC, "Initialized display Thread. Timer state: %d \n", displayTimer.isActive());
+	logger(V_BASIC, "display.cpp: Initialized display Thread. Timer state: %d \n", displayTimer.isActive());
 	while (1) {
 		pause();
 		if (1) {
@@ -385,7 +397,7 @@ void track(idx_t idx){
 void displayInit(void) {
 	lcd = lcdInit();
 	if (lcd < 0)
-		logger_error("Error: unable to init LCD (%d)\n", lcd);
+		logger_error("display2.cpp: Error: unable to init LCD (%d)\n", lcd);
 	lcdClear(lcd);
 	lcdHome(lcd);
 	displayPrintLn(0, (char*) "CoffeePi", true);
@@ -518,49 +530,47 @@ void displayRefresh(void) {
 			displayPrintLogo();
 			displayPrintLn(1, displayGetString(str_ready), true);
 			break;
-
 		case STATE_INITALHEATING:
 			displayPrintLogo();
 			displayPrintLn(1, displayGetString(str_heating), true);
 			break;
-
 		case STATE_HEATING:
 			displayPrintLogo();
 			displayPrintLn(1, displayGetString(str_heatingready), true);
 			break;
-
 		case STATE_BREW:
 			displayPrintLn(0, displayGetString(str_brewing), true);
 			displayPrintFlow(1);
 			break;
-
 		case STATE_BREWMANUAL:
 			setRefreshRate(refresh_fast);
 			displayPrintLn(0, displayGetString(str_brewing), true);
 			//displayPrintFlow(1);
 			displayPrintBrewManual(1);
 			break;
-
 		case STATE_CLEANING:
 			displayPrintLn(0, displayGetString(str_cleaning), true);
 			displayPrintCleanCycle(1);
 			break;
-
 		case STATE_ERROR:
 			displayPrintLogo();
 			displayPrintLn(1, displayGetString(str_error), true);
 			break;
-
 		case STATE_WAIT_OFF:
 			displayPrintLogo();
 			displayPrintLn(1, displayGetString(str_waitoff), true);
 			break;
-
 		case STATE_OFF:
-		default:
 			displayPrintLogo();
 			displayPrintTime(1);
 			break;
+		case STATE_FULLTANK:
+			displayPrintLn(0, displayGetString(str_fullTank), true);
+			break;
+		default:
+			displayPrintLn(0, displayGetString(str_error), true);
+			displayPrintLn(0, "???", true);
+			break;
 		}
 	} else if (coffeeMode[CURRENT] == MODE_MENU) {
 		//handle page transitions
@@ -595,9 +605,9 @@ void displayRefresh(void) {
 			displayPrintLn(0, displayGetString(str_menu), true);
 			displayPrintLn(1, displayGetString(str_menu_clean), true);
 			break;
-		case PAGE_RESTART:
+		case PAGE_REBOOT:
 			displayPrintLn(0, displayGetString(str_menu), true);
-			displayPrintLn(1, displayGetString(str_menu_restart), true);
+			displayPrintLn(1, displayGetString(str_menu_reboot), true);
 			break;
 		case PAGE_EXIT:
 			displayPrintLn(0, displayGetString(str_menu), true);
@@ -619,33 +629,40 @@ void displayRefresh(void) {
 			displayPrintLn(1, displayGetString(str_menu_changepreinf), true);
 			break;
 		case PAGE_CHANGEPREINF_VAL:
+			displayPrintLn(0, displayGetString(str_menu_changepreinf), true);
+			displayPrintNum(1, getCoffeeCfg()->amount_preinfusion, "ml");
 			break;
 		case PAGE_CHANGEBREWTIME:
 			displayPrintLn(0, displayGetString(str_menu_settings), true);
 			displayPrintLn(1, displayGetString(str_menu_changebrewtime), true);
 			break;
 		case PAGE_CHANGEBREWTIME_VAL:
-
+			displayPrintLn(0, displayGetString(str_menu_changebrewtime), true);
+			displayPrintNum(1, getCoffeeCfg()->time_infusion, "ms");
 			break;
 		case PAGE_CHANGEBREWML:
 			displayPrintLn(0, displayGetString(str_menu_settings), true);
 			displayPrintLn(1, displayGetString(str_menu_changebrewml), true);
 			break;
 		case PAGE_CHANGEBREWML_VAL:
+			displayPrintLn(0, displayGetString(str_menu_changebrewml), true);
+			displayPrintNum(1, getCoffeeCfg()->amount_espresso, "ml");
 			break;
 		case PAGE_CHANGESOAKTIME:
 			displayPrintLn(0, displayGetString(str_menu_settings), true);
 			displayPrintLn(1, displayGetString(str_menu_changesoaktime), true);
 			break;
 		case PAGE_CHANGESOAKTIME_VAL:
+			displayPrintLn(0, displayGetString(str_menu_changesoaktime), true);
+			displayPrintNum(1, getCoffeeCfg()->time_soak, "ms");
 			break;
 		case PAGE_CHANGEAUTORESET:
 			displayPrintLn(0, displayGetString(str_menu_settings), true);
 			displayPrintLn(1, displayGetString(str_menu_changeAutoReset), true);
 			break;
 		case PAGE_CHANGEAUTORESET_VAL:
-			displayPrintLn(0, displayGetString(str_menu_changeAutoReset_val), true);
-			displayPrintAutoResetVal(1);
+			displayPrintLn(0, displayGetString(str_menu_changeAutoReset), true);
+			displayPrintNum(1, halGetFlowResetTime(), "ms");
 			break;
 		case PAGE_LEAVESETTINGS:
 			displayPrintLn(0, displayGetString(str_menu_settings), true);

+ 10 - 10
CoffeeCode/display2.h

@@ -37,6 +37,7 @@ typedef enum {
 	str_ready,
 	str_brewing,
 	str_cleaning,
+	str_fullTank,
 	str_error,
 	str_flow,
 	str_bye,
@@ -49,7 +50,7 @@ typedef enum {
 	str_menu_nextdesc,
 	str_menu_temp,
 	str_menu_clean,
-	str_menu_restart,
+	str_menu_reboot,
 	str_menu_exit,
 	str_menu_settings,
 	str_menu_resetkwh,
@@ -59,7 +60,6 @@ typedef enum {
 	str_menu_changebrewml,
 	str_menu_changesoaktime,
 	str_menu_changeAutoReset,
-	str_menu_changeAutoReset_val,
 	str_menu_leavesettings,
 	str_postBrew,
 	str_last
@@ -102,6 +102,12 @@ static const display_string_t display_strings[str_last] =
 						"Cleaning.."
 				}
 		},
+		{ // full tank
+				{
+						"Abwasser leeren",
+						"Graywater full"
+				}
+		},
 		{ // error
 				{
 						"Fehler",
@@ -174,10 +180,10 @@ static const display_string_t display_strings[str_last] =
 						"Clean"
 				}
 		},
-		{ // str_menu_restart
+		{ // str_menu_reboot
 				{
 						"Neustarten",
-						"restart software"
+						"restart Pi"
 				}
 		},
 		{ // str_menu_exit
@@ -234,12 +240,6 @@ static const display_string_t display_strings[str_last] =
 						"Auto reset adj"
 				}
 		},
-		{ // str_menu_changeAutoReset_val
-				{
-						"reset zeit (ms)",
-						"reset time (ms)"
-				}
-		},
 		{ // str_leavesettings
 		        {
 		                "Verlassen",

+ 31 - 21
CoffeeCode/hal.cpp

@@ -47,8 +47,8 @@ bool brewmanual = false;
 
 //local copies of the corresponding database entries
 time_t heatingCycleStart = 0;
-uint64_t totalHeatingTime = 0;
-uint16_t flowResetTime = TIME_FLOWRESET; //see TIME_FLOWRESET for details
+uint64_t totalHeatingTime = 0; //total heating time in seconds
+uint16_t flowResetTime = 0; //see TIME_FLOWRESET for details
 
 int Int0Time, Int1Time;
 int idleCounter;
@@ -120,6 +120,7 @@ void halInit(void) {
 	}
 
 	if (!(flowResetTime = sqlGetConf(CFGFlowResetTime))) {
+		flowResetTime = TIME_FLOWRESET;
 		logger_error("hal.cpp: Couldn't read the flow reset time from the database\nFalling back to defaults.\n");
 	}
 
@@ -442,7 +443,7 @@ void halStartHeatingTime(void) {
 void halStopHeatingTime(void) {
 	if (heatingCycleStart != 0) { //only track time if stopwatch was started!
 		uint64_t timediff = (uint64_t) difftime(time(0), heatingCycleStart);
-		logger(V_HAL, "Heating time: %f\n", timediff);
+		logger(V_HAL, "hal.cpp: Heating time: %f\n", timediff);
 		totalHeatingTime += timediff;
 		heatingCycleStart = 0;
 	}
@@ -453,14 +454,12 @@ void halStopHeatingTime(void) {
  */
 void halIntProximity(void) {
 	delay(DELAY_DEBOUNCE);
-	if (halProxSensorCovered() && !pinState[2]) {
-		logger(V_HAL, "IntProximity triggered\n");
+	if (digitalRead(PIN_PROXIMITY_SENSOR) && !pinState[2]) {
+		logger(V_HAL, "hal.cpp: Proximity switch closed\n");
 		pinState[2] = 1;
-		halSendSignal(SigProxCvrd);
-	} else if(!halProxSensorCovered() && pinState[2]){
-		logger(V_HAL, "IntProximity triggered\n");
+	} else if(!digitalRead(PIN_PROXIMITY_SENSOR) && pinState[2]){
+		logger(V_HAL, "hal.cpp: Proximity switch opened\n");
 		pinState[2] = 0;
-		halSendSignal(SigProxOpn);
 	}
 }
 
@@ -540,21 +539,25 @@ bool halIsHeating(void) {
 }
 
 /**
- *
+ * Get the total elapsed heating time in seconds since the last reset
  */
-uint64_t getTotalHeatingTime() {
+uint64_t halGetTotalHeatingTime() {
 	return totalHeatingTime;
 }
+
+/**
+ * Set/Reset the total heating time in seconds
+ */
+void halSetTotalHeatingTime(uint64_t newTime) {
+	totalHeatingTime = newTime;
+}
+
 /**
  * Returns status of the proximity switch
  * @return 1 if the proximity switch is covered and 0 if uncovered
  */
 bool halProxSensorCovered(void) {
-	if(digitalRead(PIN_PROXIMITY_SENSOR) == 0){
-	 return false;
-	 } else {
-	 return true;
-	 }
+	return pinState[2];
 }
 
 /**
@@ -578,11 +581,12 @@ int halGetInt1(void) {
  * @param val Integer value assigned to signal
  */
 void halSendSignal(HalSig val) {
-	//reboot pi when lower button is pressed long
+	//restart software when lower button is pressed long
 	if (val == SigInt1RlsLong) {
 		event_trigger("terminate");
-		sleep(3);
-		system("reboot");
+		sleep(4);
+		exit(EXIT_SUCCESS);
+		return;
 	}
 
 	if (halIdle(val)) return;
@@ -747,12 +751,18 @@ void halTerminate(event_t *event){
 }
 
 /*
- * writing back non volatile variables of the hal to the database: totalHeatingTime
+ * writing back non volatile variables of the hal to the database: totalHeatingTime, flowResetTime
  */
 void halWriteBackCache(){
 	if (sqlSetConf(CFGHeatingTime, totalHeatingTime)) {
-		logger_error("hal.cpp: Couldn't write heating time to database");
+		logger_error("hal.cpp: Couldn't write heating time to database\n");
 		return;
 	}
 	logger(V_BREW, "Writing back heating time: %lld sec\n", totalHeatingTime);
+
+	if (sqlSetConf(CFGFlowResetTime, flowResetTime)) {
+		logger_error("hal.cpp: Couldn't write the flow reset time to database\n");
+		return;
+	}
+	logger(V_BREW, "Writing back flow reset time: %d ms\n", flowResetTime);
 }

+ 2 - 1
CoffeeCode/hal.h

@@ -88,7 +88,8 @@ void halIntPressure(void);
 void halStartHeatingTime(void);
 void halStopHeatingTime(void);
 void halIntProximity(void);
-uint64_t getTotalHeatingTime(void);
+uint64_t halGetTotalHeatingTime(void);
+void halSetTotalHeatingTime(uint64_t newTime);
 float halGetFlow(void);
 uint16_t halGetFlowTime(void);
 float halGetLastFlow(void);