diff --git a/lambda/airgate.c b/lambda/airgate.c index ae8ad59..dae35d7 100644 --- a/lambda/airgate.c +++ b/lambda/airgate.c @@ -90,7 +90,7 @@ } void setAirgate(uint8_t const target) { - if (target == getAirgate() || isAirgateBusy()) { + if (target == getAirgate() || isAirgateBusy() || isDriverFault()) { return; } if (bit_is_clear(PORT, PIN_SLEEP)) { @@ -117,6 +117,10 @@ return steps_c > 0; } +bool isDriverFault(void) { + return bit_is_clear(PORT, PIN_FAULT); +} + void setSleepMode(bool const on) { if (on) { PORT &= ~(1 << PIN_SLEEP); diff --git a/lambda/airgate.h b/lambda/airgate.h index 5067773..dabb1ea 100644 --- a/lambda/airgate.h +++ b/lambda/airgate.h @@ -53,6 +53,11 @@ bool isAirgateBusy(void); /** + * Returns true if the driver signals fault condition, false otherwise. + */ +bool isDriverFault(void); + +/** * Wakes up the driver or puts it in sleep mode. */ void setSleepMode(bool const on); diff --git a/lambda/messages.h b/lambda/messages.h index 33011af..00e34e2 100644 --- a/lambda/messages.h +++ b/lambda/messages.h @@ -40,6 +40,8 @@ #define MSG_HEATER_OFF_0 "Oxygen sensor" #define MSG_HEATER_OFF_1 "off" #define MSG_HEATER_CURRENT "Heater current" + #define MSG_DRIVER_FAULT_0 "Airgate motor" + #define MSG_DRIVER_FAULT_1 "driver fault!" #define MSG_TIME_SINCE_START "Time since start" #elif LANG == 1 @@ -70,6 +72,8 @@ #define MSG_HEATER_OFF_0 "Lambdasonde" #define MSG_HEATER_OFF_1 "aus" #define MSG_HEATER_CURRENT "Heizstrom" + #define MSG_DRIVER_FAULT_0 "Luftschieber-" + #define MSG_DRIVER_FAULT_1 "antrieb Fehler!" #define MSG_TIME_SINCE_START "Zeit seit Start" #endif diff --git a/lambda/rules.c b/lambda/rules.c index a019959..cb695ad 100644 --- a/lambda/rules.c +++ b/lambda/rules.c @@ -225,18 +225,29 @@ } /** - * Heater rules applied to each not averaged measured heater current value. + * Notifies that the stepper motor driver signals fault condition. */ -Rule heaterRules[] = { +static void driverFault(bool* const fired, Measurement const meas) { + if (isDriverFault()) { + alert_P(BEEPS, LENGTH, TONE, PSTR(MSG_DRIVER_FAULT_0), + PSTR(MSG_DRIVER_FAULT_1), true); + } +} + +/** + * Rules applied to each measurement. + */ +Rule fastRules[] = { {false, heaterReady}, {false, heaterFault}, - {false, heaterTimeout} + {false, heaterTimeout}, + {false, driverFault} }; /** * Rules applied to every nth averaged measurement. */ -Rule rules[] = { +Rule slowRules[] = { {false, airgate50}, {false, airgate25}, {false, airgateClose}, @@ -256,8 +267,8 @@ tempIMax = MAX(tempIMax, meas.tempI); // rules applied at each measurement - for (size_t i = 0; i < ARRAY_LENGTH(heaterRules); i++) { - heaterRules[i].cond(&(heaterRules[i].fired), meas); + for (size_t i = 0; i < ARRAY_LENGTH(fastRules); i++) { + fastRules[i].cond(&(fastRules[i].fired), meas); } // evaluation of the fire state and rules applied @@ -265,8 +276,8 @@ if (measCount == MEAS_INT) { measCount = 0; - for (size_t i = 0; i < ARRAY_LENGTH(rules); i++) { - rules[i].cond(&(rules[i].fired), meas); + for (size_t i = 0; i < ARRAY_LENGTH(slowRules); i++) { + slowRules[i].cond(&(slowRules[i].fired), meas); } // difference between current and previous temperature @@ -299,13 +310,13 @@ state = undefined; } - for (size_t i = 0; i < ARRAY_LENGTH(rules); i++) { - rules[i].fired = false; + for (size_t i = 0; i < ARRAY_LENGTH(slowRules); i++) { + slowRules[i].fired = false; } // default for warmStart should be true - rules[6].fired = true; + slowRules[6].fired = true; - for (size_t i = 0; i < ARRAY_LENGTH(heaterRules); i++) { - heaterRules[i].fired = false; + for (size_t i = 0; i < ARRAY_LENGTH(fastRules); i++) { + fastRules[i].fired = false; } }