|
@@ -66,14 +66,15 @@ timer Int0Timer(&halInt0TimerHandler);
|
|
|
timer Int1Timer(&halInt1TimerHandler);
|
|
|
timer idleTimer(&halIdleTimerHandler);
|
|
|
timer flowResetTimer (&flowResetTimerHandler);
|
|
|
+timer flowTimer(&halFlowTimerHandler);
|
|
|
|
|
|
time_t heatingCycle[] = {0, 0};
|
|
|
timespec flowTimestep[] = {{0,0},{0,0}};
|
|
|
uint8_t flowIndex = 0;
|
|
|
int16_t tickCounter = 0;
|
|
|
-
|
|
|
-
|
|
|
-timespec pumpCycle[] = {{0,0},{0,0}};
|
|
|
+uint16_t flowtime = 0;
|
|
|
+uint16_t lastFlowTime = 0;
|
|
|
+bool brewSigFired = false;
|
|
|
|
|
|
//delay of the debounce in milliseconds
|
|
|
#define DELAY_DEBOUNCE 50
|
|
@@ -126,6 +127,8 @@ void halInit(void) {
|
|
|
|
|
|
flowResetTimer.setDivider(20); //1000ms
|
|
|
|
|
|
+ flowTimer.setDivider(4); // 100ms
|
|
|
+
|
|
|
flagIgnoreRlsInt0 = false;
|
|
|
flagIgnoreRlsInt1 = false;
|
|
|
|
|
@@ -263,10 +266,6 @@ void halIntRotary(void) {
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
/**
|
|
|
* Interrupt routine for Int0 (Top button)
|
|
|
*/
|
|
@@ -356,7 +355,7 @@ void halInt1TimerHandler(void) {
|
|
|
/**
|
|
|
* Timer handler to auto-reset the flow counter.
|
|
|
* The timer is started when the flow interrupt is triggered.
|
|
|
- * It compares the last value (flowResetValue) with the current flow value (flowcnt)
|
|
|
+ * It compares the last value (flowResetValue) with the current flow value
|
|
|
* If they match (e.g no flow within 1000ms) the flow counter is reseted.
|
|
|
* Setting the last value to -1 ensures that when the timer gets called immediately after it is started the comparison will fail.
|
|
|
* This implementation is read-only and so it doesn't need semaphores.
|
|
@@ -369,6 +368,13 @@ void flowResetTimerHandler() {
|
|
|
flowResetValue = flowcnt;
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ *
|
|
|
+ */
|
|
|
+void halFlowTimerHandler() {
|
|
|
+ flowtime += 200;
|
|
|
+}
|
|
|
+
|
|
|
/**
|
|
|
* Interrupt routine for the flow sensor
|
|
|
* It counts the edges and stores the value in flowcnt
|
|
@@ -376,15 +382,17 @@ void flowResetTimerHandler() {
|
|
|
void halIntFlow(void) {
|
|
|
//halRelaisOff(RELAIS_POWER);
|
|
|
if(!flowResetTimer.isActive()) flowResetTimer.start();
|
|
|
- logger(V_HAL, "IntFlow triggered #%d total: %.2fml\n", flowcnt, halGetFlow());
|
|
|
flowcnt++;
|
|
|
+ logger(V_HAL, "IntFlow triggered #%d total: %.2fml\n", flowcnt, halGetFlow());
|
|
|
|
|
|
- if(flowcnt >= BREW_MANUAL_TRIGGER && !brewmanual) { //send signal once
|
|
|
+ //tracking of flowtime
|
|
|
+ if(!flowTimer.isActive()) flowTimer.start();
|
|
|
+
|
|
|
+ if (halGetFlow() >= BREW_MANUAL_TRIGGER && !brewSigFired) {
|
|
|
halSendSignal(SigBrewOn);
|
|
|
- brewmanual = true;
|
|
|
+ brewSigFired = true;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
//subroutine to log the flow to the database
|
|
|
/*timespec deltaT;
|
|
|
clock_gettime(CLOCK_REALTIME, &flowTimestep[flowIndex]);
|
|
@@ -457,24 +465,44 @@ float halGetFlow(void) {
|
|
|
return flowcnt * FLOW_ML_PULSE;
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * Returns the total flow time in ms
|
|
|
+ */
|
|
|
+uint16_t halGetFlowTime(void){
|
|
|
+ return flowtime;
|
|
|
+}
|
|
|
+
|
|
|
/*
|
|
|
* Returns the last total flow through the sensor in ml after reset
|
|
|
*/
|
|
|
float halGetLastFlow(void) {
|
|
|
return lastFlowcnt * FLOW_ML_PULSE;
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
- * Resets the Flow counter
|
|
|
+ * Returns the total flow time in ms before the last reset.
|
|
|
+ */
|
|
|
+uint16_t halGetLastFlowTime(void){
|
|
|
+ return lastFlowTime;
|
|
|
+}
|
|
|
+/**
|
|
|
+ * Resets the Flow counter. Do not call this function manually. It will be automatically triggered
|
|
|
+ * from the flow reset timer routine!
|
|
|
*/
|
|
|
void halResetFlow(void) {
|
|
|
logger(V_HAL, "Flow counter reset, amount so far: %.2f ml\n", halGetFlow());
|
|
|
lastFlowcnt = flowcnt;
|
|
|
flowcnt = 0;
|
|
|
|
|
|
+ lastFlowTime = flowtime;
|
|
|
+ flowtime = 0;
|
|
|
+
|
|
|
flowResetTimer.stop();
|
|
|
+ flowTimer.stop();
|
|
|
+
|
|
|
flowResetValue = -1;
|
|
|
- if(brewmanual) {
|
|
|
- brewmanual = false;
|
|
|
+ if(brewSigFired) {
|
|
|
+ brewSigFired = false;
|
|
|
halSendSignal(SigBrewOff);
|
|
|
}
|
|
|
}
|
|
@@ -619,19 +647,15 @@ 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
|
|
|
+ * Wrapper function to turn the pump on.
|
|
|
*/
|
|
|
void halPumpOn(){
|
|
|
halRelaisOn(RELAIS_PUMP);
|
|
|
- clock_gettime(CLOCK_REALTIME, &pumpCycle[0]);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
*
|
|
|
*/
|
|
|
-
|
|
|
void halIncreaseLogCycleCounter(void){
|
|
|
logcycle = logcycle + 1;
|
|
|
}
|
|
@@ -642,25 +666,6 @@ void halIncreaseLogCycleCounter(void){
|
|
|
*/
|
|
|
void halPumpOff(void){
|
|
|
halRelaisOff(RELAIS_PUMP);
|
|
|
- clock_gettime(CLOCK_REALTIME, &pumpCycle[1]);
|
|
|
-}
|
|
|
-
|
|
|
-/**
|
|
|
- * 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 time elapsed in the last pump cycle
|
|
|
- */
|
|
|
-double halGetPumpTime(void){
|
|
|
- timespec now;
|
|
|
- timespec diff = {0,0};
|
|
|
- if(halGetRelaisState(RELAIS_PUMP) == HIGH){//pump is on
|
|
|
- clock_gettime(CLOCK_REALTIME, &now);
|
|
|
- timespec_diff(&pumpCycle[0], &now, &diff);
|
|
|
- }
|
|
|
- else {
|
|
|
- timespec_diff(&pumpCycle[0], &pumpCycle[1], &diff);
|
|
|
- }
|
|
|
- return diff.tv_sec * 1000 + diff.tv_nsec/1000000;
|
|
|
}
|
|
|
|
|
|
/**
|