summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Robert C. Helling <helling@lmu.de>2013-03-18 15:22:14 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2013-03-18 07:37:08 -0700
commitae4bd802afac9723da27f2bcc3d402effd636ffc (patch)
tree4c0d95723556656c1d07eda635f26490cf638f66
parent8a5792d473bb30a6f5cbfd2168c4427c16436031 (diff)
downloadsubsurface-ae4bd802afac9723da27f2bcc3d402effd636ffc.tar.gz
Take only used gases into account when showing gas in divelist
Here is a patch that restricts the gases listed in the divelist to those that are actually used. I seem to have the indentation now under control but I am not sure about the logic: 1) First gas (with index 0) is always used. 2) If there is a gas switch event, the new gas is also used (determined by walking the list of dive computers and then the list of events). Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--divelist.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/divelist.c b/divelist.c
index ac81d9daa..aa29c72ed 100644
--- a/divelist.c
+++ b/divelist.c
@@ -459,11 +459,39 @@ static void get_dive_gas(struct dive *dive, int *o2_p, int *he_p, int *o2low_p)
int i;
int maxo2 = -1, maxhe = -1, mino2 = 1000;
+
for (i = 0; i < MAX_CYLINDERS; i++) {
cylinder_t *cyl = dive->cylinder + i;
struct gasmix *mix = &cyl->gasmix;
int o2 = mix->o2.permille;
int he = mix->he.permille;
+ struct divecomputer *dc = &dive->dc;
+ int used = !i; /* The first gas is always used */
+
+ 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 (is_air(o2, he)){
+ if (is_air(event_o2 * 10, event_he * 10))
+ used = 1;
+ }
+ else {
+ if (he == event_he*10 && o2 == event_o2*10)
+ used = 1;
+ }
+ }
+ }
+ event = event->next;
+ }
+ dc = dc->next;
+ }
+ if (!used)
+ continue;
if (cylinder_none(cyl))
continue;