From b850384100ce429d3720ce03fc39e817f123c77d Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Mon, 11 Nov 2019 14:28:49 +0100 Subject: Profile: fix pressure scale The determination of minimum pressure in calculate_max_limits_new() in profile.c was wrong for a long time. Since the loop went over all cylinders (even unused ones), the minimum pressure was always zero. Since we loop only over used cylinders, the minimum pressure was initialized to the lowest starting pressure of any cylinder. If there were no events with pressure change, the minimum pressure stayed unchanged, resulting in a funky scaling. Instead, let's initialize the minimum pressure to the lowest ending pressure. Reported-by: Willem Ferguson Signed-off-by: Berthold Stoeger --- core/profile.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'core') diff --git a/core/profile.c b/core/profile.c index bee2b7a4a..ae1bb4259 100644 --- a/core/profile.c +++ b/core/profile.c @@ -414,11 +414,12 @@ static void calculate_max_limits_new(struct dive *dive, struct divecomputer *giv /* Get the per-cylinder maximum pressure if they are manual */ for (cyl = 0; cyl < dive->cylinders.nr; cyl++) { - int mbar = get_cylinder(dive, cyl)->start.mbar; - if (mbar > maxpressure) - maxpressure = mbar; - if (mbar < minpressure) - minpressure = mbar; + int mbar_start = get_cylinder(dive, cyl)->start.mbar; + int mbar_end = get_cylinder(dive, cyl)->end.mbar; + if (mbar_start > maxpressure) + maxpressure = mbar_start; + if (mbar_end < minpressure) + minpressure = mbar_end; } /* Then do all the samples from all the dive computers */ -- cgit v1.2.3-70-g09d2