Mercurial > public > ostc4
comparison Discovery/Src/check_warning.c @ 969:81049905d829 Evo_2_23
Zusammenf?hren
| author | heinrichsweikamp |
|---|---|
| date | Sun, 19 Jan 2025 12:02:59 +0100 |
| parents | 33e24b77cc6c |
| children | 8507a87f6401 |
comparison
equal
deleted
inserted
replaced
| 968:b9a1710522b1 | 969:81049905d829 |
|---|---|
| 41 #include "tCCR.h" | 41 #include "tCCR.h" |
| 42 #include "tHome.h" | 42 #include "tHome.h" |
| 43 | 43 |
| 44 | 44 |
| 45 #define DEBOUNCE_FALLBACK_TIME_MS (5000u) /* set warning after 5 seconds of pending error condition */ | 45 #define DEBOUNCE_FALLBACK_TIME_MS (5000u) /* set warning after 5 seconds of pending error condition */ |
| 46 #define GUI_BUZZER_TIMEOUT_MS (200u) /* the buzzer should be active while Warning string is shown, but diver may be in a menu... */ | |
| 46 | 47 |
| 47 #define SETPOINT_DECO_START_RANGE_M 3.0 | 48 #define SETPOINT_DECO_START_RANGE_M 3.0 |
| 48 #define SWITCH_DEPTH_LOW_MINIMUM_M 1.0 | 49 #define SWITCH_DEPTH_LOW_MINIMUM_M 1.0 |
| 49 | 50 |
| 50 /* Private variables with access ----------------------------------------------*/ | 51 /* Private variables with access ----------------------------------------------*/ |
| 51 static uint8_t betterGasId = 0; | 52 static uint8_t betterGasId = 0; |
| 52 static uint8_t betterBailoutGasId = 0; | 53 static uint8_t betterBailoutGasId = 0; |
| 53 static uint8_t betterSetpointId = 1; | 54 static uint8_t betterSetpointId = 1; |
| 54 static int8_t fallback = 0; | 55 static int8_t fallback = 0; |
| 55 static uint16_t debounceFallbackTimeMS = 0; | 56 static uint16_t debounceFallbackTimeMS = 0; |
| 57 static uint8_t buzzerRequestActive = 0; | |
| 56 | 58 |
| 57 /* Private function prototypes -----------------------------------------------*/ | 59 /* Private function prototypes -----------------------------------------------*/ |
| 58 static int8_t check_fallback(SDiveState * pDiveState); | 60 static int8_t check_fallback(SDiveState * pDiveState); |
| 59 static int8_t check_ppO2(SDiveState * pDiveState); | 61 static int8_t check_ppO2(SDiveState * pDiveState); |
| 60 static int8_t check_O2_sensors(SDiveState * pDiveState); | 62 static int8_t check_O2_sensors(SDiveState * pDiveState); |
| 73 #endif | 75 #endif |
| 74 static int8_t check_helper_same_oxygen_and_helium_content(SGasLine * gas1, SGasLine * gas2); | 76 static int8_t check_helper_same_oxygen_and_helium_content(SGasLine * gas1, SGasLine * gas2); |
| 75 #ifdef HAVE_DEBUG_WARNINGS | 77 #ifdef HAVE_DEBUG_WARNINGS |
| 76 static int8_t check_debug(SDiveState * pDiveState); | 78 static int8_t check_debug(SDiveState * pDiveState); |
| 77 #endif | 79 #endif |
| 78 | 80 static uint8_t buzzerOn = 0; /* current state of the buzzer */ |
| 79 | 81 |
| 82 static void setBuzzer(int8_t warningActive); | |
| 80 /* Exported functions --------------------------------------------------------*/ | 83 /* Exported functions --------------------------------------------------------*/ |
| 81 | 84 |
| 85 void requestBuzzerActivation(uint8_t active) | |
| 86 { | |
| 87 buzzerRequestActive = active; | |
| 88 } | |
| 89 | |
| 90 uint8_t getBuzzerActivationState() | |
| 91 { | |
| 92 return buzzerOn; | |
| 93 } | |
| 94 | |
| 95 static void setBuzzer(int8_t warningActive) | |
| 96 { | |
| 97 static uint32_t guiTimeoutCnt = 0; /* max delay till buzzer will be activated independend from gui request */ | |
| 98 static uint32_t stateTick = 0; /* activation tick of current state */ | |
| 99 static uint8_t lastWarningState = 0; /* the parameter value of the last call*/ | |
| 100 | |
| 101 uint32_t tick = HAL_GetTick(); | |
| 102 | |
| 103 if(warningActive) | |
| 104 { | |
| 105 if(!lastWarningState) /* init structures */ | |
| 106 { | |
| 107 guiTimeoutCnt = tick; | |
| 108 stateTick = tick; | |
| 109 } | |
| 110 if(buzzerOn) | |
| 111 { | |
| 112 if(time_elapsed_ms(stateTick, tick) > EXT_INTERFACE_BUZZER_STABLE_TIME_MS) /* buzzer has to be on for a certain time */ | |
| 113 { | |
| 114 if((!buzzerRequestActive) || (time_elapsed_ms(stateTick, tick) > EXT_INTERFACE_BUZZER_ON_TIME_MS)) | |
| 115 { | |
| 116 buzzerOn = 0; | |
| 117 stateTick = tick; | |
| 118 guiTimeoutCnt = tick; | |
| 119 } | |
| 120 } | |
| 121 } | |
| 122 else | |
| 123 { | |
| 124 if(time_elapsed_ms(stateTick, tick) > EXT_INTERFACE_BUZZER_STABLE_TIME_MS) /* buzzer has to be off for a certain time */ | |
| 125 { | |
| 126 if((buzzerRequestActive) || (time_elapsed_ms(guiTimeoutCnt, tick) > EXT_INTERFACE_BUZZER_ON_TIME_MS + GUI_BUZZER_TIMEOUT_MS)) | |
| 127 { | |
| 128 buzzerOn = 1; | |
| 129 stateTick = tick; | |
| 130 } | |
| 131 } | |
| 132 } | |
| 133 } | |
| 134 else | |
| 135 { | |
| 136 buzzerOn = 0; | |
| 137 } | |
| 138 lastWarningState = warningActive; | |
| 139 } | |
| 140 | |
| 82 void check_warning(void) | 141 void check_warning(void) |
| 83 { | 142 { |
| 84 check_warning2(stateUsedWrite); | 143 check_warning2(stateUsedWrite); |
| 85 } | 144 } |
| 86 | 145 |
| 87 | 146 |
| 88 void check_warning2(SDiveState * pDiveState) | 147 void check_warning2(SDiveState * pDiveState) |
| 89 { | 148 { |
| 90 pDiveState->warnings.numWarnings = 0; | 149 pDiveState->warnings.numWarnings = 0; |
| 91 | 150 |
| 92 pDiveState->warnings.numWarnings += check_aGF(pDiveState); | 151 /* Warnings checked before the SetBuzzer call will activate the buzzer */ |
| 93 pDiveState->warnings.numWarnings += check_AscentRate(pDiveState); | 152 pDiveState->warnings.numWarnings += check_AscentRate(pDiveState); |
| 94 pDiveState->warnings.numWarnings += check_CNS(pDiveState); | |
| 95 pDiveState->warnings.numWarnings += check_Deco(pDiveState); | 153 pDiveState->warnings.numWarnings += check_Deco(pDiveState); |
| 96 pDiveState->warnings.numWarnings += check_ppO2(pDiveState); | 154 pDiveState->warnings.numWarnings += check_ppO2(pDiveState); |
| 97 pDiveState->warnings.numWarnings += check_O2_sensors(pDiveState); | 155 pDiveState->warnings.numWarnings += check_O2_sensors(pDiveState); |
| 156 pDiveState->warnings.numWarnings += check_fallback(pDiveState); | |
| 157 #ifdef ENABLE_CO2_SUPPORT | |
| 158 pDiveState->warnings.numWarnings += check_co2(pDiveState); | |
| 159 #endif | |
| 160 | |
| 161 if(settingsGetPointer()->warningBuzzer) | |
| 162 { | |
| 163 setBuzzer(pDiveState->warnings.numWarnings); | |
| 164 } | |
| 165 | |
| 166 /* Warnings checked after this line will not cause activation of the buzzer */ | |
| 167 pDiveState->warnings.numWarnings += check_aGF(pDiveState); | |
| 168 pDiveState->warnings.numWarnings += check_CNS(pDiveState); | |
| 98 pDiveState->warnings.numWarnings += check_BetterGas(pDiveState); | 169 pDiveState->warnings.numWarnings += check_BetterGas(pDiveState); |
| 99 pDiveState->warnings.numWarnings += check_BetterSetpoint(pDiveState); | 170 pDiveState->warnings.numWarnings += check_BetterSetpoint(pDiveState); |
| 100 pDiveState->warnings.numWarnings += check_Battery(pDiveState); | 171 pDiveState->warnings.numWarnings += check_Battery(pDiveState); |
| 101 pDiveState->warnings.numWarnings += check_fallback(pDiveState); | |
| 102 #ifdef ENABLE_BOTTLE_SENSOR | 172 #ifdef ENABLE_BOTTLE_SENSOR |
| 103 pDiveState->warnings.numWarnings += check_pressureSensor(pDiveState); | 173 pDiveState->warnings.numWarnings += check_pressureSensor(pDiveState); |
| 104 #endif | 174 #endif |
| 105 #ifdef ENABLE_CO2_SUPPORT | 175 |
| 106 pDiveState->warnings.numWarnings += check_co2(pDiveState); | |
| 107 #endif | |
| 108 #ifdef HAVE_DEBUG_WARNINGS | 176 #ifdef HAVE_DEBUG_WARNINGS |
| 109 pDiveState->warnings.numWarnings += check_debug(pDiveState); | 177 pDiveState->warnings.numWarnings += check_debug(pDiveState); |
| 110 #endif | 178 #endif |
| 111 } | 179 } |
| 112 | 180 |
| 162 } | 230 } |
| 163 | 231 |
| 164 | 232 |
| 165 static int8_t check_ppO2(SDiveState * pDiveState) | 233 static int8_t check_ppO2(SDiveState * pDiveState) |
| 166 { | 234 { |
| 167 if((pDiveState->mode != MODE_DIVE) || (pDiveState->warnings.fallback)) | 235 if((pDiveState->mode != MODE_DIVE) || ((isLoopMode(pDiveState->diveSettings.diveMode) && (pDiveState->warnings.fallback)))) |
| 168 { | 236 { |
| 169 pDiveState->warnings.ppO2Low = 0; | 237 pDiveState->warnings.ppO2Low = 0; |
| 170 pDiveState->warnings.ppO2High = 0; | 238 pDiveState->warnings.ppO2High = 0; |
| 171 return 0; | 239 return 0; |
| 172 } | 240 } |
| 206 pDiveState->warnings.sensorOutOfBounds[0] = 0; | 274 pDiveState->warnings.sensorOutOfBounds[0] = 0; |
| 207 pDiveState->warnings.sensorOutOfBounds[1] = 0; | 275 pDiveState->warnings.sensorOutOfBounds[1] = 0; |
| 208 pDiveState->warnings.sensorOutOfBounds[2] = 0; | 276 pDiveState->warnings.sensorOutOfBounds[2] = 0; |
| 209 | 277 |
| 210 if(isLoopMode(pDiveState->diveSettings.diveMode) && (pDiveState->diveSettings.CCR_Mode == CCRMODE_Sensors)) | 278 if(isLoopMode(pDiveState->diveSettings.diveMode) && (pDiveState->diveSettings.CCR_Mode == CCRMODE_Sensors)) |
| 211 | 279 { |
| 212 if(settingsGetPointer()->ppo2sensors_source == O2_SENSOR_SOURCE_OPTIC) | 280 if(settingsGetPointer()->ppo2sensors_source == O2_SENSOR_SOURCE_OPTIC) |
| 213 { | 281 { |
| 214 { | 282 { |
| 215 if(!get_HUD_battery_voltage_V()) | 283 if(!get_HUD_battery_voltage_V()) |
| 216 pDiveState->warnings.sensorLinkLost = 1; | 284 pDiveState->warnings.sensorLinkLost = 1; |
| 217 } | 285 } |
| 218 } | 286 } |
| 219 test_O2_sensor_values_outOfBounds(&pDiveState->warnings.sensorOutOfBounds[0], &pDiveState->warnings.sensorOutOfBounds[1], &pDiveState->warnings.sensorOutOfBounds[2]); | 287 test_O2_sensor_values_outOfBounds(&pDiveState->warnings.sensorOutOfBounds[0], &pDiveState->warnings.sensorOutOfBounds[1], &pDiveState->warnings.sensorOutOfBounds[2]); |
| 288 } | |
| 220 return pDiveState->warnings.sensorLinkLost | 289 return pDiveState->warnings.sensorLinkLost |
| 221 + pDiveState->warnings.sensorOutOfBounds[0] | 290 + pDiveState->warnings.sensorOutOfBounds[0] |
| 222 + pDiveState->warnings.sensorOutOfBounds[1] | 291 + pDiveState->warnings.sensorOutOfBounds[1] |
| 223 + pDiveState->warnings.sensorOutOfBounds[2]; | 292 + pDiveState->warnings.sensorOutOfBounds[2]; |
| 224 } | 293 } |
