comparison Discovery/Src/check_warning.c @ 773:2c243233c999

Menu shortcut for bailout / return to circuit when diving in CCR mode (mikeller)
author heinrichsweikamp
date Wed, 10 May 2023 16:24:57 +0200
parents 29d9b5bc7946
children 4abfb8a2a435
comparison
equal deleted inserted replaced
772:b7e43b28bee1 773:2c243233c999
44 #define DEBOUNCE_FALLBACK_TIME_MS (5000u) /* set warning after 5 seconds of pending error condition */ 44 #define DEBOUNCE_FALLBACK_TIME_MS (5000u) /* set warning after 5 seconds of pending error condition */
45 45
46 46
47 /* Private variables with access ----------------------------------------------*/ 47 /* Private variables with access ----------------------------------------------*/
48 static uint8_t betterGasId = 0; 48 static uint8_t betterGasId = 0;
49 static uint8_t betterBailoutGasId = 0;
49 static uint8_t betterSetpointId = 1; 50 static uint8_t betterSetpointId = 1;
50 static int8_t fallback = 0; 51 static int8_t fallback = 0;
51 static uint16_t debounceFallbackTimeMS = 0; 52 static uint16_t debounceFallbackTimeMS = 0;
52 53
53 /* Private function prototypes -----------------------------------------------*/ 54 /* Private function prototypes -----------------------------------------------*/
117 { 118 {
118 return betterGasId; 119 return betterGasId;
119 } 120 }
120 121
121 122
123 uint8_t actualBetterBailoutGasId(void)
124 {
125 return betterBailoutGasId;
126 }
127
128
122 uint8_t actualBetterSetpointId(void) 129 uint8_t actualBetterSetpointId(void)
123 { 130 {
124 return betterSetpointId; 131 return betterSetpointId;
125 } 132 }
126 133
205 + pDiveState->warnings.sensorOutOfBounds[1] 212 + pDiveState->warnings.sensorOutOfBounds[1]
206 + pDiveState->warnings.sensorOutOfBounds[2]; 213 + pDiveState->warnings.sensorOutOfBounds[2];
207 } 214 }
208 215
209 216
210 static int8_t check_BetterGas(SDiveState * pDiveState) 217 static uint8_t getBetterGasId(bool getDiluent, uint8_t startingGasId, SDiveState *diveState)
211 { 218 {
212 if(stateUsed->mode != MODE_DIVE) 219 SDiveSettings diveSettings = diveState->diveSettings;
213 { 220
214 pDiveState->warnings.betterGas = 0; 221 uint8_t betterGasIdLocal = startingGasId;
215 betterGasId = 0; 222 uint8_t bestGasDepth = 255;
216 return 0; 223
217 } 224 uint8_t gasIdOffset;
218 225 if (getDiluent) {
219 uint8_t gasIdOffset; 226 gasIdOffset = NUM_OFFSET_DILUENT;
220 uint8_t bestGasDepth, betterGasIdLocal; 227 } else {
221 228 gasIdOffset = 0;
222 SLifeData* pLifeData = &pDiveState->lifeData; 229 }
223 SDiveSettings* pDiveSettings = &pDiveState->diveSettings;
224
225 pDiveState->warnings.betterGas = 0;
226 betterGasId = 0;
227 betterGasIdLocal = pLifeData->actualGas.GasIdInSettings;
228 bestGasDepth = 255;
229
230 if(isLoopMode(pDiveSettings->diveMode))
231 gasIdOffset = NUM_OFFSET_DILUENT;
232 else
233 gasIdOffset = 0;
234 230
235 /* life data is float, gas data is uint8 */ 231 /* life data is float, gas data is uint8 */
236 if(actualLeftMaxDepth(pDiveState)) /* deco gases */ 232 if (actualLeftMaxDepth(diveState)) { /* deco gases */
237 { 233 for (int i=1+gasIdOffset; i<= 5+gasIdOffset; i++) {
238 for(int i=1+gasIdOffset; i<= 5+gasIdOffset; i++) 234 if ((diveSettings.gas[i].note.ub.active)
239 { 235 && (diveSettings.gas[i].note.ub.deco)
240 if( (pDiveSettings->gas[i].note.ub.active) 236 && (diveSettings.gas[i].depth_meter)
241 && (pDiveSettings->gas[i].note.ub.deco) 237 && (diveSettings.gas[i].depth_meter >= (diveState->lifeData.depth_meter - 0.01f ))
242 && (pDiveSettings->gas[i].depth_meter) 238 && (diveSettings.gas[i].depth_meter <= bestGasDepth)) {
243 && (pDiveSettings->gas[i].depth_meter >= (pLifeData->depth_meter - 0.01f )) 239 betterGasIdLocal = i;
244 && (pDiveSettings->gas[i].depth_meter <= bestGasDepth) 240 bestGasDepth = diveSettings.gas[i].depth_meter;
245 ) 241 }
246 {
247 betterGasIdLocal = i;
248 bestGasDepth = pDiveSettings->gas[i].depth_meter;
249 }
250 }
251
252 if(betterGasIdLocal != pLifeData->actualGas.GasIdInSettings)
253 {
254 if(!check_helper_same_oxygen_and_helium_content(&pDiveSettings->gas[betterGasIdLocal], &pDiveSettings->gas[pLifeData->actualGas.GasIdInSettings]))
255 {
256 betterGasId = betterGasIdLocal;
257 pDiveState->warnings.betterGas = 1;
258 }
259 }
260 }
261 else /* travel gases */
262 {
263 bestGasDepth = 0;
264 //check for travalgas
265 for(int i=1+gasIdOffset; i<= 5+gasIdOffset; i++)
266 {
267 if( (pDiveSettings->gas[i].note.ub.active)
268 && (pDiveSettings->gas[i].note.ub.travel)
269 && (pDiveSettings->gas[i].depth_meter_travel)
270 && (pDiveSettings->gas[i].depth_meter_travel <= (pLifeData->depth_meter + 0.01f ))
271 && (pDiveSettings->gas[i].depth_meter_travel >= bestGasDepth)
272 )
273 {
274 betterGasIdLocal = i;
275 bestGasDepth = pDiveSettings->gas[i].depth_meter;
276 } 242 }
277 } 243 } else { /* travel gases */
278 244 bestGasDepth = 0;
279 if(betterGasIdLocal != pLifeData->actualGas.GasIdInSettings) 245 //check for travalgas
280 { 246 for (int i = 1 + gasIdOffset; i <= 5 + gasIdOffset; i++) {
281 if(!check_helper_same_oxygen_and_helium_content(&pDiveSettings->gas[betterGasIdLocal], &pDiveSettings->gas[pLifeData->actualGas.GasIdInSettings])) 247 if ((diveSettings.gas[i].note.ub.active)
282 { 248 && (diveSettings.gas[i].note.ub.travel)
283 betterGasId = betterGasIdLocal; 249 && (diveSettings.gas[i].depth_meter_travel)
284 pDiveState->warnings.betterGas = 1; 250 && (diveSettings.gas[i].depth_meter_travel <= (diveState->lifeData.depth_meter + 0.01f ))
285 } 251 && (diveSettings.gas[i].depth_meter_travel >= bestGasDepth)) {
286 } 252 betterGasIdLocal = i;
287 } 253 bestGasDepth = diveSettings.gas[i].depth_meter;
288 return pDiveState->warnings.betterGas; 254 }
255 }
256 }
257
258 return betterGasIdLocal;
259 }
260
261
262 static int8_t check_BetterGas(SDiveState *diveState)
263 {
264 diveState->warnings.betterGas = 0;
265
266 if (stateUsed->mode != MODE_DIVE) {
267 betterGasId = 0;
268
269 return 0;
270 }
271
272 SDiveSettings diveSettings = diveState->diveSettings;
273 SLifeData lifeData = diveState->lifeData;
274
275 if (isLoopMode(diveSettings.diveMode)) {
276 betterGasId = getBetterGasId(true, lifeData.actualGas.GasIdInSettings, diveState);
277 betterBailoutGasId = getBetterGasId(false, lifeData.lastDiluent_GasIdInSettings, diveState);
278 } else {
279 betterGasId = getBetterGasId(false, lifeData.actualGas.GasIdInSettings, diveState);
280 }
281
282 if (betterGasId != lifeData.actualGas.GasIdInSettings && !check_helper_same_oxygen_and_helium_content(&diveSettings.gas[betterGasId], &diveSettings.gas[lifeData.actualGas.GasIdInSettings])) {
283 diveState->warnings.betterGas = 1;
284 }
285
286 return diveState->warnings.betterGas;
289 } 287 }
290 288
291 289
292 uint8_t getSetpointLowId(void) 290 uint8_t getSetpointLowId(void)
293 { 291 {