diff --git a/main/safety.c b/main/safety.c index 53ca250..94c0d04 100644 --- a/main/safety.c +++ b/main/safety.c @@ -2,10 +2,12 @@ #include "freertos/task.h" #include "esp_log.h" #include +#include #include "safety.h" #define PERIODIC_INTERVAL 1U // run safety checks every 1sec #define SENSOR_GRACE_PERIOD (60U * 30U) // period that a sensor can report the same reading in seconds +#define FLOAT_EPSILON 0.0001f static const char *TAG = "smart-oil-heater-control-system-safety"; static SemaphoreHandle_t xMutexAccessSafety = NULL; @@ -91,7 +93,7 @@ void checkSensorSanity(void) } else { - if (sCurrentMeasurement.fCurrentValue == sanityChecks[i].fSensorTemperatureLast) + if (fabsf(sCurrentMeasurement.fCurrentValue - sanityChecks[i].fSensorTemperatureLast) < FLOAT_EPSILON) { sanityChecks[i].uUnchangedCounter++; if (sanityChecks[i].uUnchangedCounter >= (SENSOR_GRACE_PERIOD / PERIODIC_INTERVAL))