diff Discovery/Src/tCCR.c @ 662:1b995079c045 Betatest

PSCR Mode
author heinrichs weikamp
date Tue, 14 Dec 2021 15:36:10 +0100
parents 980b4aa60a0e
children 8adf9b8fc7fa
line wrap: on
line diff
--- a/Discovery/Src/tCCR.c	Mon Nov 01 12:39:34 2021 +0100
+++ b/Discovery/Src/tCCR.c	Tue Dec 14 15:36:10 2021 +0100
@@ -65,6 +65,13 @@
 #define BOTTLE_SENSOR_TIMEOUT		(6000u)     /* signal pressure budget as not received after 10 minutes (6000 * 100ms) */
 
 #define MAX_SENSOR_COMPARE_DEVIATION (0.15f)	/* max deviation between two sensors allowed before their results are rated as suspect */
+#define MAX_SENSOR_VOLTAGE_MV		(250u)		/* max allowed voltage value for a sensor measurement */
+
+#ifdef ENABLE_ALTERNATIVE_SENSORTYP
+#define MIN_SENSOR_VOLTAGE_MV		(3u)		/* min allowed voltage value for a sensor measurement (Inspiration, Submatix, Sentinel Typ) */
+#else
+#define MIN_SENSOR_VOLTAGE_MV		(8u)		/* min allowed voltage value for a sensor measurement (legacy OSTC TYP)  */
+#endif
 
 /* Private variables ---------------------------------------------------------*/
 static SIrLink receiveHUD[2];
@@ -173,8 +180,8 @@
 
         if(sensorActive[i])
         {
-            if(	(stateUsed->lifeData.sensorVoltage_mV[i] < 8) ||
-                    (stateUsed->lifeData.sensorVoltage_mV[i] > 250))
+            if(	(stateUsed->lifeData.sensorVoltage_mV[i] < MIN_SENSOR_VOLTAGE_MV) ||
+                    (stateUsed->lifeData.sensorVoltage_mV[i] > MAX_SENSOR_VOLTAGE_MV))
             {
                 sensorActive[i] = 0;
                 switch(i)
@@ -330,7 +337,7 @@
 	}
 
 	/* decrease scrubber timer only in real dive mode */
-    if((pSettings->scrubTimerMode != SCRUB_TIMER_OFF) && (pSettings->dive_mode == DIVEMODE_CCR) && (stateUsed->mode == MODE_DIVE) && (stateUsed == stateRealGetPointer()))
+    if((pSettings->scrubTimerMode != SCRUB_TIMER_OFF) && (isLoopMode(pSettings->dive_mode)) && (stateUsed->mode == MODE_DIVE) && (stateUsed == stateRealGetPointer()))
     {
     	ScrubberTimeoutCount++;
     	if(ScrubberTimeoutCount >= 600)		/* resolution is minutes */
@@ -444,18 +451,25 @@
 static uint8_t tCCR_fallbackToFixedSetpoint(void)
 {
 	uint8_t retVal = 0;
-    if((stateUsed->mode == MODE_DIVE) && (stateUsed->diveSettings.diveMode == DIVEMODE_CCR) && (stateUsed->diveSettings.CCR_Mode == CCRMODE_Sensors) && (stateUsed->diveSettings.fallbackOption))
-    {
-        uint8_t setpointCbar, actualGasID;
+	uint8_t setpointCbar, actualGasID;
 
-        setpointCbar = stateUsed->diveSettings.setpoint[1].setpoint_cbar;
-        stateUsedWrite->diveSettings.CCR_Mode = CCRMODE_FixedSetpoint;
+    if((stateUsed->mode == MODE_DIVE) && (stateUsed->diveSettings.CCR_Mode == CCRMODE_Sensors) && (stateUsed->diveSettings.fallbackOption))
+    {
+    	if(stateUsed->diveSettings.diveMode == DIVEMODE_CCR)
+    	{
+			setpointCbar = stateUsed->diveSettings.setpoint[1].setpoint_cbar;
+			stateUsedWrite->diveSettings.CCR_Mode = CCRMODE_FixedSetpoint;
+    	}
+    	else
+    	{
+    		setpointCbar = stateUsed->lifeData.ppo2Simulated_bar * 100;
+    		stateUsedWrite->diveSettings.CCR_Mode = CCRMODE_Simulation;
+    	}
+    	actualGasID = stateUsed->lifeData.actualGas.GasIdInSettings;
+    	setActualGas_DM(&stateUsedWrite->lifeData,actualGasID,setpointCbar);
 
-        actualGasID = stateUsed->lifeData.actualGas.GasIdInSettings;
-        setActualGas_DM(&stateUsedWrite->lifeData,actualGasID,setpointCbar);
-
-        set_warning_fallback();
-        retVal = stateUsed->diveSettings.setpoint[1].setpoint_cbar;
+    	set_warning_fallback();
+    	retVal = setpointCbar;
     }
     return retVal;
 }