core: add a function to test for sensors of a given cylinder

We want to prevent the user from accidentally deleting a
cylinder with sensor readings. Therefore, we need such a
function.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2021-09-02 18:39:17 +02:00 committed by Dirk Hohndel
parent 5eda1c0e39
commit 28fe6a7b38
3 changed files with 15 additions and 1 deletions

View file

@ -3481,3 +3481,17 @@ struct gasmix get_gasmix_at_time(const struct dive *d, const struct divecomputer
struct gasmix gasmix = gasmix_air;
return get_gasmix(d, dc, time.seconds, &ev, gasmix);
}
/* Does that cylinder have any pressure readings? */
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) {
for (int j = 0; j < MAX_SENSORS; ++j) {
if (dc->sample[i].sensor[j] == cylinder_id)
return true;
}
}
}
return false;
}