From ff6e730e30a0ab398272b01ef95d1e974b7db172 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Fri, 31 May 2013 13:40:46 +0900 Subject: [PATCH] List only the gases used in the Info tab The equipment tab will still show all defined gases, but the info for the dive should only list the ones used. Also change the name of the two gas related boxes to better reflect the data that is shown. Signed-off-by: Dirk Hohndel --- qt-ui/maintab.ui | 4 ++-- statistics.c | 62 +++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 58 insertions(+), 8 deletions(-) diff --git a/qt-ui/maintab.ui b/qt-ui/maintab.ui index 4bf37e9a3..854e67940 100644 --- a/qt-ui/maintab.ui +++ b/qt-ui/maintab.ui @@ -240,7 +240,7 @@ - O²/HE + Gases Used @@ -335,7 +335,7 @@ - Gas Used + Gas Consumed diff --git a/statistics.c b/statistics.c index 411ba1c1f..6459b3802 100644 --- a/statistics.c +++ b/statistics.c @@ -290,23 +290,73 @@ volume_t get_gas_used(struct dive *dive) return gas_used; } +bool is_gas_used(struct dive *dive, int idx) +{ + cylinder_t *cyl = &dive->cylinder[idx]; + int o2, he; + struct divecomputer *dc; + bool used = FALSE; + bool firstGasExplicit = FALSE; + if (cylinder_none(cyl)) + return FALSE; + + o2 = get_o2(&cyl->gasmix); + he = get_he(&cyl->gasmix); + dc = &dive->dc; + while (dc) { + struct event *event = dc->events; + 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 (he == event_he * 10 && o2 == event_o2 * 10) { + used = TRUE; + } + } + } + if (used) + break; + event = event->next; + } + if (used) + break; + dc = dc->next; + } + if (idx == 0 && !firstGasExplicit) + used = TRUE; + return used; +} + #define MAXBUF 80 /* for the O2/He readings just create a list of them */ char *get_gaslist(struct dive *dive) { int idx, offset = 0; static char buf[MAXBUF]; + int o2, he; buf[0] = '\0'; for (idx = 0; idx < MAX_CYLINDERS; idx++) { - cylinder_t *cyl = &dive->cylinder[idx]; - if (!cylinder_none(cyl)) { - int o2 = get_o2(&cyl->gasmix); - int he = get_he(&cyl->gasmix); + cylinder_t *cyl; + if (!is_gas_used(dive, idx)) + continue; + cyl = &dive->cylinder[idx]; + o2 = get_o2(&cyl->gasmix); + he = get_he(&cyl->gasmix); + if (is_air(o2, he)) + snprintf(buf + offset, MAXBUF - offset, (offset > 0) ? ", %s" : "%s", _("air")); + else snprintf(buf + offset, MAXBUF - offset, (offset > 0) ? ", %d/%d" : "%d/%d", (o2 + 5) / 10, (he + 5) / 10); - offset = strlen(buf); - } + offset = strlen(buf); } + if (*buf == '\0') + strncpy(buf, _("air"), MAXBUF); return buf; }