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) bool is_gas_used(struct dive *dive, int idx)
{ {
cylinder_t *cyl = &dive->cylinder[idx]; struct divecomputer *dc = &dive->dc;
int o2, he;
struct divecomputer *dc;
bool used = FALSE;
bool firstGasExplicit = FALSE; bool firstGasExplicit = FALSE;
if (cylinder_none(cyl)) if (cylinder_none(&dive->cylinder[idx]))
return FALSE; return FALSE;
o2 = get_o2(&cyl->gasmix);
he = get_he(&cyl->gasmix);
dc = &dive->dc;
while (dc) { while (dc) {
struct event *event = dc->events; struct event *event = get_next_event(dc->events, "gaschange");
while (event) { while (event) {
if (event->value) { if (event->time.seconds < 30)
if (event->name && !strcmp(event->name, "gaschange")) { firstGasExplicit = TRUE;
unsigned int event_he = event->value >> 16; if (get_cylinder_index(dive, event) == idx)
unsigned int event_o2 = event->value & 0xffff; return TRUE;
if (event->time.seconds < 30) event = get_next_event(event->next, "gaschange");
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 (used)
break;
dc = dc->next; dc = dc->next;
} }
if (idx == 0 && !firstGasExplicit) if (idx == 0 && !firstGasExplicit)
used = TRUE; return TRUE;
return used; return FALSE;
} }
void get_gas_used(struct dive *dive, volume_t gases[MAX_CYLINDERS]) void get_gas_used(struct dive *dive, volume_t gases[MAX_CYLINDERS])