summaryrefslogtreecommitdiffstats
path: root/dive.c
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2014-01-11 21:57:06 +0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-01-11 22:02:35 +0700
commit23973e8abdfb1354de9920cc1c5896a4fc84d25b (patch)
tree35a075ce121e5849c37f179157e98a21a5cf3951 /dive.c
parentf43a3052cb3eb0bb87ea81f15e4a02487a5ed8ec (diff)
downloadsubsurface-23973e8abdfb1354de9920cc1c5896a4fc84d25b.tar.gz
Don't show tanks that aren't used during a dive
Some dive computers will always download all tanks that they store, not just the ones used in a dive. Most people only want to see the tanks that they actually used during the dive (and for the others there's an option to go back to the old behavior, just in case). All this is only in memory / during runtime. If the dive computer provided the extra data we will not throw it away. Fixes #373 Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'dive.c')
-rw-r--r--dive.c28
1 files changed, 27 insertions, 1 deletions
diff --git a/dive.c b/dive.c
index 5a10af595..1a9bdd97a 100644
--- a/dive.c
+++ b/dive.c
@@ -594,6 +594,32 @@ static struct event *find_previous_event(struct divecomputer *dc, struct event *
return previous;
}
+/* mark all tanks that we switch to in this dive computer's data as used */
+static void mark_used_tanks(struct dive *dive, struct divecomputer *dc)
+{
+ struct event *ev = get_next_event(dc->events, "gaschange");
+ // unless there is a gas change in the first 30 seconds we can
+ // always mark the first cylinder as used
+ if (!ev || ev->time.seconds > 30)
+ dive->cylinder[0].used = true;
+ while (ev) {
+ int idx = get_cylinder_index(dive, ev);
+ dive->cylinder[idx].used = true;
+ ev = get_next_event(ev->next, "gaschange");
+ }
+}
+
+/* walk all divecomputers to find the unused tanks in this dive */
+static void check_for_unused_tanks(struct dive *dive)
+{
+ int i;
+ struct divecomputer *dc;
+
+ for_each_dc(dive, dc) {
+ mark_used_tanks(dive, dc);
+ }
+}
+
static void fixup_surface_pressure(struct dive *dive)
{
struct divecomputer *dc;
@@ -879,7 +905,7 @@ struct dive *fixup_dive(struct dive *dive)
fixup_duration(dive);
fixup_watertemp(dive);
fixup_airtemp(dive);
-
+ check_for_unused_tanks(dive);
for (i = 0; i < MAX_CYLINDERS; i++) {
cylinder_t *cyl = dive->cylinder + i;
add_cylinder_description(&cyl->type);