summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Willem Ferguson <willemferguson@zoology.up.ac.za>2018-06-06 15:57:20 +0200
committerGravatar Lubomir I. Ivanov <neolit123@gmail.com>2018-06-08 17:07:20 +0300
commit42895606b1968bc56c75fd15a8aecc5960daab38 (patch)
tree9259e6226cba345b38b0a58249b0443ba9a35980
parent487a4b2c322d0f5c9f8eb4dd5d5f239dbf253abc (diff)
downloadsubsurface-42895606b1968bc56c75fd15a8aecc5960daab38.tar.gz
Provide correct cylinder pressures for bailout dives
Calculate the correct cylinder pressures for rebreather dives with bailout. Currently the cylinder pressures for a dive are calculated assuming a single dive mode for that dive. Bailout indroduces more than one dive mode for a single dive, i.e. transitions from CCR or PSCR to OC and back. Currently the start and end pressures for each cylinder are used to interpolate cylinder pressures while that cylinder is used. However, the different gas consumption rates for OC, PSCR and CCR are not taken into account in this interpolation and the cylinder pressure is indicated by an averaged interpolation accross the rebreather and OC legs of the dive. Consequently the increased drop in cylinder pressure during OC is not shown. This PR allows differentiation between CCR/PSCR legs of the dive and the OC bailout segments, showing realistic interpolation that indicate the increased rate of gas use during OC. Signed-off-by: Willem Ferguson <willemferguson@zoology.up.ac.za>
-rw-r--r--core/gaspressures.c19
1 files changed, 14 insertions, 5 deletions
diff --git a/core/gaspressures.c b/core/gaspressures.c
index 139665551..626d617bf 100644
--- a/core/gaspressures.c
+++ b/core/gaspressures.c
@@ -23,6 +23,7 @@
#include "display.h"
#include "profile.h"
#include "gaspressures.h"
+#include "pref.h"
static pr_track_t *pr_track_alloc(int start, int t_start)
{
@@ -349,8 +350,10 @@ void populate_pressure_information(struct dive *dive, struct divecomputer *dc, s
cylinder_t *cylinder = dive->cylinder + sensor;
pr_track_t *track = NULL;
pr_track_t *current = NULL;
- struct event *ev;
+ struct event *ev, *b_ev;
int missing_pr = 0, dense = 1;
+ enum divemode_t dmode = dc->divemode;
+ const double gasfactor[5] = {1.0, 0.0, prefs.pscr_ratio/1000.0, 1.0, 1.0 };
/* if we have no pressure data whatsoever, this is pointless, so let's just return */
if (!cylinder->start.mbar && !cylinder->end.mbar &&
@@ -386,21 +389,27 @@ void populate_pressure_information(struct dive *dive, struct divecomputer *dc, s
ev = NULL;
if (has_gaschange_event(dive, dc, sensor))
ev = get_next_event(dc->events, "gaschange");
+ b_ev = get_next_event(dc->events, "modechange");
for (int i = first; i <= last; i++) {
struct plot_data *entry = pi->entry + i;
unsigned pressure = SENSOR_PRESSURE(entry, sensor);
int time = entry->sec;
- while (ev && ev->time.seconds <= time) {
- cyl = get_cylinder_index(dive, ev);
+ while (ev && ev->time.seconds <= time) { // Find 1st gaschange event after
+ cyl = get_cylinder_index(dive, ev); // the current gas change.
if (cyl < 0)
cyl = sensor;
ev = get_next_event(ev->next, "gaschange");
}
- if (current) {
- entry->pressure_time = calc_pressure_time(dive, entry - 1, entry);
+ while (b_ev && b_ev->time.seconds <= time) { // Keep existing divemode, then
+ dmode = b_ev->value; // find 1st divemode change event after the current
+ b_ev = get_next_event(b_ev->next, "modechange"); // divemode change.
+ }
+
+ if (current) { // calculate pressure-time, taking into account the dive mode for this specific segment.
+ entry->pressure_time = (int)(calc_pressure_time(dive, entry - 1, entry) * gasfactor[dmode] + 0.5);
current->pressure_time += entry->pressure_time;
current->t_end = entry->sec;
if (pressure)