Ver Fonte

changed the display of the descaling star so it doesnt blink anymore, added temperatur to the CoffeePi when machine is on, added functions to measure running time of pump

Sebastian há 6 anos atrás
pai
commit
a4ed6b3cce
5 ficheiros alterados com 121 adições e 25 exclusões
  1. 1 1
      CoffeeCode/buildno
  2. 1 0
      CoffeeCode/coffee.cpp
  3. 41 24
      CoffeeCode/display.cpp
  4. 74 0
      CoffeeCode/hal.cpp
  5. 4 0
      CoffeeCode/hal.h

+ 1 - 1
CoffeeCode/buildno

@@ -1 +1 @@
-254
+260

+ 1 - 0
CoffeeCode/coffee.cpp

@@ -645,6 +645,7 @@ void changeMode(coffee_mode_t newMode) {
  *  sets the start page for the next menu call to softoff
  */
 void leaveMenu() {
+	//TODO leave the menu after certain time automatically
 	logger(V_BREW, "Leaving the menu again...\n");
 	//leave the menu again
 	changeMode(MODE_STATE);

+ 41 - 24
CoffeeCode/display.cpp

@@ -35,7 +35,6 @@ bool coffeeDescaling = false;
  * Prints out the current time in a centered position
  * @param line Target line in display
  */
-
 void displayPrintTime(int line) {
 	time_t rawtime;
 	struct tm * timeinfo;
@@ -53,18 +52,20 @@ void displayPrintTime(int line) {
  * Prints out the current temperature in a centered position
  * @param line Target line in display
  */
-//TODO: the temperature is wrong(old value) the first time the page is opened
-//after the first refresh the right temperature is displayed
-//no idea where this comes from, datasheet says nothing about dummy readouts.
-//no old values are used, conversion is started before every readout...
 void displayPrintTemp(int line) {
+	//TODO: the temperature is wrong(old value) the first time the page is opened
+	//after the first refresh the right temperature is displayed
+	//no idea where this comes from, datasheet says nothing about dummy readouts.
+	//no old values are used, conversion is started before every readout...
 	if (line > DISPLAY_ROWS)
 		line = 0;
 
 	lcdPosition(lcd, 0, line);
 	lcdPrintf(lcd, "       %d C      ", DS18B20_readTemp());
 }
-
+/**
+ * Prints the total epsressi brewed since reset
+ */
 void displayPrintStats(int line) {
 	char buffer[17];
 	if (line > DISPLAY_ROWS)
@@ -74,7 +75,9 @@ void displayPrintStats(int line) {
 	sprintf(buffer, "%7d espressi", getBrewCounter());
 	lcdPrintf(lcd, buffer);
 }
-
+/**
+ * Prints the total heating time in kWh
+ */
 void displayPrintStats2(int line) {
 	char buffer[17];
 	if (line > DISPLAY_ROWS)
@@ -86,7 +89,7 @@ void displayPrintStats2(int line) {
 }
 
 /**
- *
+ * Prints the remaining time or the remaining cups until the next descaling is necessary
  */
 void displayPrintNextDesc(int line) {
 	char buffer[17];
@@ -101,7 +104,6 @@ void displayPrintNextDesc(int line) {
  * Prints out the total volume flow
  * @param line Target line in display
  */
-
 void displayPrintFlow(int line) {
 	float flow = halGetFlow();
 	lcdPosition(lcd, 0, line);
@@ -142,6 +144,10 @@ void displayPrintLn(int line, const char* str, bool centered) {
 			buf[i] = ' ';
 		}
 	}
+	//draw the descaling star
+	if(coffeeDescaling && line == 0){
+		buf[15] = '*';
+	}
 	lcdPosition(lcd, 0, line);
 	buf[DISPLAY_COLS] = '\0';
 	lcdPrintf(lcd, buf);
@@ -216,6 +222,24 @@ void displayDescaling(event_t *event) {
 	coffeeDescaling = *(bool*) event->data;
 }
 
+/**
+ * Prints the logo (CoffeePi) and also the temperature with the logo (CoffeePi@72C) if the machine is on
+ */
+void displayPrintLogo(void) {
+	char buffer[17];
+	switch (coffeeState) {
+		case STATE_HEATING:
+		case STATE_INITALHEATING:
+		case STATE_IDLE:
+			sprintf(buffer, "CoffeePi @ %dC", DS18B20_readTemp());
+			break;
+		default:
+			sprintf(buffer, "CoffeePi");
+			break;
+	}
+	displayPrintLn(0, buffer, true);
+}
+
 /**
  * Handles cleanup before program termination
  */
@@ -342,25 +366,24 @@ void displaySetLang(display_lang_t lang) {
 void displayRefresh(void) {
 	if (coffeeMode == MODE_STATE) {
 		switch (coffeeState) { //coffeeGetState()
-		//TODO show the temperature when the machine is ready to brew
 		case STATE_IDLE:
-			displayPrintLn(0, "CoffeePi", true);
+			displayPrintLogo();
 			displayPrintLn(1, displayGetString(str_ready), true);
 			break;
 
 		case STATE_INITALHEATING:
-			displayPrintLn(0, "CoffeePi", true);
+			displayPrintLogo();
 			displayPrintLn(1, displayGetString(str_heating), true);
 			break;
 
 		case STATE_HEATING:
-			displayPrintLn(0, "CoffeePi", true);
+			displayPrintLogo();
 			displayPrintLn(1, displayGetString(str_heatingready), true);
 			break;
 
 		case STATE_BREW:
 			if (elapsedCnt <= 2 * REFRESH_RATE) {
-				displayPrintLn(0, "CoffeePi", true);
+				displayPrintLogo();
 				displayPrintLn(1, displayGetString(str_brewing), true);
 			} else {
 				displayPrintLn(0, displayGetString(str_brewing), true);
@@ -374,32 +397,26 @@ void displayRefresh(void) {
 			break;
 
 		case STATE_CLEANING:
-			displayPrintLn(0, "CoffeePi", true);
+			displayPrintLogo();
 			displayPrintLn(1, displayGetString(str_cleaning), true);
 			break;
 
 		case STATE_ERROR:
-			displayPrintLn(0, "CoffeePi", true);
+			displayPrintLogo();
 			displayPrintLn(1, displayGetString(str_error), true);
 			break;
 
 		case STATE_WAIT_OFF:
-			displayPrintLn(0, "CoffeePi", true);
+			displayPrintLogo();
 			displayPrintLn(1, displayGetString(str_waitoff), true);
 			break;
 
 		case STATE_OFF:
 		default:
-			displayPrintLn(0, "CoffeePi", true);
+			displayPrintLogo();
 			displayPrintTime(1);
 			break;
 		}
-		//draw the descaling star
-		if(coffeeDescaling){
-			lcdPosition(lcd, 15, 0);
-			lcdPutchar(lcd, '*');
-		}
-
 	} else if (coffeeMode == MODE_MENU) {
 		switch (coffeePage) {
 		case PAGE_SOFTOFF:

+ 74 - 0
CoffeeCode/hal.cpp

@@ -10,14 +10,19 @@
 #include <string.h>
 #include <signal.h>
 #include <ctime>
+#include <time.h>
 #include <unistd.h>
 #include "hal.h"
 #include "global.h"
 #include "logger.h"
 #include "timer.h"
 
+
+typedef struct timespec timespec;
+
 volatile int flowcnt = 0;
 
+
 int Int0Time, Int1Time;
 int idleCounter;
 bool idle;
@@ -31,6 +36,7 @@ timer Int1Timer(&halInt1TimerHandler);
 timer idleTimer(&halIdleTimerHandler);
 
 time_t heatingCycle[] = {0, 0};
+timespec pumpCycle[] = {{0,0},{0,0}};
 
 //delay of the debounce in milliseconds
 #define DELAY_DEBOUNCE	50
@@ -39,6 +45,7 @@ time_t heatingCycle[] = {0, 0};
 //minimal time is 2min
 #define IDLE_TIME	10
 
+
 /**
  * Initializes HAL
  */
@@ -451,3 +458,70 @@ void halLeaveIdle(void){
 	idleTimer.start();
 	idle = false;
 }
+
+/**
+ * Wrapper function to turn the pump on
+ * and is used for time measurements on how long the pump is running
+ */
+void halPumpOn(void){
+	halRelaisOn(RELAIS_PUMP);
+	clock_gettime(CLOCK_REALTIME, &pumpCycle[0]);
+}
+
+/**
+ * Wrapper function to turn the pump off
+ * and is used for time measurements on how long the pump is running
+ */
+void halPumpOff(void){
+	halRelaisOff(RELAIS_PUMP);
+	clock_gettime(CLOCK_REALTIME, &pumpCycle[1]);
+}
+
+/**
+ * Function to get the elapsed time the pump is running in ms
+ * when the pump is on, this function returns the time between turning the pump on and the call
+ * when the pump is off, this function returns the last
+ */
+double halGetPumpTime(void){
+	timespec now;
+	timespec diff = {0,0};
+	if(halGetRelaisState(RELAIS_PUMP) == HIGH){//pump is on
+		clock_gettime(CLOCK_REALTIME, &now);
+		timespec_diff(&pumpCycle[0], &now, &diff);
+	}
+	else {
+		timespec_diff(&pumpCycle[0], &pumpCycle[1], &diff);
+	}
+	return diff.tv_sec * 1000 + diff.tv_nsec/1000000;
+}
+
+/**
+ * Function to calculate the difference between two timespecs
+ */
+void timespec_diff(timespec *start, timespec *stop, timespec *result) {
+	long int secDiff = stop->tv_sec - start->tv_sec;
+	long int nsecDiff = stop->tv_nsec - start->tv_nsec;
+
+	if (secDiff > 0) {
+		if (nsecDiff >= 0) {
+			result->tv_sec = secDiff;
+			result->tv_nsec = nsecDiff;
+		} else if (nsecDiff < 0) {
+			result->tv_sec = --secDiff;
+			result->tv_nsec = 1000000000 + nsecDiff;
+		}
+	} else if (secDiff < 0) {
+		if (nsecDiff >= 0) {
+			result->tv_sec = ++secDiff;
+			result->tv_nsec = -(1000000000 - nsecDiff);
+
+		} else if (nsecDiff < 0) {
+			result->tv_sec = secDiff;
+			result->tv_nsec = nsecDiff;
+		}
+	} else if (secDiff == 0){
+		result->tv_sec = secDiff;
+		result->tv_nsec = nsecDiff;
+	}
+	return;
+}

+ 4 - 0
CoffeeCode/hal.h

@@ -84,5 +84,9 @@ void halInt1TimerHandler(void);
 void halIdleTimerHandler(void);
 void halEnterIdle (void);
 void halLeaveIdle (void);
+void halPumpOn(void);
+void halPumpOff(void);
+double halGetPumpTime(void);
+void timespec_diff(timespec *start, timespec *stop, timespec *result);
 
 #endif /* HAL_H_ */