فهرست منبع

implemented manual brewing

Sebastian Vendt 5 سال پیش
والد
کامیت
07df0f73c8
6فایلهای تغییر یافته به همراه116 افزوده شده و 10 حذف شده
  1. 1 1
      CoffeeCode/buildno
  2. 36 2
      CoffeeCode/coffee.cpp
  3. 3 0
      CoffeeCode/coffee.h
  4. 18 4
      CoffeeCode/display2.cpp
  5. 55 2
      CoffeeCode/hal.cpp
  6. 3 1
      CoffeeCode/hal.h

+ 1 - 1
CoffeeCode/buildno

@@ -1 +1 @@
-338
+339

+ 36 - 2
CoffeeCode/coffee.cpp

@@ -566,8 +566,19 @@ void *coffeeThread(void *threadid) {
 			 *
 			 */
 		case STATE_BREWMANUAL:
+			coffeeManualBrewStart();
 			if (SigValueEmpty() && mode == MODE_STATE)
 				pause();
+			switch (getSigValue(MODE_STATE)) {
+				case SigBrewOff:
+					coffeeManualBrewStop();
+					if (halIsHeating()) {
+						changeState(STATE_HEATING);
+					} else {
+						changeState(STATE_IDLE);
+					}
+					break;
+			}
 			break;
 
 			/*
@@ -638,8 +649,8 @@ void *coffeeThread(void *threadid) {
 void coffeeHandler(int signum, siginfo_t *siginfo, void *context) {
 	sigval_t sigVal = (siginfo->si_value);
 	sigValue = sigVal.sival_int;
-	logger(V_BREW, "coffee.cpp: CoffeeHandler called with Signal %d\n",
-			sigValue);
+	logger(V_BREW, "coffee.cpp: CoffeeHandler called with Signal %s\n",
+			SigName[sigValue]);
 }
 
 /**
@@ -756,6 +767,10 @@ coffee_status_t getState(void) {
 	return state;
 }
 
+uint16_t getBrewTime(void) {
+	return brewTime;
+}
+
 /**
  * Returns the last elapsed brew time in ms
  */
@@ -893,6 +908,25 @@ void coffeeClean(void) {
 	event_trigger("descaling", &descaling, sizeof(bool));
 }
 
+/*
+ *
+ */
+void coffeeManualBrewStart (void) {
+	logger(V_BREW, "Starting manual brewing...\n");
+	coffeeIncreaseBrewCounter();
+	brewTime = 0;
+	brewTimer.start();
+}
+
+/*
+ *
+ */
+void coffeeManualBrewStop (void) {
+	lastBrewTime = brewTime;
+	brewTime = 0;
+	brewTimer.stop();
+}
+
 /**
  * Brewing process
  */

+ 3 - 0
CoffeeCode/coffee.h

@@ -67,6 +67,7 @@ void changePage(coffee_menuPage_t newPage);
 void leaveMenu(void);
 void enterMenu(void);
 coffee_status_t getState(void);
+uint16_t getBrewTime(void);
 uint16_t getLastBrewTime(void);
 int getSigValue(coffee_mode_t mode);
 uint16_t getCurrentCleanCycle(void);
@@ -79,6 +80,8 @@ void menuTimeHandler(void);
 void writeBackCache(void);
 void coffeeTerminate(event_t *event);
 void coffeeNap (uint64_t sec, uint64_t nanosec);
+void coffeeManualBrewStart (void);
+void coffeeManualBrewStop (void);
 void coffeeBrew(void);
 void coffeeClean(void);
 void stopBrewing(void);

+ 18 - 4
CoffeeCode/display2.cpp

@@ -139,6 +139,16 @@ void displayPrintPostBrew(int line){
 	displayPrintLn(line, buffer, true);
 }
 
+void displayPrintBrewManual(int line) {
+	char buffer[17];
+	if (line > DISPLAY_ROWS) line = 0;
+
+	float brewTime = (float)getBrewTime();
+
+	sprintf(buffer, "%.1f ml / %.1f s", halGetFlow(), brewTime / 1000);
+	displayPrintLn(line, buffer, true);
+}
+
 /**
  * Prints out the total volume flow
  * @param line Target line in display
@@ -431,8 +441,10 @@ void switchToNextState(coffee_status_t* history){
  * to one of the predefined refresh rates.
  */
 void setRefreshRate(refreshRate_t rate) {
-	currentRefreshRate = rate;
-	displayTimer.setDivider(20 / rate);
+	if (currentRefreshRate != rate) {
+		currentRefreshRate = rate;
+		displayTimer.setDivider(20 / rate);
+	}
 }
 
 /**
@@ -463,7 +475,7 @@ void displayRefresh(void) {
 			displayPrintLogo();
 			displayPrintLn(1, displayGetString(str_brewing), true);
 			return;
-		} else if (coffeeState[CURRENT] == STATE_BREW && coffeeState[NEXT] != STATE_NULL) { //Post brew
+		} else if ((coffeeState[CURRENT] == STATE_BREW || coffeeState[CURRENT] == STATE_BREWMANUAL) && coffeeState[NEXT] != STATE_NULL) { //Post brew
 			setSwitchToNextTimeout(state_idx, TIMEOUT_POSTBREW);
 			setRefreshRate(refresh_std);
 			displayPrintLn(0, displayGetString(str_postBrew), true);
@@ -495,8 +507,10 @@ void displayRefresh(void) {
 			break;
 
 		case STATE_BREWMANUAL:
+			setRefreshRate(refresh_fast);
 			displayPrintLn(0, displayGetString(str_brewing), true);
-			displayPrintFlow(1);
+			//displayPrintFlow(1);
+			displayPrintBrewManual(1);
 			break;
 
 		case STATE_CLEANING:

+ 55 - 2
CoffeeCode/hal.cpp

@@ -19,11 +19,29 @@
 #include "timer.h"
 #include "database.h"
 
+const char* SigName[] = {"SigInt0Psh",
+		"SigInt0Rls",
+		"SigInt0RlsLong",
+		"SigInt1Psh",
+		"SigInt1Rls",
+		"SigInt1RlsLong",
+		"SigPressCls",
+		"SigPressOpn",
+		"SigProxOpn",
+		"SigProxCvrd",
+		"SigBrewOn",
+		"SigBrewOff",
+		"SigPowerUp",
+		"SigPowerDown",
+		"SigRotCW",
+		"SigRotCCW"};
 
 typedef struct timespec timespec;
 
 volatile int flowcnt = 0;
 int lastFlowcnt = 0;
+int flowResetValue = -1;
+bool brewmanual = false;
 
 int Int0Time, Int1Time;
 int idleCounter;
@@ -45,6 +63,7 @@ uint16_t logcycle = 1;
 timer Int0Timer(&halInt0TimerHandler);
 timer Int1Timer(&halInt1TimerHandler);
 timer idleTimer(&halIdleTimerHandler);
+timer flowResetTimer (&flowResetTimerHandler);
 
 time_t heatingCycle[] = {0, 0};
 timespec flowTimestep[] = {{0,0},{0,0}};
@@ -103,6 +122,8 @@ void halInit(void) {
 	Int0Time = 0;
 	Int1Time = 0;
 
+	flowResetTimer.setDivider(20); //1000ms
+
 	flagIgnoreRlsInt0 = false;
 	flagIgnoreRlsInt1 = false;
 
@@ -134,6 +155,7 @@ void halInit(void) {
 	}
 
 	//TODO when machine is turned off above the logcycle 1 is written back from cache...
+	//TODO logcycle is not used atm
 	if (!(logcycle = sqlGetConf(CFGSweepCounter))) {
 		logger_error("hal.cpp: Couldn't read the  logcycle counter from the database\n");
 		//pthread_exit(EXIT_SUCCESS);
@@ -285,6 +307,8 @@ void halInt0TimerHandler(void) {
  *
  */
 void halIdleTimerHandler(void) {
+	//TODO the idle counter is once resetted when a button is pressed. From this moment the machine
+	//will enter the idle state no matter what the user does -> reset Idle counter on every input!
 	if(++idleCounter == IDLE_TIME){
 		halEnterIdle();
 	}
@@ -327,15 +351,37 @@ void halInt1TimerHandler(void) {
 	}
 }
 
+/**
+ * Timer handler to auto-reset the flow counter.
+ * The timer is started when the flow interrupt is triggered.
+ * It compares the last value (flowResetValue) with the current flow value (flowcnt)
+ * If they match (e.g no flow within 1000ms) the flow counter is reseted.
+ * Setting the last value to -1 ensures that when the timer gets called immediately after it is started the comparison will fail.
+ * This implementation is read-only and so it doesn't need semaphores.
+ */
+void flowResetTimerHandler() {
+	if(flowResetValue == flowcnt) {
+		halResetFlow();
+		return;
+	}
+	flowResetValue = flowcnt;
+}
+
 /**
  * Interrupt routine for the flow sensor
  * It counts the edges and stores the value in flowcnt
  */
 void halIntFlow(void) {
 	//halRelaisOff(RELAIS_POWER);
+	if(!flowResetTimer.isActive()) flowResetTimer.start();
 	logger(V_HAL, "IntFlow triggered #%d total: %.2fml\n", flowcnt, halGetFlow());
 	flowcnt++;
 
+	if(flowcnt >= BREW_MANUAL_TRIGGER) {
+		halSendSignal(SigBrewOn);
+		brewmanual = true;
+	}
+
 	//detect a manual brewing process
 	//TODO to be able to detect a manual brewing process we need to have the following
 	//autoclear the flowcnt after certain idle time
@@ -344,7 +390,7 @@ void halIntFlow(void) {
 
 
 	//subroutine to log the flow to the database
-	timespec deltaT;
+	/*timespec deltaT;
 	clock_gettime(CLOCK_REALTIME, &flowTimestep[flowIndex]);
 	timespec_diff(&flowTimestep[((flowIndex + 1) % 2)], &flowTimestep[flowIndex], &deltaT);
 
@@ -352,7 +398,7 @@ void halIntFlow(void) {
 		logger_error("hal.cpp: could not log flow to database!");
 		return;
 	}
-	flowIndex = (flowIndex + 1) % 2;
+	flowIndex = (flowIndex + 1) % 2;*/
 }
 
 /**
@@ -428,6 +474,13 @@ void halResetFlow(void) {
 	logger(V_HAL, "Flow counter reset, amount so far: %.2f ml\n", halGetFlow());
 	lastFlowcnt = flowcnt;
 	flowcnt = 0;
+
+	flowResetTimer.stop();
+	flowResetValue = -1;
+	if(brewmanual) {
+		brewmanual = false;
+		halSendSignal(SigBrewOff);
+	}
 }
 
 /**

+ 3 - 1
CoffeeCode/hal.h

@@ -31,6 +31,7 @@
 
 
 #define TIME_BUTTONLONGPRESS	3	//Time in s until a Signal for a long pressed button is sent
+#define BREW_MANUAL_TRIGGER		15	//specifes the flow ticks after which a brew_manual signal is triggered (14 eq. approx. 7ml)
 /*
  * Explanation for the signal levels
  * SigInt_Psh 			Button is pushed
@@ -68,7 +69,7 @@ enum HalSig {
 	SigRotCCW = 16
 };
 
-
+extern const char* SigName[];
 
 void halInit(void);
 void halDisplayOff();
@@ -80,6 +81,7 @@ int halGetRelaisState(int relais);
 void halIntRotary(void);
 void halInt0(void);
 void halInt1(void);
+void flowResetTimerHandler(void);
 void halIntFlow(void);
 void halIntPressure(void);
 double halgetHeatingTime(void);