summaryrefslogtreecommitdiffstats
path: root/dive.c
diff options
context:
space:
mode:
authorGravatar Linus Torvalds <torvalds@linux-foundation.org>2011-11-10 21:33:38 -0200
committerGravatar Linus Torvalds <torvalds@linux-foundation.org>2011-11-10 21:33:38 -0200
commitb4938ec2de87c3a43b749a1607d3bacb17d37cff (patch)
treeb703335d280e9cc9d214934fef0720bcbd115044 /dive.c
parent2b0f30c3d4773d4e78daf7e2ce76f5c3f3a2d0b3 (diff)
downloadsubsurface-b4938ec2de87c3a43b749a1607d3bacb17d37cff.tar.gz
Make the sample-vs-cylinder pressure check more liberal
This makes it consider them to be identical if they are within half a bar of each other. If you edit the pressures by hand and set them to the same bar pressure as the samples, they may not be identical to the last milli-bar, but clearly the manually entered cylinder pressure isn't significantly different from the sample data, so consider it redundant. We do want manual overrides of cylinder pressures to take precedence over sample data (as Dirk so eloquently puts it, some dive computers really don't have very reliable sample data), but at the same time the sample data is the one we are expecting to be fairly accurate. The starting and ending pressure overrides are for when there is no sample data, or when the sample data is totally wrong for some reason. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'dive.c')
-rw-r--r--dive.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/dive.c b/dive.c
index bd1b92619..dad0e237b 100644
--- a/dive.c
+++ b/dive.c
@@ -224,6 +224,16 @@ static void fixup_pressure(struct dive *dive, struct sample *sample)
cyl->sample_end.mbar = pressure;
}
+/*
+ * If the cylinder tank pressures are within half a bar
+ * (about 8 PSI) of the sample pressures, we consider it
+ * to be a rounding error, and throw them away as redundant.
+ */
+static int same_rounded_pressure(pressure_t a, pressure_t b)
+{
+ return abs(a.mbar - b.mbar) <= 500;
+}
+
struct dive *fixup_dive(struct dive *dive)
{
int i;
@@ -287,9 +297,9 @@ struct dive *fixup_dive(struct dive *dive)
for (i = 0; i < MAX_CYLINDERS; i++) {
cylinder_t *cyl = dive->cylinder + i;
add_cylinder_description(&cyl->type);
- if (cyl->sample_start.mbar == cyl->start.mbar)
+ if (same_rounded_pressure(cyl->sample_start, cyl->start))
cyl->start.mbar = 0;
- if (cyl->sample_end.mbar == cyl->end.mbar)
+ if (same_rounded_pressure(cyl->sample_end, cyl->end))
cyl->end.mbar = 0;
}