summaryrefslogtreecommitdiffstats
path: root/dive.c
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2013-11-29 12:05:21 -0800
committerGravatar Dirk Hohndel <dirk@hohndel.org>2013-11-29 12:05:21 -0800
commitff5fa70a88d2ac0c424a1f1a994837ebe7e27d9d (patch)
treea226397bac03cb6928d761a96c23a32d11593dee /dive.c
parentd936c55a015789f61f7e93426b11218ebb4312af (diff)
downloadsubsurface-ff5fa70a88d2ac0c424a1f1a994837ebe7e27d9d.tar.gz
Editing air or water temperature should modify dive computer, not dive
The dive fields are summary fields, the actual data needs to be in the divecomputer specific fields. Fixes #307
Diffstat (limited to 'dive.c')
-rw-r--r--dive.c22
1 files changed, 16 insertions, 6 deletions
diff --git a/dive.c b/dive.c
index bc628589d..d0c22734c 100644
--- a/dive.c
+++ b/dive.c
@@ -646,19 +646,29 @@ static void fixup_duration(struct dive *dive)
dive->duration.seconds = duration;
}
-static void fixup_watertemp(struct dive *dive)
+/*
+ * What do the dive computers say the water temperature is?
+ * (not in the samples, but as dc property for dcs that support that)
+ */
+unsigned int dc_watertemp(struct divecomputer *dc)
{
- struct divecomputer *dc;
int sum = 0, nr = 0;
- for_each_dc(dive, dc) {
+ do {
if (dc->watertemp.mkelvin) {
sum += dc->watertemp.mkelvin;
nr++;
}
- }
- if (nr)
- dive->watertemp.mkelvin = (sum + nr / 2) / nr;
+ } while ((dc = dc->next) != NULL);
+ if (!nr)
+ return 0;
+ return (sum + nr / 2) / nr;
+}
+
+static void fixup_watertemp(struct dive *dive)
+{
+ if (!dive->watertemp.mkelvin)
+ dive->watertemp.mkelvin = dc_watertemp(&dive->dc);
}
/*