|
@@ -34,6 +34,7 @@ bool flagIgnoreRlsInt0, flagIgnoreRlsInt1;
|
|
|
int pinState[4] = {1, 1, 1, 0};
|
|
|
|
|
|
//sweep counter to log every brew
|
|
|
+uint16_t logcycle = 0;
|
|
|
|
|
|
timer Int0Timer(&halInt0TimerHandler);
|
|
|
timer Int1Timer(&halInt1TimerHandler);
|
|
@@ -92,6 +93,8 @@ void halInit(void) {
|
|
|
flagIgnoreRlsInt0 = false;
|
|
|
flagIgnoreRlsInt1 = false;
|
|
|
|
|
|
+ event_subscribe("terminate", &halTerminate);
|
|
|
+
|
|
|
if (wiringPiISR(PIN_INT0, INT_EDGE_BOTH, &halInt0) < 0) {
|
|
|
logger_error("Unable to setup ISR0: %s\n", strerror(errno));
|
|
|
return;
|
|
@@ -112,7 +115,12 @@ void halInit(void) {
|
|
|
logger_error("Unable to setup ISRProximity: %s\n", strerror(errno));
|
|
|
return;
|
|
|
}
|
|
|
- // in long term a manual brew detection would be nice
|
|
|
+
|
|
|
+ if (!(logcycle = sqlGetConf(CFGSweepCounter))) {
|
|
|
+ logger_error("hal.cpp: Couldn't read the logcycle counter from the database\n");
|
|
|
+ //pthread_exit(EXIT_SUCCESS);
|
|
|
+ exit(EXIT_FAILURE);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -276,7 +284,7 @@ void halIntFlow(void) {
|
|
|
clock_gettime(CLOCK_REALTIME, &flowTimestep[flowIndex]);
|
|
|
timespec_diff(&flowTimestep[((flowIndex + 1) % 2)], &flowTimestep[flowIndex], &deltaT);
|
|
|
|
|
|
- if (sqlLogFlow(2, halGetFlow()*1000, deltaT.tv_sec * 1000 + deltaT.tv_nsec/1000000)) {
|
|
|
+ if (sqlLogFlow(logcycle, halGetFlow()*1000, deltaT.tv_sec * 1000 + deltaT.tv_nsec/1000000)) {
|
|
|
logger_error("hal.cpp: could not log flow to database!");
|
|
|
return;
|
|
|
}
|
|
@@ -453,6 +461,7 @@ void halMachineOff(void) {
|
|
|
|
|
|
idleCounter = 0;
|
|
|
idleTimer.start();
|
|
|
+ halWriteBackCache();
|
|
|
logger(V_HAL, "Turning machine off\n");
|
|
|
}
|
|
|
|
|
@@ -480,12 +489,21 @@ void halLeaveIdle(void){
|
|
|
/**
|
|
|
* Wrapper function to turn the pump on
|
|
|
* and to measure how long the pump is running
|
|
|
+ * @param cycle the number of the sweep in the database
|
|
|
*/
|
|
|
-void halPumpOn(void){
|
|
|
+void halPumpOn(){
|
|
|
halRelaisOn(RELAIS_PUMP);
|
|
|
clock_gettime(CLOCK_REALTIME, &pumpCycle[0]);
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ *
|
|
|
+ */
|
|
|
+
|
|
|
+void halIncreaseLogCycleCounter(void){
|
|
|
+ logcycle++;
|
|
|
+}
|
|
|
+
|
|
|
/**
|
|
|
* Wrapper function to turn the pump off
|
|
|
* and to measure how long the pump is running
|
|
@@ -543,3 +561,21 @@ void timespec_diff(timespec *start, timespec *stop, timespec *result) {
|
|
|
}
|
|
|
return;
|
|
|
}
|
|
|
+
|
|
|
+/*
|
|
|
+ * Handler for Termination of the hal
|
|
|
+ */
|
|
|
+void halTerminate(event_t *event){
|
|
|
+ halWriteBackCache();
|
|
|
+}
|
|
|
+
|
|
|
+/*
|
|
|
+ * writing back non volatile variables of the hal to the database: SweepCounter
|
|
|
+ */
|
|
|
+void halWriteBackCache(){
|
|
|
+ if (sqlSetConf(CFGSweepCounter, logcycle)) {
|
|
|
+ logger_error("hall.cpp: Couldn't write logcycle to database");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ logger(V_BREW, "Writing back logcycle %d\n", logcycle);
|
|
|
+}
|