Jelajahi Sumber

Fixing pagename bug, fixing proximity sensor problems

Sebastian Vendt 3 tahun lalu
induk
melakukan
9df08655f4

+ 1 - 1
CoffeeCode/buildno

@@ -1 +1 @@
-377
+386

+ 5 - 3
CoffeeCode/coffee.cpp

@@ -43,7 +43,7 @@ uint16_t oldCoffeeCFGVal; //temporary variable to save any old config value to r
 const char* PageName[] = {
 		"SOFTOFF",
 		"KILL",
-		"SINGLEESPRESSO"
+		"SINGLEESPRESSO",
 		"STATS",
 		"STATS2",
 		"DESCALING",
@@ -64,7 +64,7 @@ const char* PageName[] = {
 		"CHANGEAUTORESET",
 		"CHANGEAUTORESET_VAL",
 		"LEAVESETTINGS",
-		"Exit",
+		"EXIT",
 		"PAGE_NULL"
 };
 
@@ -899,7 +899,6 @@ void *coffeeThread(void *threadid) {
 			if (SigValueEmpty() && mode == MODE_STATE)
 				pause();
 			switch (getSigValue(MODE_STATE)) {
-			case SigInt1RlsLong:
 			case SigInt0RlsLong:
 				if (!halProxSensorCovered()) {
 					if (halIsHeating() && initalHeating) {
@@ -1238,6 +1237,7 @@ void coffeeBrew(uint16_t amount_preinfusion, uint16_t time_soak, uint16_t time_i
 	 */
 	logger(V_BREW, "coffee.cpp: Starting infusion...\n");
 	halPumpOn();
+	brewTimer.start();
 	while (brewTime < time_infusion && halGetFlow() < amount_espresso) {
 		//coffeeNap(1, 100000000);
 		usleep(100000);
@@ -1247,6 +1247,8 @@ void coffeeBrew(uint16_t amount_preinfusion, uint16_t time_soak, uint16_t time_i
 		}
 	}
 	halPumpOff();
+	brewTimer.stop();
+	brewTime = 0;
 	return;
 }
 

+ 1 - 1
CoffeeCode/coffee.h

@@ -35,7 +35,7 @@ typedef enum {
 } coffee_mode_t;
 
 typedef enum {
-	PAGE_SOFTOFF,
+	PAGE_SOFTOFF=0,
 	PAGE_KILL,
 	PAGE_SINGLEESPRESSO,
 	PAGE_STATS,

+ 6 - 0
CoffeeCode/display2.cpp

@@ -566,6 +566,7 @@ void displayRefresh(void) {
 			break;
 		case STATE_FULLTANK:
 			displayPrintLn(0, displayGetString(str_fullTank), true);
+			displayClearLine(1);
 			break;
 		default:
 			displayPrintLn(0, displayGetString(str_error), true);
@@ -585,6 +586,10 @@ void displayRefresh(void) {
 			displayPrintLn(0, displayGetString(str_menu), true);
 			displayPrintLn(1, displayGetString(str_menu_kill), true);
 			break;
+		case PAGE_SINGLEESPRESSO:
+			displayPrintLn(0, displayGetString(str_menu), true);
+			displayPrintLn(1, displayGetString(str_menu_singleEspresso), true);
+			break;
 		case PAGE_STATS:
 			displayPrintLn(0, displayGetString(str_menu_stats), true);
 			displayPrintStats(1);
@@ -623,6 +628,7 @@ void displayRefresh(void) {
 			break;
 		case PAGE_RESETKWH_VAL: //confirmation dialog
 			displayPrintLn(0, displayGetString(str_menu_resetkwh_val), true);
+			displayClearLine(1);
 			break;
 		case PAGE_CHANGEPREINF:
 			displayPrintLn(0, displayGetString(str_menu_settings), true);

+ 8 - 1
CoffeeCode/display2.h

@@ -45,6 +45,7 @@ typedef enum {
 	str_menu,
 	str_menu_softoff,
 	str_menu_kill,
+	str_menu_singleEspresso,
 	str_menu_stats,
 	str_menu_stats2,
 	str_menu_nextdesc,
@@ -146,10 +147,16 @@ static const display_string_t display_strings[str_last] =
 		},
 		{ // str_menu_kill
 				{
-						"Sofort ausschalten",
+						"sofort aus",
 						"Turn off now"
 				}
 		},
+		{ // str_menu_singleEspresso
+				{
+						"einf. Espresso",
+						"single espresso"
+				}
+		},
 		{ // str_menu_stats
 				{
 						"Stats",

+ 32 - 13
CoffeeCode/hal.cpp

@@ -56,7 +56,7 @@ bool idle;
 bool flagIgnoreRlsInt0, flagIgnoreRlsInt1;
 
 //storage for the last state of the buttons, the proximity sensor and the pressure sensor
-int pinState[4] = {1, 1, 1, 0};
+int pinState[4] = {1, 1, 0, 0};
 //state of the rotary encoder
 //0: rotary1 state at t-1
 //1: rotary2 state at t-1
@@ -131,7 +131,15 @@ void halInit(void) {
 	}
 	sleep(1); //wait till the machine eventually turned on when optPower
 
-	pinState[3] = halIsHeating();
+	//Determine the inital state of the pins for the pressure control and the graywater tank sensor
+	//TODO do a proper averaging here
+	pinState[3] = halGetPressureSensorPin();
+	if (halIsHeating()) logger(V_HAL, "hal.cpp: pressure sensor state set initially to: HEATING\n");
+	else logger(V_HAL, "hal.cpp: pressure sensor state set initially to: OPEN\n");
+
+	pinState[2] = halGetProxSensorPin();
+	if (halProxSensorCovered()) logger(V_HAL, "hal.cpp: proximity sensor state set initially to: COVERED\n");
+	else logger(V_HAL, "hal.cpp: proximity sensor state set initially to: OPEN\n");
 
 	Int0Timer.setDivider(ms2Divider(200));
 	Int1Timer.setDivider(ms2Divider(200));
@@ -417,14 +425,14 @@ void halIntFlow(void) {
  */
 void halIntPressure(void) {
 	delay(DELAY_DEBOUNCE);
-	if (halIsHeating() && !pinState[3]) {
+	if (!halGetPressureSensorPin() && pinState[3]) {
 		logger(V_HAL, "hal.cpp: Pressure Control closed\n");
-		pinState[3] = 1;
+		pinState[3] = 0;
 		halStartHeatingTime();
 		halSendSignal(SigPressCls);
-	} else if(!halIsHeating() && pinState[3]) {
+	} else if(halGetPressureSensorPin() && !pinState[3]) {
 		logger(V_HAL, "hal.cpp: Pressure Control opened\n");
-		pinState[3] = 0;
+		pinState[3] = 1;
 		halStopHeatingTime();
 		halSendSignal(SigPressOpn);
 	}
@@ -454,10 +462,10 @@ void halStopHeatingTime(void) {
  */
 void halIntProximity(void) {
 	delay(DELAY_DEBOUNCE);
-	if (digitalRead(PIN_PROXIMITY_SENSOR) && !pinState[2]) {
+	if (halGetProxSensorPin() && !pinState[2]) {
 		logger(V_HAL, "hal.cpp: Proximity switch closed\n");
 		pinState[2] = 1;
-	} else if(!digitalRead(PIN_PROXIMITY_SENSOR) && pinState[2]){
+	} else if(!halGetProxSensorPin() && pinState[2]){
 		logger(V_HAL, "hal.cpp: Proximity switch opened\n");
 		pinState[2] = 0;
 	}
@@ -532,10 +540,7 @@ void halResetFlow(void) {
  * @return 1 (true) for closed Pressure Control (heating) and 0 (false) for open
  */
 bool halIsHeating(void) {
-	//TODO: eventually rely on the pinState variable instead of reading the pin
-	//then the state of the pin needs to be set at the very beginning of the initialization
-	if (digitalRead(PIN_PRESSURE_CTRL) == 0) return true;
-	else return false;
+	return !pinState[3];
 }
 
 /**
@@ -553,13 +558,27 @@ void halSetTotalHeatingTime(uint64_t newTime) {
 }
 
 /**
- * Returns status of the proximity switch
+ * Returns filtered status of the proximity switch
  * @return 1 if the proximity switch is covered and 0 if uncovered
  */
 bool halProxSensorCovered(void) {
 	return pinState[2];
 }
 
+/**
+ *
+ */
+int halGetPressureSensorPin(void) {
+	return digitalRead(PIN_PRESSURE_CTRL);
+}
+
+/**
+ * Returns the pin status of the proximity sensor
+ */
+int halGetProxSensorPin(void) {
+	return digitalRead(PIN_PROXIMITY_SENSOR);
+}
+
 /**
  * Returns the value of the top button Int0 (low active)
  * @return LOW or HIGH

+ 2 - 0
CoffeeCode/hal.h

@@ -99,6 +99,8 @@ void halSetFlowResetTime(uint16_t val);
 void halResetFlow(void);
 bool halIsHeating(void);
 bool halProxSensorCovered(void);
+int halGetPressureSensorPin(void);
+int halGetProxSensorPin(void);
 int halGetInt0(void);
 int halGetInt1(void);
 void halSendSignal(HalSig value);

+ 8 - 1
CoffeeCode/stripe.cpp

@@ -64,14 +64,21 @@ void *stripeThread(void *threadid) {
 			case STATE_HEATING:
 			case STATE_BREW:
 			case STATE_BREWMANUAL:
-			case STATE_FULLTANK:
 			case STATE_CLEANING:
+			case STATE_NULL:
 				col.red = 255;
 				col.green = 0;
 				col.blue = 0;
 				stripeEffectPulse(col);
 				break;
 
+			case STATE_FULLTANK:
+				col.red = 255;
+				col.green = 0;
+				col.blue = 255;
+				stripeEffectPulse(col);
+				break;
+
 			case STATE_INITALHEATING:
 				col.red = 0;
 				col.green = 0;