summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Robert C. Helling <helling@atdotde.de>2021-02-21 17:43:26 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2021-02-26 08:42:30 -0800
commit6b8a07f0d93b09021490b6c4c7595e3cb0ea17c2 (patch)
tree5cd5852f06b6ffa56e9fb353283525cafbce07fb
parent5595a70bd5a73e4acaef3af6157aa50274721669 (diff)
downloadsubsurface-6b8a07f0d93b09021490b6c4c7595e3cb0ea17c2.tar.gz
Planner: Depth dependent setpoint changes in CCR mode
We had a user request to allow for setpoint changes at certain depths for CCR deco. You can now enter a cylinder with name like "SP 1.4" ('S' and 'P' and ' ' and a float) with a switch depth and that cylinder is interpreted as a depth dependent setpoint switch. This user interface is a hack. But I believe that such setpoint changes are similar enough to gas switches during deco and should thus be handled in a simiar manner. I would be happy to hear ideas how this could be made less easter eggish. Suggested-by: Justin Ashworth Signed-off-by: Robert C. Helling <helling@atdotde.de>
-rw-r--r--core/planner.c32
1 files changed, 24 insertions, 8 deletions
diff --git a/core/planner.c b/core/planner.c
index 49e044f05..be257a0a0 100644
--- a/core/planner.c
+++ b/core/planner.c
@@ -382,7 +382,23 @@ struct gaschanges {
int gasidx;
};
-static struct gaschanges *analyze_gaslist(struct diveplan *diveplan, struct dive *dive, int *gaschangenr, int depth, int *asc_cylinder)
+// Return new setpoint if cylinderi is a setpoint change an 0 if not
+
+static int setpoint_change(struct dive *dive, int cylinderid)
+{
+ cylinder_t *cylinder = get_cylinder(dive, cylinderid);
+ if (!cylinder->type.description)
+ return 0;
+ if (!strncmp(cylinder->type.description, "SP ", 3)) {
+ float sp;
+ sscanf(cylinder->type.description + 3, "%f", &sp);
+ return (int) (sp * 1000);
+ } else {
+ return 0;
+ }
+}
+
+static struct gaschanges *analyze_gaslist(struct diveplan *diveplan, struct dive *dive, int *gaschangenr, int depth, int *asc_cylinder, bool ccr)
{
int nr = 0;
struct gaschanges *gaschanges = NULL;
@@ -390,7 +406,7 @@ static struct gaschanges *analyze_gaslist(struct diveplan *diveplan, struct dive
int best_depth = get_cylinder(dive, *asc_cylinder)->depth.mm;
bool total_time_zero = true;
while (dp) {
- if (dp->time == 0 && total_time_zero) {
+ if (dp->time == 0 && total_time_zero && (ccr == (bool) setpoint_change(dive, dp->cylinderid))) {
if (dp->depth.mm <= depth) {
int i = 0;
nr++;
@@ -737,12 +753,8 @@ bool plan(struct deco_state *ds, struct diveplan *diveplan, struct dive *dive, i
best_first_ascend_cylinder = current_cylinder;
/* Find the gases available for deco */
- if (divemode == CCR && !prefs.dobailout) { // Don't change gas in CCR mode
- gaschanges = NULL;
- gaschangenr = 0;
- } else {
- gaschanges = analyze_gaslist(diveplan, dive, &gaschangenr, depth, &best_first_ascend_cylinder);
- }
+ gaschanges = analyze_gaslist(diveplan, dive, &gaschangenr, depth, &best_first_ascend_cylinder, divemode == CCR && !prefs.dobailout);
+
/* Find the first potential decostopdepth above current depth */
for (stopidx = 0; stopidx < decostoplevelcount; stopidx++)
if (*(decostoplevels + stopidx) >= depth)
@@ -929,6 +941,8 @@ bool plan(struct deco_state *ds, struct diveplan *diveplan, struct dive *dive, i
previous_point_time = clock;
current_cylinder = gaschanges[gi].gasidx;
gas = get_cylinder(dive, current_cylinder)->gasmix;
+ if (divemode == CCR)
+ po2 = setpoint_change(dive, current_cylinder);
#if DEBUG_PLAN & 16
printf("switch to gas %d (%d/%d) @ %5.2lfm\n", gaschanges[gi].gasidx,
(get_o2(&gas) + 5) / 10, (get_he(&gas) + 5) / 10, gaschanges[gi].depth / 1000.0);
@@ -983,6 +997,8 @@ bool plan(struct deco_state *ds, struct diveplan *diveplan, struct dive *dive, i
if (pendinggaschange) {
current_cylinder = gaschanges[gi + 1].gasidx;
gas = get_cylinder(dive, current_cylinder)->gasmix;
+ if (divemode == CCR)
+ po2 = setpoint_change(dive, current_cylinder);
#if DEBUG_PLAN & 16
printf("switch to gas %d (%d/%d) @ %5.2lfm\n", gaschanges[gi + 1].gasidx,
(get_o2(&gas) + 5) / 10, (get_he(&gas) + 5) / 10, gaschanges[gi + 1].depth / 1000.0);