comparison Discovery/Src/check_warning.c @ 831:da632300e7d4 Evo_2_23

Activated work gas for (p)scr mode: In previous version setting of change depth for work (travel) gases was not possible. For (p)scr operation this is not possible. Work gases will not be considered for deco calculation. In addition the first gas will be handled as "deco" gas. This allows switching back to the first gas in case the current gas becomes no longer breathable (ppo2 low).
author Ideenmodellierer
date Thu, 16 Nov 2023 20:36:35 +0100
parents 4abfb8a2a435
children ba1aebc6d5af
comparison
equal deleted inserted replaced
830:b7d93ff6b3b2 831:da632300e7d4
218 218
219 219
220 static uint8_t getBetterGasId(bool getDiluent, uint8_t startingGasId, SDiveState *diveState) 220 static uint8_t getBetterGasId(bool getDiluent, uint8_t startingGasId, SDiveState *diveState)
221 { 221 {
222 SDiveSettings diveSettings = diveState->diveSettings; 222 SDiveSettings diveSettings = diveState->diveSettings;
223 223 SGasLine localGas;
224 uint8_t betterGasIdLocal = startingGasId; 224 uint8_t betterGasIdLocal = startingGasId;
225 uint8_t bestGasDepth = 255; 225 uint8_t bestGasDepth = 255;
226 uint8_t i;
226 227
227 uint8_t gasIdOffset; 228 uint8_t gasIdOffset;
228 if (getDiluent) { 229 if (getDiluent) {
229 gasIdOffset = NUM_OFFSET_DILUENT; 230 gasIdOffset = NUM_OFFSET_DILUENT;
230 } else { 231 } else {
231 gasIdOffset = 0; 232 gasIdOffset = 0;
232 } 233 }
233 234
234 /* life data is float, gas data is uint8 */ 235 /* life data is float, gas data is uint8 */
235 if (actualLeftMaxDepth(diveState)) { /* deco gases */ 236 if (actualLeftMaxDepth(diveState)) { /* deco gases */
236 for (int i=1+gasIdOffset; i<= 5+gasIdOffset; i++) { 237 for (i=1+gasIdOffset; i<= 5+gasIdOffset; i++) {
237 if ((diveSettings.gas[i].note.ub.active) 238 memcpy(&localGas,&diveSettings.gas[i],sizeof(SGasLine));
238 && (diveSettings.gas[i].note.ub.deco) 239 if((localGas.note.ub.first) && (diveSettings.diveMode == DIVEMODE_PSCR)) /* handle first gas as if it would be a deco gas set to MOD */
239 && (diveSettings.gas[i].depth_meter) 240 {
240 && (diveSettings.gas[i].depth_meter >= (diveState->lifeData.depth_meter - 0.01f )) 241 localGas.note.ub.active = 1;
241 && (diveSettings.gas[i].depth_meter <= bestGasDepth)) { 242 localGas.note.ub.deco = 1;
243 localGas.depth_meter = calc_MOD(i);
244 }
245 if ((localGas.note.ub.active)
246 && (localGas.note.ub.deco)
247 && (localGas.depth_meter)
248 && (localGas.depth_meter >= (diveState->lifeData.depth_meter - 0.01f ))
249 && (localGas.depth_meter <= bestGasDepth)) {
242 betterGasIdLocal = i; 250 betterGasIdLocal = i;
243 bestGasDepth = diveSettings.gas[i].depth_meter; 251 bestGasDepth = diveSettings.gas[i].depth_meter;
244 } 252 }
245 } 253 }
246 } else { /* travel gases */ 254 } else { /* travel gases */
247 bestGasDepth = 0; 255 bestGasDepth = 0;
248 //check for travalgas 256 //check for travalgas
249 for (int i = 1 + gasIdOffset; i <= 5 + gasIdOffset; i++) { 257 for (i = 1 + gasIdOffset; i <= 5 + gasIdOffset; i++) {
250 if ((diveSettings.gas[i].note.ub.active) 258 if ((diveSettings.gas[i].note.ub.active)
251 && (diveSettings.gas[i].note.ub.travel) 259 && (diveSettings.gas[i].note.ub.travel)
252 && (diveSettings.gas[i].depth_meter_travel) 260 && (diveSettings.gas[i].depth_meter_travel)
253 && (diveSettings.gas[i].depth_meter_travel <= (diveState->lifeData.depth_meter + 0.01f )) 261 && (diveSettings.gas[i].depth_meter_travel <= (diveState->lifeData.depth_meter + 0.01f ))
254 && (diveSettings.gas[i].depth_meter_travel >= bestGasDepth)) { 262 && (diveSettings.gas[i].depth_meter_travel >= bestGasDepth)) {
255 betterGasIdLocal = i; 263 betterGasIdLocal = i;
256 bestGasDepth = diveSettings.gas[i].depth_meter; 264 bestGasDepth = diveSettings.gas[i].depth_meter;
257 } 265 }
258 } 266 }
259 } 267 }
268 if((!getDiluent) && (betterGasIdLocal > NUM_OFFSET_DILUENT)) /* an OC gas was requested but Id is pointing to a diluent => return first OC */
269 {
270 for (i = 1 ; i <= NUM_OFFSET_DILUENT; i++)
271 {
272 if(diveSettings.gas[i].note.ub.first)
273 {
274 betterGasIdLocal = i;
275 break;
276 }
277 }
278 }
279
260 280
261 return betterGasIdLocal; 281 return betterGasIdLocal;
262 } 282 }
263 283
264 284
556 #endif 576 #endif
557 577
558 #ifdef ENABLE_CO2_SUPPORT 578 #ifdef ENABLE_CO2_SUPPORT
559 static int8_t check_co2(SDiveState * pDiveState) 579 static int8_t check_co2(SDiveState * pDiveState)
560 { 580 {
561 if(pDiveState->mode != MODE_DIVE) 581 if((pDiveState->mode != MODE_DIVE) || (settingsGetPointer()->co2_sensor_active == 0))
562 { 582 {
563 pDiveState->warnings.co2High = 0; 583 pDiveState->warnings.co2High = 0;
564 } 584 }
565 else 585 else
566 { 586 {