comparison Discovery/Src/tCCR.c @ 635:66c8a4ff9fc4

Debounce fallback warning: In previous versions the fallback option (automatical setting of a fixed setpoint) was only done for communication timeout scenario in combination with a HUD. It is now also applied in case all sensors are rated as out of bounds. The signaling of the fallback warning (including optional automatic setpoint change) is now done taking a 5 seconds debounds time into account. In case a fallback warning is active, then the only way to reset it is by selecting a new setpoint or by changing the sensor configuration (no change compared to previous implementation
author Ideenmodellierer
date Wed, 24 Feb 2021 21:03:22 +0100
parents 7c73f066cd16
children 980b4aa60a0e
comparison
equal deleted inserted replaced
634:7c73f066cd16 635:66c8a4ff9fc4
80 static uint32_t LastReceivedTick_HUD = 0; 80 static uint32_t LastReceivedTick_HUD = 0;
81 81
82 /* Private variables with external access via get_xxx() function -------------*/ 82 /* Private variables with external access via get_xxx() function -------------*/
83 83
84 /* Private function prototypes -----------------------------------------------*/ 84 /* Private function prototypes -----------------------------------------------*/
85 static void tCCR_fallbackToFixedSetpoint(void); 85 static uint8_t tCCR_fallbackToFixedSetpoint(void);
86 86
87 #ifndef USART_IR_HUD 87 #ifndef USART_IR_HUD
88 88
89 void tCCR_init(void) 89 void tCCR_init(void)
90 { 90 {
250 } 250 }
251 } 251 }
252 } 252 }
253 } 253 }
254 254
255 255 /* this function is called out of the 100ms callback => to be considered for debouncing */
256 uint8_t get_ppO2SensorWeightedResult_cbar(void) 256 uint8_t get_ppO2SensorWeightedResult_cbar(void)
257 { 257 {
258 static uint8_t lastValidValue = 0; 258 static uint8_t lastValidValue = 0;
259 int8_t sensorOutOfBound[3]; 259 int8_t sensorOutOfBound[3];
260 uint16_t result = 0; 260 uint16_t result = 0;
271 count++; 271 count++;
272 } 272 }
273 } 273 }
274 if(count == 0) /* all sensors out of bounds! => return last valid value as workaround till diver takes action */ 274 if(count == 0) /* all sensors out of bounds! => return last valid value as workaround till diver takes action */
275 { 275 {
276 set_warning_fallback(); 276 if(debounce_warning_fallback(100))
277 retVal = lastValidValue; 277 {
278 set_warning_fallback();
279 retVal = tCCR_fallbackToFixedSetpoint(); /* this function only changes setpoint if option is enabled */
280 }
281 if(retVal == 0)
282 {
283 retVal = lastValidValue;
284 }
278 } 285 }
279 else 286 else
280 { 287 {
281 retVal = (uint8_t)(result / count); 288 reset_debounce_warning_fallback();
282 lastValidValue = retVal; 289 retVal = (uint8_t)(result / count);
290 lastValidValue = retVal;
283 } 291 }
284 return retVal; 292 return retVal;
285 } 293 }
286 294
287 295
414 } 422 }
415 423
416 #endif 424 #endif
417 /* Private functions ---------------------------------------------------------*/ 425 /* Private functions ---------------------------------------------------------*/
418 426
419 static void tCCR_fallbackToFixedSetpoint(void) 427 static uint8_t tCCR_fallbackToFixedSetpoint(void)
420 { 428 {
429 uint8_t retVal = 0;
421 if((stateUsed->mode == MODE_DIVE) && (stateUsed->diveSettings.diveMode == DIVEMODE_CCR) && (stateUsed->diveSettings.CCR_Mode == CCRMODE_Sensors) && (stateUsed->diveSettings.fallbackOption)) 430 if((stateUsed->mode == MODE_DIVE) && (stateUsed->diveSettings.diveMode == DIVEMODE_CCR) && (stateUsed->diveSettings.CCR_Mode == CCRMODE_Sensors) && (stateUsed->diveSettings.fallbackOption))
422 { 431 {
423 uint8_t setpointCbar, actualGasID; 432 uint8_t setpointCbar, actualGasID;
424 433
425 setpointCbar = stateUsed->diveSettings.setpoint[1].setpoint_cbar; 434 setpointCbar = stateUsed->diveSettings.setpoint[1].setpoint_cbar;
427 436
428 actualGasID = stateUsed->lifeData.actualGas.GasIdInSettings; 437 actualGasID = stateUsed->lifeData.actualGas.GasIdInSettings;
429 setActualGas_DM(&stateUsedWrite->lifeData,actualGasID,setpointCbar); 438 setActualGas_DM(&stateUsedWrite->lifeData,actualGasID,setpointCbar);
430 439
431 set_warning_fallback(); 440 set_warning_fallback();
432 } 441 retVal = stateUsed->diveSettings.setpoint[1].setpoint_cbar;
433 } 442 }
443 return retVal;
444 }