summaryrefslogtreecommitdiffstats
path: root/profile.c
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2014-02-23 08:36:20 -0800
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-02-23 08:36:20 -0800
commit4c68d4c61607aefabcca7d3b60ab7c715c586f6c (patch)
tree29d7603d822feec7fe11898b6ad56ae379b27485 /profile.c
parentf5862201a86051191290887414c5ed05fd450853 (diff)
downloadsubsurface-4c68d4c61607aefabcca7d3b60ab7c715c586f6c.tar.gz
Make sure that there are plot_info entries for events
We use the plot_info as basis for our dataModel in the new profile. In order to be able to place events at the right spot we need to have a plot_info entry when the event happens. So let's add interpolated entries not only based on time but also whenever there's an event between them. This should address Robert's comment in commit 0474fe70fc47 ("New profile: add image pixmaps for image events"). Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'profile.c')
-rw-r--r--profile.c59
1 files changed, 49 insertions, 10 deletions
diff --git a/profile.c b/profile.c
index 80fb0e016..3b0018a4d 100644
--- a/profile.c
+++ b/profile.c
@@ -687,6 +687,17 @@ struct event *get_next_event(struct event *event, char *name)
return event;
}
+static int count_events(struct divecomputer *dc)
+{
+ int result = 0;
+ struct event *ev = dc->events;
+ while (ev != NULL) {
+ result++;
+ ev = ev->next;
+ }
+ return result;
+}
+
static int set_cylinder_index(struct plot_info *pi, int i, int cylinderindex, unsigned int end)
{
while (i < pi->nr) {
@@ -846,21 +857,34 @@ void calculate_max_limits(struct dive *dive, struct divecomputer *dc, struct gra
pi->maxtemp = maxtemp;
}
+/* copy the previous entry (we know this exists), update time and depth
+ * and zero out the sensor pressure (since this is a synthetic entry)
+ * increment the entry pointer and the count of synthetic entries. */
+#define INSERT_ENTRY(_time,_depth) \
+ *entry = entry[-1]; \
+ entry->sec = _time; \
+ entry->depth = _depth; \
+ SENSOR_PRESSURE(entry) = 0; \
+ entry++; \
+ idx++
+
struct plot_data *populate_plot_entries(struct dive *dive, struct divecomputer *dc, struct plot_info *pi)
{
int idx, maxtime, nr, i;
int lastdepth, lasttime, lasttemp = 0;
struct plot_data *plot_data;
+ struct event *ev = dc->events;
maxtime = pi->maxtime;
/*
* We want to have a plot_info event at least every 10s (so "maxtime/10+1"),
- * but samples could be more dense than that (so add in dc->samples), and
+ * but samples could be more dense than that (so add in dc->samples). We also
+ * need to have one for every event (so count events and add that) and
* additionally we want two surface events around the whole thing (thus the
* additional 4).
*/
- nr = dc->samples + 5 + maxtime / 10;
+ nr = dc->samples + 5 + maxtime / 10 + count_events(dc);
plot_data = calloc(nr, sizeof(struct plot_data));
pi->entry = plot_data;
if (!plot_data)
@@ -870,6 +894,9 @@ struct plot_data *populate_plot_entries(struct dive *dive, struct divecomputer *
lastdepth = 0;
lasttime = 0;
+ /* skip events at time = 0 */
+ while (ev && ev->time.seconds == 0)
+ ev = ev->next;
for (i = 0; i < dc->samples; i++) {
struct plot_data *entry = plot_data + idx;
struct sample *sample = dc->sample+i;
@@ -887,17 +914,24 @@ struct plot_data *populate_plot_entries(struct dive *dive, struct divecomputer *
if (lasttime + offset > maxtime)
break;
- /* Use the data from the previous plot entry */
- *entry = entry[-1];
+ /* Add events if they are between plot entries */
+ while (ev && ev->time.seconds < lasttime + offset) {
+ INSERT_ENTRY(ev->time.seconds, interpolate(lastdepth, depth, ev->time.seconds - lasttime, delta));
+ ev = ev->next;
+ }
- /* .. but update depth and time, obviously */
- entry->sec = lasttime + offset;
- entry->depth = interpolate(lastdepth, depth, offset, delta);
+ /* now insert the time interpolated entry */
+ INSERT_ENTRY(lasttime + offset, interpolate(lastdepth, depth, offset, delta));
- /* And clear out the sensor pressure, since we'll interpolate */
- SENSOR_PRESSURE(entry) = 0;
+ /* skip events that happened at this time */
+ while (ev && ev->time.seconds == lasttime + offset)
+ ev = ev->next;
+ }
- idx++; entry++;
+ /* Add events if they are between plot entries */
+ while (ev && ev->time.seconds < time) {
+ INSERT_ENTRY(ev->time.seconds, interpolate(lastdepth, depth, ev->time.seconds - lasttime, delta));
+ ev = ev->next;
}
if (time > maxtime)
@@ -923,6 +957,9 @@ struct plot_data *populate_plot_entries(struct dive *dive, struct divecomputer *
entry->heartbeat = sample->heartbeat;
entry->bearing = sample->bearing;
+ /* skip events that happened at this time */
+ while (ev && ev->time.seconds == time)
+ ev = ev->next;
lasttime = time;
lastdepth = depth;
idx++;
@@ -936,6 +973,8 @@ struct plot_data *populate_plot_entries(struct dive *dive, struct divecomputer *
return plot_data;
}
+#undef INSERT_ENTRY
+
static void populate_cylinder_pressure_data(int idx, int start, int end, struct plot_info *pi)
{
int i;