diff options
author | Robert C. Helling <helling@atdotde.de> | 2021-02-23 22:05:00 +0100 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2021-02-26 08:42:30 -0800 |
commit | fdcfcb1b329a7388fbbd0fa801d61fddb0f961d4 (patch) | |
tree | 7eb0d43f0c40fd12eb3ab934ec3383ef7f81aaf7 /core | |
parent | fb11f8efa668dec74d104375c75c91675ac9b87f (diff) | |
download | subsurface-fdcfcb1b329a7388fbbd0fa801d61fddb0f961d4.tar.gz |
Get O2 right in bailout mode
When doing OC bailout from a CCR dive, there could still
be pO2 sensor readings but those are not valid.
This fixes a problem noticed by Justin Ashworth.
Signed-off-by: Robert C. Helling <helling@atdotde.de>
Diffstat (limited to 'core')
-rw-r--r-- | core/divelist.c | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/core/divelist.c b/core/divelist.c index a62245954..a6debfb20 100644 --- a/core/divelist.c +++ b/core/divelist.c @@ -104,7 +104,7 @@ static int calculate_otu(const struct dive *dive) struct sample *sample = dc->sample + i; struct sample *psample = sample - 1; t = sample->time.seconds - psample->time.seconds; - if (sample->o2sensor[0].mbar) { // if dive computer has o2 sensor(s) (CCR & PSCR) .. + if ((dc->divemode == CCR || dc->divemode == PSCR) && sample->o2sensor[0].mbar) { // if dive computer has o2 sensor(s) (CCR & PSCR) .. po2i = psample->o2sensor[0].mbar; po2f = sample->o2sensor[0].mbar; // ... use data from the first o2 sensor } else { @@ -160,7 +160,7 @@ static double calculate_cns_dive(const struct dive *dive) struct sample *sample = dc->sample + n; struct sample *psample = sample - 1; t = sample->time.seconds - psample->time.seconds; - if (sample->o2sensor[0].mbar) { // if dive computer has o2 sensor(s) (CCR & PSCR) + if ((dc->divemode == CCR || dc->divemode == PSCR) && sample->o2sensor[0].mbar) { // if dive computer has o2 sensor(s) (CCR & PSCR) po2i = psample->o2sensor[0].mbar; po2f = sample->o2sensor[0].mbar; // then use data from the first o2 sensor trueo2 = true; @@ -177,13 +177,13 @@ static double calculate_cns_dive(const struct dive *dive) po2i = lrint(o2 * depth_to_bar(psample->depth.mm, dive)); // (initial) po2 at start of segment po2f = lrint(o2 * depth_to_bar(sample->depth.mm, dive)); // (final) po2 at end of segment } - po2i = (po2i + po2f) / 2; // po2i now holds the mean po2 of initial and final po2 values of segment. + int po2avg = (po2i + po2f) / 2; // po2i now holds the mean po2 of initial and final po2 values of segment. /* Don't increase CNS when po2 below 500 matm */ - if (po2i <= 500) + if (po2avg <= 500) continue; // This formula is the result of fitting two lines to the Log of the NOAA CNS table - rate = po2i <= 1500 ? exp(-11.7853 + 0.00193873 * po2i) : exp(-23.6349 + 0.00980829 * po2i); + rate = po2i <= 1500 ? exp(-11.7853 + 0.00193873 * po2avg) : exp(-23.6349 + 0.00980829 * po2avg); cns += (double) t * rate * 100.0; } return cns; |