Переглянути джерело

added two menu pages: next descaling and total heating time, added more output for heating time since here is a bug somewhere...

Sebastian 7 роки тому
батько
коміт
afa1450486
6 змінених файлів з 132 додано та 13 видалено
  1. 1 1
      CoffeeCode/buildno
  2. 78 12
      CoffeeCode/coffee.cpp
  3. 7 0
      CoffeeCode/coffee.h
  4. 30 0
      CoffeeCode/display.cpp
  5. 14 0
      CoffeeCode/display.h
  6. 2 0
      CoffeeCode/hal.cpp

+ 1 - 1
CoffeeCode/buildno

@@ -1 +1 @@
-241
+244

+ 78 - 12
CoffeeCode/coffee.cpp

@@ -38,7 +38,7 @@ bool descaling; //flag to indicate descaling and cleaning
 uint16_t descBrewcount;
 time_t descRawTimestamp;
 
-const char* PageName[] = { "SoftOff", "Kill", "Stats", "Temp", "Clean", "Demo",
+const char* PageName[] = { "SoftOff", "Kill", "Stats", "Stats2", "Descaling", "Temp", "Clean", "Demo",
 		"Exit" };
 const char* StateName[] = { "OFF", "HEATING", "INITHEAT", "IDLE", "BREW",
 		"BREWMAN", "CLEAN", "ERROR", "WAITOFF" };
@@ -210,18 +210,36 @@ void *coffeeThread(void *threadid) {
 				break;
 			}
 			break;
-		//TODO: Add page heating time in minutes and Wh
 		case PAGE_STATS:
 			if (SigValueEmpty() && mode == MODE_MENU)
 				pause();
 
+			switch (getSigValue(MODE_MENU)) {
+			case SigInt1Psh:
+				changePage(PAGE_STATS2);
+				break;
+			}
+			break;
+		case PAGE_STATS2:
+			if (SigValueEmpty() && mode == MODE_MENU)
+				pause();
+
+			switch (getSigValue(MODE_MENU)) {
+			case SigInt1Psh:
+				changePage(PAGE_DESCALING);
+				break;
+			}
+			break;
+		case PAGE_DESCALING:
+			if (SigValueEmpty() && mode == MODE_MENU)
+				pause();
+
 			switch (getSigValue(MODE_MENU)) {
 			case SigInt1Psh:
 				changePage(PAGE_EXIT);
 				break;
 			}
 			break;
-		//TODO: Add page when next descaling is necessary
 		case PAGE_EXIT:
 			if (SigValueEmpty() && mode == MODE_MENU)
 				pause();
@@ -647,6 +665,27 @@ uint16_t getBrewCounter(void) {
 	return brewCounter;
 }
 
+/**
+ * Returns the total heating time in seconds
+ */
+uint64_t getTotalHeatingTime(void) {
+	return totalHeatingTime;
+}
+
+/**
+ * Returns the value of the brewcounter when the last descaling happened
+ */
+uint16_t getDescBrewCounter (void) {
+	return descBrewcount;
+}
+
+/**
+ * Returns the raw time stamp when the last descaling happened
+ */
+time_t * getDescTimestamp (void) {
+	return &descRawTimestamp;
+}
+
 /**
  * Counter for the brew time
  * refresh every 200ms
@@ -672,18 +711,25 @@ void coffeeTerminate(event_t *event) {
  *
  */
 void writeBackCache(void) {
+	logger(V_BREW, "Writing back cache...\n");
+	logger(V_BREW, "Writing back brewCounter with %d\n", brewCounter);
 	if (sqlSetConf(CFGbrewcounter, brewCounter)) {
 		logger_error("coffee.cpp: Couldn't write brewcounter to database");
 		return;
 	}
+	logger(V_BREW, "Writing back total heating Time with %lld sec\n", totalHeatingTime);
 	if (sqlSetConf(CFGHeatingTime, totalHeatingTime)) {
 		logger_error("coffee.cpp: Couldn't write heating time to database");
 		return;
 	}
+	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");
 		return;
 	}
+	struct tm * timeinfo;
+	timeinfo = localtime(&descRawTimestamp);
+	logger(V_BREW, "Writing back descaling timestamp %d-%d-%d %d:%d\n", timeinfo->tm_mday, timeinfo->tm_mon, timeinfo->tm_year+1900, timeinfo->tm_hour, timeinfo->tm_min);
 	if (sqlSetConf(CFGDescTimestamp, (uint64_t)descRawTimestamp)) {
 		logger_error("coffee.cpp: Couldn't write descaling timestamp to database");
 		return;
@@ -758,7 +804,7 @@ void coffeeBrew(void) {
 	}
 	stopBrewing();
 	return;
-	//TODO: I want to see the total elapes brewing time!!
+	//TODO: I want to see the total elapsed brewing time!!
 }
 
 /*
@@ -793,24 +839,44 @@ void coffeeIncreaseHeatingTime(uint64_t heatingTime) {
  * uses descBrewcount and descTimestamp
  */
 void checkDescaling(){
-	time_t rawtime;
-	time(&rawtime);
-	double diffseconds = difftime(rawtime, descRawTimestamp);
-	diffseconds /= 24*60*60;
+	int16_t dirtyEspresso = checkDirtyEspresso ();
+	int16_t dirtyTime = checkDirtyTime ();
 
-	if((brewCounter - descBrewcount) >= DIRTY_ESPRESSO) {
-		logger(V_BREW, "Descaling necessary due to quantity: %d\n", brewCounter - descBrewcount);
+	if(dirtyEspresso <= 0) {
+		logger(V_BREW, "Descaling necessary due to quantity: %d\n", dirtyEspresso);
 		descaling = true;
 		event_trigger("descaling", &descaling, sizeof(bool));
 
 	}
-	if(diffseconds >= DIRTY_TIME) {
-		logger(V_BREW, "Descaling necessary due to time in days: %d\n", diffseconds);
+	if(dirtyTime <= 0) {
+		logger(V_BREW, "Descaling necessary due to time in days: %d\n", dirtyTime);
 		descaling = true;
 		event_trigger("descaling", &descaling, sizeof(bool));
 	}
 }
 
+/**
+ * this function returns the remaining espressi to be brewed before the descaling event is fired
+ * returns a positive integer when there are cups remaining
+ * and a negative when the number of cups are exceeded
+ * Number of cups after a descaling is defined with DIRTY_ESPRESSO
+ */
+int16_t checkDirtyEspresso (void) {
+	return descBrewcount + DIRTY_ESPRESSO - brewCounter;
+}
+
+/**
+ * Returns the remaining days before the next descaling event is fired
+ * returns a positive integer if there is time left and a negative one if the descaling time was exceeded
+ */
+int16_t checkDirtyTime (void) {
+	time_t rawtime;
+	time(&rawtime);
+	double diffseconds = difftime(rawtime, descRawTimestamp);
+	diffseconds /= 24*60*60; //calculate the days
+	return DIRTY_TIME - diffseconds;
+}
+
 /**
  * updates the corresponding variables after a descaling process
  */

+ 7 - 0
CoffeeCode/coffee.h

@@ -34,6 +34,8 @@ typedef enum {
 	PAGE_SOFTOFF,
 	PAGE_KILL,
 	PAGE_STATS,
+	PAGE_STATS2,
+	PAGE_DESCALING,
 	PAGE_TEMP,
 	PAGE_CLEAN,
 	PAGE_DEMO,
@@ -60,6 +62,9 @@ void leaveMenu(void);
 coffee_status_t getState(void);
 int getSigValue(coffee_mode_t mode);
 uint16_t getBrewCounter(void);
+uint64_t getTotalHeatingTime(void);
+uint16_t getDescBrewCounter (void);
+time_t * getDescTimestamp (void);
 void brewTimeHandler(void);
 void writeBackCache(void);
 void coffeeTerminate(event_t *event);
@@ -69,6 +74,8 @@ void stopBrewing(void);
 void coffeeIncreaseBrewCounter(void);
 void coffeeIncreaseHeatingTime(uint64_t heatingTime);
 void checkDescaling(void);
+int16_t checkDirtyEspresso (void);
+int16_t checkDirtyTime (void);
 void updateDescaling(void);
 
 #endif /* COFFEE_H_ */

+ 30 - 0
CoffeeCode/display.cpp

@@ -75,6 +75,28 @@ void displayPrintStats(int line) {
 	lcdPrintf(lcd, buffer);
 }
 
+void displayPrintStats2(int line) {
+	char buffer[17];
+	if (line > DISPLAY_ROWS)
+		line = 0;
+
+	uint64_t totalkWh = 2 * getTotalHeatingTime()/(60*60);
+	sprintf(buffer, "%lld min %lld kWh", getTotalHeatingTime()/60, totalkWh);
+	displayPrintLn(line, buffer, true);
+}
+
+/**
+ *
+ */
+void displayPrintNextDesc(int line) {
+	char buffer[17];
+	if (line > DISPLAY_ROWS)
+		line = 0;
+
+	sprintf(buffer, "%d d or %d C", checkDirtyTime(), checkDirtyEspresso());
+	displayPrintLn(line, buffer, true);
+}
+
 /**
  * Prints out the total volume flow
  * @param line Target line in display
@@ -390,6 +412,14 @@ void displayRefresh(void) {
 			displayPrintLn(0, displayGetString(str_menu_stats), true);
 			displayPrintStats(1);
 			break;
+		case PAGE_STATS2:
+			displayPrintLn(0, displayGetString(str_menu_stats2), true);
+			displayPrintStats2(1);
+			break;
+		case PAGE_DESCALING:
+			displayPrintLn(0, displayGetString(str_menu_nextdesc), true);
+			displayPrintNextDesc(1);
+			break;
 		case PAGE_TEMP:
 			displayPrintLn(0, displayGetString(str_menu_temp), true);
 			displayPrintTemp(1);

+ 14 - 0
CoffeeCode/display.h

@@ -30,6 +30,8 @@ typedef enum {
 	str_menu_softoff,
 	str_menu_kill,
 	str_menu_stats,
+	str_menu_stats2,
+	str_menu_nextdesc,
 	str_menu_temp,
 	str_menu_clean,
 	str_menu_demo,
@@ -120,6 +122,17 @@ static const display_string_t display_strings[str_last] =
 						"Stats",
 						"Stats"
 				}
+		},{ // str_menu_stats2
+				{
+						"Energieverbrauch",
+						"Energy consumed"
+				}
+		},
+		{ // str_menu_nextdesc
+				{
+						"Reiningung in",
+						"Descaling in"
+				}
 		},
 		{ // str_menu_temp
 				{
@@ -156,6 +169,7 @@ void *displayThread(void *threadid);
 void *displayTimerHandler(void *threadid);
 void displayInit(void);
 void displaySetLang(display_lang_t lang);
+void displayPrintLn(int line, const char* str, bool centered);
 
 void displayPushState(coffee_status_t state);
 

+ 2 - 0
CoffeeCode/hal.cpp

@@ -277,9 +277,11 @@ void halIntPressure(void) {
  */
 double halgetHeatingTime(void){
 	if (halIsHeating()) {
+		logger(V_HAL, "Heating Time: %f", (double)(clock() - heatingCycle[0]) / CLOCKS_PER_SEC);
 		return (double)(clock() - heatingCycle[0]) / CLOCKS_PER_SEC;
 	}
 	else {
+		logger(V_HAL, "Heating Time: %f", (double)(heatingCycle[1] - heatingCycle[0]) / CLOCKS_PER_SEC);
 		return (double)(heatingCycle[1] - heatingCycle[0]) / CLOCKS_PER_SEC;
 	}
 }