changeset 831:da632300e7d4 Evo_2_23

Activated work gas for (p)scr mode: In previous version setting of change depth for work (travel) gases was not possible. For (p)scr operation this is not possible. Work gases will not be considered for deco calculation. In addition the first gas will be handled as "deco" gas. This allows switching back to the first gas in case the current gas becomes no longer breathable (ppo2 low).
author Ideenmodellierer
date Thu, 16 Nov 2023 20:36:35 +0100
parents b7d93ff6b3b2
children 7b0033246b12
files Discovery/Src/check_warning.c Discovery/Src/data_exchange_main.c
diffstat 2 files changed, 30 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/Discovery/Src/check_warning.c	Thu Nov 16 20:32:09 2023 +0100
+++ b/Discovery/Src/check_warning.c	Thu Nov 16 20:36:35 2023 +0100
@@ -220,9 +220,10 @@
 static uint8_t getBetterGasId(bool getDiluent, uint8_t startingGasId, SDiveState *diveState)
 {
     SDiveSettings diveSettings = diveState->diveSettings;
-
+    SGasLine localGas;
     uint8_t betterGasIdLocal = startingGasId;
     uint8_t bestGasDepth = 255;
+    uint8_t i;
 
     uint8_t gasIdOffset;
     if (getDiluent) {
@@ -233,12 +234,19 @@
 
 	/* life data is float, gas data is uint8 */
     if (actualLeftMaxDepth(diveState)) { /* deco gases */
-        for (int i=1+gasIdOffset; i<= 5+gasIdOffset; i++) {
-            if ((diveSettings.gas[i].note.ub.active)
-                && (diveSettings.gas[i].note.ub.deco)
-                && (diveSettings.gas[i].depth_meter)
-                && (diveSettings.gas[i].depth_meter >= (diveState->lifeData.depth_meter - 0.01f ))
-                && (diveSettings.gas[i].depth_meter <= bestGasDepth)) {
+        for (i=1+gasIdOffset; i<= 5+gasIdOffset; i++) {
+        	memcpy(&localGas,&diveSettings.gas[i],sizeof(SGasLine));
+        	if((localGas.note.ub.first) && (diveSettings.diveMode == DIVEMODE_PSCR))	/* handle first gas as if it would be a deco gas set to MOD */
+        	{
+        		localGas.note.ub.active = 1;
+        		localGas.note.ub.deco = 1;
+        		localGas.depth_meter = calc_MOD(i);
+        	}
+            if ((localGas.note.ub.active)
+                && (localGas.note.ub.deco)
+                && (localGas.depth_meter)
+                && (localGas.depth_meter >= (diveState->lifeData.depth_meter - 0.01f ))
+                && (localGas.depth_meter <= bestGasDepth)) {
                 betterGasIdLocal = i;
                 bestGasDepth = diveSettings.gas[i].depth_meter;
             }
@@ -246,7 +254,7 @@
     } else { /* travel gases */
         bestGasDepth = 0;
         //check for travalgas
-        for (int i = 1 + gasIdOffset; i <= 5 + gasIdOffset; i++) {
+        for (i = 1 + gasIdOffset; i <= 5 + gasIdOffset; i++) {
             if ((diveSettings.gas[i].note.ub.active)
                 && (diveSettings.gas[i].note.ub.travel)
                 && (diveSettings.gas[i].depth_meter_travel)
@@ -257,6 +265,18 @@
             }
         }
     }
+    if((!getDiluent) && (betterGasIdLocal > NUM_OFFSET_DILUENT))	/* an OC gas was requested but Id is pointing to a diluent => return first OC */
+    {
+    	for (i = 1 ; i <= NUM_OFFSET_DILUENT; i++)
+    	{
+    		if(diveSettings.gas[i].note.ub.first)
+    		{
+    			betterGasIdLocal = i;
+    			break;
+    		}
+    	}
+    }
+
 
     return betterGasIdLocal;
 }
@@ -558,7 +578,7 @@
 #ifdef ENABLE_CO2_SUPPORT
 static int8_t check_co2(SDiveState * pDiveState)
 {
-	if(pDiveState->mode != MODE_DIVE)
+	if((pDiveState->mode != MODE_DIVE) || (settingsGetPointer()->co2_sensor_active == 0))
 	{
 		pDiveState->warnings.co2High = 0;
 	}
--- a/Discovery/Src/data_exchange_main.c	Thu Nov 16 20:32:09 2023 +0100
+++ b/Discovery/Src/data_exchange_main.c	Thu Nov 16 20:36:35 2023 +0100
@@ -1159,7 +1159,7 @@
 		pStateReal->sensorErrorsRTE = dataIn.sensorErrors;
 
 		/* data from CO2 sensor */
-		pStateReal->lifeData.CO2_data.CO2_ppm = dataIn.data[(dataIn.boolADCO2Data && DATA_BUFFER_CO2)].CO2_ppm * 10;	/* Scale factor depends on sensor */
+		pStateReal->lifeData.CO2_data.CO2_ppm = dataIn.data[(dataIn.boolADCO2Data && DATA_BUFFER_CO2)].CO2_ppm;
 		pStateReal->lifeData.CO2_data.signalStrength = dataIn.data[(dataIn.boolADCO2Data && DATA_BUFFER_CO2)].CO2_signalStrength;
 
 #ifdef ENABLE_EXTERNAL_PRESSURE