|
@@ -56,7 +56,7 @@ bool idle;
|
|
|
bool flagIgnoreRlsInt0, flagIgnoreRlsInt1;
|
|
|
|
|
|
//storage for the last state of the buttons, the proximity sensor and the pressure sensor
|
|
|
-int pinState[4] = {1, 1, 1, 0};
|
|
|
+int pinState[4] = {1, 1, 0, 0};
|
|
|
//state of the rotary encoder
|
|
|
//0: rotary1 state at t-1
|
|
|
//1: rotary2 state at t-1
|
|
@@ -131,7 +131,15 @@ void halInit(void) {
|
|
|
}
|
|
|
sleep(1); //wait till the machine eventually turned on when optPower
|
|
|
|
|
|
- pinState[3] = halIsHeating();
|
|
|
+ //Determine the inital state of the pins for the pressure control and the graywater tank sensor
|
|
|
+ //TODO do a proper averaging here
|
|
|
+ pinState[3] = halGetPressureSensorPin();
|
|
|
+ if (halIsHeating()) logger(V_HAL, "hal.cpp: pressure sensor state set initially to: HEATING\n");
|
|
|
+ else logger(V_HAL, "hal.cpp: pressure sensor state set initially to: OPEN\n");
|
|
|
+
|
|
|
+ pinState[2] = halGetProxSensorPin();
|
|
|
+ if (halProxSensorCovered()) logger(V_HAL, "hal.cpp: proximity sensor state set initially to: COVERED\n");
|
|
|
+ else logger(V_HAL, "hal.cpp: proximity sensor state set initially to: OPEN\n");
|
|
|
|
|
|
Int0Timer.setDivider(ms2Divider(200));
|
|
|
Int1Timer.setDivider(ms2Divider(200));
|
|
@@ -417,14 +425,14 @@ void halIntFlow(void) {
|
|
|
*/
|
|
|
void halIntPressure(void) {
|
|
|
delay(DELAY_DEBOUNCE);
|
|
|
- if (halIsHeating() && !pinState[3]) {
|
|
|
+ if (!halGetPressureSensorPin() && pinState[3]) {
|
|
|
logger(V_HAL, "hal.cpp: Pressure Control closed\n");
|
|
|
- pinState[3] = 1;
|
|
|
+ pinState[3] = 0;
|
|
|
halStartHeatingTime();
|
|
|
halSendSignal(SigPressCls);
|
|
|
- } else if(!halIsHeating() && pinState[3]) {
|
|
|
+ } else if(halGetPressureSensorPin() && !pinState[3]) {
|
|
|
logger(V_HAL, "hal.cpp: Pressure Control opened\n");
|
|
|
- pinState[3] = 0;
|
|
|
+ pinState[3] = 1;
|
|
|
halStopHeatingTime();
|
|
|
halSendSignal(SigPressOpn);
|
|
|
}
|
|
@@ -454,10 +462,10 @@ void halStopHeatingTime(void) {
|
|
|
*/
|
|
|
void halIntProximity(void) {
|
|
|
delay(DELAY_DEBOUNCE);
|
|
|
- if (digitalRead(PIN_PROXIMITY_SENSOR) && !pinState[2]) {
|
|
|
+ if (halGetProxSensorPin() && !pinState[2]) {
|
|
|
logger(V_HAL, "hal.cpp: Proximity switch closed\n");
|
|
|
pinState[2] = 1;
|
|
|
- } else if(!digitalRead(PIN_PROXIMITY_SENSOR) && pinState[2]){
|
|
|
+ } else if(!halGetProxSensorPin() && pinState[2]){
|
|
|
logger(V_HAL, "hal.cpp: Proximity switch opened\n");
|
|
|
pinState[2] = 0;
|
|
|
}
|
|
@@ -532,10 +540,7 @@ void halResetFlow(void) {
|
|
|
* @return 1 (true) for closed Pressure Control (heating) and 0 (false) for open
|
|
|
*/
|
|
|
bool halIsHeating(void) {
|
|
|
- //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;
|
|
|
+ return !pinState[3];
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -553,13 +558,27 @@ void halSetTotalHeatingTime(uint64_t newTime) {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Returns status of the proximity switch
|
|
|
+ * Returns filtered status of the proximity switch
|
|
|
* @return 1 if the proximity switch is covered and 0 if uncovered
|
|
|
*/
|
|
|
bool halProxSensorCovered(void) {
|
|
|
return pinState[2];
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ *
|
|
|
+ */
|
|
|
+int halGetPressureSensorPin(void) {
|
|
|
+ return digitalRead(PIN_PRESSURE_CTRL);
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * Returns the pin status of the proximity sensor
|
|
|
+ */
|
|
|
+int halGetProxSensorPin(void) {
|
|
|
+ return digitalRead(PIN_PROXIMITY_SENSOR);
|
|
|
+}
|
|
|
+
|
|
|
/**
|
|
|
* Returns the value of the top button Int0 (low active)
|
|
|
* @return LOW or HIGH
|