|
@@ -13,21 +13,24 @@
|
|
|
#include "hal.h"
|
|
|
#include "global.h"
|
|
|
#include "logger.h"
|
|
|
+#include "timer.h"
|
|
|
|
|
|
int flowcnt = 0;
|
|
|
|
|
|
+int Int0Time;
|
|
|
+int Int1Time;
|
|
|
+bool flagIgnoreRlsInt0;
|
|
|
+bool flagIgnoreRlsInt1;
|
|
|
+timer Int0Timer(&halInt0TimerHandler);
|
|
|
+timer Int1Timer(&halInt1TimerHandler);
|
|
|
/**
|
|
|
* Initializes HAL
|
|
|
*/
|
|
|
void halInit(void) {
|
|
|
if (optPower) {
|
|
|
- halRelaisOn(RELAIS_HEAT);
|
|
|
- halRelaisOff(RELAIS_PUMP);
|
|
|
- halRelaisOn(RELAIS_POWER);
|
|
|
+ halMachineOn();
|
|
|
} else {
|
|
|
- halRelaisOff(RELAIS_HEAT);
|
|
|
- halRelaisOff(RELAIS_PUMP);
|
|
|
- halRelaisOff(RELAIS_POWER);
|
|
|
+ halMachineOff();
|
|
|
}
|
|
|
pinMode(RELAIS_HEAT, OUTPUT);
|
|
|
pinMode(RELAIS_PUMP, OUTPUT);
|
|
@@ -37,6 +40,15 @@ void halInit(void) {
|
|
|
pinMode(PIN_INT0, INPUT);
|
|
|
pinMode(PIN_INT1, INPUT);
|
|
|
pinMode(PIN_FLOW, INPUT);
|
|
|
+
|
|
|
+ Int0Timer.setDivider(4); //200ms
|
|
|
+ Int1Timer.setDivider(4);
|
|
|
+ Int0Time = 0;
|
|
|
+ Int1Time = 0;
|
|
|
+
|
|
|
+ flagIgnoreRlsInt0 = false;
|
|
|
+ flagIgnoreRlsInt1 = false;
|
|
|
+
|
|
|
if (wiringPiISR(PIN_INT0, INT_EDGE_BOTH, &halInt0) < 0) {
|
|
|
logger_error("Unable to setup ISR0: %s\n", strerror(errno));
|
|
|
return;
|
|
@@ -49,11 +61,11 @@ void halInit(void) {
|
|
|
logger_error("Unable to setup ISRFLOW: %s\n", strerror(errno));
|
|
|
return;
|
|
|
}
|
|
|
- if(wiringPiISR(PIN_PRESSURE_CTRL, INT_EDGE_BOTH, &halIntPressure) < 0) {
|
|
|
+ if (wiringPiISR(PIN_PRESSURE_CTRL, INT_EDGE_BOTH, &halIntPressure) < 0) {
|
|
|
logger_error("Unable to setup ISRPressure: %s\n", strerror(errno));
|
|
|
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));
|
|
|
return;
|
|
|
}
|
|
@@ -109,26 +121,64 @@ int halGetRelaisState(int relais) {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Interrupt routine for Int0 (bottom button)
|
|
|
+ * Interrupt routine for Int0 (Top button)
|
|
|
*/
|
|
|
void halInt0(void) {
|
|
|
logger(V_BASIC, "Int0 triggered\n");
|
|
|
if (halGetInt0()) {
|
|
|
- halSendSignal(SigInt0Rls);
|
|
|
+ if (flagIgnoreRlsInt0) {
|
|
|
+ flagIgnoreRlsInt0 = false;
|
|
|
+ } else {
|
|
|
+ halSendSignal(SigInt0Rls);
|
|
|
+ }
|
|
|
} else {
|
|
|
halSendSignal(SigInt0Psh);
|
|
|
+ Int0Time = 0;
|
|
|
+ Int0Timer.start();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Interrupt routine for Int1 (top button)
|
|
|
+ *
|
|
|
+ */
|
|
|
+void halInt0TimerHandler(void) {
|
|
|
+ Int0Time += 200;
|
|
|
+ if (Int0Time >= (TIME_BUTTONLONGPRESS * 1000)) {
|
|
|
+ halSendSignal(SigInt0RlsLong);
|
|
|
+ flagIgnoreRlsInt0 = true;
|
|
|
+ Int0Time = 0;
|
|
|
+ Int0Timer.stop();
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * Interrupt routine for Int1 (Bottom button)
|
|
|
*/
|
|
|
void halInt1(void) {
|
|
|
logger(V_BASIC, "Int1 triggered\n");
|
|
|
- if (halGetInt1()) {
|
|
|
- halSendSignal(SigInt1Rls);
|
|
|
- } else {
|
|
|
- halSendSignal(SigInt1Psh);
|
|
|
+ if (halGetInt1()) {
|
|
|
+ if (flagIgnoreRlsInt1) {
|
|
|
+ flagIgnoreRlsInt1 = false;
|
|
|
+ } else {
|
|
|
+ halSendSignal(SigInt1Rls);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ halSendSignal(SigInt1Psh);
|
|
|
+ Int1Time = 0;
|
|
|
+ Int1Timer.start();
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+/*
|
|
|
+ *
|
|
|
+ */
|
|
|
+void halInt1TimerHandler(void) {
|
|
|
+ Int1Time += 200;
|
|
|
+ if (Int1Time >= TIME_BUTTONLONGPRESS) {
|
|
|
+ halSendSignal(SigInt1RlsLong);
|
|
|
+ flagIgnoreRlsInt1 = true;
|
|
|
+ Int1Time = 0;
|
|
|
+ Int1Timer.stop();
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -140,11 +190,11 @@ void halIntFlow(void) {
|
|
|
//halRelaisOff(RELAIS_POWER);
|
|
|
logger(V_BASIC, "IntFlow triggered #%d total: %.2fml\n", flowcnt, halGetFlow());
|
|
|
lcdPosition(lcd, 0, 0);
|
|
|
- lcdPrintf(lcd, "ml = %.2f ", halGetFlow());
|
|
|
- if (flowcnt == 99) {
|
|
|
- halRelaisOff(RELAIS_PUMP);
|
|
|
- }
|
|
|
- flowcnt++;
|
|
|
+ lcdPrintf(lcd, "ml = %.2f ", halGetFlow());
|
|
|
+ if (flowcnt == 99) {
|
|
|
+ halRelaisOff(RELAIS_PUMP);
|
|
|
+ }
|
|
|
+ flowcnt++;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -175,13 +225,13 @@ void halIntProximity(void) {
|
|
|
* Returns total flow trough sensor in ml
|
|
|
*/
|
|
|
float halGetFlow(void) {
|
|
|
- return flowcnt*FLOW_ML_PULSE;
|
|
|
+ return flowcnt * FLOW_ML_PULSE;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Resets the Flow counter
|
|
|
*/
|
|
|
-void halResetFlow(void){
|
|
|
+void halResetFlow(void) {
|
|
|
flowcnt = 0;
|
|
|
}
|
|
|
|
|
@@ -190,7 +240,7 @@ void halResetFlow(void){
|
|
|
* @return 0 for closed Pressure Control(heating) and 1 for open
|
|
|
*/
|
|
|
bool halIsHeating(void) {
|
|
|
- if(digitalRead(PIN_PRESSURE_CTRL) == 0){
|
|
|
+ if (digitalRead(PIN_PRESSURE_CTRL) == 0) {
|
|
|
return true;
|
|
|
} else {
|
|
|
return false;
|
|
@@ -201,13 +251,13 @@ bool halIsHeating(void) {
|
|
|
* Returns status of the proximity switch
|
|
|
* @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){
|
|
|
- return false;
|
|
|
- } else {
|
|
|
- return true;
|
|
|
- }*/
|
|
|
+ return false;
|
|
|
+ } else {
|
|
|
+ return true;
|
|
|
+ }*/
|
|
|
return true;
|
|
|
}
|
|
|
|
|
@@ -215,7 +265,7 @@ bool halProxSensorCovered(void){
|
|
|
* Returns the value of the top button Int0 (low active)
|
|
|
* @return LOW or HIGH
|
|
|
*/
|
|
|
-int halGetInt0(void){
|
|
|
+int halGetInt0(void) {
|
|
|
return digitalRead(PIN_INT0);
|
|
|
}
|
|
|
|
|
@@ -223,7 +273,7 @@ int halGetInt0(void){
|
|
|
* Returns the value of the bottom button Int1 (low active)
|
|
|
* @return LOW or HIGH
|
|
|
*/
|
|
|
-int halGetInt1(void){
|
|
|
+int halGetInt1(void) {
|
|
|
return digitalRead(PIN_INT1);
|
|
|
}
|
|
|
|
|
@@ -231,14 +281,31 @@ int halGetInt1(void){
|
|
|
* send Signal to coffee thread
|
|
|
* @param val Integer value assigned to signal
|
|
|
*/
|
|
|
-void halSendSignal(int val){
|
|
|
- sigval value = {0};
|
|
|
+void halSendSignal(int val) {
|
|
|
+ sigval value = { 0 };
|
|
|
value.sival_int = (int) val;
|
|
|
|
|
|
- if(pthread_sigqueue(thread[THREAD_COFFEE], SIGUSR2, value)) {
|
|
|
+ if (pthread_sigqueue(thread[THREAD_COFFEE], SIGUSR2, value)) {
|
|
|
logger_error("Failed to queue signal %d %s", val, strerror(errno));
|
|
|
//No Signals reach the state machine anymore...
|
|
|
exit(EXIT_FAILURE);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * Turn machine on
|
|
|
+ */
|
|
|
+void halMachineOn(void) {
|
|
|
+ halRelaisOn(RELAIS_HEAT);
|
|
|
+ halRelaisOff(RELAIS_PUMP);
|
|
|
+ halRelaisOn(RELAIS_POWER);
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * Turn machine off
|
|
|
+ */
|
|
|
+void halMachineOff(void) {
|
|
|
+ halRelaisOff(RELAIS_HEAT);
|
|
|
+ halRelaisOff(RELAIS_PUMP);
|
|
|
+ halRelaisOff(RELAIS_POWER);
|
|
|
+}
|