summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2012-11-28 21:13:21 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2012-11-28 21:13:21 -0700
commit10fac7a6af7e95b45029372f32ce544c705f6887 (patch)
tree9777ea690e990051934d6ae38c0afb8963deb1ec
parent7259cf5bb64f7cf914c216c4c46cef5f416bb5a6 (diff)
downloadsubsurface-10fac7a6af7e95b45029372f32ce544c705f6887.tar.gz
Updating events for libdivecomputer 0.3 (and tracking uemis support)
I was a little too eager to add the deco feature to Subsurface. Jef and I went back and forth a few more times and the definition of those events changed. I guess I shouldn't have commited that code until the corresponding libdivecomputer code had been pushed. This commit now brings us in sync with the current master of libdivecomputer (but should compile with 0.2 as well - only deco events won't work then). One issue that I see is that deco / ndl aren't really a good fit for the event model. I actually disabled the drawing of the little yellow triangles for ndl events as for example on the Uemis those events are created whenever the remaining non stop time changes - and that can be every few seconds. The correct solution may be to treat this as a function of the samples, but for now this works and is tested with both OSTC and Uemis SDA. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--libdivecomputer.c4
-rw-r--r--profile.c87
-rw-r--r--uemis.c32
3 files changed, 77 insertions, 46 deletions
diff --git a/libdivecomputer.c b/libdivecomputer.c
index 164b3a30f..dba6e6fe5 100644
--- a/libdivecomputer.c
+++ b/libdivecomputer.c
@@ -77,12 +77,12 @@ static void handle_event(struct divecomputer *dc, struct sample *sample, dc_samp
/* we mark these for translation here, but we store the untranslated strings
* and only translate them when they are displayed on screen */
static const char *events[] = {
- N_("none"), N_("deco"), N_("rbt"), N_("ascent"), N_("ceiling"), N_("workload"),
+ N_("none"), N_("deco stop"), N_("rbt"), N_("ascent"), N_("ceiling"), N_("workload"),
N_("transmitter"), N_("violation"), N_("bookmark"), N_("surface"), N_("safety stop"),
N_("gaschange"), N_("safety stop (voluntary)"), N_("safety stop (mandatory)"),
N_("deepstop"), N_("ceiling (safety stop)"), N_("unknown"), N_("divetime"),
N_("maxdepth"), N_("OLF"), N_("PO2"), N_("airtime"), N_("rgbm"), N_("heading"),
- N_("tissue level warning")
+ N_("tissue level warning"), N_("gaschange"), N_("non stop time")
};
const int nr_events = sizeof(events) / sizeof(const char *);
const char *name;
diff --git a/profile.c b/profile.c
index a385d6825..5b2334a42 100644
--- a/profile.c
+++ b/profile.c
@@ -16,6 +16,7 @@
#include "divelist.h"
#include "color.h"
#include "libdivecomputer/parser.h"
+#include "libdivecomputer/version.h"
int selected_dive = 0;
char zoomed_plot = 0;
@@ -369,27 +370,50 @@ static void plot_one_event(struct graphics_context *gc, struct plot_info *pi, st
break;
depth = data->depth;
}
- /* draw a little tirangular marker and attach tooltip */
- x = SCALEX(gc, event->time.seconds);
- y = SCALEY(gc, depth);
- set_source_rgba(gc, ALERT_BG);
- cairo_move_to(gc->cr, x-15, y+6);
- cairo_line_to(gc->cr, x-3 , y+6);
- cairo_line_to(gc->cr, x-9, y-6);
- cairo_line_to(gc->cr, x-15, y+6);
- cairo_stroke_preserve(gc->cr);
- cairo_fill(gc->cr);
- set_source_rgba(gc, ALERT_FG);
- cairo_move_to(gc->cr, x-9, y-3);
- cairo_line_to(gc->cr, x-9, y+1);
- cairo_move_to(gc->cr, x-9, y+4);
- cairo_line_to(gc->cr, x-9, y+4);
- cairo_stroke(gc->cr);
+ /* don't draw NDL event triangles */
+ if (strcmp(event->name, "non stop time")) {
+ /* draw a little triangular marker and attach tooltip */
+ x = SCALEX(gc, event->time.seconds);
+ y = SCALEY(gc, depth);
+ set_source_rgba(gc, ALERT_BG);
+ cairo_move_to(gc->cr, x-15, y+6);
+ cairo_line_to(gc->cr, x-3 , y+6);
+ cairo_line_to(gc->cr, x-9, y-6);
+ cairo_line_to(gc->cr, x-15, y+6);
+ cairo_stroke_preserve(gc->cr);
+ cairo_fill(gc->cr);
+ set_source_rgba(gc, ALERT_FG);
+ cairo_move_to(gc->cr, x-9, y-3);
+ cairo_line_to(gc->cr, x-9, y+1);
+ cairo_move_to(gc->cr, x-9, y+4);
+ cairo_line_to(gc->cr, x-9, y+4);
+ cairo_stroke(gc->cr);
+ }
/* we display the event on screen - so translate */
- if (event->value)
- snprintf(buffer, sizeof(buffer), "%s: %d", _(event->name), event->value);
- else
+ if (event->value) {
+ if (event->type == SAMPLE_EVENT_DECOSTOP) {
+ /* deal with the packed depth / time data */
+ int seconds = (event->value >> 16) % 60;
+ if (seconds)
+ snprintf(buffer, sizeof(buffer), "%s: %dmin %ds @ %dm", _(event->name), (event->value >> 16) / 60,
+ seconds, event->value & 0xFFFF);
+ else
+ snprintf(buffer, sizeof(buffer), "%s: %dmin @ %dm", _(event->name), (event->value >> 16) / 60,
+ event->value & 0xFFFF);
+#if DC_VERSION_CHECK(0, 3, 0)
+ } else if (event->type == SAMPLE_EVENT_NDL) {
+ int seconds = event->value % 60;
+ if (seconds)
+ snprintf(buffer, sizeof(buffer), "%s: %dmin %ds", _(event->name), event->value / 60, seconds);
+ else
+ snprintf(buffer, sizeof(buffer), "%s: %dmin", _(event->name), event->value / 60);
+#endif
+ } else {
+ snprintf(buffer, sizeof(buffer), "%s: %d", _(event->name), event->value);
+ }
+ } else {
snprintf(buffer, sizeof(buffer), "%s", _(event->name));
+ }
attach_tooltip(x-15, y-6, 12, 12, buffer);
}
@@ -1690,7 +1714,7 @@ static struct plot_info *create_plot_info(struct dive *dive, struct divecomputer
pr_track_t *pr_track, *current;
gboolean missing_pr = FALSE;
struct plot_data *entry = NULL;
- struct event *ev, *ceil_ev;
+ struct event *ev, *deco_ev, *ndl_ev;
double amb_pressure;
/* we want to potentially add synthetic plot_info elements for the gas changes */
@@ -1716,7 +1740,8 @@ static struct plot_info *create_plot_info(struct dive *dive, struct divecomputer
ev = get_next_event(ev->next, "gaschange");
}
/* find the first deco/ceiling event (if any) */
- ceil_ev = get_next_event(dc->events, "ceiling");
+ deco_ev = get_next_event(dc->events, "deco stop");
+ ndl_ev = get_next_event(dc->events, "non stop time");
sec = 0;
lastindex = 0;
lastdepth = -1;
@@ -1731,15 +1756,21 @@ static struct plot_info *create_plot_info(struct dive *dive, struct divecomputer
continue;
}
entry = pi->entry + i + pi_idx;
- while (ceil_ev && ceil_ev->time.seconds <= sample->time.seconds) {
- struct event *next_ceil_ev = get_next_event(ceil_ev->next, "ceiling");
- if (!next_ceil_ev || next_ceil_ev->time.seconds > sample->time.seconds)
+ while (deco_ev && deco_ev->time.seconds <= sample->time.seconds) {
+ struct event *next_deco_ev = get_next_event(deco_ev->next, "deco stop");
+ if (!next_deco_ev || next_deco_ev->time.seconds > sample->time.seconds)
break;
- ceil_ev = next_ceil_ev;
+ deco_ev = next_deco_ev;
}
- if (ceil_ev && ceil_ev->time.seconds <= sample->time.seconds) {
- ceiling = ceil_ev->value;
- ceil_ev = get_next_event(ceil_ev->next, "ceiling");
+ if (deco_ev)
+ ndl_ev = get_next_event(deco_ev, "non stop time");
+ /* if there is an NDL event that comes after the latest deco stop event but
+ * prior to this sample, then deco has ended */
+ if (ndl_ev && ndl_ev->time.seconds <= sample->time.seconds) {
+ ceiling = 0;
+ } else if (deco_ev && deco_ev->time.seconds <= sample->time.seconds) {
+ ceiling = 1000 * (deco_ev->value & 0xffff);
+ deco_ev = get_next_event(deco_ev->next, "deco stop");
}
while (ev && ev->time.seconds < sample->time.seconds) {
/* insert two fake plot info structures for the end of
diff --git a/uemis.c b/uemis.c
index 88099beb3..198d90358 100644
--- a/uemis.c
+++ b/uemis.c
@@ -19,6 +19,7 @@
#include "dive.h"
#include "uemis.h"
#include <libdivecomputer/parser.h>
+#include <libdivecomputer/version.h>
/*
* following code is based on code found in at base64.sourceforge.net/b64.c
@@ -101,8 +102,6 @@ bail:
return datalen;
}
-static gboolean in_deco;
-
/* Create events from the flag bits and other data in the sample;
* These bits basically represent what is displayed on screen at sample time.
* Many of these 'warnings' are way hyper-active and seriously clutter the
@@ -160,19 +159,21 @@ static void uemis_event(struct dive *dive, struct divecomputer *dc, struct sampl
/* flags[7] reflects the little on screen icons that remind of previous
* warnings / alerts - not useful for events */
- /* now add deco / ceiling events */
- if (u_sample->p_amb_tol > dive->surface_pressure.mbar &&
- u_sample->hold_time &&
- u_sample->hold_time < 99) {
- add_event(dc, sample->time.seconds, SAMPLE_EVENT_CEILING, SAMPLE_FLAGS_BEGIN,
- u_sample->hold_depth * 10, N_("ceiling"));
- add_event(dc, sample->time.seconds, SAMPLE_EVENT_DECOSTOP, 0,
- u_sample->hold_time * 60, N_("deco"));
- in_deco = TRUE;
- } else if (in_deco) {
- in_deco = FALSE;
- add_event(dc, sample->time.seconds, SAMPLE_EVENT_CEILING, SAMPLE_FLAGS_END,
- 0, N_("ceiling"));
+ /* now add deco / NDL
+ * This will create an event for every sample (SUCK) but the
+ * code in the parser will then do the right thing and just
+ * keep the relevant ones */
+ if (u_sample->p_amb_tol > dive->surface_pressure.mbar) {
+ if (u_sample->hold_time && u_sample->hold_time < 99) {
+ int hold_depth = u_sample->hold_depth / 100.0 + 0.5;
+ add_event(dc, sample->time.seconds, SAMPLE_EVENT_DECOSTOP, 0,
+ hold_depth | (u_sample->hold_time * 60) << 16 , N_("deco stop"));
+ }
+#if DC_VERSION_CHECK(0, 3, 0)
+ } else {
+ add_event(dc, sample->time.seconds, SAMPLE_EVENT_NDL, 0,
+ u_sample->hold_time * 60, N_("non stop time"));
+#endif
}
}
@@ -189,7 +190,6 @@ void uemis_parse_divelog_binary(char *base64, void *datap) {
struct divecomputer *dc = &dive->dc;
int template, gasoffset;
- in_deco = FALSE;
datalen = uemis_convert_base64(base64, &data);
dive->airtemp.mkelvin = *(uint16_t *)(data + 45) * 100 + 273150;