From fb4d9b34f87f71b072bccb36633d7247b9d9dd9d Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Sun, 1 Jun 2014 10:02:38 -0700 Subject: Planner: correctly track gas used This part of the algorithm was off as part of it (but not all of it - crazy, I know) assumed the old semantic for gas changes where the new gas was introduced at the end of the segment and not at the beginning. Signed-off-by: Dirk Hohndel --- planner.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'planner.c') diff --git a/planner.c b/planner.c index 88c7f32f9..512034a2e 100644 --- a/planner.c +++ b/planner.c @@ -246,6 +246,7 @@ static struct dive *create_dive_from_plan(struct diveplan *diveplan, struct dive int oldo2, oldhe; int oldpo2 = 0; int lasttime = 0; + int lastdepth = 0; if (!diveplan || !diveplan->dp) return NULL; @@ -307,15 +308,12 @@ static struct dive *create_dive_from_plan(struct diveplan *diveplan, struct dive int idx; if ((idx = verify_gas_exists(dive, plano2, planhe)) < 0) goto gas_error_exit; - add_gas_switch_event(dive, dc, lasttime, idx); - /* need to insert a last sample for the old gas */ + /* need to insert a first sample for the new gas */ + add_gas_switch_event(dive, dc, lasttime + 1, idx); sample = prepare_sample(dc); sample[-1].po2 = po2; - sample->time.seconds = time - 1; - sample->depth.mm = depth; - update_cylinder_pressure(dive, sample[-1].depth.mm, depth, time - sample[-1].time.seconds, - dp->entered ? diveplan->bottomsac : diveplan->decosac, cyl); - sample->cylinderpressure.mbar = cyl->end.mbar; + sample->time.seconds = lasttime + 1; + sample->depth.mm = lastdepth; finish_sample(dc); cyl = &dive->cylinder[idx]; oldo2 = o2; @@ -327,13 +325,12 @@ static struct dive *create_dive_from_plan(struct diveplan *diveplan, struct dive /* and keep it valid for last sample - where it likely doesn't matter */ sample[-1].po2 = po2; sample->po2 = po2; - sample->time.seconds = time; - sample->depth.mm = depth; + sample->time.seconds = lasttime = time; + sample->depth.mm = lastdepth = depth; update_cylinder_pressure(dive, sample[-1].depth.mm, depth, time - sample[-1].time.seconds, dp->entered ? diveplan->bottomsac : diveplan->decosac, cyl); sample->cylinderpressure.mbar = cyl->end.mbar; finish_sample(dc); - lasttime = time; dp = dp->next; } if (dc->samples <= 1) { -- cgit v1.2.3-70-g09d2