diff options
author | Anton Lundin <glance@acc.umu.se> | 2018-03-05 21:21:28 +0100 |
---|---|---|
committer | Lubomir I. Ivanov <neolit123@gmail.com> | 2018-03-13 18:54:16 +0200 |
commit | b48eb4717810f53b13145525974086b3fdcc04c4 (patch) | |
tree | 5830db0b6fa630201e779d3bae4a48c38e812fac /core | |
parent | 15b6953438fd45921fe7adc16995eb89d25339a9 (diff) | |
download | subsurface-b48eb4717810f53b13145525974086b3fdcc04c4.tar.gz |
Fix up CCR/PSCR dives with sensors values without no_o2sensors
This introduces a fixup function that walks all the samples and
populates the no_o2sensors if its zero and supposed to be something
else.
There is a bug somewhere which Willem hit, causing this to never be set.
Reported-by: Willem Ferguson <willemferguson@zoology.up.ac.za>
Signed-off-by: Anton Lundin <glance@acc.umu.se>
Diffstat (limited to 'core')
-rw-r--r-- | core/dive.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/core/dive.c b/core/dive.c index 900677eb4..7866962d4 100644 --- a/core/dive.c +++ b/core/dive.c @@ -1642,6 +1642,34 @@ static void fixup_dc_gasswitch(struct dive *dive, struct divecomputer *dc) } } +static void fixup_no_o2sensors(struct divecomputer *dc) +{ + // Its only relevant to look for sensor values on CCR and PSCR dives without any no_o2sensors recorded. + if (dc->no_o2sensors != 0 || !(dc->divemode == CCR || dc->divemode == PSCR)) + return; + + for (int i = 0; i < dc->samples; i++) { + int nsensor = 0; + struct sample *s = dc->sample + i; + + // How many o2 sensors can we find in this sample? + if (s->o2sensor[0].mbar) + nsensor++; + if (s->o2sensor[1].mbar) + nsensor++; + if (s->o2sensor[2].mbar) + nsensor++; + + // If we fond more than the previous found max, record it. + if (nsensor > dc->no_o2sensors) + dc->no_o2sensors = nsensor; + + // Already found the maximum posible amount. + if (nsensor == 3) + return; + } +} + static void fixup_dive_dc(struct dive *dive, struct divecomputer *dc) { /* Add device information to table */ @@ -1667,6 +1695,9 @@ static void fixup_dive_dc(struct dive *dive, struct divecomputer *dc) fixup_dive_pressures(dive, dc); fixup_dc_events(dc); + + /* Fixup CCR / PSCR dives with o2sensor values, but without no_o2sensors */ + fixup_no_o2sensors(dc); } struct dive *fixup_dive(struct dive *dive) |