summaryrefslogtreecommitdiffstats
path: root/profile.c
diff options
context:
space:
mode:
authorGravatar Linus Torvalds <torvalds@linux-foundation.org>2014-08-17 12:26:21 -0600
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-10-12 07:45:37 -0400
commitdf4e26c8757a81bb40ba2fd60431d5d1ecd64b11 (patch)
treea7f46fb0a25a5131a42727ab0ca770f2fc0c8f30 /profile.c
parentb47e0658cf5e60e18d4c9405e3b28f196ac3e2d8 (diff)
downloadsubsurface-df4e26c8757a81bb40ba2fd60431d5d1ecd64b11.tar.gz
Start sanitizing gaschange event information
Decode the gasmix data into a sane format when creating the event, and add the (currently unused) ability to specify a gas change to a particular cylinder rather than (or in addition to) the gasmix. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'profile.c')
-rw-r--r--profile.c22
1 files changed, 12 insertions, 10 deletions
diff --git a/profile.c b/profile.c
index 71a9164e6..79917d6e6 100644
--- a/profile.c
+++ b/profile.c
@@ -289,6 +289,14 @@ struct plot_info *analyze_plot_info(struct plot_info *pi)
return pi;
}
+/*
+ * If the event has an explicit cylinder index,
+ * we return that. If it doesn't, we return the best
+ * match based on the gasmix.
+ *
+ * Some dive computers give cylinder indexes, some
+ * give just the gas mix.
+ */
int get_cylinder_index(struct dive *dive, struct event *ev)
{
int i;
@@ -296,10 +304,9 @@ int get_cylinder_index(struct dive *dive, struct event *ev)
int target_o2, target_he;
struct gasmix *g;
- /*
- * Crazy gas change events give us odd encoded o2/he in percent.
- * Decode into our internal permille format.
- */
+ if (ev->gas.index >= 0)
+ return ev->gas.index;
+
g = get_gasmix_from_event(ev);
target_o2 = get_o2(g);
target_he = get_he(g);
@@ -318,13 +325,8 @@ int get_cylinder_index(struct dive *dive, struct event *ev)
delta_o2 = get_o2(&cyl->gasmix) - target_o2;
delta_he = get_he(&cyl->gasmix) - target_he;
distance = delta_o2 * delta_o2;
+ distance += delta_he * delta_he;
- /* Check the event type to figure out if we should care about the he part.
- * SAMPLE_EVENT_GASCHANGE, aka without he
- * SAMPLE_EVENT_GASCHANGE2, aka with he
- */
- if (ev->type == SAMPLE_EVENT_GASCHANGE2)
- distance += delta_he * delta_he;
if (distance >= score)
continue;
score = distance;