changeset 959:5d5fa0a3b409 Evo_2_23 tip

Devbugfix: external surface pressure calibration: Due to mixing of mBar and Bar units the calculation of the new offset for the surface pressure could be wrong. The code was cleaned up and the problem is solved.
author Ideenmodellierer
date Mon, 06 Jan 2025 21:36:31 +0100
parents 902cb199eee6
children
files Discovery/Src/tMenuEditSystem.c
diffstat 1 files changed, 21 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/Discovery/Src/tMenuEditSystem.c	Mon Jan 06 21:34:33 2025 +0100
+++ b/Discovery/Src/tMenuEditSystem.c	Mon Jan 06 21:36:31 2025 +0100
@@ -41,6 +41,7 @@
 #include "tMenuEditCustom.h"
 #include "motion.h"
 #include "t7.h"
+#include "math.h"
 
 
 /*#define HAVE_DEBUG_VIEW */
@@ -1687,28 +1688,39 @@
     const SDiveState* pDiveState = stateRealGetPointer();
     SSettings* pSettings = settingsGetPointer();
     uint8_t index = 0;
-    int8_t newOffset = 0;
+    float orgpressure_surface_mbar;
+    float DiveO2_mbar;
+    int8_t newOffset_mbar = 0;
+
 
     char text[32];
 
-    float orgpressure_surface;
+
 
     for (index = 0; index < 3; index++)
     {
     	if(settingsGetPointer()->ext_sensor_map[index] == SENSOR_DIGO2M)
     	{
     		pDiveO2Data = (SSensorDataDiveO2*)stateRealGetPointer()->lifeData.extIf_sensor_data[index];
-    		orgpressure_surface = pDiveState->lifeData.pressure_surface_bar - (settingsGetPointer()->offsetPressure_mbar / 1000.0);
-    		newOffset = ((pDiveO2Data->pressure/1000) - (orgpressure_surface * 1000));
+    		DiveO2_mbar = (pDiveO2Data->pressure/1000.0);
+
+    		orgpressure_surface_mbar = (pDiveState->lifeData.pressure_surface_bar * 1000) - (settingsGetPointer()->offsetPressure_mbar);
+    		newOffset_mbar = DiveO2_mbar - orgpressure_surface_mbar;
 
-    		if((pDiveState->lifeData.pressure_surface_bar * 1000 + newOffset) != (pDiveO2Data->pressure/1000)) /* there might be a rounding difference => compensate */
+    		if(fabs(orgpressure_surface_mbar + ((float)newOffset_mbar) - DiveO2_mbar) > 0.5) /* there might be a rounding difference => compensate */
 			{
-    			newOffset += (pDiveO2Data->pressure/1000) - (pDiveState->lifeData.pressure_surface_bar * 1000 + newOffset);
+    			if((orgpressure_surface_mbar + ((float)newOffset_mbar)) - (pDiveO2Data->pressure/1000.0) > 0.0)
+				{
+    				newOffset_mbar -=1;
+				}
+				else
+				{
+					newOffset_mbar +=1;
+				}
 			}
 
-    		pSettings->offsetPressure_mbar = newOffset;
-    		snprintf(text,32,"%c%c (%1.3lf => %1.3f)\016\016Bar",TXT_2BYTE,TXT2BYTE_AdjustAmbPressure,(float)(pDiveO2Data->pressure/1000000.0),
-    		        													pDiveState->lifeData.pressure_surface_bar + pSettings->offsetPressure_mbar / 1000.0);
+    		pSettings->offsetPressure_mbar = newOffset_mbar;
+    		snprintf(text,32,"%c%c (%1.3lf => %1.3f)\016\016Bar",TXT_2BYTE,TXT2BYTE_AdjustAmbPressure,(float)(pDiveO2Data->pressure/1000000.0),	(orgpressure_surface_mbar + pSettings->offsetPressure_mbar) / 1000.0);
     		tMenuEdit_newButtonText(StMSYS5_AdjustSurfPres,text);
     		break;
     	}