comparison Discovery/Src/tMenuEditSystem.c @ 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 c6b858f2e025
children
comparison
equal deleted inserted replaced
958:902cb199eee6 959:5d5fa0a3b409
39 #include "tMenuEdit.h" 39 #include "tMenuEdit.h"
40 #include "tMenuSystem.h" 40 #include "tMenuSystem.h"
41 #include "tMenuEditCustom.h" 41 #include "tMenuEditCustom.h"
42 #include "motion.h" 42 #include "motion.h"
43 #include "t7.h" 43 #include "t7.h"
44 #include "math.h"
44 45
45 46
46 /*#define HAVE_DEBUG_VIEW */ 47 /*#define HAVE_DEBUG_VIEW */
47 static uint8_t infoPage = 0; 48 static uint8_t infoPage = 0;
48 49
1685 { 1686 {
1686 SSensorDataDiveO2* pDiveO2Data; 1687 SSensorDataDiveO2* pDiveO2Data;
1687 const SDiveState* pDiveState = stateRealGetPointer(); 1688 const SDiveState* pDiveState = stateRealGetPointer();
1688 SSettings* pSettings = settingsGetPointer(); 1689 SSettings* pSettings = settingsGetPointer();
1689 uint8_t index = 0; 1690 uint8_t index = 0;
1690 int8_t newOffset = 0; 1691 float orgpressure_surface_mbar;
1692 float DiveO2_mbar;
1693 int8_t newOffset_mbar = 0;
1694
1691 1695
1692 char text[32]; 1696 char text[32];
1693 1697
1694 float orgpressure_surface; 1698
1695 1699
1696 for (index = 0; index < 3; index++) 1700 for (index = 0; index < 3; index++)
1697 { 1701 {
1698 if(settingsGetPointer()->ext_sensor_map[index] == SENSOR_DIGO2M) 1702 if(settingsGetPointer()->ext_sensor_map[index] == SENSOR_DIGO2M)
1699 { 1703 {
1700 pDiveO2Data = (SSensorDataDiveO2*)stateRealGetPointer()->lifeData.extIf_sensor_data[index]; 1704 pDiveO2Data = (SSensorDataDiveO2*)stateRealGetPointer()->lifeData.extIf_sensor_data[index];
1701 orgpressure_surface = pDiveState->lifeData.pressure_surface_bar - (settingsGetPointer()->offsetPressure_mbar / 1000.0); 1705 DiveO2_mbar = (pDiveO2Data->pressure/1000.0);
1702 newOffset = ((pDiveO2Data->pressure/1000) - (orgpressure_surface * 1000)); 1706
1703 1707 orgpressure_surface_mbar = (pDiveState->lifeData.pressure_surface_bar * 1000) - (settingsGetPointer()->offsetPressure_mbar);
1704 if((pDiveState->lifeData.pressure_surface_bar * 1000 + newOffset) != (pDiveO2Data->pressure/1000)) /* there might be a rounding difference => compensate */ 1708 newOffset_mbar = DiveO2_mbar - orgpressure_surface_mbar;
1709
1710 if(fabs(orgpressure_surface_mbar + ((float)newOffset_mbar) - DiveO2_mbar) > 0.5) /* there might be a rounding difference => compensate */
1705 { 1711 {
1706 newOffset += (pDiveO2Data->pressure/1000) - (pDiveState->lifeData.pressure_surface_bar * 1000 + newOffset); 1712 if((orgpressure_surface_mbar + ((float)newOffset_mbar)) - (pDiveO2Data->pressure/1000.0) > 0.0)
1713 {
1714 newOffset_mbar -=1;
1715 }
1716 else
1717 {
1718 newOffset_mbar +=1;
1719 }
1707 } 1720 }
1708 1721
1709 pSettings->offsetPressure_mbar = newOffset; 1722 pSettings->offsetPressure_mbar = newOffset_mbar;
1710 snprintf(text,32,"%c%c (%1.3lf => %1.3f)\016\016Bar",TXT_2BYTE,TXT2BYTE_AdjustAmbPressure,(float)(pDiveO2Data->pressure/1000000.0), 1723 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);
1711 pDiveState->lifeData.pressure_surface_bar + pSettings->offsetPressure_mbar / 1000.0);
1712 tMenuEdit_newButtonText(StMSYS5_AdjustSurfPres,text); 1724 tMenuEdit_newButtonText(StMSYS5_AdjustSurfPres,text);
1713 break; 1725 break;
1714 } 1726 }
1715 } 1727 }
1716 1728