diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2016-08-29 14:07:17 -0700 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2016-08-29 21:43:14 -0700 |
commit | 99d1cecf067daca5d7ed45effac659150e978504 (patch) | |
tree | e281e6c7e5af72ced721e133f057f187d83be057 | |
parent | 1b074838308b6377af1461c4bd69028c193edd17 (diff) | |
download | subsurface-99d1cecf067daca5d7ed45effac659150e978504.tar.gz |
Hacky workaround for multiple gas pressures per sample
In subsurface, we only have one cylinder pressure per sample (well,
technically two: we have a separate o2 pressure for rebreather diving).
Which makes things "interesting" if the dive computer can actually have
multiple pressure sensors, and can report them all concurrently. Like
the Suunto EON Steel.
We used to just take the last one (each sensor reading would just
overwrite any previous ones), and this quick hack just changes the logic
to prefer the "current" cylinder instead.
It's wrong, and it's stupid, but it's the best we can do without major
surgery.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r-- | core/libdivecomputer.c | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/core/libdivecomputer.c b/core/libdivecomputer.c index 5ba445390..90c2c61cb 100644 --- a/core/libdivecomputer.c +++ b/core/libdivecomputer.c @@ -43,6 +43,7 @@ double progress_bar_fraction = 0.0; static int stoptime, stopdepth, ndl, po2, cns; static bool in_deco, first_temp_is_air; +static int current_gas_index; /* * Directly taken from libdivecomputer's examples/common.c to improve @@ -215,6 +216,8 @@ static int parse_gasmixes(device_data_t *devdata, struct dive *dive, dc_parser_t static void handle_event(struct divecomputer *dc, struct sample *sample, dc_sample_value_t value) { int type, time; + struct event *ev; + /* we mark these for translation here, but we store the untranslated strings * and only translate them when they are displayed on screen */ static const char *events[] = { @@ -244,7 +247,9 @@ static void handle_event(struct divecomputer *dc, struct sample *sample, dc_samp if (sample) time += sample->time.seconds; - add_event(dc, time, type, value.event.flags, value.event.value, name); + ev = add_event(dc, time, type, value.event.flags, value.event.value, name); + if (event_is_gaschange(ev) && ev->gas.index >= 0) + current_gas_index = ev->gas.index; } void @@ -293,6 +298,13 @@ sample_cb(dc_sample_type_t type, dc_sample_value_t value, void *userdata) sample->depth.mm = rint(value.depth * 1000); break; case DC_SAMPLE_PRESSURE: + /* Do we already have a pressure reading? */ + if (sample->cylinderpressure.mbar) { + /* Do we prefer the one we already have? */ + /* If so, just ignore the new one */ + if (sample->sensor == current_gas_index) + break; + } sample->sensor = value.pressure.tank; sample->cylinderpressure.mbar = rint(value.pressure.value * 1000); break; @@ -699,6 +711,7 @@ static int dive_cb(const unsigned char *data, unsigned int size, /* reset the deco / ndl data */ ndl = stoptime = stopdepth = 0; in_deco = false; + current_gas_index = -1; rc = create_parser(devdata, &parser); if (rc != DC_STATUS_SUCCESS) { |