# HG changeset patch # User Ideenmodellierer # Date 1659705209 -7200 # Node ID 8c92f7743e14f92a3a02744b35b4432470d44c10 # Parent 5e99739573186fb88af2ab02d23ef7a471c63717 Added sanity check for temperature and pressure values: It happens from time to time at the debug hardware (electronic without housing) that pressure or temperature are in an invalid range . To avoid side effects a sanity check has been added. diff -r 5e9973957318 -r 8c92f7743e14 Small_CPU/Src/pressure.c --- a/Small_CPU/Src/pressure.c Fri Aug 05 15:10:10 2022 +0200 +++ b/Small_CPU/Src/pressure.c Fri Aug 05 15:13:29 2022 +0200 @@ -49,8 +49,12 @@ /* remove comment to use a predefined profile for pressure changes instead of real world data */ /* #define SIMULATE_PRESSURE */ + #define PRESSURE_SURFACE_MAX_MBAR (1060.0f) /* It is unlikely that pressure at surface is greater than this value => clip to it */ +#define PRESSURE_MINIMUM (0.0f) +#define TEMPERATURE_MINIMUM (-100.0f) + #define PRESSURE_SURFACE_QUE (30u) /* history buffer [minutes] for past pressure measurements */ #define PRESSURE_SURFACE_EVA_WINDOW (15u) /* Number of entries evaluated during instability test. Used to avoid detection while dive enters water */ #define PRESSURE_SURFACE_STABLE_LIMIT (10u) /* Define pressure as stable if delta (mBar) is below this value */ @@ -664,6 +668,11 @@ ambient_temperature = ((float)local_Tx100) / 100; ambient_temperature += temperature_offset; + if(ambient_temperature < TEMPERATURE_MINIMUM) + { + ambient_temperature = 20.0; + } + calc_pressure = ((float)local_Px10) / 10; calc_pressure += pressure_offset; @@ -673,6 +682,11 @@ avgCnt++; /* by the measurement range of the sensor which is focused on under water pressure measurement */ } ambient_pressure_mbar = runningAvg; + + if(ambient_pressure_mbar < PRESSURE_MINIMUM) + { + ambient_pressure_mbar = 1000.0; + } }