[PATCH] libdivecomputer: add air temperature fixups for Suunto

Linus Torvalds torvalds at linux-foundation.org
Tue Jan 22 18:21:20 PST 2013

From: Linus Torvalds <torvalds at linux-foundation.org>
Date: Tue, 22 Jan 2013 18:15:07 -0800
Subject: [PATCH] libdivecomputer: add air temperature fixups for Suunto

libdivecomputer doesn't actually seem to support air temperature
reporting at all, but at least for Suunto dive computers the air
temperature is recorded as the temperature for the first sample.

So since we already have vendor-specific libdivecomputer hacks, let's
just add that one as a rule.  It may be that other divecomputers do this
too, so this adds it as a generic concept - it's just that right now the
flag for "air temperature in first sample" is only set for Suunto dive

Signed-off-by: Linus Torvalds <torvalds at linux-foundation.org>

This is not pretty, but it's *tiny* and it works. I don't know how common 
this "air temperature in first sample" might be, and maybe it's only 
Suunto that does this, but if we think that vendor-specific fixups for 
these kinds of things are acceptable, at least it's simple.

I'm not going to push this patch very hard, though. Because it *is* a 

 libdivecomputer.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/libdivecomputer.c b/libdivecomputer.c
index 2672fb72a84d..cb4789f49d68 100644
--- a/libdivecomputer.c
+++ b/libdivecomputer.c
@@ -24,7 +24,7 @@
 static const char *progress_bar_text = "";
 static double progress_bar_fraction = 0.0;
 static int stoptime, stopdepth, ndl, po2, cns;
-static gboolean in_deco;
+static gboolean in_deco, first_temp_is_air;
 static GError *error(const char *fmt, ...)
@@ -495,6 +495,12 @@ static int dive_cb(const unsigned char *data, unsigned int size,
 	if (!devdata->force_download && find_dive(&dive->dc))
 		return 0;
+	/* Various libdivecomputer interface fixups */
+	if (first_temp_is_air && dive->dc.samples) {
+		dive->airtemp = dive->dc.sample[0].temperature;
+		dive->dc.sample[0].temperature.mkelvin = 0;
+	}
 	dive->downloaded = TRUE;
@@ -572,6 +578,8 @@ static unsigned int fixup_suunto_versions(device_data_t *devdata, const dc_event
 	struct device_info *info;
 	unsigned int serial = devinfo->serial;
+	first_temp_is_air = 1;
 	serial = undo_libdivecomputer_suunto_nr_changes(serial);
 	info = create_device_info(devdata->model, devdata->deviceid);
@@ -681,6 +689,7 @@ static const char *do_libdivecomputer_import(device_data_t *data)
 	const char *err;
 	import_dive_number = 0;
+	first_temp_is_air = 0;
 	data->device = NULL;
 	data->context = NULL;

More information about the subsurface mailing list