Best mix O2 calculated based on planner Bottom O2 preference
Best mix He calculated based on EAD of 30m (should be made user-configurable)

Signed-off-by: Rick Walsh <[email protected]>
---
 core/dive.c | 23 +++++++++++++++++++++++
 core/dive.h |  3 +++
 2 files changed, 26 insertions(+)

diff --git a/core/dive.c b/core/dive.c
index c2ea11a..6d5ba1d 100644
--- a/core/dive.c
+++ b/core/dive.c
@@ -3639,3 +3639,26 @@ int get_depth_at_time(struct divecomputer *dc, unsigned 
int time)
                }
        return depth;
 }
+
+//Calculate O2 in best mix
+fraction_t best_o2(depth_t depth, struct dive *dive)
+{
+       fraction_t fo2;
+
+       fo2.permille = (prefs.bottompo2 * 100 / depth_to_mbar(depth.mm, dive)) 
* 10;    //use integer arithmetic to round down to nearest percent
+       return fo2;
+}
+
+//Calculate He in best mix. O2 is considered narcopic
+fraction_t best_He(depth_t depth, struct dive *dive)
+{
+       fraction_t fhe;
+       int ead = 30000; //this should be user-configurable
+       int pnarcotic, ambient;
+       pnarcotic = depth_to_mbar(ead, dive);
+       ambient = depth_to_mbar(depth.mm, dive);
+       fhe.permille = (100 - 100 * pnarcotic / ambient) * 10;  //use integer 
arithmetic to round up to nearest percent
+       if (fhe.permille < 0)
+               fhe.permille = 0;
+       return fhe;
+}
diff --git a/core/dive.h b/core/dive.h
index 82cda67..5988990 100644
--- a/core/dive.h
+++ b/core/dive.h
@@ -402,6 +402,9 @@ extern void picture_free(struct picture *picture);
 extern int explicit_first_cylinder(struct dive *dive, struct divecomputer *dc);
 extern int get_depth_at_time(struct divecomputer *dc, unsigned int time);
 
+extern fraction_t best_o2(depth_t depth, struct dive *dive);
+extern fraction_t best_He(depth_t depth, struct dive *dive);
+
 static inline int get_surface_pressure_in_mbar(const struct dive *dive, bool 
non_null)
 {
        int mbar = dive->surface_pressure.mbar;
-- 
2.5.5

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

Reply via email to