aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorGravatar Robert C. Helling <helling@atdotde.de>2019-10-29 17:57:34 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2019-10-31 00:30:38 -0700
commit9c8fbe494db231b59c2e072b54af85bc217c00d8 (patch)
tree2b387fea841a6a154135c8b268f3e40298ddbea5 /core
parent43b16f0810f7aa8328fd946e0e014d0625e3b53b (diff)
downloadsubsurface-9c8fbe494db231b59c2e072b54af85bc217c00d8.tar.gz
Planner: Add option to treat O2 as narcotic
When computing the best mix for a target depth, for helium, one can either require that the partial pressure of N2 is the same as at the target depth or the partial pressure of N2 plus O2. Signed-off-by: Robert C. Helling <helling@atdotde.de>
Diffstat (limited to 'core')
-rw-r--r--core/dive.c8
-rw-r--r--core/dive.h2
-rw-r--r--core/pref.h1
-rw-r--r--core/settings/qPrefDivePlanner.cpp2
-rw-r--r--core/settings/qPrefDivePlanner.h5
-rw-r--r--core/subsurfacestartup.c1
6 files changed, 16 insertions, 3 deletions
diff --git a/core/dive.c b/core/dive.c
index d845d8077..9788e64c7 100644
--- a/core/dive.c
+++ b/core/dive.c
@@ -3761,13 +3761,17 @@ fraction_t best_o2(depth_t depth, const struct dive *dive)
}
//Calculate He in best mix. O2 is considered narcopic
-fraction_t best_he(depth_t depth, const struct dive *dive)
+fraction_t best_he(depth_t depth, const struct dive *dive, bool o2narcotic, fraction_t fo2)
{
fraction_t fhe;
int pnarcotic, ambient;
pnarcotic = depth_to_mbar(prefs.bestmixend.mm, 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 (o2narcotic) {
+ fhe.permille = (100 - 100 * pnarcotic / ambient) * 10; //use integer arithmetic to round up to nearest percent
+ } else {
+ fhe.permille = 1000 - fo2.permille - N2_IN_AIR * pnarcotic / ambient;
+ }
if (fhe.permille < 0)
fhe.permille = 0;
return fhe;
diff --git a/core/dive.h b/core/dive.h
index 87aa3e5fd..6d1bd450d 100644
--- a/core/dive.h
+++ b/core/dive.h
@@ -226,7 +226,7 @@ extern int explicit_first_cylinder(const struct dive *dive, const struct divecom
extern int get_depth_at_time(const struct divecomputer *dc, unsigned int time);
extern fraction_t best_o2(depth_t depth, const struct dive *dive);
-extern fraction_t best_he(depth_t depth, const struct dive *dive);
+extern fraction_t best_he(depth_t depth, const struct dive *dive, bool o2narcotic, fraction_t fo2);
extern int get_surface_pressure_in_mbar(const struct dive *dive, bool non_null);
extern int calculate_depth_to_mbar(int depth, pressure_t surface_pressure, int salinity);
diff --git a/core/pref.h b/core/pref.h
index 50e13a117..f7af35415 100644
--- a/core/pref.h
+++ b/core/pref.h
@@ -160,6 +160,7 @@ struct preferences {
bool display_variations;
bool doo2breaks;
bool dobailout;
+ bool o2narcotic;
bool drop_stone_mode;
bool last_stop; // At 6m?
int min_switch_duration; // seconds
diff --git a/core/settings/qPrefDivePlanner.cpp b/core/settings/qPrefDivePlanner.cpp
index f33b390cf..e094bfed0 100644
--- a/core/settings/qPrefDivePlanner.cpp
+++ b/core/settings/qPrefDivePlanner.cpp
@@ -35,6 +35,7 @@ void qPrefDivePlanner::loadSync(bool doSync)
disk_display_variations(doSync);
disk_doo2breaks(doSync);
disk_dobailout(doSync);
+ disk_o2narcotic(doSync);
disk_drop_stone_mode(doSync);
disk_last_stop(doSync);
disk_min_switch_duration(doSync);
@@ -76,6 +77,7 @@ HANDLE_PREFERENCE_BOOL(DivePlanner, "display_variations", display_variations);
HANDLE_PREFERENCE_BOOL(DivePlanner, "doo2breaks", doo2breaks);
HANDLE_PREFERENCE_BOOL(DivePlanner, "dobailbout", dobailout);
+HANDLE_PREFERENCE_BOOL(DivePlanner, "o2narcotic", o2narcotic);
HANDLE_PREFERENCE_BOOL(DivePlanner, "drop_stone_mode", drop_stone_mode);
diff --git a/core/settings/qPrefDivePlanner.h b/core/settings/qPrefDivePlanner.h
index 09d8fabae..7a75fa4ce 100644
--- a/core/settings/qPrefDivePlanner.h
+++ b/core/settings/qPrefDivePlanner.h
@@ -23,6 +23,7 @@ class qPrefDivePlanner : public QObject {
Q_PROPERTY(bool display_variations READ display_variations WRITE set_display_variations NOTIFY display_variationsChanged);
Q_PROPERTY(bool doo2breaks READ doo2breaks WRITE set_doo2breaks NOTIFY doo2breaksChanged);
Q_PROPERTY(bool dobailout READ dobailout WRITE set_dobailout NOTIFY dobailoutChanged);
+ Q_PROPERTY(bool o2narcotic READ o2narcotic WRITE set_o2narcotic NOTIFY o2narcoticChanged)
Q_PROPERTY(bool drop_stone_mode READ drop_stone_mode WRITE set_drop_stone_mode NOTIFY drop_stone_modeChanged);
Q_PROPERTY(bool last_stop READ last_stop WRITE set_last_stop NOTIFY last_stopChanged);
Q_PROPERTY(int min_switch_duration READ min_switch_duration WRITE set_min_switch_duration NOTIFY min_switch_durationChanged);
@@ -60,6 +61,7 @@ public:
static bool display_variations() { return prefs.display_variations; }
static bool doo2breaks() { return prefs.doo2breaks; }
static bool dobailout() { return prefs.dobailout; }
+ static bool o2narcotic() { return prefs.o2narcotic; }
static bool drop_stone_mode() { return prefs.drop_stone_mode; }
static bool last_stop() { return prefs.last_stop; }
static int min_switch_duration() { return prefs.min_switch_duration; }
@@ -89,6 +91,7 @@ public slots:
static void set_display_variations(bool value);
static void set_doo2breaks(bool value);
static void set_dobailout(bool value);
+ static void set_o2narcotic(bool value);
static void set_drop_stone_mode(bool value);
static void set_last_stop(bool value);
static void set_min_switch_duration(int value);
@@ -118,6 +121,7 @@ signals:
void display_variationsChanged(bool value);
void doo2breaksChanged(bool value);
void dobailoutChanged(bool value);
+ void o2narcoticChanged(bool value);
void drop_stone_modeChanged(bool value);
void last_stopChanged(bool value);
void min_switch_durationChanged(int value);
@@ -148,6 +152,7 @@ private:
static void disk_display_variations(bool doSync);
static void disk_doo2breaks(bool doSync);
static void disk_dobailout(bool doSync);
+ static void disk_o2narcotic(bool doSync);
static void disk_drop_stone_mode(bool doSync);
static void disk_last_stop(bool doSync);
static void disk_min_switch_duration(bool doSync);
diff --git a/core/subsurfacestartup.c b/core/subsurfacestartup.c
index 8b7c14179..920285b14 100644
--- a/core/subsurfacestartup.c
+++ b/core/subsurfacestartup.c
@@ -73,6 +73,7 @@ struct preferences default_prefs = {
.display_duration = true,
.display_transitions = true,
.display_variations = false,
+ .o2narcotic = true,
.safetystop = true,
.bottomsac = 20000,
.decosac = 17000,