aboutsummaryrefslogtreecommitdiffstats
path: root/dive.c
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2014-06-01 12:07:29 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-06-01 12:07:29 -0700
commit1a040134538b7733f3088ea34f101cfedecc2c64 (patch)
tree53eb0fc9dd65f3e75fb886075cc5b952b3800157 /dive.c
parentfb4d9b34f87f71b072bccb36633d7247b9d9dd9d (diff)
downloadsubsurface-1a040134538b7733f3088ea34f101cfedecc2c64.tar.gz
Encapsulate the horrid gas encoding in gas change events
We should never pass permille values around as integers. And we shouldn't have to decode the stupid value in more than one place. This doesn't tackle all the places where we access O2 and He "too early" and should instead keep passing around a gaxmix. But it's a first step. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'dive.c')
-rw-r--r--dive.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/dive.c b/dive.c
index 0d8f48754..6545fecab 100644
--- a/dive.c
+++ b/dive.c
@@ -6,6 +6,7 @@
#include <limits.h>
#include "gettext.h"
#include "dive.h"
+#include "libdivecomputer.h"
struct tag_entry *g_tag_list = NULL;
@@ -76,6 +77,19 @@ void remove_event(struct event* event)
}
}
+/* this returns a pointer to static variable - so use it right away after calling */
+struct gasmix *get_gasmix_from_event(struct event *ev)
+{
+ static struct gasmix g;
+ g.o2.permille = g.he.permille = 0;
+ if (ev && (ev->type == SAMPLE_EVENT_GASCHANGE || ev->type == SAMPLE_EVENT_GASCHANGE2)) {
+ g.o2.permille = 10 * ev->value & 0xffff;
+ if (ev->type == SAMPLE_EVENT_GASCHANGE2)
+ g.he.permille = 10 * (ev->value >> 16);
+ }
+ return &g;
+}
+
int get_pressure_units(int mb, const char **units)
{
int pressure;