summaryrefslogtreecommitdiffstats
path: root/dive.c
diff options
context:
space:
mode:
authorGravatar Linus Torvalds <torvalds@linux-foundation.org>2012-11-17 11:20:10 -1000
committerGravatar Dirk Hohndel <dirk@hohndel.org>2012-11-19 12:02:30 -0800
commit8a45a3ffb9e55b29cb7bdd056ba60eb7968e8fcd (patch)
tree4cf0c76e7249dee752b5ffa1a822952aa7640f5e /dive.c
parentd166e34fed53786000b9afa353e806b918d53714 (diff)
downloadsubsurface-8a45a3ffb9e55b29cb7bdd056ba60eb7968e8fcd.tar.gz
When merging non-overlapping dives, add surface events in between
Most of the dive computers I have access to don't do the whole surface event thing at the beginning or the end of the dive, so when you merge two consecutive dives, you got this odd merged dive where the diver spent the time in between at a depth of 1.2m or so (whatever the dive computer "I'm now under water" depth limit happens to be). Don't do that. Add surface events at the end of the first dive to be merged, and the beginning of the second one, so that the time in between dives is properly marked as being at the surface. The logic for "time in between dives" is a bit iffy - it's "more than 60 seconds with no samples". If somebody has dive computers with samples more than 60 seconds apart, this will break and we may have to revisit the logic. But dang, that's some seriously broken sample rate. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'dive.c')
-rw-r--r--dive.c29
1 files changed, 26 insertions, 3 deletions
diff --git a/dive.c b/dive.c
index 15038bd9e..ae9ecde00 100644
--- a/dive.c
+++ b/dive.c
@@ -606,6 +606,29 @@ static struct dive *add_sample(struct sample *sample, int time, struct dive *div
}
/*
+ * This is like add_sample(), but if the distance from the last sample
+ * is excessive, we add two surface samples in between.
+ *
+ * This is so that if you merge two non-overlapping dives, we make sure
+ * that the time in between the dives is at the surface, not some "last
+ * sample that happened to be at a depth of 1.2m".
+ */
+static struct dive *merge_one_sample(struct sample *sample, int time, struct dive *dive)
+{
+ int last = dive->samples-1;
+ if (last >= 0) {
+ static struct sample surface;
+ int last_time = dive->sample[last].time.seconds;
+ if (time > last_time + 60) {
+ dive = add_sample(&surface, last_time+20, dive);
+ dive = add_sample(&surface, time - 20, dive);
+ }
+ }
+ return add_sample(sample, time, dive);
+}
+
+
+/*
* Merge samples. Dive 'a' is "offset" seconds before Dive 'b'
*/
static struct dive *merge_samples(struct dive *res, struct dive *a, struct dive *b, int offset)
@@ -647,7 +670,7 @@ static struct dive *merge_samples(struct dive *res, struct dive *a, struct dive
/* Only samples from a? */
if (bt < 0) {
add_sample_a:
- res = add_sample(as, at, res);
+ res = merge_one_sample(as, at, res);
as++;
asamples--;
continue;
@@ -656,7 +679,7 @@ add_sample_a:
/* Only samples from b? */
if (at < 0) {
add_sample_b:
- res = add_sample(bs, bt, res);
+ res = merge_one_sample(bs, bt, res);
bs++;
bsamples--;
continue;
@@ -678,7 +701,7 @@ add_sample_b:
if (as->cylinderindex)
sample.cylinderindex = as->cylinderindex;
- res = add_sample(&sample, at, res);
+ res = merge_one_sample(&sample, at, res);
as++;
bs++;