From b48eb4717810f53b13145525974086b3fdcc04c4 Mon Sep 17 00:00:00 2001 From: Anton Lundin Date: Mon, 5 Mar 2018 21:21:28 +0100 Subject: 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 Signed-off-by: Anton Lundin --- core/dive.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'core') 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) -- cgit v1.2.3-70-g09d2