mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-30 22:20:21 +00:00
Merge branch 'sensor-index-fixup' of https://github.com/torvalds/subsurface-for-dirk
This commit is contained in:
commit
99e6e11c8c
3 changed files with 31 additions and 7 deletions
34
core/dive.c
34
core/dive.c
|
@ -1210,16 +1210,40 @@ static void fixup_no_o2sensors(struct divecomputer *dc)
|
|||
}
|
||||
}
|
||||
|
||||
static void fixup_dc_sample_sensors(struct divecomputer *dc, int nr_cylinders)
|
||||
static void fixup_dc_sample_sensors(struct dive *dive, struct divecomputer *dc)
|
||||
{
|
||||
unsigned long sensor_mask = 0;
|
||||
|
||||
for (int i = 0; i < dc->samples; i++) {
|
||||
struct sample *s = dc->sample + i;
|
||||
for (int j = 0; j < MAX_SENSORS; j++) {
|
||||
if (s->sensor[j] < 0 || s->sensor[j] >= nr_cylinders) {
|
||||
int sensor = s->sensor[j];
|
||||
|
||||
// No invalid sensor ID's, please
|
||||
if (sensor < 0 || sensor > MAX_SENSORS) {
|
||||
s->sensor[j] = NO_SENSOR;
|
||||
s->pressure[j].mbar = 0;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Don't bother tracking sensors with no data
|
||||
if (!s->pressure[j].mbar) {
|
||||
s->sensor[j] = NO_SENSOR;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Remember the set of sensors we had
|
||||
sensor_mask |= 1ul << sensor;
|
||||
}
|
||||
}
|
||||
|
||||
// Ignore the sensors we have cylinders for
|
||||
sensor_mask >>= dive->cylinders.nr;
|
||||
|
||||
// Do we need to add empty cylinders?
|
||||
while (sensor_mask) {
|
||||
add_empty_cylinder(&dive->cylinders);
|
||||
sensor_mask >>= 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1240,12 +1264,12 @@ static void fixup_dive_dc(struct dive *dive, struct divecomputer *dc)
|
|||
/* Fix up gas switch events */
|
||||
fixup_dc_gasswitch(dive, dc);
|
||||
|
||||
/* Fix up cylinder ids in pressure sensors */
|
||||
fixup_dc_sample_sensors(dive, dc);
|
||||
|
||||
/* Fix up cylinder pressures based on DC info */
|
||||
fixup_dive_pressures(dive, dc);
|
||||
|
||||
/* Fix up cylinder ids in pressure sensors */
|
||||
fixup_dc_sample_sensors(dc, dive->cylinders.nr);
|
||||
|
||||
fixup_dc_events(dc);
|
||||
|
||||
/* Fixup CCR / PSCR dives with o2sensor values, but without no_o2sensors */
|
||||
|
|
|
@ -644,7 +644,7 @@ static char *parse_sample_unit(struct sample *sample, double val, char *unit)
|
|||
/*
|
||||
* If the given cylinder doesn't exist, return NO_SENSOR.
|
||||
*/
|
||||
static uint8_t sanitize_sensor_id(const struct dive *d, int nr)
|
||||
static int sanitize_sensor_id(const struct dive *d, int nr)
|
||||
{
|
||||
return d && nr >= 0 && nr < d->cylinders.nr ? nr : NO_SENSOR;
|
||||
}
|
||||
|
|
|
@ -393,7 +393,7 @@ void ws_end(struct parser_state *state)
|
|||
/*
|
||||
* If the given cylinder doesn't exist, return NO_SENSOR.
|
||||
*/
|
||||
static uint8_t sanitize_sensor_id(const struct dive *d, int nr)
|
||||
static int sanitize_sensor_id(const struct dive *d, int nr)
|
||||
{
|
||||
return d && nr >= 0 && nr < d->cylinders.nr ? nr : NO_SENSOR;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue