diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2014-11-07 22:45:59 -0800 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2014-11-07 22:55:38 -0800 |
commit | 082e59ea724f3b44fef0d2a4f21766e981b35194 (patch) | |
tree | b4d1892da0daacf150bf02819a1a102f7b5a5e11 /libdivecomputer.c | |
parent | dbc7dbb0741cd6fc5af1c8c389c3ed0caba4ad57 (diff) | |
download | subsurface-082e59ea724f3b44fef0d2a4f21766e981b35194.tar.gz |
Add support for libdivecomputer's new TEMPERATURE fields
Parse air temperature and water temperature if available from the dive
computer. Subsurface happily tracks the temperatures in the dive samples,
but for water temperature in the header ("overall" water temperature) we
currently support only one field. So I ordered the code so that if it is
available, the minimum water temperature will be used, absent a minimum
water temperature we use the maximum water temperature.
Side note:
Since the libdivecomputer maintainer disagrees with the Subsurface
developers regarding a sane way to allow a consumer of his library to
detect if a feature is supported in a particular commit of the library,
the way we decide whether to build this code or not is decidedly hacky.
DC_GASMIX_UNKNOWN happens to be a #define we can check that was added
right around the time the temperature support was added. Sadly there is
no #define that we could check to see if temperature fields are supported.
How insane is that...
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'libdivecomputer.c')
-rw-r--r-- | libdivecomputer.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/libdivecomputer.c b/libdivecomputer.c index c78d3b620..6974bccdf 100644 --- a/libdivecomputer.c +++ b/libdivecomputer.c @@ -497,6 +497,34 @@ static int dive_cb(const unsigned char *data, unsigned int size, } dive->dc.maxdepth.mm = rint(maxdepth * 1000); +#if DC_VERSION_CHECK(0, 5, 0) && defined(DC_GASMIX_UNKNOWN) + // if this is defined then we have a fairly late version of libdivecomputer + // from the 0.5 development cylcle - most likely temperatures and tank sizes + // are supported + + // Parse temperatures + double temperature; + dc_field_type_t temp_fields[] = {DC_FIELD_TEMPERATURE_SURFACE, + DC_FIELD_TEMPERATURE_MAXIMUM, + DC_FIELD_TEMPERATURE_MINIMUM}; + for (int i = 0; i < 3; i++) { + rc = dc_parser_get_field(parser, temp_fields[i], 0, &temperature); + if (rc != DC_STATUS_SUCCESS && rc != DC_STATUS_UNSUPPORTED) { + dev_info(devdata, translate("gettextFromC", "Error parsing temperature")); + goto error_exit; + } + switch(i) { + case 0: + dive->dc.airtemp.mkelvin = C_to_mkelvin(temperature); + break; + case 1: // we don't distinguish min and max water temp here, so take min if given, max otherwise + case 2: + dive->dc.watertemp.mkelvin = C_to_mkelvin(temperature); + break; + } + } +#endif + // Parse the gas mixes. unsigned int ngases = 0; rc = dc_parser_get_field(parser, DC_FIELD_GASMIX_COUNT, 0, &ngases); |