aboutsummaryrefslogtreecommitdiffstats
path: root/dive.c
diff options
context:
space:
mode:
authorGravatar Linus Torvalds <torvalds@linux-foundation.org>2011-09-04 13:06:47 -0700
committerGravatar Linus Torvalds <torvalds@linux-foundation.org>2011-09-04 13:06:47 -0700
commitf448b68de0e844db3628332ebf70f2746882527c (patch)
tree81d7d795c805948718b23e1cd614acb46163170f /dive.c
parentaab4d593bdbffef8442282318778a9833cbc7a43 (diff)
downloadsubsurface-f448b68de0e844db3628332ebf70f2746882527c.tar.gz
Clean up 'fixup_dive()' a bit
We don't want to override potentially more exact values for water temperature etc either. The sample save interval may be longer than some internally kept state of key per-dive values like that. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'dive.c')
-rw-r--r--dive.c54
1 files changed, 40 insertions, 14 deletions
diff --git a/dive.c b/dive.c
index 5ddb6bc80..7fe6eb17b 100644
--- a/dive.c
+++ b/dive.c
@@ -21,10 +21,38 @@
*/
static void update_depth(depth_t *depth, int new)
{
- int old = depth->mm;
+ if (new) {
+ int old = depth->mm;
- if (abs(old - new) > 1000)
- depth->mm = new;
+ if (abs(old - new) > 1000)
+ depth->mm = new;
+ }
+}
+
+static void update_pressure(pressure_t *pressure, int new)
+{
+ if (new) {
+ int old = pressure->mbar;
+
+ if (abs(old - new) > 1000)
+ pressure->mbar = new;
+ }
+}
+
+static void update_duration(duration_t *duration, int new)
+{
+ if (new)
+ duration->seconds = new;
+}
+
+static void update_temperature(temperature_t *temperature, int new)
+{
+ if (new) {
+ int old = temperature->mkelvin;
+
+ if (abs(old - new) > 1000)
+ temperature->mkelvin = new;
+ }
}
struct dive *fixup_dive(struct dive *dive)
@@ -85,18 +113,16 @@ struct dive *fixup_dive(struct dive *dive)
}
if (end < 0)
return dive;
- dive->duration.seconds = end - start;
+
+ update_duration(&dive->duration, end - start);
if (start != end)
- 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)
- update_depth(&dive->maxdepth, maxdepth);
+ depthtime /= (end - start);
+
+ update_depth(&dive->meandepth, depthtime);
+ update_pressure(&dive->beginning_pressure, startpress);
+ update_pressure(&dive->end_pressure, endpress);
+ update_temperature(&dive->watertemp, mintemp);
+ update_depth(&dive->maxdepth, maxdepth);
return dive;
}