aboutsummaryrefslogtreecommitdiffstats
path: root/statistics.c
diff options
context:
space:
mode:
authorGravatar Anton Lundin <glance@acc.umu.se>2013-11-29 00:40:38 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2013-11-29 08:22:56 -0800
commitd4da15f53fb1fa813329ea0990a313afd714254d (patch)
tree41215386fdf36e99aa56a1576e5aacec3794ddba /statistics.c
parentf24748253c4e5500f3fba113bfb6cfc4a4e13df6 (diff)
downloadsubsurface-d4da15f53fb1fa813329ea0990a313afd714254d.tar.gz
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>
Diffstat (limited to 'statistics.c')
-rw-r--r--statistics.c44
1 files changed, 10 insertions, 34 deletions
diff --git a/statistics.c b/statistics.c
index c4beba3b2..807539f2a 100644
--- a/statistics.c
+++ b/statistics.c
@@ -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])