|
@@ -9,6 +9,7 @@
|
|
#include <errno.h>
|
|
#include <errno.h>
|
|
#include <string.h>
|
|
#include <string.h>
|
|
#include <signal.h>
|
|
#include <signal.h>
|
|
|
|
+#include <ctime>
|
|
#include "hal.h"
|
|
#include "hal.h"
|
|
#include "global.h"
|
|
#include "global.h"
|
|
#include "logger.h"
|
|
#include "logger.h"
|
|
@@ -16,23 +17,19 @@
|
|
|
|
|
|
volatile int flowcnt = 0;
|
|
volatile int flowcnt = 0;
|
|
|
|
|
|
-int Int0Time;
|
|
|
|
-int Int1Time;
|
|
|
|
-bool flagIgnoreRlsInt0;
|
|
|
|
-bool flagIgnoreRlsInt1;
|
|
|
|
|
|
+int Int0Time, Int1Time;
|
|
|
|
+bool flagIgnoreRlsInt0, flagIgnoreRlsInt1;
|
|
|
|
+
|
|
timer Int0Timer(&halInt0TimerHandler);
|
|
timer Int0Timer(&halInt0TimerHandler);
|
|
timer Int1Timer(&halInt1TimerHandler);
|
|
timer Int1Timer(&halInt1TimerHandler);
|
|
|
|
|
|
|
|
+clock_t heatingCycle[2] = {0, 0};
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Initializes HAL
|
|
* Initializes HAL
|
|
*/
|
|
*/
|
|
|
|
|
|
void halInit(void) {
|
|
void halInit(void) {
|
|
- if (optPower) {
|
|
|
|
- halMachineOn();
|
|
|
|
- } else {
|
|
|
|
- halMachineOff();
|
|
|
|
- }
|
|
|
|
pinMode(RELAIS_HEAT, OUTPUT);
|
|
pinMode(RELAIS_HEAT, OUTPUT);
|
|
pinMode(RELAIS_PUMP, OUTPUT);
|
|
pinMode(RELAIS_PUMP, OUTPUT);
|
|
pinMode(RELAIS_POWER, OUTPUT);
|
|
pinMode(RELAIS_POWER, OUTPUT);
|
|
@@ -42,6 +39,12 @@ void halInit(void) {
|
|
pinMode(PIN_INT1, INPUT);
|
|
pinMode(PIN_INT1, INPUT);
|
|
pinMode(PIN_FLOW, INPUT);
|
|
pinMode(PIN_FLOW, INPUT);
|
|
|
|
|
|
|
|
+ if (optPower) {
|
|
|
|
+ halMachineOn();
|
|
|
|
+ } else {
|
|
|
|
+ halMachineOff();
|
|
|
|
+ }
|
|
|
|
+
|
|
Int0Timer.setDivider(4); //200ms
|
|
Int0Timer.setDivider(4); //200ms
|
|
Int1Timer.setDivider(4);
|
|
Int1Timer.setDivider(4);
|
|
Int0Time = 0;
|
|
Int0Time = 0;
|
|
@@ -66,8 +69,7 @@ void halInit(void) {
|
|
logger_error("Unable to setup ISRPressure: %s\n", strerror(errno));
|
|
logger_error("Unable to setup ISRPressure: %s\n", strerror(errno));
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
- if (wiringPiISR(PIN_PROXIMITY_SENSOR, INT_EDGE_BOTH, &halIntProximity)
|
|
|
|
- < 0) {
|
|
|
|
|
|
+ if (wiringPiISR(PIN_PROXIMITY_SENSOR, INT_EDGE_BOTH, &halIntProximity) < 0) {
|
|
logger_error("Unable to setup ISRProximity: %s\n", strerror(errno));
|
|
logger_error("Unable to setup ISRProximity: %s\n", strerror(errno));
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
@@ -126,14 +128,17 @@ int halGetRelaisState(int relais) {
|
|
* Interrupt routine for Int0 (Top button)
|
|
* Interrupt routine for Int0 (Top button)
|
|
*/
|
|
*/
|
|
void halInt0(void) {
|
|
void halInt0(void) {
|
|
- logger(V_HAL, "Int0 triggered\n");
|
|
|
|
- if (halGetInt0()) {
|
|
|
|
|
|
+ if (halGetInt0()) { //released
|
|
|
|
+ logger(V_HAL, "Int0 released\n");
|
|
if (flagIgnoreRlsInt0) {
|
|
if (flagIgnoreRlsInt0) {
|
|
flagIgnoreRlsInt0 = false;
|
|
flagIgnoreRlsInt0 = false;
|
|
} else {
|
|
} else {
|
|
|
|
+ Int0Time = 0;
|
|
|
|
+ Int0Timer.stop();
|
|
halSendSignal(SigInt0Rls);
|
|
halSendSignal(SigInt0Rls);
|
|
}
|
|
}
|
|
- } else {
|
|
|
|
|
|
+ } else { //pressed
|
|
|
|
+ logger(V_HAL, "Int0 pushed\n");
|
|
halSendSignal(SigInt0Psh);
|
|
halSendSignal(SigInt0Psh);
|
|
Int0Time = 0;
|
|
Int0Time = 0;
|
|
Int0Timer.start();
|
|
Int0Timer.start();
|
|
@@ -157,14 +162,17 @@ void halInt0TimerHandler(void) {
|
|
* Interrupt routine for Int1 (Bottom button)
|
|
* Interrupt routine for Int1 (Bottom button)
|
|
*/
|
|
*/
|
|
void halInt1(void) {
|
|
void halInt1(void) {
|
|
- logger(V_HAL, "Int1 triggered\n");
|
|
|
|
if (halGetInt1()) {
|
|
if (halGetInt1()) {
|
|
|
|
+ logger(V_HAL, "Int1 released\n");
|
|
if (flagIgnoreRlsInt1) {
|
|
if (flagIgnoreRlsInt1) {
|
|
flagIgnoreRlsInt1 = false;
|
|
flagIgnoreRlsInt1 = false;
|
|
} else {
|
|
} else {
|
|
|
|
+ Int0Time = 0;
|
|
|
|
+ Int0Timer.stop();
|
|
halSendSignal(SigInt1Rls);
|
|
halSendSignal(SigInt1Rls);
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
|
|
+ logger(V_HAL, "Int1 pushed\n");
|
|
halSendSignal(SigInt1Psh);
|
|
halSendSignal(SigInt1Psh);
|
|
Int1Time = 0;
|
|
Int1Time = 0;
|
|
Int1Timer.start();
|
|
Int1Timer.start();
|
|
@@ -190,8 +198,7 @@ void halInt1TimerHandler(void) {
|
|
*/
|
|
*/
|
|
void halIntFlow(void) {
|
|
void halIntFlow(void) {
|
|
//halRelaisOff(RELAIS_POWER);
|
|
//halRelaisOff(RELAIS_POWER);
|
|
- logger(V_HAL, "IntFlow triggered #%d total: %.2fml\n", flowcnt,
|
|
|
|
- halGetFlow());
|
|
|
|
|
|
+ //logger(V_HAL, "IntFlow triggered #%d total: %.2fml\n", flowcnt, halGetFlow());
|
|
if (flowcnt == 99) {
|
|
if (flowcnt == 99) {
|
|
halRelaisOff(RELAIS_PUMP);
|
|
halRelaisOff(RELAIS_PUMP);
|
|
}
|
|
}
|
|
@@ -200,16 +207,34 @@ void halIntFlow(void) {
|
|
|
|
|
|
/**
|
|
/**
|
|
* Interrupt routine for the pressure control
|
|
* Interrupt routine for the pressure control
|
|
|
|
+ * It captures the time at closing point and opening point
|
|
|
|
+ * Reading heating time via the getHeatingTime function
|
|
*/
|
|
*/
|
|
void halIntPressure(void) {
|
|
void halIntPressure(void) {
|
|
logger(V_HAL, "IntPressure Control triggered\n");
|
|
logger(V_HAL, "IntPressure Control triggered\n");
|
|
if (halIsHeating()) {
|
|
if (halIsHeating()) {
|
|
|
|
+ heatingCycle[0] = clock();
|
|
halSendSignal(SigPressCls);
|
|
halSendSignal(SigPressCls);
|
|
} else {
|
|
} else {
|
|
|
|
+ heatingCycle[1] = clock();
|
|
halSendSignal(SigPressOpn);
|
|
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 elapes during the heating cycle
|
|
|
|
+ */
|
|
|
|
+uint64_t halgetHeatingTime(void){
|
|
|
|
+ if (halIsHeating()) {
|
|
|
|
+ return (uint64_t)(clock() - heatingCycle[0]) / CLOCKS_PER_SEC;
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ return (uint64_t)(heatingCycle[1] - heatingCycle[0]) / CLOCKS_PER_SEC;
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Method to handle toggle of the proximity sensor
|
|
* Method to handle toggle of the proximity sensor
|
|
*/
|
|
*/
|
|
@@ -240,7 +265,7 @@ void halResetFlow(void) {
|
|
|
|
|
|
/**
|
|
/**
|
|
* Reads the status of the Pressure Control
|
|
* Reads the status of the Pressure Control
|
|
- * @return 0 for closed Pressure Control(heating) and 1 for open
|
|
|
|
|
|
+ * @return 1 (true) for closed Pressure Control(heating) and 0 (false) for open
|
|
*/
|
|
*/
|
|
bool halIsHeating(void) {
|
|
bool halIsHeating(void) {
|
|
if (digitalRead(PIN_PRESSURE_CTRL) == 0) {
|
|
if (digitalRead(PIN_PRESSURE_CTRL) == 0) {
|
|
@@ -255,13 +280,11 @@ bool halIsHeating(void) {
|
|
* @return 1 if the proximity switch is covered and 0 if uncovered
|
|
* @return 1 if the proximity switch is covered and 0 if uncovered
|
|
*/
|
|
*/
|
|
bool halProxSensorCovered(void) {
|
|
bool halProxSensorCovered(void) {
|
|
- //for legacy till sensor is installed
|
|
|
|
- /*if(digitalRead(PROXIMITY_SENSOR) == 0){
|
|
|
|
|
|
+ if(digitalRead(PIN_PROXIMITY_SENSOR) == 0){
|
|
return false;
|
|
return false;
|
|
} else {
|
|
} else {
|
|
return true;
|
|
return true;
|
|
- }*/
|
|
|
|
- return true;
|
|
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|