Handle CCR setpoint when replanning a dive

When replanning a dive, the setpoint information from the profile waypoints
were reset to 0, resulting in a dive that has a dive mode of CCR, but only with
OC legs in the profile. This is just wrong, and is corrected here. Notice
that there is no averaging involved (in the reduction of a replanned real
dive that has more than 100 waypoints) as is done for depth. This is just
fine for setpoint data.

Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
This commit is contained in:
Jan Mulder 2017-04-20 08:43:48 +02:00 committed by Dirk Hohndel
parent 89b914e47d
commit abbb0a244d

View file

@ -69,6 +69,7 @@ void DivePlannerPointsModel::loadFromDive(dive *d)
{
int depthsum = 0;
int samplecount = 0;
o2pressure_t last_sp;
bool oldRec = recalc;
struct divecomputer *dc = &(d->dc);
recalc = false;
@ -97,11 +98,13 @@ void DivePlannerPointsModel::loadFromDive(dive *d)
int plansamples = dc->samples <= 100 ? dc->samples : 100;
int j = 0;
int cylinderid = 0;
last_sp.mbar = 0;
for (int i = 0; i < plansamples - 1; i++) {
while (j * plansamples <= i * dc->samples) {
const sample &s = dc->sample[j];
if (s.time.seconds != 0 && (!hasMarkedSamples || s.manually_entered)) {
depthsum += s.depth.mm;
last_sp = s.setpoint;
++samplecount;
newtime = s.time;
}
@ -110,7 +113,7 @@ void DivePlannerPointsModel::loadFromDive(dive *d)
if (samplecount) {
cylinderid = get_cylinderid_at_time(d, dc, lasttime);
if (newtime.seconds - lastrecordedtime.seconds > 10) {
addStop(depthsum / samplecount, newtime.seconds, cylinderid, 0, true);
addStop(depthsum / samplecount, newtime.seconds, cylinderid, last_sp.mbar, true);
lastrecordedtime = newtime;
}
lasttime = newtime;
@ -119,7 +122,7 @@ void DivePlannerPointsModel::loadFromDive(dive *d)
}
}
// make sure we get the last point right so the duration is correct
if (!hasMarkedSamples) addStop(0, d->dc.duration.seconds,cylinderid, 0, true);
if (!hasMarkedSamples) addStop(0, d->dc.duration.seconds,cylinderid, last_sp.mbar, true);
recalc = oldRec;
emitDataChanged();
}