diff Discovery/Src/tCCR.c @ 563:d97f0e395058

Refine o2 sensor diagnostic functions: Changed implementation to ignore connection errors if analog interface is selected. Because the HUD is using cBars, the code has been modified to be compatible with the Bar units provided by the analog interface. Behavior (outofbounds) should be identical to the previous implementation.
author Ideenmodellierer
date Sun, 15 Nov 2020 20:01:56 +0100
parents 4bd01f48c285
children 64bf41faab83
line wrap: on
line diff
--- a/Discovery/Src/tCCR.c	Sun Nov 15 19:58:14 2020 +0100
+++ b/Discovery/Src/tCCR.c	Sun Nov 15 20:01:56 2020 +0100
@@ -128,7 +128,7 @@
 }
 
 
-void test_HUD_sensor_values_outOfBounds(int8_t * outOfBouds1, int8_t * outOfBouds2, int8_t * outOfBouds3)
+void test_O2_sensor_values_outOfBounds(int8_t * outOfBouds1, int8_t * outOfBouds2, int8_t * outOfBouds3)
 {
     uint8_t sensorNotActiveBinary;
     uint8_t sensorActive[3];
@@ -156,8 +156,8 @@
     {
         if(sensorActive[i])
         {
-            if(	(receiveHUD[boolHUDdata].sensor_voltage_100uV[i] < 80) ||
-                    (receiveHUD[boolHUDdata].sensor_voltage_100uV[i] > 2500))
+            if(	(stateUsed->lifeData.sensorVoltage_mV[i] < 8) ||
+                    (stateUsed->lifeData.sensorVoltage_mV[i] > 250))
             {
                 sensorActive[i] = 0;
                 switch(i)
@@ -199,9 +199,9 @@
     else
     {
         uint8_t sensor_id_ordered[3];
-        uint8_t difference[2];
+        float difference[2];
 
-        if((receiveHUD[boolHUDdata].sensor_ppo2_cbar[1]) > (receiveHUD[boolHUDdata].sensor_ppo2_cbar[0]))
+        if((stateUsed->lifeData.ppO2Sensor_bar[1] > stateUsed->lifeData.ppO2Sensor_bar[0]))
         {
             sensor_id_ordered[0] = 0;
             sensor_id_ordered[1] = 1;
@@ -211,14 +211,14 @@
             sensor_id_ordered[0] = 1;
             sensor_id_ordered[1] = 0;
         }
-        if(receiveHUD[boolHUDdata].sensor_ppo2_cbar[2] > receiveHUD[boolHUDdata].sensor_ppo2_cbar[sensor_id_ordered[1]])
+        if(stateUsed->lifeData.ppO2Sensor_bar[2] > stateUsed->lifeData.ppO2Sensor_bar[sensor_id_ordered[1]])
         {
             sensor_id_ordered[2] = 2;
         }
         else
         {
             sensor_id_ordered[2] = sensor_id_ordered[1];
-            if(receiveHUD[boolHUDdata].sensor_ppo2_cbar[2] > receiveHUD[boolHUDdata].sensor_ppo2_cbar[sensor_id_ordered[0]])
+            if(stateUsed->lifeData.ppO2Sensor_bar[2] > stateUsed->lifeData.ppO2Sensor_bar[sensor_id_ordered[0]])
             {
                 sensor_id_ordered[1] = 2;
             }
@@ -229,10 +229,10 @@
             }
         }
 
-        difference[0] = receiveHUD[boolHUDdata].sensor_ppo2_cbar[sensor_id_ordered[1]]- receiveHUD[boolHUDdata].sensor_ppo2_cbar[sensor_id_ordered[0]];
-        difference[1] = receiveHUD[boolHUDdata].sensor_ppo2_cbar[sensor_id_ordered[2]]- receiveHUD[boolHUDdata].sensor_ppo2_cbar[sensor_id_ordered[1]];
+        difference[0] = stateUsed->lifeData.ppO2Sensor_bar[sensor_id_ordered[1]]- stateUsed->lifeData.ppO2Sensor_bar[sensor_id_ordered[0]];
+        difference[1] = stateUsed->lifeData.ppO2Sensor_bar[sensor_id_ordered[2]]- stateUsed->lifeData.ppO2Sensor_bar[sensor_id_ordered[1]];
 
-        if((difference[0] > difference[1]) && (difference[0] > 15))
+        if((difference[0] > difference[1]) && (difference[0] > 0.15))		/* was 15cBar ==> 0.15 bar */
         {
             switch(sensor_id_ordered[0])
             {
@@ -248,7 +248,7 @@
             }
         }
         else
-        if((difference[0] < difference[1]) && (difference[1] > 15))
+        if((difference[0] < difference[1]) && (difference[1] > 0.15))
         {
             switch(sensor_id_ordered[2])
             {
@@ -273,13 +273,13 @@
     uint16_t result = 0;
     uint8_t count = 0;
 
-    test_HUD_sensor_values_outOfBounds(&sensorOutOfBound[0], &sensorOutOfBound[1], &sensorOutOfBound[2]);
+    test_O2_sensor_values_outOfBounds(&sensorOutOfBound[0], &sensorOutOfBound[1], &sensorOutOfBound[2]);
 
     for(int i=0;i<3;i++)
     {
         if(!sensorOutOfBound[i])
         {
-            result += receiveHUD[boolHUDdata].sensor_ppo2_cbar[i];
+            result += stateUsed->lifeData.ppO2Sensor_bar[i] * 100.0;		/* convert centibar used by HUB */
             count++;
         }
     }
@@ -309,16 +309,19 @@
     */
 void tCCR_tick(void)
 {
-    if(HUDTimeoutCount < 3 * 10)
-        HUDTimeoutCount++;
-    else
-    {
-        data_old__lost_connection_to_HUD = 1;
-        if(HUDTimeoutCount < 20 * 10)
-            HUDTimeoutCount++;
-        else
-            tCCR_fallbackToFixedSetpoint();
-    }
+	if(settingsGetPointer()->ppo2sensors_source == O2_SENSOR_SOURCE_OPTIC)
+	{
+		if(HUDTimeoutCount < 3 * 10)
+			HUDTimeoutCount++;
+		else
+		{
+			data_old__lost_connection_to_HUD = 1;
+			if(HUDTimeoutCount < 20 * 10)
+				HUDTimeoutCount++;
+			else
+				tCCR_fallbackToFixedSetpoint();
+		}
+	}
 }
 
 void tCCR_SetRXIndication(void)