|
@@ -6,6 +6,7 @@
|
|
|
*/
|
|
|
#include <wiringPi.h>
|
|
|
#include <stdlib.h>
|
|
|
+#include <stdint.h>
|
|
|
#include <errno.h>
|
|
|
#include <string.h>
|
|
|
#include <signal.h>
|
|
@@ -16,6 +17,7 @@
|
|
|
#include "global.h"
|
|
|
#include "logger.h"
|
|
|
#include "timer.h"
|
|
|
+#include "database.h"
|
|
|
|
|
|
|
|
|
typedef struct timespec timespec;
|
|
@@ -31,11 +33,16 @@ bool flagIgnoreRlsInt0, flagIgnoreRlsInt1;
|
|
|
//storage for the last state of the buttons, the proximity sensor and the pressure sensor
|
|
|
int pinState[4] = {1, 1, 1, 0};
|
|
|
|
|
|
+//sweep counter to log every brew
|
|
|
+
|
|
|
timer Int0Timer(&halInt0TimerHandler);
|
|
|
timer Int1Timer(&halInt1TimerHandler);
|
|
|
timer idleTimer(&halIdleTimerHandler);
|
|
|
|
|
|
time_t heatingCycle[] = {0, 0};
|
|
|
+timespec flowTimestep[] = {{0,0},{0,0}};
|
|
|
+uint8_t flowIndex = 0;
|
|
|
+
|
|
|
timespec pumpCycle[] = {{0,0},{0,0}};
|
|
|
|
|
|
//delay of the debounce in milliseconds
|
|
@@ -64,6 +71,8 @@ void halInit(void) {
|
|
|
idleTimer.setDivider(1200); //1 min
|
|
|
idleCounter = 0;
|
|
|
idle = false;
|
|
|
+ clock_gettime(CLOCK_REALTIME, &flowTimestep[0]);
|
|
|
+ clock_gettime(CLOCK_REALTIME, &flowTimestep[1]);
|
|
|
halDisplayOn();
|
|
|
|
|
|
if (optPower) {
|
|
@@ -103,6 +112,7 @@ void halInit(void) {
|
|
|
logger_error("Unable to setup ISRProximity: %s\n", strerror(errno));
|
|
|
return;
|
|
|
}
|
|
|
+ // in long term a manual brew detection would be nice
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -260,6 +270,16 @@ void halIntFlow(void) {
|
|
|
//halRelaisOff(RELAIS_POWER);
|
|
|
logger(V_HAL, "IntFlow triggered #%d total: %.2fml\n", flowcnt, halGetFlow());
|
|
|
flowcnt++;
|
|
|
+
|
|
|
+ //subroutine to log the flow to the database
|
|
|
+ timespec deltaT;
|
|
|
+ clock_gettime(CLOCK_REALTIME, &flowTimestep[flowIndex]);
|
|
|
+ timespec_diff(&flowTimestep[((flowIndex + 1) % 2)], &flowTimestep[flowIndex], &deltaT);
|
|
|
+ if (sqlLogFlow(0, halGetFlow(), deltaT.tv_sec * 1000 + deltaT.tv_nsec/1000000)) {
|
|
|
+ logger_error("coffee.cpp: Couldn't write brewcounter to database");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ flowIndex = (flowIndex + 1) % 2;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -458,7 +478,7 @@ void halLeaveIdle(void){
|
|
|
|
|
|
/**
|
|
|
* Wrapper function to turn the pump on
|
|
|
- * and is used for time measurements on how long the pump is running
|
|
|
+ * and to measure how long the pump is running
|
|
|
*/
|
|
|
void halPumpOn(void){
|
|
|
halRelaisOn(RELAIS_PUMP);
|
|
@@ -467,7 +487,7 @@ void halPumpOn(void){
|
|
|
|
|
|
/**
|
|
|
* Wrapper function to turn the pump off
|
|
|
- * and is used for time measurements on how long the pump is running
|
|
|
+ * and to measure how long the pump is running
|
|
|
*/
|
|
|
void halPumpOff(void){
|
|
|
halRelaisOff(RELAIS_PUMP);
|
|
@@ -477,7 +497,7 @@ void halPumpOff(void){
|
|
|
/**
|
|
|
* 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
|
|
|
+ * when the pump is off, this function returns the time elapsed in the last pump cycle
|
|
|
*/
|
|
|
double halGetPumpTime(void){
|
|
|
timespec now;
|