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

View file

@ -78,8 +78,9 @@ void get_gas_from_events(struct divecomputer *dc, int time, int *o2, int *he)
struct event *event = dc->events;
while (event && event->time.seconds <= time) {
if (!strcmp(event->name, "gaschange")) {
*o2 = 10 * event->value & 0xffff;
*he = 10 * event->value >> 16;
struct gasmix *g = get_gasmix_from_event(event);
*o2 = get_o2(g);
*he = get_he(g);
}
event = event->next;
}