changeset 864:fa431d42b5fb

Fix incorrect logging of bailout to Open Circuit when using the best gas. This happened because the starting gas used for 'best gas' calculation was a diluent - in most cases not a problem as the same gas is also used as a bailout gas. Now use the 'first' open circuit gas configured as the starting point. Also fixes the problem of a custom bailout gas not being logged as such, and consequently not being shown as bailout in the on-device log.
author heinrichsweikamp
date Mon, 22 Jul 2024 16:38:36 +0200
parents dff26bf4b542
children cb386cccc7c5
files Common/Inc/settings.h Discovery/Src/check_warning.c Discovery/Src/data_central.c
diffstat 3 files changed, 22 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/Common/Inc/settings.h	Mon Oct 09 11:23:27 2023 +0200
+++ b/Common/Inc/settings.h	Mon Jul 22 16:38:36 2024 +0200
@@ -46,6 +46,7 @@
 #define NUM_GASES 5
 #define NUM_OFFSET_DILUENT 5
 #define SPECIAL_GAS_ID 0
+#define NO_GAS_ID 255
 
 #define ERROR_ 0xFF
 
--- a/Discovery/Src/check_warning.c	Mon Oct 09 11:23:27 2023 +0200
+++ b/Discovery/Src/check_warning.c	Mon Jul 22 16:38:36 2024 +0200
@@ -231,6 +231,14 @@
         gasIdOffset = 0;
     }
 
+    if (betterGasIdLocal == NO_GAS_ID) {
+        for (unsigned i = gasIdOffset + 1; i <= gasIdOffset + 5; i++) {
+            if (diveSettings.gas[i].note.ub.active && diveSettings.gas[i].note.ub.first) {
+                betterGasIdLocal = i;
+            }
+        }
+    }
+
 	/* life data is float, gas data is uint8 */
     if (actualLeftMaxDepth(diveState)) { /* deco gases */
         for (int i=1+gasIdOffset; i<= 5+gasIdOffset; i++) {
@@ -245,7 +253,7 @@
         }
     } else { /* travel gases */
         bestGasDepth = 0;
-        //check for travalgas
+        //check for travelgas
         for (int i = 1 + gasIdOffset; i <= 5 + gasIdOffset; i++) {
             if ((diveSettings.gas[i].note.ub.active)
                 && (diveSettings.gas[i].note.ub.travel)
@@ -277,7 +285,7 @@
 
     if (isLoopMode(diveSettings.diveMode)) {
         betterGasId = getBetterGasId(true, lifeData.actualGas.GasIdInSettings, diveState);
-        betterBailoutGasId = getBetterGasId(false, lifeData.lastDiluent_GasIdInSettings, diveState);
+        betterBailoutGasId = getBetterGasId(false, NO_GAS_ID, diveState);
     } else {
         betterGasId = getBetterGasId(false, lifeData.actualGas.GasIdInSettings, diveState);
     }
--- a/Discovery/Src/data_central.c	Mon Oct 09 11:23:27 2023 +0200
+++ b/Discovery/Src/data_central.c	Mon Jul 22 16:38:36 2024 +0200
@@ -547,12 +547,19 @@
 	nitrogen -= helium;
 
 
-	if((lifeData->actualGas.nitrogen_percentage != nitrogen) || (lifeData->actualGas.helium_percentage != helium) || (lifeData->actualGas.AppliedDiveMode != DIVEMODE_OC))
+	if ((lifeData->actualGas.nitrogen_percentage != nitrogen) || (lifeData->actualGas.helium_percentage != helium) || lifeData->actualGas.AppliedDiveMode != DIVEMODE_OC)
     {
-    	stateUsedWrite->events.manualGasSet = 1;
-    	stateUsedWrite->events.info_manualGasSetHe = helium;
-    	stateUsedWrite->events.info_manualGasSetO2 = oxygen;
+       if (stateUsed->diveSettings.ccrOption) {
+            stateUsedWrite->events.bailout = 1;
+            stateUsedWrite->events.info_bailoutHe = helium;
+            stateUsedWrite->events.info_bailoutO2 = oxygen;
+        } else {
+            stateUsedWrite->events.manualGasSet = 1;
+            stateUsedWrite->events.info_manualGasSetHe = helium;
+            stateUsedWrite->events.info_manualGasSetO2 = oxygen;
+        }
     }
+
     if(	lifeData->actualGas.setPoint_cbar != setpoint_cbar)
     {
     	stateUsedWrite->events.setpointChange = 1;