From c7171179b35217a09af75742e0f8e330b8e62e91 Mon Sep 17 00:00:00 2001 From: Micha WERLE Date: Tue, 14 Nov 2023 13:12:08 +0900 Subject: [PATCH] Core: extend last gas mix instead of defaulting to air. Instead of defaulting to air when we run out of gas mixes to assign to cylinders, use the last gas mix provided by the dive computer. If no gas mixes are provided at all, then default to air. This prevents Subsurface from "inventing" gas mixes which are not reported by the dive computer. It also works very nicely with a sidemount configuration where the dive computer typically reports two cylinders but only a single gas mix. Signed-off-by: Micha WERLE --- core/libdivecomputer.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/core/libdivecomputer.c b/core/libdivecomputer.c index 572368fb9..57b1f0da5 100644 --- a/core/libdivecomputer.c +++ b/core/libdivecomputer.c @@ -113,14 +113,16 @@ static int parse_gasmixes(device_data_t *devdata, struct dive *dive, dc_parser_t report_error("Warning: different number of gases (%d) and cylinders (%d)", ngases, ntanks); } else if (ntanks > ngases) { shown_warning = true; - report_error("Warning: smaller number of gases (%d) than cylinders (%d). Assuming air.", ngases, ntanks); + report_error("Warning: smaller number of gases (%d) than cylinders (%d).", ngases, ntanks); } } bool no_volume = true; + cylinder_t cyl = empty_cylinder; + struct gasmix last_mix = gasmix_air; /* default to air */ clear_cylinder_table(&dive->cylinders); - for (i = 0; i < ngases || i < ntanks; i++) { - cylinder_t cyl = empty_cylinder; + for (i = 0; i < MAX(ngases, ntanks); i++) { + cyl = empty_cylinder; if (i < ngases) { dc_gasmix_t gasmix = { 0 }; int o2, he; @@ -147,9 +149,10 @@ static int parse_gasmixes(device_data_t *devdata, struct dive *dive, dc_parser_t } he = 0; } - cyl.gasmix.o2.permille = o2; - cyl.gasmix.he.permille = he; + last_mix.o2.permille = o2; + last_mix.he.permille = he; } + cyl.gasmix = last_mix; if (rc == DC_STATUS_UNSUPPORTED) // Gasmix is inactive