From 42895606b1968bc56c75fd15a8aecc5960daab38 Mon Sep 17 00:00:00 2001 From: Willem Ferguson Date: Wed, 6 Jun 2018 15:57:20 +0200 Subject: 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 --- core/gaspressures.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'core/gaspressures.c') 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) -- cgit v1.2.3-70-g09d2