From: Linus Torvalds <[email protected]>
Date: Sat, 2 Apr 2016 11:13:35 -0500
Subject: [PATCH 1/4] Make "is_gasmix_redundant()" more robust

The gas switch event handling is somewhat fragile, mostly because the
legacy event encoding for gas switches is odd.  It's also limited to
whole percentages, unlike our internal gas mix model.

In addition, it also ends up comparing the values to the raw permille
values, which is wrong for air, and wouldn't match our O2_IN_AIR which
is 209 permille (closest approximation to 20.946%).

So handle air separately, since "21" really is a valid oxygen value for
air, and should match 20.9%.  And use the proper accessor functions to
get the gasmix values.

Signed-off-by: Linus Torvalds <[email protected]>
---

This is fairly safe but also not very important. It just makes the gas mix 
event notice that a value of "21" matches any of our air formats.

 subsurface-core/dive.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/subsurface-core/dive.c b/subsurface-core/dive.c
index f870d90e2a4e..8d8765aa04f3 100644
--- a/subsurface-core/dive.c
+++ b/subsurface-core/dive.c
@@ -49,13 +49,17 @@ int event_is_gaschange(struct event *ev)
  */
 int event_gasmix_redundant(struct event *ev)
 {
+       struct gasmix *mix = &ev->gas.mix;
        int value = ev->value;
        int o2, he;
 
+       if (value == 21)
+               return gasmix_is_air(mix);
+
        o2 = (value & 0xffff) * 10;
        he = (value >> 16) * 10;
-       return  o2 == ev->gas.mix.o2.permille &&
-               he == ev->gas.mix.he.permille;
+       return  o2 == get_o2(mix) &&
+               he == get_he(mix);
 }
 
 struct event *add_event(struct divecomputer *dc, unsigned int time, int type, 
int flags, int value, const char *name)
-- 
2.8.0.rc4.303.g3931579

_______________________________________________
subsurface mailing list
[email protected]
http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface

Reply via email to