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>
This commit is contained in:
Dirk Hohndel 2014-06-01 12:07:29 -07:00
parent fb4d9b34f8
commit 1a04013453
6 changed files with 38 additions and 23 deletions

14
dive.c
View file

@ -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;