changeset 688:8c92f7743e14 Betatest

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.
author Ideenmodellierer
date Fri, 05 Aug 2022 15:13:29 +0200
parents 5e9973957318
children 4dd487b407f7
files Small_CPU/Src/pressure.c
diffstat 1 files changed, 14 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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;
+	}
 }