Sfoglia il codice sorgente

fixed: the endless brewing bug, leaving the menu turning on the machine added: display now showing the total amount of espressi, display now turns off after certain idle time and turns on after anykey

Sebastian 7 anni fa
parent
commit
8f1a8a5f01
6 ha cambiato i file con 91 aggiunte e 15 eliminazioni
  1. 1 1
      CoffeeCode/buildno
  2. 20 10
      CoffeeCode/coffee.cpp
  3. 1 0
      CoffeeCode/coffee.h
  4. 12 2
      CoffeeCode/display.cpp
  5. 54 2
      CoffeeCode/hal.cpp
  6. 3 0
      CoffeeCode/hal.h

+ 1 - 1
CoffeeCode/buildno

@@ -1 +1 @@
-225
+230

+ 20 - 10
CoffeeCode/coffee.cpp

@@ -115,7 +115,7 @@ void *coffeeThread(void *threadid) {
 				pause();
 
 			switch (getSigValue(MODE_MENU)) {
-			case SigInt0Psh:
+			case SigInt0Rls:
 				changeState(STATE_WAIT_OFF);
 				leaveMenu();
 				break;
@@ -131,7 +131,7 @@ void *coffeeThread(void *threadid) {
 				pause();
 
 			switch (getSigValue(MODE_MENU)) {
-			case SigInt0Psh:
+			case SigInt0Rls:
 				if (halIsHeating()) {
 					coffeeIncreaseHeatingTime(halgetHeatingTime());
 				}
@@ -154,7 +154,7 @@ void *coffeeThread(void *threadid) {
 				pause();
 
 			switch (getSigValue(MODE_MENU)) {
-			case SigInt0Psh:
+			case SigInt0Rls:
 				changeMode(MODE_STATE);
 				if (!halProxSensorCovered()) {
 					changeState(STATE_CLEANING);
@@ -209,7 +209,7 @@ void *coffeeThread(void *threadid) {
 				pause();
 
 			switch (getSigValue(MODE_MENU)) {
-			case SigInt0Psh:
+			case SigInt0Rls:
 				leaveMenu();
 				break;
 
@@ -226,9 +226,6 @@ void *coffeeThread(void *threadid) {
 			break;
 		} //end switch (page)
 
-		/* FIXME: Display events are reacting on Psh signal, leads to instant
-		 * machine turn on when leave menu is pressed */
-
 		/*
 		 * Hardware FSM
 		 */
@@ -240,6 +237,7 @@ void *coffeeThread(void *threadid) {
 			if (mode == MODE_STATE) {
 				halMachineOff();
 				writeBackCache();
+				changePage(PAGE_DEMO);
 				if (SigValueEmpty())
 					pause();
 			}
@@ -538,6 +536,7 @@ int getSigValue(coffee_mode_t mode) {
 		case SigInt1RlsLong:
 			sigValue = 0;
 			return tmp;
+			break;
 
 		default:
 			break;
@@ -594,6 +593,7 @@ void changeMode(coffee_mode_t newMode) {
 
 /*
  * leaving the menu
+ *  sets the start page for the next menu call to softoff
  */
 void leaveMenu() {
 	logger(V_BREW, "Leaving the menu again...\n");
@@ -609,6 +609,13 @@ coffee_status_t getState(void) {
 	return state;
 }
 
+/**
+ * Returns the local up-to-date brewcounter
+ */
+uint16_t getBrewCounter(void) {
+	return brewCounter;
+}
+
 /**
  * Counter for the brew time
  * refresh every 200ms
@@ -673,9 +680,10 @@ void coffeeBrew(void) {
 	brewTimer.start();
 	while (halGetFlow() < AMOUNT_PREINFUSION) {
 		usleep(50000);
-		if (getSigValue(MODE_STATE) == SigInt0Psh)
+		if (getSigValue(MODE_STATE) == SigInt0Psh){
 			stopBrewing();
-		return;
+			return;
+		}
 	}
 	stopBrewing();
 
@@ -700,8 +708,10 @@ void coffeeBrew(void) {
 	brewTimer.start();
 	while (brewTime < TIME_INFUSION && halGetFlow() < AMOUNT_DBLESPRESSO) {
 		usleep(100000);
-		if (getSigValue(MODE_STATE) == SigInt0Psh)
+		if (getSigValue(MODE_STATE) == SigInt0Psh){
+			stopBrewing();
 			break;
+		}
 	}
 	stopBrewing();
 	return;

+ 1 - 0
CoffeeCode/coffee.h

@@ -58,6 +58,7 @@ void changePage(coffee_menuPage_t newPage);
 void leaveMenu(void);
 coffee_status_t getState(void);
 int getSigValue(coffee_mode_t mode);
+uint16_t getBrewCounter(void);
 void brewTimeHandler(void);
 void writeBackCache(void);
 void coffeeTerminate(event_t *event);

+ 12 - 2
CoffeeCode/display.cpp

@@ -61,6 +61,16 @@ void displayPrintTemp(int line) {
 	lcdPrintf(lcd, "       %d C      ", DS18B20_readTemp());
 }
 
+void displayPrintStats(int line) {
+	char buffer[17];
+	if (line > DISPLAY_ROWS)
+			line = 0;
+
+	lcdPosition(lcd, 0, line);
+	sprintf(buffer, "%7d espressi", getBrewCounter());
+	lcdPrintf(lcd, buffer);
+}
+
 /**
  * Prints out the total volume flow
  * @param line Target line in display
@@ -349,8 +359,8 @@ void displayRefresh(void) {
 			displayPrintLn(1, displayGetString(str_menu_kill), true);
 			break;
 		case PAGE_STATS:
-			displayPrintLn(0, displayGetString(str_menu), true);
-			displayPrintLn(1, displayGetString(str_menu_stats), true); // FIXME: Show stats
+			displayPrintLn(0, displayGetString(str_menu_stats), true);
+			displayPrintStats(1);
 			break;
 		case PAGE_TEMP:
 			displayPrintLn(0, displayGetString(str_menu_temp), true);

+ 54 - 2
CoffeeCode/hal.cpp

@@ -18,6 +18,8 @@
 volatile int flowcnt = 0;
 
 int Int0Time, Int1Time;
+int idleCounter;
+bool idle;
 bool flagIgnoreRlsInt0, flagIgnoreRlsInt1;
 
 //storage for the last state of the buttons and the proximity sensor
@@ -25,12 +27,17 @@ int pinState[3] = {0, 0, 0};
 
 timer Int0Timer(&halInt0TimerHandler);
 timer Int1Timer(&halInt1TimerHandler);
+timer idleTimer(&halIdleTimerHandler);
 
 clock_t heatingCycle[2] = {0, 0};
 
 //delay of the debounce in milliseconds
 #define DELAY_DEBOUNCE	50
 
+//display turn off after idle time in min
+//minimal time is 2min
+#define IDLE_TIME	10
+
 /**
  * Initializes HAL
  */
@@ -57,6 +64,11 @@ void halInit(void) {
 	Int0Time = 0;
 	Int1Time = 0;
 
+	idleTimer.setDivider(1200); //1 min
+	idleTimer.start();
+	idleCounter = 0;
+	idle = false;
+
 	flagIgnoreRlsInt0 = false;
 	flagIgnoreRlsInt1 = false;
 
@@ -183,6 +195,15 @@ void halInt0TimerHandler(void) {
 	}
 }
 
+/**
+ *
+ */
+void halIdleTimerHandler(void) {
+	if(++idleCounter == IDLE_TIME){
+		halEnterIdle();
+	}
+}
+
 /**
  * Interrupt routine for Int1 (Bottom button)
  */
@@ -339,13 +360,28 @@ int halGetInt1(void) {
  * @param val Integer value assigned to signal
  */
 void halSendSignal(HalSig val) {
+	//catch if machine is idle and drop button event
+
+	switch (val) {
+	case SigInt0Psh:
+	case SigInt0Rls:
+	case SigInt0RlsLong:
+	case SigInt1Psh:
+	case SigInt1Rls:
+	case SigInt1RlsLong:
+		idleCounter = 0;
+		if (idle) {
+			halLeaveIdle();
+			return;
+		}
+
+	}
 	sigval value = { 0 };
 	value.sival_int = (int) val;
 
 	try {
 		if (pthread_sigqueue(thread[THREAD_COFFEE], SIGUSR2, value)) {
-			logger_error("hal.cpp: Failed to queue signal %d %s\n", val,
-					strerror(errno));
+			logger_error("hal.cpp: Failed to queue signal %d %s\n", val, strerror(errno));
 			//No Signals reach the state machine anymore...
 			exit(EXIT_FAILURE);
 		}
@@ -374,3 +410,19 @@ void halMachineOff(void) {
 	halRelaisOff(RELAIS_POWER);
 	logger(V_HAL, "Turning machine off\n");
 }
+
+/**
+ *
+ */
+void halEnterIdle(void){
+	halDisplayOff();
+	idle = true;
+}
+
+/**
+ *
+ */
+void halLeaveIdle(void){
+	halDisplayOn();
+	idle = false;
+}

+ 3 - 0
CoffeeCode/hal.h

@@ -79,5 +79,8 @@ void halMachineOn(void);
 void halMachineOff(void);
 void halInt0TimerHandler(void);
 void halInt1TimerHandler(void);
+void halIdleTimerHandler(void);
+void halEnterIdle (void);
+void halLeaveIdle (void);
 
 #endif /* HAL_H_ */