|
@@ -19,11 +19,29 @@
|
|
|
#include "timer.h"
|
|
|
#include "database.h"
|
|
|
|
|
|
+const char* SigName[] = {"SigInt0Psh",
|
|
|
+ "SigInt0Rls",
|
|
|
+ "SigInt0RlsLong",
|
|
|
+ "SigInt1Psh",
|
|
|
+ "SigInt1Rls",
|
|
|
+ "SigInt1RlsLong",
|
|
|
+ "SigPressCls",
|
|
|
+ "SigPressOpn",
|
|
|
+ "SigProxOpn",
|
|
|
+ "SigProxCvrd",
|
|
|
+ "SigBrewOn",
|
|
|
+ "SigBrewOff",
|
|
|
+ "SigPowerUp",
|
|
|
+ "SigPowerDown",
|
|
|
+ "SigRotCW",
|
|
|
+ "SigRotCCW"};
|
|
|
|
|
|
typedef struct timespec timespec;
|
|
|
|
|
|
volatile int flowcnt = 0;
|
|
|
int lastFlowcnt = 0;
|
|
|
+int flowResetValue = -1;
|
|
|
+bool brewmanual = false;
|
|
|
|
|
|
int Int0Time, Int1Time;
|
|
|
int idleCounter;
|
|
@@ -45,6 +63,7 @@ uint16_t logcycle = 1;
|
|
|
timer Int0Timer(&halInt0TimerHandler);
|
|
|
timer Int1Timer(&halInt1TimerHandler);
|
|
|
timer idleTimer(&halIdleTimerHandler);
|
|
|
+timer flowResetTimer (&flowResetTimerHandler);
|
|
|
|
|
|
time_t heatingCycle[] = {0, 0};
|
|
|
timespec flowTimestep[] = {{0,0},{0,0}};
|
|
@@ -103,6 +122,8 @@ void halInit(void) {
|
|
|
Int0Time = 0;
|
|
|
Int1Time = 0;
|
|
|
|
|
|
+ flowResetTimer.setDivider(20); //1000ms
|
|
|
+
|
|
|
flagIgnoreRlsInt0 = false;
|
|
|
flagIgnoreRlsInt1 = false;
|
|
|
|
|
@@ -134,6 +155,7 @@ void halInit(void) {
|
|
|
}
|
|
|
|
|
|
//TODO when machine is turned off above the logcycle 1 is written back from cache...
|
|
|
+ //TODO logcycle is not used atm
|
|
|
if (!(logcycle = sqlGetConf(CFGSweepCounter))) {
|
|
|
logger_error("hal.cpp: Couldn't read the logcycle counter from the database\n");
|
|
|
//pthread_exit(EXIT_SUCCESS);
|
|
@@ -285,6 +307,8 @@ void halInt0TimerHandler(void) {
|
|
|
*
|
|
|
*/
|
|
|
void halIdleTimerHandler(void) {
|
|
|
+ //TODO the idle counter is once resetted when a button is pressed. From this moment the machine
|
|
|
+ //will enter the idle state no matter what the user does -> reset Idle counter on every input!
|
|
|
if(++idleCounter == IDLE_TIME){
|
|
|
halEnterIdle();
|
|
|
}
|
|
@@ -327,15 +351,37 @@ 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)
|
|
|
+ * 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.
|
|
|
+ */
|
|
|
+void flowResetTimerHandler() {
|
|
|
+ if(flowResetValue == flowcnt) {
|
|
|
+ halResetFlow();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ flowResetValue = flowcnt;
|
|
|
+}
|
|
|
+
|
|
|
/**
|
|
|
* Interrupt routine for the flow sensor
|
|
|
* It counts the edges and stores the value in flowcnt
|
|
|
*/
|
|
|
void halIntFlow(void) {
|
|
|
//halRelaisOff(RELAIS_POWER);
|
|
|
+ if(!flowResetTimer.isActive()) flowResetTimer.start();
|
|
|
logger(V_HAL, "IntFlow triggered #%d total: %.2fml\n", flowcnt, halGetFlow());
|
|
|
flowcnt++;
|
|
|
|
|
|
+ if(flowcnt >= BREW_MANUAL_TRIGGER) {
|
|
|
+ halSendSignal(SigBrewOn);
|
|
|
+ brewmanual = true;
|
|
|
+ }
|
|
|
+
|
|
|
//detect a manual brewing process
|
|
|
//TODO to be able to detect a manual brewing process we need to have the following
|
|
|
//autoclear the flowcnt after certain idle time
|
|
@@ -344,7 +390,7 @@ void halIntFlow(void) {
|
|
|
|
|
|
|
|
|
//subroutine to log the flow to the database
|
|
|
- timespec deltaT;
|
|
|
+ /*timespec deltaT;
|
|
|
clock_gettime(CLOCK_REALTIME, &flowTimestep[flowIndex]);
|
|
|
timespec_diff(&flowTimestep[((flowIndex + 1) % 2)], &flowTimestep[flowIndex], &deltaT);
|
|
|
|
|
@@ -352,7 +398,7 @@ void halIntFlow(void) {
|
|
|
logger_error("hal.cpp: could not log flow to database!");
|
|
|
return;
|
|
|
}
|
|
|
- flowIndex = (flowIndex + 1) % 2;
|
|
|
+ flowIndex = (flowIndex + 1) % 2;*/
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -428,6 +474,13 @@ void halResetFlow(void) {
|
|
|
logger(V_HAL, "Flow counter reset, amount so far: %.2f ml\n", halGetFlow());
|
|
|
lastFlowcnt = flowcnt;
|
|
|
flowcnt = 0;
|
|
|
+
|
|
|
+ flowResetTimer.stop();
|
|
|
+ flowResetValue = -1;
|
|
|
+ if(brewmanual) {
|
|
|
+ brewmanual = false;
|
|
|
+ halSendSignal(SigBrewOff);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|