diff options
author | Patrick Valsecchi <patrick@thus.ch> | 2013-10-03 14:06:12 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2013-10-03 09:40:45 -0700 |
commit | b79a8ec3866f16f95342ba4b344f5bcf5a33de6d (patch) | |
tree | 2ad81a6fb1c203c4731a7a4b6046d6c952f530be /libdivecomputer.c | |
parent | 30f315fc55002fa2b17f8fb0f1b7acef0ba9f91d (diff) | |
download | subsurface-b79a8ec3866f16f95342ba4b344f5bcf5a33de6d.tar.gz |
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 <patrick@thus.ch>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'libdivecomputer.c')
-rw-r--r-- | libdivecomputer.c | 20 |
1 files 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); |