From b79a8ec3866f16f95342ba4b344f5bcf5a33de6d Mon Sep 17 00:00:00 2001 From: Patrick Valsecchi Date: Thu, 3 Oct 2013 14:06:12 +0200 Subject: Importing salinity and atmospheric pressure from DC. One cannot expect #ifdef to work with enum values. So the code for getting the salinity was basically never compiled in. And it was putting it in the wrong location anyway (in the dive struct instead of the divecomputer struct where it is expected). I took the opportunity to add the reading of the atmospheric pressure as well. Signed-off-by: Patrick Valsecchi Signed-off-by: Dirk Hohndel --- libdivecomputer.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/libdivecomputer.c b/libdivecomputer.c index 6f2f1f66c..01c356873 100644 --- a/libdivecomputer.c +++ b/libdivecomputer.c @@ -467,16 +467,28 @@ static int dive_cb(const unsigned char *data, unsigned int size, return rc; } -#ifdef DC_FIELD_SALINITY - // Check if the libdivecomputer version already supports salinity - double salinity = 1.03; +#if DC_VERSION_CHECK(0, 3, 0) + // Check if the libdivecomputer version already supports salinity & atmospheric + dc_salinity_t salinity = { + .type = DC_WATER_SALT, + .density = 1.03 + }; rc = dc_parser_get_field(parser, DC_FIELD_SALINITY, 0, &salinity); if (rc != DC_STATUS_SUCCESS && rc != DC_STATUS_UNSUPPORTED) { dev_info(devdata, _("Error obtaining water salinity")); dc_parser_destroy(parser); return rc; } - dive->salinity = salinity * 10000.0 + 0.5; + dive->dc.salinity = salinity.density * 10000.0 + 0.5; + + double surface_pressure = 1.0; + rc = dc_parser_get_field(parser, DC_FIELD_ATMOSPHERIC, 0, &surface_pressure); + if (rc != DC_STATUS_SUCCESS && rc != DC_STATUS_UNSUPPORTED) { + dev_info(devdata, _("Error obtaining surface pressure")); + dc_parser_destroy(parser); + return rc; + } + dive->dc.surface_pressure.mbar = surface_pressure * 1000.0 + 0.5; #endif rc = parse_gasmixes(devdata, dive, parser, ngases, data); -- cgit v1.2.3-70-g09d2