|
@@ -8,6 +8,7 @@
|
|
|
#include <stdlib.h>
|
|
|
#include <errno.h>
|
|
|
#include <string.h>
|
|
|
+#include <signal.h>
|
|
|
#include "lcd.h"
|
|
|
#include "hal.h"
|
|
|
#include "global.h"
|
|
@@ -33,21 +34,29 @@ void halInit(void) {
|
|
|
pinMode(RELAIS_POWER, OUTPUT);
|
|
|
pinMode(PRESSURE_CTRL, INPUT);
|
|
|
pinMode(PROXIMITY_SENSOR, INPUT);
|
|
|
- pinMode(HAL_INT0, INPUT);
|
|
|
- pinMode(HAL_INT1, INPUT);
|
|
|
- pinMode(HAL_FLOW, INPUT);
|
|
|
- if (wiringPiISR(HAL_INT0, INT_EDGE_FALLING, &halInt0) < 0) {
|
|
|
+ pinMode(INT0, INPUT);
|
|
|
+ pinMode(INT1, INPUT);
|
|
|
+ pinMode(FLOW, INPUT);
|
|
|
+ if (wiringPiISR(INT0, INT_EDGE_BOTH, &halInt0) < 0) {
|
|
|
logger_error("Unable to setup ISR0: %s\n", strerror(errno));
|
|
|
return;
|
|
|
}
|
|
|
- if (wiringPiISR(HAL_INT1, INT_EDGE_FALLING, &halInt1) < 0) {
|
|
|
+ if (wiringPiISR(INT1, INT_EDGE_BOTH, &halInt1) < 0) {
|
|
|
logger_error("Unable to setup ISR1: %s\n", strerror(errno));
|
|
|
return;
|
|
|
}
|
|
|
- if (wiringPiISR(HAL_FLOW, INT_EDGE_FALLING, &halIntFlow) < 0) {
|
|
|
+ if (wiringPiISR(FLOW, INT_EDGE_FALLING, &halIntFlow) < 0) {
|
|
|
logger_error("Unable to setup ISRFLOW: %s\n", strerror(errno));
|
|
|
return;
|
|
|
}
|
|
|
+ if(wiringPiISR(PRESSURE_CTRL, INT_EDGE_BOTH, &halIntPressure) < 0) {
|
|
|
+ logger_error("Unable to setup ISRPressure: %s\n", strerror(errno));
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if(wiringPiISR(PROXIMITY_SENSOR, INT_EDGE_BOTH, &halIntProximity) < 0) {
|
|
|
+ logger_error("Unable to setup ISRProximity: %s\n", strerror(errno));
|
|
|
+ return;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/*
|
|
@@ -78,33 +87,78 @@ void halRelaisSet(int relais, int state) {
|
|
|
case RELAIS_POWER:
|
|
|
case RELAIS_HEAT:
|
|
|
case RELAIS_PUMP:
|
|
|
- digitalWrite(relais, state);
|
|
|
+ //digitalWrite(relais, state);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+/*
|
|
|
+ * Returns the state of the relais relais
|
|
|
+ * Returns HIGH when Relais is ON
|
|
|
+ * @param relais Relais ID
|
|
|
+ */
|
|
|
+int halGetRelaisState(int relais) {
|
|
|
+ switch (relais) {
|
|
|
+ case RELAIS_POWER:
|
|
|
+ case RELAIS_HEAT:
|
|
|
+ case RELAIS_PUMP:
|
|
|
+ return !digitalRead(relais);
|
|
|
break;
|
|
|
}
|
|
|
+ return -1;
|
|
|
}
|
|
|
|
|
|
void halInt0(void) {
|
|
|
- //halRelaisOn(RELAIS_POWER);
|
|
|
logger(V_BASIC, "Int0 triggered\n");
|
|
|
- flowcnt = 0;
|
|
|
- halRelaisOn(RELAIS_PUMP);
|
|
|
+ if (halGetInt0()) {
|
|
|
+ halSendSignal(SigInt0Rls);
|
|
|
+ } else {
|
|
|
+ halSendSignal(SigInt0Psh);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
void halInt1(void) {
|
|
|
- //halRelaisOff(RELAIS_POWER);
|
|
|
logger(V_BASIC, "Int1 triggered\n");
|
|
|
- flowcnt = 0;
|
|
|
+ if (halGetInt1()) {
|
|
|
+ halSendSignal(SigInt1Rls);
|
|
|
+ } else {
|
|
|
+ halSendSignal(SigInt1Psh);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
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);
|
|
|
+ lcdPrintf(lcd, "ml = %.2f ", halGetFlow());
|
|
|
+ if (flowcnt == 99) {
|
|
|
+ halRelaisOff(RELAIS_PUMP);
|
|
|
+ }
|
|
|
+ flowcnt++;
|
|
|
+}
|
|
|
+
|
|
|
+/*
|
|
|
+ * Method to handle toggle of the pressure control
|
|
|
+ */
|
|
|
+void halIntPressure(void) {
|
|
|
+ logger(V_BASIC, "IntPressure Control triggered\n");
|
|
|
+ if (halIsHeating()) {
|
|
|
+ halSendSignal(SigPressCls);
|
|
|
+ } else {
|
|
|
+ halSendSignal(SigPressOpn);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+/*
|
|
|
+ * Method to handle toggle of the proximity sensor
|
|
|
+ */
|
|
|
+void halIntProximity(void) {
|
|
|
+ logger(V_BASIC, "IntProximity triggered\n");
|
|
|
+ if (halProxSensorCovered()) {
|
|
|
+ halSendSignal(SigProxCvrd);
|
|
|
+ } else {
|
|
|
+ halSendSignal(SigProxOpn);
|
|
|
}
|
|
|
- flowcnt++;
|
|
|
}
|
|
|
|
|
|
/*
|
|
@@ -114,22 +168,64 @@ float halGetFlow(void) {
|
|
|
return flowcnt*FLOW_ML_PULSE;
|
|
|
}
|
|
|
|
|
|
+/*
|
|
|
+ * Resets the Flow counter
|
|
|
+ */
|
|
|
+void halResetFlow(void){
|
|
|
+ flowcnt = 0;
|
|
|
+}
|
|
|
+
|
|
|
/*
|
|
|
* Reads the status of the Pressure Control
|
|
|
- * @return 1 for closed Pressure Control and 0 for open
|
|
|
+ * @return 0 for closed Pressure Control(heating) and 1 for open
|
|
|
*/
|
|
|
-int halGetPressureCtrl(void) {
|
|
|
- if (digitalRead(PRESSURE_CTRL)) {
|
|
|
- return 0;
|
|
|
- } else
|
|
|
- return 1;
|
|
|
+bool halIsHeating(void) {
|
|
|
+ if(digitalRead(PRESSURE_CTRL) == 0){
|
|
|
+ return true;
|
|
|
+ } else {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
* Returns status of the proximity switch
|
|
|
* @return 1 if the proximity switch is covered and 0 if uncovered
|
|
|
*/
|
|
|
-int halGetProximitySensor(void){
|
|
|
- return digitalRead(PROXIMITY_SENSOR);
|
|
|
+bool halProxSensorCovered(void){
|
|
|
+ /*if(digitalRead(PROXIMITY_SENSOR) == 0){
|
|
|
+ return false;
|
|
|
+ } else {
|
|
|
+ return true;
|
|
|
+ }*/
|
|
|
+ return true;
|
|
|
+}
|
|
|
+
|
|
|
+/*
|
|
|
+ * Returns the value of the top button Int0 (low active)
|
|
|
+ * @return LOW or HIGH
|
|
|
+ */
|
|
|
+int halGetInt0(void){
|
|
|
+ return digitalRead(INT0);
|
|
|
+}
|
|
|
+
|
|
|
+/*
|
|
|
+ * Returns the value of the bottom button Int1 (low active)
|
|
|
+ * @return LOW or HIGH
|
|
|
+ */
|
|
|
+int halGetInt1(void){
|
|
|
+ return digitalRead(INT1);
|
|
|
+}
|
|
|
+
|
|
|
+/*
|
|
|
+ * send Signal to coffee thread
|
|
|
+ */
|
|
|
+void halSendSignal(int val){
|
|
|
+ sigval value = {0};
|
|
|
+ value.sival_int = (int) val;
|
|
|
+
|
|
|
+ if(pthread_sigqueue(thread[THREAD_COFFEE], SIGUSR2, value)) {
|
|
|
+ logger_error("Failed to queue signal %d %s", val, strerror(errno));
|
|
|
+ //exit program?
|
|
|
+ }
|
|
|
}
|
|
|
|