Rewrite is_gas_used to use get_cylinder_index

get_cylinder_index implements a algorithm to map gaschange events to gas
idx. This is a bit clumsy to use it to map if a gas idx have bin used,
but its consistent with other parts.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Anton Lundin 2013-11-29 00:40:38 +01:00 committed by Dirk Hohndel
parent f24748253c
commit d4da15f53f

View file

@ -295,49 +295,25 @@ void get_selected_dives_text(char *buffer, int size)
bool is_gas_used(struct dive *dive, int idx)
{
cylinder_t *cyl = &dive->cylinder[idx];
int o2, he;
struct divecomputer *dc;
bool used = FALSE;
struct divecomputer *dc = &dive->dc;
bool firstGasExplicit = FALSE;
if (cylinder_none(cyl))
if (cylinder_none(&dive->cylinder[idx]))
return FALSE;
o2 = get_o2(&cyl->gasmix);
he = get_he(&cyl->gasmix);
dc = &dive->dc;
while (dc) {
struct event *event = dc->events;
struct event *event = get_next_event(dc->events, "gaschange");
while (event) {
if (event->value) {
if (event->name && !strcmp(event->name, "gaschange")) {
unsigned int event_he = event->value >> 16;
unsigned int event_o2 = event->value & 0xffff;
if (event->time.seconds < 30)
firstGasExplicit = TRUE;
if (is_air(o2, he)) {
if (is_air(event_o2 * 10, event_he * 10))
used = TRUE;
} else if (event->type == 25 && he == event_he * 10 && o2 == event_o2 * 10) {
/* SAMPLE_EVENT_GASCHANGE2(25) contains both o2 and he */
used = TRUE;
} else if (o2 == event_o2 * 10) {
/* SAMPLE_EVENT_GASCHANGE(11) only contains o2 */
used = TRUE;
}
}
}
if (used)
break;
event = event->next;
if (event->time.seconds < 30)
firstGasExplicit = TRUE;
if (get_cylinder_index(dive, event) == idx)
return TRUE;
event = get_next_event(event->next, "gaschange");
}
if (used)
break;
dc = dc->next;
}
if (idx == 0 && !firstGasExplicit)
used = TRUE;
return used;
return TRUE;
return FALSE;
}
void get_gas_used(struct dive *dive, volume_t gases[MAX_CYLINDERS])