|
@@ -35,6 +35,8 @@ uint64_t totalHeatingTime; //local copies of the corresponding database entries
|
|
|
uint16_t brewCounter;
|
|
|
bool initalHeating;
|
|
|
bool descaling; //flag to indicate descaling and cleaning
|
|
|
+uint16_t descBrewcount;
|
|
|
+time_t descRawTimestamp;
|
|
|
|
|
|
const char* PageName[] = { "SoftOff", "Kill", "Stats", "Temp", "Clean", "Demo",
|
|
|
"Exit" };
|
|
@@ -67,19 +69,30 @@ void *coffeeThread(void *threadid) {
|
|
|
page = PAGE_SOFTOFF;
|
|
|
descaling = false;
|
|
|
|
|
|
+
|
|
|
//read the database values
|
|
|
if (!(totalHeatingTime = sqlGetConf(CFGHeatingTime))) {
|
|
|
- logger_error(
|
|
|
- "coffee.cpp: Couldn't read the heating time from the database");
|
|
|
+ logger_error("coffee.cpp: Couldn't read the heating time from the database");
|
|
|
//pthread_exit(EXIT_SUCCESS);
|
|
|
exit(EXIT_FAILURE);
|
|
|
}
|
|
|
if (!(brewCounter = sqlGetConf(CFGbrewcounter))) {
|
|
|
- logger_error(
|
|
|
- "coffee.cpp: Couldn't read the brew counter from the database");
|
|
|
+ logger_error("coffee.cpp: Couldn't read the brew counter from the database");
|
|
|
+ //pthread_exit(EXIT_SUCCESS);
|
|
|
+ exit(EXIT_FAILURE);
|
|
|
+ }
|
|
|
+ if (!(descRawTimestamp = (time_t) sqlGetConf(CFGDescTimestamp))) {
|
|
|
+ logger_error("coffee.cpp: Couldn't read the descaling time from the database");
|
|
|
//pthread_exit(EXIT_SUCCESS);
|
|
|
exit(EXIT_FAILURE);
|
|
|
}
|
|
|
+ if (!(descBrewcount = sqlGetConf(CFGDescBrewCount))) {
|
|
|
+ logger_error("coffee.cpp: Couldn't read the descaling brewcount time from the database");
|
|
|
+ //pthread_exit(EXIT_SUCCESS);
|
|
|
+ exit(EXIT_FAILURE);
|
|
|
+ }
|
|
|
+
|
|
|
+ checkDescaling();
|
|
|
|
|
|
event_subscribe("terminate", &coffeeTerminate);
|
|
|
|
|
@@ -425,6 +438,7 @@ void *coffeeThread(void *threadid) {
|
|
|
logger_error("coffee.cpp: Full tank detection failed..\n");
|
|
|
} else {
|
|
|
coffeeBrew();
|
|
|
+ checkDescaling();
|
|
|
logger(V_BREW, "Finishing brewing\n");
|
|
|
if (!halProxSensorCovered()) {
|
|
|
if (halIsHeating()) {
|
|
@@ -455,6 +469,7 @@ void *coffeeThread(void *threadid) {
|
|
|
if (!halProxSensorCovered()) {
|
|
|
//execute the cleaning procedure
|
|
|
coffeeClean();
|
|
|
+ updateDescaling();
|
|
|
if (halIsHeating()) {
|
|
|
changeState(STATE_HEATING);
|
|
|
} else {
|
|
@@ -649,6 +664,14 @@ void writeBackCache(void) {
|
|
|
logger_error("coffee.cpp: Couldn't write heating time to database");
|
|
|
return;
|
|
|
}
|
|
|
+ if (sqlSetConf(CFGDescBrewCount, descBrewcount)) {
|
|
|
+ logger_error("coffee.cpp: Couldn't write descaling brewcount to database");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (sqlSetConf(CFGDescTimestamp, (uint64_t)descRawTimestamp)) {
|
|
|
+ logger_error("coffee.cpp: Couldn't write descaling timestamp to database");
|
|
|
+ return;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/*
|
|
@@ -663,6 +686,7 @@ void coffeeClean(void) {
|
|
|
sleep(15);
|
|
|
}
|
|
|
descaling = false;
|
|
|
+ event_trigger("descaling", &descaling, sizeof(bool));
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -743,3 +767,44 @@ void coffeeIncreaseBrewCounter(void) {
|
|
|
void coffeeIncreaseHeatingTime(uint64_t heatingTime) {
|
|
|
totalHeatingTime += heatingTime;
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+ * Checks if the descaling is necessary
|
|
|
+ * uses descBrewcount and descTimestamp
|
|
|
+ */
|
|
|
+void checkDescaling(){
|
|
|
+ time_t rawtime;
|
|
|
+ time(&rawtime);
|
|
|
+ double diffseconds = difftime(rawtime, descRawTimestamp);
|
|
|
+ diffseconds /= 24*60*60;
|
|
|
+
|
|
|
+ if((brewCounter - descBrewcount) >= DIRTY_ESPRESSO) {
|
|
|
+ logger(V_BREW, "Descaling necessary due to quantity: %d\n", brewCounter - descBrewcount);
|
|
|
+ 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);
|
|
|
+ descaling = true;
|
|
|
+ event_trigger("descaling", &descaling, sizeof(bool));
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * updates the corresponding variables after a descaling process
|
|
|
+ */
|
|
|
+void updateDescaling(){
|
|
|
+ descBrewcount = brewCounter;
|
|
|
+ time_t newDesTimestamp;
|
|
|
+ time(&newDesTimestamp);
|
|
|
+ if(newDesTimestamp == -1){
|
|
|
+ logger(V_BREW, "Whoops, couldn't retrieve new descaling timestamp\n");
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ descRawTimestamp = newDesTimestamp;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|