Floating-point equality comparison
This commit is contained in:
@ -2,10 +2,12 @@
|
||||
#include "freertos/task.h"
|
||||
#include "esp_log.h"
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#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))
|
||||
|
||||
Reference in New Issue
Block a user