summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Linus Torvalds <torvalds@linux-foundation.org>2011-09-03 13:36:25 -0700
committerGravatar Linus Torvalds <torvalds@linux-foundation.org>2011-09-03 13:36:25 -0700
commit2804dc42d81a728c62b173f55bbfc075cf643a00 (patch)
tree2b673a917aa72edec0dd51c66b216b62161805e9
parent1e75ceac0dbbf6a6eef1e13f076c3ae6a7af4c55 (diff)
downloadsubsurface-2804dc42d81a728c62b173f55bbfc075cf643a00.tar.gz
Only update mean/max depths with computed ones if they are way off
The computer may track "real" max depth more closely than it tracks samples. So we trust the non-computed mean/max depths more than the computed ones. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--dive.c29
1 files changed, 27 insertions, 2 deletions
diff --git a/dive.c b/dive.c
index 2ecd10cb0..70d6d4269 100644
--- a/dive.c
+++ b/dive.c
@@ -3,6 +3,30 @@
#include "dive.h"
+/*
+ * So when we re-calculate maxdepth and meandepth, we will
+ * not override the old numbers if they are close to the
+ * new ones.
+ *
+ * Why? Because a dive computer may well actually track the
+ * max depth and mean depth at finer granularity than the
+ * samples it stores. So it's possible that the max and mean
+ * have been reported more correctly originally.
+ *
+ * Only if the values calulcated from the samples are clearly
+ * different do we override the normal depth values.
+ *
+ * This considers 1m to be "clearly different". That's
+ * a totally random number.
+ */
+static void update_depth(depth_t *depth, int new)
+{
+ int old = depth->mm;
+
+ if (abs(old - new) > 1000)
+ depth->mm = new;
+}
+
struct dive *fixup_dive(struct dive *dive)
{
int i;
@@ -50,15 +74,16 @@ struct dive *fixup_dive(struct dive *dive)
return dive;
dive->duration.seconds = end - start;
if (start != end)
- dive->meandepth.mm = depthtime / (end - start);
+ update_depth(&dive->meandepth, depthtime / (end - start));
if (startpress)
dive->beginning_pressure.mbar = startpress;
if (endpress)
dive->end_pressure.mbar = endpress;
if (mintemp)
dive->watertemp.mkelvin = mintemp;
+
if (maxdepth)
- dive->maxdepth.mm = maxdepth;
+ update_depth(&dive->maxdepth, maxdepth);
return dive;
}