diff Discovery/Src/tMenuEditSystem.c @ 969:81049905d829 Evo_2_23

Zusammenf?hren
author heinrichsweikamp
date Sun, 19 Jan 2025 12:02:59 +0100
parents 5d5fa0a3b409
children d9290c76b840
line wrap: on
line diff
--- a/Discovery/Src/tMenuEditSystem.c	Sun Jan 19 12:00:50 2025 +0100
+++ b/Discovery/Src/tMenuEditSystem.c	Sun Jan 19 12:02:59 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;
     	}