summaryrefslogtreecommitdiffstats
path: root/statistics.c
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2013-05-31 13:40:46 +0900
committerGravatar Dirk Hohndel <dirk@hohndel.org>2013-05-31 13:43:49 +0900
commitff6e730e30a0ab398272b01ef95d1e974b7db172 (patch)
treea8cbe291ec80fa307a596da4d6d9a06ccbb07de0 /statistics.c
parent34c7aa940ca369389133c82d096a84f7a80fa6d9 (diff)
downloadsubsurface-ff6e730e30a0ab398272b01ef95d1e974b7db172.tar.gz
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 <dirk@hohndel.org>
Diffstat (limited to 'statistics.c')
-rw-r--r--statistics.c62
1 files changed, 56 insertions, 6 deletions
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;
}