aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2021-09-02 18:39:17 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2021-09-03 13:35:28 -0700
commit28fe6a7b3856f1359f875f9d53d4c64e7dc1ea15 (patch)
treed6ed06f1d5e8ca5b97049e1ab9feeebceb28a692
parent5eda1c0e39b7c5e4e68ec68596cb023e37503ba7 (diff)
downloadsubsurface-28fe6a7b3856f1359f875f9d53d4c64e7dc1ea15.tar.gz
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>
-rw-r--r--core/dive.c14
-rw-r--r--core/dive.h1
-rw-r--r--core/divecomputer.c1
3 files changed, 15 insertions, 1 deletions
diff --git a/core/dive.c b/core/dive.c
index a7d202ba5..c97e1ba11 100644
--- a/core/dive.c
+++ b/core/dive.c
@@ -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;
+}
diff --git a/core/dive.h b/core/dive.h
index 3e5ec1324..394c37ef1 100644
--- a/core/dive.h
+++ b/core/dive.h
@@ -198,6 +198,7 @@ extern int get_cylinder_index(const struct dive *dive, const struct event *ev);
extern struct gasmix get_gasmix_from_event(const struct dive *, const struct event *ev);
extern int nr_cylinders(const struct dive *dive);
extern int nr_weightsystems(const struct dive *dive);
+extern bool cylinder_with_sensor_sample(const struct dive *dive, int cylinder_id);
/* UI related protopypes */
diff --git a/core/divecomputer.c b/core/divecomputer.c
index 19d4a6fee..6f8964601 100644
--- a/core/divecomputer.c
+++ b/core/divecomputer.c
@@ -548,4 +548,3 @@ void free_dc(struct divecomputer *dc)
free_dc_contents(dc);
free(dc);
}
-