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 <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2022-04-12 15:28:13 -10:00
parent ecfbf2a9ba
commit 795cf1bee2
2 changed files with 15 additions and 1 deletions

View file

@ -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
---

View file

@ -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);