Mercurial > public > ostc4
comparison 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 |
comparison
equal
deleted
inserted
replaced
562:ec76fa85009e | 563:d97f0e395058 |
---|---|
126 | 126 |
127 return (float)(receiveHUD[boolHUDdata].battery_voltage_mV) / 1000.0f; | 127 return (float)(receiveHUD[boolHUDdata].battery_voltage_mV) / 1000.0f; |
128 } | 128 } |
129 | 129 |
130 | 130 |
131 void test_HUD_sensor_values_outOfBounds(int8_t * outOfBouds1, int8_t * outOfBouds2, int8_t * outOfBouds3) | 131 void test_O2_sensor_values_outOfBounds(int8_t * outOfBouds1, int8_t * outOfBouds2, int8_t * outOfBouds3) |
132 { | 132 { |
133 uint8_t sensorNotActiveBinary; | 133 uint8_t sensorNotActiveBinary; |
134 uint8_t sensorActive[3]; | 134 uint8_t sensorActive[3]; |
135 | 135 |
136 // test1: user deactivation | 136 // test1: user deactivation |
154 // test2: mV of remaining sensors | 154 // test2: mV of remaining sensors |
155 for(int i=0;i<3;i++) | 155 for(int i=0;i<3;i++) |
156 { | 156 { |
157 if(sensorActive[i]) | 157 if(sensorActive[i]) |
158 { | 158 { |
159 if( (receiveHUD[boolHUDdata].sensor_voltage_100uV[i] < 80) || | 159 if( (stateUsed->lifeData.sensorVoltage_mV[i] < 8) || |
160 (receiveHUD[boolHUDdata].sensor_voltage_100uV[i] > 2500)) | 160 (stateUsed->lifeData.sensorVoltage_mV[i] > 250)) |
161 { | 161 { |
162 sensorActive[i] = 0; | 162 sensorActive[i] = 0; |
163 switch(i) | 163 switch(i) |
164 { | 164 { |
165 case 0: | 165 case 0: |
197 return; | 197 return; |
198 } | 198 } |
199 else | 199 else |
200 { | 200 { |
201 uint8_t sensor_id_ordered[3]; | 201 uint8_t sensor_id_ordered[3]; |
202 uint8_t difference[2]; | 202 float difference[2]; |
203 | 203 |
204 if((receiveHUD[boolHUDdata].sensor_ppo2_cbar[1]) > (receiveHUD[boolHUDdata].sensor_ppo2_cbar[0])) | 204 if((stateUsed->lifeData.ppO2Sensor_bar[1] > stateUsed->lifeData.ppO2Sensor_bar[0])) |
205 { | 205 { |
206 sensor_id_ordered[0] = 0; | 206 sensor_id_ordered[0] = 0; |
207 sensor_id_ordered[1] = 1; | 207 sensor_id_ordered[1] = 1; |
208 } | 208 } |
209 else | 209 else |
210 { | 210 { |
211 sensor_id_ordered[0] = 1; | 211 sensor_id_ordered[0] = 1; |
212 sensor_id_ordered[1] = 0; | 212 sensor_id_ordered[1] = 0; |
213 } | 213 } |
214 if(receiveHUD[boolHUDdata].sensor_ppo2_cbar[2] > receiveHUD[boolHUDdata].sensor_ppo2_cbar[sensor_id_ordered[1]]) | 214 if(stateUsed->lifeData.ppO2Sensor_bar[2] > stateUsed->lifeData.ppO2Sensor_bar[sensor_id_ordered[1]]) |
215 { | 215 { |
216 sensor_id_ordered[2] = 2; | 216 sensor_id_ordered[2] = 2; |
217 } | 217 } |
218 else | 218 else |
219 { | 219 { |
220 sensor_id_ordered[2] = sensor_id_ordered[1]; | 220 sensor_id_ordered[2] = sensor_id_ordered[1]; |
221 if(receiveHUD[boolHUDdata].sensor_ppo2_cbar[2] > receiveHUD[boolHUDdata].sensor_ppo2_cbar[sensor_id_ordered[0]]) | 221 if(stateUsed->lifeData.ppO2Sensor_bar[2] > stateUsed->lifeData.ppO2Sensor_bar[sensor_id_ordered[0]]) |
222 { | 222 { |
223 sensor_id_ordered[1] = 2; | 223 sensor_id_ordered[1] = 2; |
224 } | 224 } |
225 else | 225 else |
226 { | 226 { |
227 sensor_id_ordered[1] = sensor_id_ordered[0]; | 227 sensor_id_ordered[1] = sensor_id_ordered[0]; |
228 sensor_id_ordered[0] = 2; | 228 sensor_id_ordered[0] = 2; |
229 } | 229 } |
230 } | 230 } |
231 | 231 |
232 difference[0] = receiveHUD[boolHUDdata].sensor_ppo2_cbar[sensor_id_ordered[1]]- receiveHUD[boolHUDdata].sensor_ppo2_cbar[sensor_id_ordered[0]]; | 232 difference[0] = stateUsed->lifeData.ppO2Sensor_bar[sensor_id_ordered[1]]- stateUsed->lifeData.ppO2Sensor_bar[sensor_id_ordered[0]]; |
233 difference[1] = receiveHUD[boolHUDdata].sensor_ppo2_cbar[sensor_id_ordered[2]]- receiveHUD[boolHUDdata].sensor_ppo2_cbar[sensor_id_ordered[1]]; | 233 difference[1] = stateUsed->lifeData.ppO2Sensor_bar[sensor_id_ordered[2]]- stateUsed->lifeData.ppO2Sensor_bar[sensor_id_ordered[1]]; |
234 | 234 |
235 if((difference[0] > difference[1]) && (difference[0] > 15)) | 235 if((difference[0] > difference[1]) && (difference[0] > 0.15)) /* was 15cBar ==> 0.15 bar */ |
236 { | 236 { |
237 switch(sensor_id_ordered[0]) | 237 switch(sensor_id_ordered[0]) |
238 { | 238 { |
239 case 0: | 239 case 0: |
240 *outOfBouds1 = 1; | 240 *outOfBouds1 = 1; |
246 *outOfBouds3 = 1; | 246 *outOfBouds3 = 1; |
247 break; | 247 break; |
248 } | 248 } |
249 } | 249 } |
250 else | 250 else |
251 if((difference[0] < difference[1]) && (difference[1] > 15)) | 251 if((difference[0] < difference[1]) && (difference[1] > 0.15)) |
252 { | 252 { |
253 switch(sensor_id_ordered[2]) | 253 switch(sensor_id_ordered[2]) |
254 { | 254 { |
255 case 0: | 255 case 0: |
256 *outOfBouds1 = 1; | 256 *outOfBouds1 = 1; |
271 { | 271 { |
272 int8_t sensorOutOfBound[3]; | 272 int8_t sensorOutOfBound[3]; |
273 uint16_t result = 0; | 273 uint16_t result = 0; |
274 uint8_t count = 0; | 274 uint8_t count = 0; |
275 | 275 |
276 test_HUD_sensor_values_outOfBounds(&sensorOutOfBound[0], &sensorOutOfBound[1], &sensorOutOfBound[2]); | 276 test_O2_sensor_values_outOfBounds(&sensorOutOfBound[0], &sensorOutOfBound[1], &sensorOutOfBound[2]); |
277 | 277 |
278 for(int i=0;i<3;i++) | 278 for(int i=0;i<3;i++) |
279 { | 279 { |
280 if(!sensorOutOfBound[i]) | 280 if(!sensorOutOfBound[i]) |
281 { | 281 { |
282 result += receiveHUD[boolHUDdata].sensor_ppo2_cbar[i]; | 282 result += stateUsed->lifeData.ppO2Sensor_bar[i] * 100.0; /* convert centibar used by HUB */ |
283 count++; | 283 count++; |
284 } | 284 } |
285 } | 285 } |
286 if(count == 0) // all sensors out of bounds! | 286 if(count == 0) // all sensors out of bounds! |
287 return 0; | 287 return 0; |
307 /* after 3 seconds without update from HUD | 307 /* after 3 seconds without update from HUD |
308 * data is considered old | 308 * data is considered old |
309 */ | 309 */ |
310 void tCCR_tick(void) | 310 void tCCR_tick(void) |
311 { | 311 { |
312 if(HUDTimeoutCount < 3 * 10) | 312 if(settingsGetPointer()->ppo2sensors_source == O2_SENSOR_SOURCE_OPTIC) |
313 HUDTimeoutCount++; | 313 { |
314 else | 314 if(HUDTimeoutCount < 3 * 10) |
315 { | 315 HUDTimeoutCount++; |
316 data_old__lost_connection_to_HUD = 1; | 316 else |
317 if(HUDTimeoutCount < 20 * 10) | 317 { |
318 HUDTimeoutCount++; | 318 data_old__lost_connection_to_HUD = 1; |
319 else | 319 if(HUDTimeoutCount < 20 * 10) |
320 tCCR_fallbackToFixedSetpoint(); | 320 HUDTimeoutCount++; |
321 } | 321 else |
322 tCCR_fallbackToFixedSetpoint(); | |
323 } | |
324 } | |
322 } | 325 } |
323 | 326 |
324 void tCCR_SetRXIndication(void) | 327 void tCCR_SetRXIndication(void) |
325 { | 328 { |
326 static uint8_t floatingRXCount = 0; | 329 static uint8_t floatingRXCount = 0; |