diff options
author | Robert C. Helling <helling@lmu.de> | 2013-03-18 15:50:47 +0100 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2013-03-18 08:08:02 -0700 |
commit | 959dc942be8c8caa026d90c7492edfb11f3911ba (patch) | |
tree | 1ce0daf5ef53e0046b2dc66c305712dfed4b437f /divelist.c | |
parent | ae4bd802afac9723da27f2bcc3d402effd636ffc (diff) | |
download | subsurface-959dc942be8c8caa026d90c7492edfb11f3911ba.tar.gz |
Correctly handle first gas when deciding if gas is used
Gas with index 0 is assumed to be the first gas only if there is no
gaschage event in the first 30 seconds of the dive.
[Dirk Hohndel: minor formatting change in a logical expression]
Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'divelist.c')
-rw-r--r-- | divelist.c | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/divelist.c b/divelist.c index aa29c72ed..feec27b19 100644 --- a/divelist.c +++ b/divelist.c @@ -466,7 +466,8 @@ static void get_dive_gas(struct dive *dive, int *o2_p, int *he_p, int *o2low_p) int o2 = mix->o2.permille; int he = mix->he.permille; struct divecomputer *dc = &dive->dc; - int used = !i; /* The first gas is always used */ + int used = 0; + int first_gas_explicit = 0; while (dc){ struct event *event = dc->events; @@ -476,6 +477,8 @@ static void get_dive_gas(struct dive *dive, int *o2_p, int *he_p, int *o2low_p) unsigned int event_he = event->value >> 16; unsigned int event_o2 = event->value & 0xffff; + if (event->time.seconds < 30) + first_gas_explicit = 1; if (is_air(o2, he)){ if (is_air(event_o2 * 10, event_he * 10)) used = 1; @@ -490,6 +493,11 @@ static void get_dive_gas(struct dive *dive, int *o2_p, int *he_p, int *o2low_p) } dc = dc->next; } + + /* Unless explicity set, the first gas to use has index 0 */ + if (i == 0 && !first_gas_explicit) + used = 1; + if (!used) continue; |