|
@@ -20,11 +20,17 @@ volatile int flowcnt = 0;
|
|
|
int Int0Time, Int1Time;
|
|
|
bool flagIgnoreRlsInt0, flagIgnoreRlsInt1;
|
|
|
|
|
|
+//storage for the last state of the buttons and the proximity sensor
|
|
|
+int pinState[3] = {0, 0, 0};
|
|
|
+
|
|
|
timer Int0Timer(&halInt0TimerHandler);
|
|
|
timer Int1Timer(&halInt1TimerHandler);
|
|
|
|
|
|
clock_t heatingCycle[2] = {0, 0};
|
|
|
|
|
|
+//delay of the debounce in milliseconds
|
|
|
+#define DELAY_DEBOUNCE 50
|
|
|
+
|
|
|
/**
|
|
|
* Initializes HAL
|
|
|
*/
|
|
@@ -128,8 +134,11 @@ int halGetRelaisState(int relais) {
|
|
|
* Interrupt routine for Int0 (Top button)
|
|
|
*/
|
|
|
void halInt0(void) {
|
|
|
- if (halGetInt0()) { //released
|
|
|
+ //wait for a debounce
|
|
|
+ delay(DELAY_DEBOUNCE);
|
|
|
+ if (halGetInt0() && !pinState[0]) { //released
|
|
|
logger(V_HAL, "Int0 released\n");
|
|
|
+ pinState[0] = 1;
|
|
|
if (flagIgnoreRlsInt0) {
|
|
|
flagIgnoreRlsInt0 = false;
|
|
|
} else {
|
|
@@ -137,8 +146,9 @@ void halInt0(void) {
|
|
|
Int0Timer.stop();
|
|
|
halSendSignal(SigInt0Rls);
|
|
|
}
|
|
|
- } else { //pressed
|
|
|
+ } else if(!halGetInt0() && pinState[0]) { //pressed
|
|
|
logger(V_HAL, "Int0 pushed\n");
|
|
|
+ pinState[0] = 0;
|
|
|
halSendSignal(SigInt0Psh);
|
|
|
Int0Time = 0;
|
|
|
Int0Timer.start();
|
|
@@ -162,8 +172,10 @@ void halInt0TimerHandler(void) {
|
|
|
* Interrupt routine for Int1 (Bottom button)
|
|
|
*/
|
|
|
void halInt1(void) {
|
|
|
- if (halGetInt1()) {
|
|
|
+ delay(DELAY_DEBOUNCE);
|
|
|
+ if (halGetInt1() && !pinState[1]) {
|
|
|
logger(V_HAL, "Int1 released\n");
|
|
|
+ pinState[1] = 1;
|
|
|
if (flagIgnoreRlsInt1) {
|
|
|
flagIgnoreRlsInt1 = false;
|
|
|
} else {
|
|
@@ -171,8 +183,9 @@ void halInt1(void) {
|
|
|
Int0Timer.stop();
|
|
|
halSendSignal(SigInt1Rls);
|
|
|
}
|
|
|
- } else {
|
|
|
+ } else if(!halGetInt1() && pinState[1]) {
|
|
|
logger(V_HAL, "Int1 pushed\n");
|
|
|
+ pinState[1] = 0;
|
|
|
halSendSignal(SigInt1Psh);
|
|
|
Int1Time = 0;
|
|
|
Int1Timer.start();
|
|
@@ -198,7 +211,7 @@ void halInt1TimerHandler(void) {
|
|
|
*/
|
|
|
void halIntFlow(void) {
|
|
|
//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) {
|
|
|
halRelaisOff(RELAIS_PUMP);
|
|
|
}
|
|
@@ -239,11 +252,14 @@ double halgetHeatingTime(void){
|
|
|
* Method to handle toggle of the proximity sensor
|
|
|
*/
|
|
|
void halIntProximity(void) {
|
|
|
- //logger(V_HAL, "IntProximity triggered\n");
|
|
|
- return;
|
|
|
- if (halProxSensorCovered()) {
|
|
|
+ delay(DELAY_DEBOUNCE);
|
|
|
+ if (halProxSensorCovered() && !pinState[2]) {
|
|
|
+ logger(V_HAL, "IntProximity triggered\n");
|
|
|
+ pinState[2] = 1;
|
|
|
halSendSignal(SigProxCvrd);
|
|
|
- } else {
|
|
|
+ } else if(!halProxSensorCovered() && pinState[2]){
|
|
|
+ logger(V_HAL, "IntProximity triggered\n");
|
|
|
+ pinState[2] = 0;
|
|
|
halSendSignal(SigProxOpn);
|
|
|
}
|
|
|
}
|
|
@@ -280,12 +296,11 @@ bool halIsHeating(void) {
|
|
|
* @return 1 if the proximity switch is covered and 0 if uncovered
|
|
|
*/
|
|
|
bool halProxSensorCovered(void) {
|
|
|
-// if(digitalRead(PIN_PROXIMITY_SENSOR) == 0){
|
|
|
-// return false;
|
|
|
-// } else {
|
|
|
-// return true;
|
|
|
-// }
|
|
|
- return true;
|
|
|
+ if(digitalRead(PIN_PROXIMITY_SENSOR) == 0){
|
|
|
+ return false;
|
|
|
+ } else {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|