aboutsummaryrefslogtreecommitdiffstats
path: root/core/profile.c
diff options
context:
space:
mode:
authorGravatar Linus Torvalds <torvalds@linux-foundation.org>2017-07-30 10:41:20 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2017-07-30 16:37:45 -0700
commit8f0d71ce2b36bbd23e3e5d5d520bcb793797cad6 (patch)
tree9d4714e4bb13fca12916b67a15d42400f870b3f6 /core/profile.c
parent5b28fcea3a731a3c031604df4bdca4b95684e2ea (diff)
downloadsubsurface-8f0d71ce2b36bbd23e3e5d5d520bcb793797cad6.tar.gz
Fix another cylinder pressure plotting special case
The core to plot manually entered pressures without any sample data did the obvious thing: it ended the pressures at the end of the dive as indicated by the last sample. However, that obvious thing didn't actually work, because sometimes the last sample is long long after the dive has actually ended, and we have no plot_info data for that. This depends on the dive computer used: most dive computers will not report samples after the end (even if they may internally remember them in case the diver just came up to the surface temporarily), but some definitely do. The OSTC3 is a prime example of that. Anyway, the code was fragile and wrong - even if passed a time past the end of the plot_info data, "add_plot_pressure()" should just have associated that with the last entry instead. Which also allows us to simplify the whole endtime logic entirely, and just use INT_MAX for it. Gaetan Bisson's test-case also showed another oddity: we would plot the gas pressure even for cylinders that had no has use (ie beginning and ending pressures were the same). That's kind of pointless in so many ways. So limit the manual pressure population to cylinders that actually have seen use. Reported-by: Gaetan Bisson <bisson@archlinux.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'core/profile.c')
-rw-r--r--core/profile.c17
1 files changed, 8 insertions, 9 deletions
diff --git a/core/profile.c b/core/profile.c
index e9a625d30..7b5827416 100644
--- a/core/profile.c
+++ b/core/profile.c
@@ -804,14 +804,14 @@ static void populate_secondary_sensor_data(struct divecomputer *dc, struct plot_
*/
static void add_plot_pressure(struct plot_info *pi, int time, int cyl, int mbar)
{
+ struct plot_data *entry;
for (int i = 0; i < pi->nr; i++) {
- struct plot_data *entry = pi->entry + i;
+ entry = pi->entry + i;
- if (entry->sec < time)
- continue;
- SENSOR_PRESSURE(entry, cyl) = mbar;
- return;
+ if (entry->sec >= time)
+ break;
}
+ SENSOR_PRESSURE(entry, cyl) = mbar;
}
static void setup_gas_sensor_pressure(struct dive *dive, struct divecomputer *dc, struct plot_info *pi)
@@ -822,10 +822,9 @@ 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;
+ last[i] = INT_MAX;
for (ev = get_next_event(dc->events, "gaschange"); ev != NULL; ev = get_next_event(ev->next, "gaschange")) {
int cyl = ev->gas.index;
@@ -846,14 +845,14 @@ static void setup_gas_sensor_pressure(struct dive *dive, struct divecomputer *dc
}
}
if (prev >= 0)
- last[prev] = endtime;
+ last[prev] = INT_MAX;
for (i = 0; i < MAX_CYLINDERS; i++) {
cylinder_t *cyl = dive->cylinder + i;
int start = cyl->start.mbar;
int end = cyl->end.mbar;
- if (start && end) {
+ if (start && end && start != end) {
add_plot_pressure(pi, first[i], i, start);
add_plot_pressure(pi, last[i], i, end);
}