From a28b11e14d4dd714fcbeb6bc656918e4b1cfa7a9 Mon Sep 17 00:00:00 2001 From: "Robert C. Helling" Date: Thu, 2 Apr 2015 10:49:24 +0200 Subject: [PATCH 2/2] Only do safety stop of dive has at least max depth of 10m Signed-off-by: Robert C. Helling --- dive.c | 11 ++++++----- dive.h | 2 +- planner.c | 6 +++--- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/dive.c b/dive.c index 4afb21f..bdb6937 100644 --- a/dive.c +++ b/dive.c @@ -2838,15 +2838,14 @@ void set_userid(char *rUserId) prefs.userid[30]='\0'; } -int average_depth(struct diveplan *dive) +void average_max_depth(struct diveplan *dive, int *avg_depth, int *max_depth) { int integral = 0; int last_time = 0; int last_depth = 0; struct divedatapoint *dp = dive->dp; - if (!dp) - return 0; + *max_depth = 0; while (dp) { if (dp->time) { @@ -2854,13 +2853,15 @@ int average_depth(struct diveplan *dive) integral += (dp->depth + last_depth) * (dp->time - last_time) / 2; last_time = dp->time; last_depth = dp->depth; + if (dp->depth > *max_depth) + *max_depth = dp->depth; } dp = dp->next; } if (last_time) - return integral / last_time; + *avg_depth = integral / last_time; else - return 0; + *avg_depth = *max_depth = 0; } struct picture *alloc_picture() diff --git a/dive.h b/dive.h index 86c288f..140e14d 100644 --- a/dive.h +++ b/dive.h @@ -872,7 +872,7 @@ extern depth_t string_to_depth(const char *str); extern pressure_t string_to_pressure(const char *str); extern volume_t string_to_volume(const char *str, pressure_t workp); extern fraction_t string_to_fraction(const char *str); -extern int average_depth(struct diveplan *dive); +extern void average_max_depth(struct diveplan *dive, int *avg_depth, int *max_depth); #include "pref.h" diff --git a/planner.c b/planner.c index c7bc889..8dac4d2 100644 --- a/planner.c +++ b/planner.c @@ -840,7 +840,7 @@ int plan(struct diveplan *diveplan, char **cached_datap, bool is_planner, bool s bool stopping = false; bool clear_to_ascend; int clock, previous_point_time; - int avg_depth, bottom_time = 0; + int avg_depth, max_depth, bottom_time = 0; int last_ascend_rate; int best_first_ascend_cylinder; struct gasmix gas; @@ -865,7 +865,7 @@ int plan(struct diveplan *diveplan, char **cached_datap, bool is_planner, bool s current_cylinder = 0; } depth = displayed_dive.dc.sample[displayed_dive.dc.samples - 1].depth.mm; - avg_depth = average_depth(diveplan); + average_max_depth(diveplan, &avg_depth, &max_depth); last_ascend_rate = ascend_velocity(depth, avg_depth, bottom_time); /* if all we wanted was the dive just get us back to the surface */ @@ -905,7 +905,7 @@ int plan(struct diveplan *diveplan, char **cached_datap, bool is_planner, bool s bottom_time = clock = previous_point_time = displayed_dive.dc.sample[displayed_dive.dc.samples - 1].time.seconds; gi = gaschangenr - 1; if(prefs.recreational_mode) { - bool safety_stop = prefs.safetystop; + bool safety_stop = prefs.safetystop && max_depth >= 10000; // How long can we stay at the current depth and still directly ascent to the surface? while (trial_ascent(depth, 0, avg_depth, bottom_time, tissue_tolerance, &displayed_dive.cylinder[current_cylinder].gasmix, po2, diveplan->surface_pressure / 1000.0)) { -- 1.9.5 (Apple Git-50.3)