Fix manual pressures for cylinders with no gas switches

"If it hasn't been tested, it doesn't work".

All my testing of the multiple sensor pressures have been with some
reasonably "interesting" dives: they actually *have* sensor pressures.

But that test coverage means that I missed the truly trivial case of
just having manual pressures for a single cylinder.

Because there's only a single cylinder, it doesn't have any cylinder
changes, and because there were no cylinder changes, it never filled in
the use range for that cylinder.

So then it never showed the pressure profile at all.

Duh.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Linus Torvalds 2017-07-28 11:49:03 -07:00 committed by Dirk Hohndel
parent df1bd0015a
commit 92b1c318bd

View file

@ -822,6 +822,10 @@ static void setup_gas_sensor_pressure(struct dive *dive, struct divecomputer *dc
unsigned int first[MAX_CYLINDERS] = { 0, };
unsigned int last[MAX_CYLINDERS] = { 0, };
struct divecomputer *secondary;
int endtime = dc->samples ? dc->sample[dc->samples-1].time.seconds : dive->duration.seconds;
for (i = 0; i < MAX_CYLINDERS; i++)
last[i] = endtime;
for (ev = get_next_event(dc->events, "gaschange"); ev != NULL; ev = get_next_event(ev->next, "gaschange")) {
int cyl = ev->gas.index;
@ -836,27 +840,22 @@ static void setup_gas_sensor_pressure(struct dive *dive, struct divecomputer *dc
last[cyl] = sec;
if (!seen[cyl]) {
int endtime = sec;
if (dc->samples)
endtime = dc->sample[dc->samples-1].time.seconds;
// The end time may be updated by a subsequent cylinder change
first[cyl] = sec;
last[cyl] = endtime;
seen[cyl] = 1;
}
}
if (prev >= 0)
last[prev] = endtime;
for (i = 0; i < MAX_CYLINDERS; i++) {
if (seen[i]) {
cylinder_t *cyl = dive->cylinder + i;
int start = cyl->start.mbar;
int end = cyl->end.mbar;
cylinder_t *cyl = dive->cylinder + i;
int start = cyl->start.mbar;
int end = cyl->end.mbar;
if (start)
add_plot_pressure(pi, first[i], i, start);
if (end)
add_plot_pressure(pi, last[i], i, end);
if (start && end) {
add_plot_pressure(pi, first[i], i, start);
add_plot_pressure(pi, last[i], i, end);
}
}