core: add a special NO_SENSOR value for sample::sensor

The sensor member of sample refers to a cylinder from which
the pressure was read. However, some dives don't even have
a cylinder. Therefore, introduce a special NO_SENSOR value
for these dives. Since the cylinder is given as a uint8_t,
0xff seems to be a sensible choice.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2021-07-18 22:26:38 +02:00 committed by Dirk Hohndel
parent 48c2929f48
commit 7e11a35371
3 changed files with 8 additions and 5 deletions

View file

@ -1657,9 +1657,10 @@ static void sample_renumber(struct sample *s, int i, const int mapping[])
int j;
for (j = 0; j < MAX_SENSORS; j++) {
int sensor;
int sensor = -1;
sensor = mapping[s->sensor[j]];
if (s->sensor[j] != NO_SENSOR)
sensor = mapping[s->sensor[j]];
if (sensor == -1) {
// Remove sensor and gas pressure info
if (i == 0) {

View file

@ -566,9 +566,9 @@ static void populate_plot_entries(const struct dive *dive, const struct divecomp
} else {
entry->pressures.o2 = sample->setpoint.mbar / 1000.0;
}
if (sample->pressure[0].mbar)
if (sample->pressure[0].mbar && sample->sensor[0] != NO_SENSOR)
set_plot_pressure_data(pi, idx, SENSOR_PR, sample->sensor[0], sample->pressure[0].mbar);
if (sample->pressure[1].mbar)
if (sample->pressure[1].mbar && sample->sensor[1] != NO_SENSOR)
set_plot_pressure_data(pi, idx, SENSOR_PR, sample->sensor[1], sample->pressure[1].mbar);
if (sample->temperature.mkelvin)
entry->temperature = lasttemp = sample->temperature.mkelvin;

View file

@ -9,6 +9,8 @@ extern "C" {
#endif
#define MAX_SENSORS 2
#define NO_SENSOR ((uint8_t)-1)
struct sample // BASE TYPE BYTES UNITS RANGE DESCRIPTION
{ // --------- ----- ----- ----- -----------
duration_t time; // int32_t 4 seconds (0-34 yrs) elapsed dive time up to this sample
@ -23,7 +25,7 @@ struct sample // BASE TYPE BYTES UNITS RANGE
o2pressure_t setpoint; // uint16_t 2 mbar (0-65 bar) O2 partial pressure (will be setpoint)
o2pressure_t o2sensor[3]; // uint16_t 6 mbar (0-65 bar) Up to 3 PO2 sensor values (rebreather)
bearing_t bearing; // int16_t 2 degrees (-1 no val, 0-360 deg) compass bearing
uint8_t sensor[MAX_SENSORS]; // uint8_t 1 sensorID (0-255) ID of cylinder pressure sensor
uint8_t sensor[MAX_SENSORS]; // uint8_t 1 sensorID (0-254) ID of cylinder pressure sensor
uint16_t cns; // uint16_t 1 % (0-64k %) cns% accumulated
uint8_t heartbeat; // uint8_t 1 beats/m (0-255) heart rate measurement
volume_t sac; // 4 ml/min predefined SAC