Dirk,

On 07 Feb 2015, at 17:10, Dirk Hohndel <[email protected]> wrote:

I have a draft patch that does that but wanted to talk to you about it.
This is a non-reversible change. So if the user has a dive that includes
pO₂ values in the samples, we show that dive as CCR. If the user then
switches to OC we can easily clear out the pO₂ values, but of course if
those were not just calculated values but in fact were setpoint data that
the user entered during a dive (i.e., if the switch to OC was a mistake),
then that data is gone.

I think that's acceptable, but I wanted to run this by others before
pushing that patch.

here i a bit more careful version of the deletion of pO2 data.

From fd95a43f02505dbc024578cb17d98740482f8267 Mon Sep 17 00:00:00 2001
From: "Robert C. Helling" <[email protected]>
Date: Sat, 7 Feb 2015 21:02:02 +0100
Subject: [PATCH] Be a bit more careful when deleting pO2 values

This patch adds tests if the computer is actually a Predator and
if the value is close to what we would have computed anyway.

Signed-off-by: Robert C. Helling <[email protected]>
---
 dive.c | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

diff --git a/dive.c b/dive.c
index c120dde..020d3c9 100644
--- a/dive.c
+++ b/dive.c
@@ -883,12 +883,28 @@ void update_setpoint_events(struct divecomputer *dc)
        if (dc->divemode == CCR)
                new_setpoint = prefs.defaultsetpoint;
 
-       if (dc->divemode == OC)
+       if (dc->divemode == OC && !strcmp(dc->model, "Shearwater Predator")) {
                // make sure there's no setpoint in the samples
                // this is an irreversible change - so switching a dive to OC
                // by mistake when it's actually CCR is _bad_
-               for (int i = 0; i < dc->samples; i++)
-                       dc->sample[i].setpoint.mbar = 0;
+               // So we make sure, this comes from a Predator and we only 
remove
+               // pO2 values we would have computed anyway.
+               struct event *ev = get_next_event(dc->events, "gaschange");
+               struct gasmix *gasmix = get_gasmix_from_event(ev);
+               struct event *next = get_next_event(ev, "gaschange");
+
+               for (int i = 0; i < dc->samples; i++) {
+                       struct gas_pressures pressures;
+                       if (next && dc->sample[i].time.seconds >= 
next->time.seconds) {
+                               ev = next;
+                               gasmix = get_gasmix_from_event(ev);
+                               next = get_next_event(ev, "gaschange");
+                       }
+                       fill_pressures(&pressures, 
calculate_depth_to_mbar(dc->sample[i].depth.mm, dc->surface_pressure, 0), 
gasmix ,0, OC);
+                       if (abs(dc->sample[i].setpoint.mbar - (int)(1000 * 
pressures.o2) <= 50))
+                               dc->sample[i].setpoint.mbar = 0;
+               }
+       }
 
        // an "SP change" event at t=0 is currently our marker for OC vs CCR
        // this will need to change to a saner setup, but for now we can just
-- 
1.9.3 (Apple Git-50)


I wrote it in a bit of a hurry, so I am not 100% sure I get the gas calculation right. Please double check!

Best
Robert

Attachment: signature.asc
Description: Message signed with OpenPGP using GPGMail

_______________________________________________
subsurface mailing list
[email protected]
http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface

Reply via email to