diff options
-rw-r--r-- | core/dive.c | 2 | ||||
-rw-r--r-- | core/dive.h | 11 | ||||
-rw-r--r-- | core/pref.h | 2 | ||||
-rw-r--r-- | core/subsurface-qt/SettingsObjectWrapper.cpp | 4 | ||||
-rw-r--r-- | core/subsurfacestartup.c | 2 | ||||
-rw-r--r-- | desktop-widgets/diveplanner.cpp | 8 |
6 files changed, 20 insertions, 9 deletions
diff --git a/core/dive.c b/core/dive.c index 29198afd6..9db233dca 100644 --- a/core/dive.c +++ b/core/dive.c @@ -3661,7 +3661,7 @@ fraction_t best_He(depth_t depth, struct dive *dive) { fraction_t fhe; int pnarcotic, ambient; - pnarcotic = depth_to_mbar(prefs.bestmixend, dive); + 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 (fhe.permille < 0) diff --git a/core/dive.h b/core/dive.h index 9c612048d..c968746f8 100644 --- a/core/dive.h +++ b/core/dive.h @@ -481,6 +481,17 @@ static inline depth_t gas_mod(struct gasmix *mix, pressure_t po2_limit, struct d return rounded_depth; } +/* Maximum narcotic depth rounded to multiples of roundto mm */ +static inline depth_t gas_mnd(struct gasmix *mix, depth_t end, struct dive *dive, int roundto) { + depth_t rounded_depth; + pressure_t ppo2n2; + ppo2n2.mbar = depth_to_mbar(end.mm, dive); + + double maxambient = ppo2n2.mbar / (1 - get_he(mix) / 1000.0); + rounded_depth.mm = rint(mbar_to_depth(maxambient, dive) / roundto) * roundto; + return rounded_depth; +} + #define SURFACE_THRESHOLD 750 /* somewhat arbitrary: only below 75cm is it really diving */ /* this is a global spot for a temporary dive structure that we use to diff --git a/core/pref.h b/core/pref.h index a0f9158b8..a30417923 100644 --- a/core/pref.h +++ b/core/pref.h @@ -92,7 +92,7 @@ struct preferences { int descrate; int bottompo2; int decopo2; - int bestmixend; + depth_t bestmixend; int proxy_type; char *proxy_host; int proxy_port; diff --git a/core/subsurface-qt/SettingsObjectWrapper.cpp b/core/subsurface-qt/SettingsObjectWrapper.cpp index b8865e256..4604abfd7 100644 --- a/core/subsurface-qt/SettingsObjectWrapper.cpp +++ b/core/subsurface-qt/SettingsObjectWrapper.cpp @@ -917,7 +917,7 @@ int DivePlannerSettings::decopo2() const int DivePlannerSettings::bestmixend() const { - return prefs.bestmixend; + return prefs.bestmixend.mm; } int DivePlannerSettings::reserveGas() const @@ -1099,7 +1099,7 @@ void DivePlannerSettings::setBestmixend(int value) QSettings s; s.beginGroup(group); s.setValue("bestmixend", value); - prefs.bestmixend = value; + prefs.bestmixend.mm = value; emit bestmixendChanged(value); } diff --git a/core/subsurfacestartup.c b/core/subsurfacestartup.c index 1dba381de..126cc5ee1 100644 --- a/core/subsurfacestartup.c +++ b/core/subsurfacestartup.c @@ -52,7 +52,7 @@ struct preferences default_prefs = { .descrate = 18000 / 60, .bottompo2 = 1400, .decopo2 = 1600, - .bestmixend = 30000, + .bestmixend.mm = 30000, .doo2breaks = false, .drop_stone_mode = false, .switch_at_req_stop = false, diff --git a/desktop-widgets/diveplanner.cpp b/desktop-widgets/diveplanner.cpp index 7ac88f9bc..31dd4bb93 100644 --- a/desktop-widgets/diveplanner.cpp +++ b/desktop-widgets/diveplanner.cpp @@ -291,7 +291,7 @@ PlannerSettingsWidget::PlannerSettingsWidget(QWidget *parent, Qt::WindowFlags f) prefs.descrate = s.value("descrate", prefs.descrate).toInt(); prefs.bottompo2 = s.value("bottompo2", prefs.bottompo2).toInt(); prefs.decopo2 = s.value("decopo2", prefs.decopo2).toInt(); - prefs.bestmixend = s.value("bestmixend", prefs.bestmixend).toInt(); + prefs.bestmixend.mm = s.value("bestmixend", prefs.bestmixend.mm).toInt(); prefs.doo2breaks = s.value("doo2breaks", prefs.doo2breaks).toBool(); prefs.switch_at_req_stop = s.value("switch_at_req_stop", prefs.switch_at_req_stop).toBool(); prefs.min_switch_duration = s.value("min_switch_duration", prefs.min_switch_duration).toInt(); @@ -385,7 +385,7 @@ void PlannerSettingsWidget::updateUnitsUI() ui.ascRateStops->setValue(rint(prefs.ascratestops / UNIT_FACTOR)); ui.ascRateLast6m->setValue(rint(prefs.ascratelast6m / UNIT_FACTOR)); ui.descRate->setValue(rint(prefs.descrate / UNIT_FACTOR)); - ui.bestmixEND->setValue(rint(get_depth_units(prefs.bestmixend, NULL, NULL))); + ui.bestmixEND->setValue(rint(get_depth_units(prefs.bestmixend.mm, NULL, NULL))); } PlannerSettingsWidget::~PlannerSettingsWidget() @@ -406,7 +406,7 @@ PlannerSettingsWidget::~PlannerSettingsWidget() s.setValue("descrate", prefs.descrate); s.setValue("bottompo2", prefs.bottompo2); s.setValue("decopo2", prefs.decopo2); - s.setValue("bestmixend", prefs.bestmixend); + s.setValue("bestmixend", prefs.bestmixend.mm); s.setValue("doo2breaks", prefs.doo2breaks); s.setValue("drop_stone_mode", prefs.drop_stone_mode); s.setValue("switch_at_req_stop", prefs.switch_at_req_stop); @@ -522,7 +522,7 @@ void PlannerSettingsWidget::setDecoPo2(double po2) void PlannerSettingsWidget::setBestmixEND(int depth) { - prefs.bestmixend = units_to_depth(depth); + prefs.bestmixend.mm = units_to_depth(depth); } void PlannerSettingsWidget::setBackgasBreaks(bool dobreaks) |