From 795cf1bee2e5750df1038c6dc16b4d86319acd12 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Tue, 12 Apr 2022 15:28:13 -1000 Subject: [PATCH] libdc integration: correctly parse DC_FIELD_SALINITY response libdivecomputer tries to be super careful in what it tells us. It only offers a density value if that is something that the dive computer explicitly supports, otherwise it just offers back a flag. We need to then update the density value ourselves. Signed-off-by: Dirk Hohndel --- CHANGELOG.md | 1 + core/libdivecomputer.c | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ff1e802f0..4e6c2d748 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,4 @@ +- core: correctly parse DC_FIELD_SALINITY response; fixes incorrect water type with some dive computers, including the Mares Smart - Desktop: Allow more than one media file to be imported from web - undo: Clear undo stack when the current file is closed --- diff --git a/core/libdivecomputer.c b/core/libdivecomputer.c index 281a99c3e..ed097e2a5 100644 --- a/core/libdivecomputer.c +++ b/core/libdivecomputer.c @@ -677,8 +677,21 @@ static dc_status_t libdc_header_parser(dc_parser_t *parser, device_data_t *devda download_error(translate("gettextFromC", "Error obtaining water salinity")); return rc; } - if (rc == DC_STATUS_SUCCESS) + if (rc == DC_STATUS_SUCCESS) { dive->dc.salinity = lrint(salinity.density * 10.0); + if (dive->dc.salinity == 0) { + // sometimes libdivecomputer gives us density values, sometimes just + // a water type and a density of zero; let's make this work as best as we can + switch (salinity.type) { + case DC_WATER_FRESH: + dive->dc.salinity = FRESHWATER_SALINITY; + break; + default: + dive->dc.salinity = SEAWATER_SALINITY; + break; + } + } + } double surface_pressure = 0; rc = dc_parser_get_field(parser, DC_FIELD_ATMOSPHERIC, 0, &surface_pressure);