|
@@ -45,6 +45,9 @@ int lastFlowcnt = 0;
|
|
|
int flowResetValue = -1;
|
|
|
bool brewmanual = false;
|
|
|
|
|
|
+time_t heatingCycleStart = 0;
|
|
|
+uint64_t totalHeatingTime = 0; //local copies of the corresponding database entries
|
|
|
+
|
|
|
int Int0Time, Int1Time;
|
|
|
int idleCounter;
|
|
|
bool idle;
|
|
@@ -68,10 +71,10 @@ 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;
|
|
|
+int16_t tickCounter = 0; //rotary encoder
|
|
|
uint16_t flowtime = 0;
|
|
|
uint16_t lastFlowTime = 0;
|
|
|
bool brewSigFired = false;
|
|
@@ -104,13 +107,19 @@ void halInit(void) {
|
|
|
pinMode(PIN_ROTARY2, INPUT);
|
|
|
|
|
|
|
|
|
- idleTimer.setDivider(1200); //1 min
|
|
|
+ idleTimer.setDivider(ms2Divider(60000));
|
|
|
idleCounter = 0;
|
|
|
idle = false;
|
|
|
clock_gettime(CLOCK_REALTIME, &flowTimestep[0]);
|
|
|
clock_gettime(CLOCK_REALTIME, &flowTimestep[1]);
|
|
|
halDisplayOn();
|
|
|
|
|
|
+ if (!(totalHeatingTime = sqlGetConf(CFGHeatingTime))) {
|
|
|
+ logger_error("hal.cpp: Couldn't read the total heating time from the database\n");
|
|
|
+ //pthread_exit(EXIT_SUCCESS);
|
|
|
+ exit(EXIT_FAILURE);
|
|
|
+ }
|
|
|
+
|
|
|
if (optPower) {
|
|
|
halMachineOn();
|
|
|
} else {
|
|
@@ -120,13 +129,14 @@ void halInit(void) {
|
|
|
|
|
|
pinState[3] = halIsHeating();
|
|
|
|
|
|
- Int0Timer.setDivider(4); //200ms
|
|
|
- Int1Timer.setDivider(4);
|
|
|
+ Int0Timer.setDivider(ms2Divider(200));
|
|
|
+ Int1Timer.setDivider(ms2Divider(200));
|
|
|
Int0Time = 0;
|
|
|
Int1Time = 0;
|
|
|
|
|
|
- flowResetTimer.setDivider(20); //1000ms
|
|
|
- flowTimer.setDivider(4); // 100ms
|
|
|
+
|
|
|
+ flowResetTimer.setDivider(ms2Divider(TIME_FLOWRESET));
|
|
|
+ flowTimer.setDivider(ms2Divider(200));
|
|
|
|
|
|
flagIgnoreRlsInt0 = false;
|
|
|
flagIgnoreRlsInt1 = false;
|
|
@@ -157,15 +167,7 @@ void halInit(void) {
|
|
|
logger_error("Unable to setup ISRRotary2: %s\n", strerror(errno));
|
|
|
return;
|
|
|
}
|
|
|
-
|
|
|
- //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);
|
|
|
- exit(EXIT_FAILURE);
|
|
|
- }
|
|
|
- logger(V_BASIC, "hal.cpp Initialized hal\n");
|
|
|
+ logger(V_BASIC, "hal.cpp: Initialized\n");
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -411,36 +413,36 @@ void halIntFlow(void) {
|
|
|
* Reading heating time via the getHeatingTime function
|
|
|
*/
|
|
|
void halIntPressure(void) {
|
|
|
- logger(V_HAL, "IntPressure Control triggered\n");
|
|
|
+ delay(DELAY_DEBOUNCE);
|
|
|
if (halIsHeating() && !pinState[3]) {
|
|
|
+ logger(V_HAL, "hal.cpp: Pressure Control closed\n");
|
|
|
pinState[3] = 1;
|
|
|
- time(&heatingCycle[0]);
|
|
|
+ halStartHeatingTime();
|
|
|
halSendSignal(SigPressCls);
|
|
|
} else if(!halIsHeating() && pinState[3]) {
|
|
|
+ logger(V_HAL, "hal.cpp: Pressure Control opened\n");
|
|
|
pinState[3] = 0;
|
|
|
- time(&heatingCycle[1]);
|
|
|
+ halStopHeatingTime();
|
|
|
halSendSignal(SigPressOpn);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Function to read the heating time in sec
|
|
|
- * If called during a heating process, it returns the time elapsed since the heating started
|
|
|
- * If called after a heating process, it returns the total time elapsed during the heating cycle
|
|
|
+ *
|
|
|
*/
|
|
|
-double halgetHeatingTime(void){
|
|
|
- //TODO check return value on negative times
|
|
|
- //TODO move the tracking of the heating time into hal.cpp and fix issue of wrong tracking -> inital pressure close is not
|
|
|
- //recognized and so heatingCycle has no time
|
|
|
- //quickfix:
|
|
|
- return 0;
|
|
|
- if (halIsHeating()) {
|
|
|
- logger(V_HAL, "Hot Heating Time: %f\n", difftime(time(NULL), heatingCycle[0]));
|
|
|
- return difftime(time(0), heatingCycle[0]);
|
|
|
- }
|
|
|
- else {
|
|
|
- logger(V_HAL, "Heating time: %f\n", difftime(heatingCycle[1], heatingCycle[0]));
|
|
|
- return difftime(heatingCycle[1], heatingCycle[0]);
|
|
|
+void halStartHeatingTime(void) {
|
|
|
+ time(&heatingCycleStart);
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ *
|
|
|
+ */
|
|
|
+void halStopHeatingTime(void) {
|
|
|
+ if (heatingCycleStart != 0) { //only track time if stopwatch was started!
|
|
|
+ uint64_t timediff = (uint64_t) difftime(time(0), heatingCycleStart);
|
|
|
+ logger(V_HAL, "Heating time: %f\n", timediff);
|
|
|
+ totalHeatingTime += timediff;
|
|
|
+ heatingCycleStart = 0;
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -511,16 +513,21 @@ void halResetFlow(void) {
|
|
|
|
|
|
/**
|
|
|
* Reads the status of the Pressure Control
|
|
|
- * @return 1 (true) for closed Pressure Control(heating) and 0 (false) for open
|
|
|
+ * @return 1 (true) for closed Pressure Control (heating) and 0 (false) for open
|
|
|
*/
|
|
|
bool halIsHeating(void) {
|
|
|
- if (digitalRead(PIN_PRESSURE_CTRL) == 0) {
|
|
|
- return true;
|
|
|
- } else {
|
|
|
- return false;
|
|
|
- }
|
|
|
+ //TODO: eventually rely on the pinState variable instead of reading the pin
|
|
|
+ //then the state of the pin needs to be set at the very beginning of the initialization
|
|
|
+ if (digitalRead(PIN_PRESSURE_CTRL) == 0) return true;
|
|
|
+ else return false;
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ *
|
|
|
+ */
|
|
|
+uint64_t getTotalHeatingTime() {
|
|
|
+ return totalHeatingTime;
|
|
|
+}
|
|
|
/**
|
|
|
* Returns status of the proximity switch
|
|
|
* @return 1 if the proximity switch is covered and 0 if uncovered
|
|
@@ -599,7 +606,6 @@ void halSendSignal(HalSig val) {
|
|
|
} catch (int e) {
|
|
|
logger_error("Whoops.. %d\n", e);
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -609,8 +615,10 @@ void halMachineOn(void) {
|
|
|
halRelaisOn(RELAIS_HEAT);
|
|
|
halRelaisOff(RELAIS_PUMP);
|
|
|
halRelaisOn(RELAIS_POWER);
|
|
|
+
|
|
|
idleTimer.stop();
|
|
|
- logger(V_HAL, "Turning machine on\n");
|
|
|
+ if(halIsHeating()) halStartHeatingTime();
|
|
|
+ logger(V_HAL, "hal.cpp: Turning machine on\n");
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -623,15 +631,16 @@ void halMachineOff(void) {
|
|
|
|
|
|
idleCounter = 0;
|
|
|
idleTimer.start();
|
|
|
+ halStopHeatingTime();
|
|
|
halWriteBackCache();
|
|
|
- logger(V_HAL, "Turning machine off\n");
|
|
|
+ logger(V_HAL, "hal.cpp: Turning machine off\n");
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
*
|
|
|
*/
|
|
|
void halEnterIdle(void){
|
|
|
- logger(V_HAL, "Entering Idle Mode\n");
|
|
|
+ logger(V_HAL, "hal.cpp: Entering Idle Mode\n");
|
|
|
idleTimer.stop();
|
|
|
halDisplayOff();
|
|
|
idle = true;
|
|
@@ -642,7 +651,7 @@ void halEnterIdle(void){
|
|
|
*/
|
|
|
void halLeaveIdle(void){
|
|
|
idleCounter = 0;
|
|
|
- logger(V_HAL, "Leaving Idle Mode\n");
|
|
|
+ logger(V_HAL, "hal.cpp: Leaving Idle Mode\n");
|
|
|
halDisplayOn();
|
|
|
idleTimer.start();
|
|
|
idle = false;
|
|
@@ -705,18 +714,17 @@ void timespec_diff(timespec *start, timespec *stop, timespec *result) {
|
|
|
* Handler for Termination of the hal
|
|
|
*/
|
|
|
void halTerminate(event_t *event){
|
|
|
+ halStopHeatingTime();
|
|
|
halWriteBackCache();
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
- * writing back non volatile variables of the hal to the database: SweepCounter
|
|
|
+ * writing back non volatile variables of the hal to the database: totalHeatingTime
|
|
|
*/
|
|
|
void halWriteBackCache(){
|
|
|
- /*
|
|
|
- if (sqlSetConf(CFGSweepCounter, logcycle)) {
|
|
|
- logger_error("hal.cpp: Couldn't write logcycle to database");
|
|
|
+ if (sqlSetConf(CFGHeatingTime, totalHeatingTime)) {
|
|
|
+ logger_error("hal.cpp: Couldn't write heating time to database");
|
|
|
return;
|
|
|
}
|
|
|
- logger(V_BREW, "Writing back logcycle %d\n", logcycle);
|
|
|
- */
|
|
|
+ logger(V_BREW, "Writing back heating time: %lld sec\n", totalHeatingTime);
|
|
|
}
|