From 1b0ddfbbe218e25001512a18e5cc9224aabf8698 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Mon, 7 Jan 2013 08:38:55 -0800 Subject: Dive planner: add gas change events & start dive with the correct gas When incrementally building dives with gas changes there are still some serious issues and inconsistencies. But at least now the gases in the dive we create appear to be correct. Signed-off-by: Dirk Hohndel --- planner.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/planner.c b/planner.c index fab5996ce..ce7b67279 100644 --- a/planner.c +++ b/planner.c @@ -108,13 +108,19 @@ struct dive *create_dive_from_plan(struct diveplan *diveplan) dc = &dive->dc; dc->model = "Simulated Dive"; dp = diveplan->dp; + /* let's start with the gas given on the first segment */ + if(dp) + add_gas(dive, dp->o2, dp->he); while (dp && dp->time) { int i, depth; if (dp->o2 != dive->cylinder[gasused].gasmix.o2.permille || - dp->he != dive->cylinder[gasused].gasmix.he.permille) + dp->he != dive->cylinder[gasused].gasmix.he.permille) { + int value; gasused = add_gas(dive, dp->o2, dp->he); - + value = dp->o2 / 10 | (dp->he / 10) << 16; + add_event(dc, dp->time, 11, 0, value, "gaschange"); + } for (i = t; i < dp->time; i += 10) { depth = lastdepth + (i - t) * (dp->depth - lastdepth) / (dp->time - t); sample = prepare_sample(dc); @@ -198,8 +204,13 @@ void add_depth_to_nth_dp(struct diveplan *diveplan, int idx, int depth) void add_gas_to_nth_dp(struct diveplan *diveplan, int idx, int o2, int he) { struct divedatapoint *dp = get_nth_dp(diveplan, idx); - dp->o2 = o2; - dp->he = he; + if (o2 > 206 && o2 < 213 && he == 0) { + /* we treat air in a special case */ + dp->o2 = dp->he = 0; + } else { + dp->o2 = o2; + dp->he = he; + } } void add_to_end_of_diveplan(struct diveplan *diveplan, struct divedatapoint *dp) { -- cgit v1.2.3-70-g09d2