From bdeeba4a67c2ccfcfbf3010755d57f67104f269c Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Thu, 28 Apr 2022 12:30:10 -0700 Subject: [PATCH] core: fix detection of used cylinders The cylinder_with_sensor_sample() function only tests "do we have a mapping to this cylinder for this sample". It also needs to test if there are any tank pressure readings for that cylinder. Signed-off-by: Linus Torvalds Signed-off-by: Dirk Hohndel --- core/dive.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/core/dive.c b/core/dive.c index 1d20e1421..39157f5d0 100644 --- a/core/dive.c +++ b/core/dive.c @@ -3495,8 +3495,11 @@ extern bool cylinder_with_sensor_sample(const struct dive *dive, int cylinder_id { for (const struct divecomputer *dc = &dive->dc; dc; dc = dc->next) { for (int i = 0; i < dc->samples; ++i) { + struct sample *sample = dc->sample + i; for (int j = 0; j < MAX_SENSORS; ++j) { - if (dc->sample[i].sensor[j] == cylinder_id) + if (!sample->pressure[j].mbar) + continue; + if (sample->sensor[j] == cylinder_id) return true; } }