summaryrefslogtreecommitdiffstats
path: root/dive.c
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2012-11-10 11:56:28 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2012-11-10 12:02:33 +0100
commite29a43681049ef30eb5129f140a1ed0936a9b516 (patch)
tree4c57c2582e72e42266b7b51ec92276d1b8250347 /dive.c
parent7f515eb7e53c5ab6d8dde4d2e6876464ed7fdeae (diff)
parent6ad73a8f043be283c07df34c6a5a43fee1b444e8 (diff)
downloadsubsurface-e29a43681049ef30eb5129f140a1ed0936a9b516.tar.gz
Merge branch 'ceiling-plot'
This enables plotting the ceiling in deco dives and also adds the necessary code to the uemis importer. The only other dive computer this has been tested with the OSTC and that needs a libdivecomputer patch in order to provide the deco/ceiling information to Subsurface. Fixes #5
Diffstat (limited to 'dive.c')
-rw-r--r--dive.c61
1 files changed, 61 insertions, 0 deletions
diff --git a/dive.c b/dive.c
index ca6fda649..caf1eedfe 100644
--- a/dive.c
+++ b/dive.c
@@ -373,6 +373,30 @@ static void sanitize_cylinder_info(struct dive *dive)
}
}
+/* some events should never be thrown away */
+static gboolean is_potentially_redundant(struct event *event)
+{
+ if (!strcmp(event->name, "gaschange"))
+ return FALSE;
+ return TRUE;
+}
+
+/* match just by name - we compare the details in the code that uses this helper */
+static struct event *find_previous_event(struct dive *dive, struct event *event)
+{
+ struct event *ev = dive->events;
+ struct event *previous = NULL;
+
+ if (!event->name)
+ return NULL;
+ while (ev && ev != event) {
+ if(ev->name && !strcmp(ev->name, event->name))
+ previous = ev;
+ ev = ev->next;
+ }
+ return previous;
+}
+
struct dive *fixup_dive(struct dive *dive)
{
int i,j;
@@ -384,6 +408,7 @@ struct dive *fixup_dive(struct dive *dive)
int lastdepth = 0;
int lasttemp = 0, lastpressure = 0;
int pressure_delta[MAX_CYLINDERS] = {INT_MAX, };
+ struct event *event;
add_people(dive->buddy);
add_people(dive->divemaster);
@@ -514,6 +539,42 @@ struct dive *fixup_dive(struct dive *dive)
add_weightsystem_description(ws);
}
+ /* events are stored as a linked list, so the concept of
+ * "consecutive, identical events" is somewhat hard to
+ * implement correctly (especially given that on some dive
+ * computers events are asynchronous, so they can come in
+ * between what would be the non-constant sample rate).
+ *
+ * So what we do is that we throw away clearly redundant
+ * events that are fewer than 61 seconds apart (assuming there
+ * is no dive computer with a sample rate of more than 60
+ * seconds... that would be pretty pointless to plot the
+ * profile with)
+ * We first only mark the events for deletion so that we
+ * still know when the previous event happened. */
+ event = dive->events;
+ while (event) {
+ struct event *prev;
+ if (is_potentially_redundant(event)) {
+ prev = find_previous_event(dive, event);
+ if (prev && prev->value == event->value &&
+ prev->flags == event->flags &&
+ event->time.seconds - prev->time.seconds < 61)
+ event->deleted = TRUE;
+ }
+ event = event->next;
+ }
+ event = dive->events;
+ while (event) {
+ if (event->next && event->next->deleted) {
+ struct event *nextnext = event->next->next;
+ free(event->next);
+ event->next = nextnext;
+ } else {
+ event = event->next;
+ }
+ }
+
return dive;
}