summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar willemferguson <willemferguson@zoology.up.ac.za>2019-05-15 18:39:29 +0200
committerGravatar bstoeger <32835590+bstoeger@users.noreply.github.com>2019-05-17 09:46:05 +0200
commita969d1dd4518ce77e8fba920aec4a5d8cfd1f636 (patch)
tree0906b0c0305cf323585b67522b0487d646e74677
parent9590709e8c379e5d8b62b426cf4d5b1d59aa8b84 (diff)
downloadsubsurface-a969d1dd4518ce77e8fba920aec4a5d8cfd1f636.tar.gz
Implement height-to-pressure functions in planner
The units.h file has two functions to convert atm pressure to mbar and also to convert mbar to atm pressure. Implement these two functions in the planner. Signed-off-by: willemferguson <willemferguson@zoology.up.ac.za>
-rw-r--r--core/plannernotes.c3
-rw-r--r--desktop-widgets/diveplanner.cpp9
2 files changed, 7 insertions, 5 deletions
diff --git a/core/plannernotes.c b/core/plannernotes.c
index e7a09d96d..9353fa2ec 100644
--- a/core/plannernotes.c
+++ b/core/plannernotes.c
@@ -11,6 +11,7 @@
#include <string.h>
#include "dive.h"
#include "deco.h"
+#include "units.h"
#include "divelist.h"
#include "planner.h"
#include "gettext.h"
@@ -420,7 +421,7 @@ void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool show_d
put_string(&buf, "<br>");
const char *depth_unit;
- int altitude = (int) get_depth_units((int) (log(1013.0 / diveplan->surface_pressure) * 7800000), NULL, &depth_unit);
+ int altitude = (int) get_depth_units((int) (pressure_to_altitude(diveplan->surface_pressure)), NULL, &depth_unit);
put_format_loc(&buf, translate("gettextFromC", "ATM pressure: %dmbar (%d%s)<br></div>"), diveplan->surface_pressure, altitude, depth_unit);
diff --git a/desktop-widgets/diveplanner.cpp b/desktop-widgets/diveplanner.cpp
index 4988389c5..af19ed079 100644
--- a/desktop-widgets/diveplanner.cpp
+++ b/desktop-widgets/diveplanner.cpp
@@ -4,6 +4,7 @@
#include "desktop-widgets/mainwindow.h"
#include "core/planner.h"
#include "core/qthelper.h"
+#include "core/units.h"
#include "core/settings/qPrefDivePlanner.h"
#include "core/gettextfromc.h"
@@ -235,7 +236,7 @@ void DivePlannerWidget::settingsChanged()
ui.atmHeight->setMaximum(3000);
}
ui.atmHeight->blockSignals(true);
- ui.atmHeight->setValue((int) get_depth_units((int) (log(1013.0 / plannerModel->getSurfacePressure()) * 7800000), NULL,NULL));
+ ui.atmHeight->setValue((int) get_depth_units((int) pressure_to_altitude(plannerModel->getSurfacePressure()), NULL,NULL));
ui.atmHeight->blockSignals(false);
}
@@ -243,13 +244,13 @@ void DivePlannerWidget::atmPressureChanged(const int pressure)
{
plannerModel->setSurfacePressure(pressure);
ui.atmHeight->blockSignals(true);
- ui.atmHeight->setValue((int) get_depth_units((int) (log(1013.0 / pressure) * 7800000), NULL,NULL));
+ ui.atmHeight->setValue((int) get_depth_units((int) pressure_to_altitude(pressure), NULL,NULL));
ui.atmHeight->blockSignals(false);
}
void DivePlannerWidget::heightChanged(const int height)
-{
- int pressure = (int) (1013.0 * exp(- (double) units_to_depth((double) height).mm / 7800000.0));
+{ // height is in ft or in meters
+ int pressure = (int) (altitude_to_pressure(units_to_depth((double) height).mm));
ui.ATMPressure->blockSignals(true);
ui.ATMPressure->setValue(pressure);
ui.ATMPressure->blockSignals(false);