|
@@ -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
|
|
|
*/
|