diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2016-06-01 12:49:32 -0700 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2016-06-01 13:09:26 -0700 |
commit | 7a77569019adde1a623229baf52f30a9345d0616 (patch) | |
tree | 6d138b26f73403fff4cbd9e45fddcb6a93be6371 /core/profile.c | |
parent | 36a3f649c5896b660ba3640a30b4ffc56d6ad679 (diff) | |
download | subsurface-7a77569019adde1a623229baf52f30a9345d0616.tar.gz |
Make sure all dive computer events are represented in the plot_info data
We could create a plot_info data that didn't contain all the time slots
for the events fromt he dive computer, which would terminally confuse
the plotting of the event profile widgets because it couldn't match up
the event with the dive plot data model.
So for example, in DiveEventItem::recalculatePos(), when the code tries
to figure out the spot in the data model, it could fail, and then try to
hide the event (because without the data model information it doesn't
know where it should go). But that hiding would then not match the
logic in DiveEventItem::shouldBeHidden(), and the event would end up
being shown in the upper left-hand corner of the profile after all.
The reason the plot_info data wouldn't contain the time slots is that
the slots are allocated primarily for the sample data, and then the
events would be added in between sample data in populate_plot_entries().
But since we'd only add the event pointer *between* samples, that would
mean that events after the last samples would not get plot-info points
allocated to them.
That issue was exacerbated by how we also truncate uninteresting samples
at the end when some dive computers end up giving a long stream
(possibly several minutes) of "at the surface" events before they
finally turn off logging.
This makes sure that we take the event timestamps into account for the
"maxtime" calculation, and also that we finish populating the plot_info
data with any final event timestamps.
Now all the events will have a matching plot_info entry.
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.c | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/core/profile.c b/core/profile.c index 4e9ee88ee..4438154e3 100644 --- a/core/profile.c +++ b/core/profile.c @@ -472,6 +472,7 @@ struct plot_info calculate_max_limits_new(struct dive *dive, struct divecomputer int i = dc->samples; int lastdepth = 0; struct sample *s = dc->sample; + struct event *ev; while (--i >= 0) { int depth = s->depth.mm; @@ -501,6 +502,15 @@ struct plot_info calculate_max_limits_new(struct dive *dive, struct divecomputer lastdepth = depth; s++; } + + /* Make sure we can fit all events */ + ev = dc->events; + while (ev) { + if (ev->time.seconds > maxtime) + maxtime = ev->time.seconds; + ev = ev->next; + } + dc = dc->next; if (dc == NULL && !seen) { dc = given_dc; @@ -608,7 +618,6 @@ struct plot_data *populate_plot_entries(struct dive *dive, struct divecomputer * ev = ev->next; } - entry->sec = time; entry->depth = depth; @@ -652,6 +661,18 @@ struct plot_data *populate_plot_entries(struct dive *dive, struct divecomputer * break; } + /* Add any remaining events */ + while (ev) { + struct plot_data *entry = plot_data + idx; + int time = ev->time.seconds; + + if (time > lasttime) { + INSERT_ENTRY(ev->time.seconds, 0, 0); + lasttime = time; + } + ev = ev->next; + } + /* Add two final surface events */ plot_data[idx++].sec = lasttime + 1; plot_data[idx++].sec = lasttime + 2; |