diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2016-04-02 16:07:06 -0500 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2016-04-04 22:37:18 -0700 |
commit | eff405980214d8324d5448b5ed9e80a96addde9c (patch) | |
tree | 715d7d0f6e731361d69441724fe12fd6aa7f02ab /core/save-git.c | |
parent | e0824ef9f3e2a0cc0fae435b8e3560b309d9708e (diff) | |
download | subsurface-eff405980214d8324d5448b5ed9e80a96addde9c.tar.gz |
Start using the actual cylinder data for gas switch events
Now that gas switch events always have indices into the cylinder table,
start using that to look up the gas mix from the cylinders rather than
from the gas switch event itself. In other words, the cylinder index is
now the primary data for gas switch events.
This means that now as you change the cylinder information, the gas
switch events will automatically update to reflect those changes.
Note that on loading data from the outside (either from a xml file, from
a git/cloud account, or from a dive computer), we may or may not
initially have an index for the gas change event. The external data may
be from an older version of subsurface, or it may be from a
libdivecomputer download that just doesn't give index data at all.
In that case, we will do:
- if there is no index, but there is explicit gas mix information, we
will look up the index based on that gas mix, picking the cylinder
that has the closest mix.
- if there isn't even explicit gas mix data, so we only have the event
value from libdivecomputer, we will turn that value into a gasmix,
and use that to look up the cylinder index as above.
- if no valid cylinder information is available at all, gas switch
events will just be dropped.
When saving the data, we now always save the cylinder index, and the gas
mix associated with that cylinder (that gas mix will be ignored on load,
since the index is the primary, but it makes the event much easier to
read).
It is worth noting we do not modify the libdivecomputer value, even if
the gasmix has changed, so that remains as a record of the original
download.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'core/save-git.c')
-rw-r--r-- | core/save-git.c | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/core/save-git.c b/core/save-git.c index ed91debf4..f2803c315 100644 --- a/core/save-git.c +++ b/core/save-git.c @@ -220,10 +220,15 @@ static void show_date(struct membuffer *b, timestamp_t when) tm.tm_hour, tm.tm_min, tm.tm_sec); } +static void show_integer(struct membuffer *b, int value, const char *pre, const char *post) +{ + put_format(b, " %s%d%s", pre, value, post); +} + static void show_index(struct membuffer *b, int value, const char *pre, const char *post) { if (value) - put_format(b, " %s%d%s", pre, value, post); + show_integer(b, value, pre, post); } /* @@ -314,7 +319,7 @@ static void save_samples(struct membuffer *b, int nr, struct sample *s) } } -static void save_one_event(struct membuffer *b, struct event *ev) +static void save_one_event(struct membuffer *b, struct dive *dive, struct event *ev) { put_format(b, "event %d:%02d", FRACTION(ev->time.seconds, 60)); show_index(b, ev->type, "type=", ""); @@ -322,19 +327,18 @@ static void save_one_event(struct membuffer *b, struct event *ev) show_index(b, ev->value, "value=", ""); show_utf8(b, " name=", ev->name, ""); if (event_is_gaschange(ev)) { - if (ev->gas.index >= 0) { - show_index(b, ev->gas.index, "cylinder=", ""); - put_gasmix(b, &ev->gas.mix); - } else - put_gasmix(b, &ev->gas.mix); + struct gasmix *mix = get_gasmix_from_event(dive, ev); + if (ev->gas.index >= 0) + show_integer(b, ev->gas.index, "cylinder=", ""); + put_gasmix(b, mix); } put_string(b, "\n"); } -static void save_events(struct membuffer *b, struct event *ev) +static void save_events(struct membuffer *b, struct dive *dive, struct event *ev) { while (ev) { - save_one_event(b, ev); + save_one_event(b, dive, ev); ev = ev->next; } } @@ -362,7 +366,7 @@ static void save_dc(struct membuffer *b, struct dive *dive, struct divecomputer put_duration(b, dc->surfacetime, "surfacetime ", "min\n"); save_extra_data(b, dc->extra_data); - save_events(b, dc->events); + save_events(b, dive, dc->events); save_samples(b, dc->samples, dc->sample); } |