diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2020-10-25 13:28:55 +0100 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2020-10-25 13:59:52 -0700 |
commit | 0e196310f9cda2ccca27e9cf96186639b5658249 (patch) | |
tree | f53ee1f276774aa85b6bbe7015a302aa33339eb6 /core/sample.c | |
parent | 4aa571d5a09e7c114633dc046bb8a61044a05d63 (diff) | |
download | subsurface-0e196310f9cda2ccca27e9cf96186639b5658249.tar.gz |
cleanup: split out divecomputer functions from dive.c
Since dive.c is so huge, split out divecomputer-related functions
into divecomputer.[c|h], sample.[c|h] and extradata.[c|h].
This does not give huge compile time improvements, since
struct dive contains a struct divecomputer and therefore
dive.h has to include divecomputer.h. However, it make things
distinctly more clear.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'core/sample.c')
-rw-r--r-- | core/sample.c | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/core/sample.c b/core/sample.c new file mode 100644 index 000000000..fd68a4aa7 --- /dev/null +++ b/core/sample.c @@ -0,0 +1,45 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include "sample.h" + +/* + * Adding a cylinder pressure sample field is not quite as trivial as it + * perhaps should be. + * + * We try to keep the same sensor index for the same sensor, so that even + * if the dive computer doesn't give pressure information for every sample, + * we don't move pressure information around between the different sensor + * indices. + * + * The "prepare_sample()" function will always copy the sensor indices + * from the previous sample, so the indices are pre-populated (but the + * pressures obviously are not) + */ +void add_sample_pressure(struct sample *sample, int sensor, int mbar) +{ + int idx; + + if (!mbar) + return; + + /* Do we already have a slot for this sensor */ + for (idx = 0; idx < MAX_SENSORS; idx++) { + if (sensor != sample->sensor[idx]) + continue; + sample->pressure[idx].mbar = mbar; + return; + } + + /* Pick the first unused index if we couldn't reuse one */ + for (idx = 0; idx < MAX_SENSORS; idx++) { + if (sample->pressure[idx].mbar) + continue; + sample->sensor[idx] = sensor; + sample->pressure[idx].mbar = mbar; + return; + } + + /* We do not have enough slots for the pressure samples. */ + /* Should we warn the user about dropping pressure data? */ +} + |