summaryrefslogtreecommitdiffstats
path: root/planner.c
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2014-06-01 09:59:38 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-06-01 10:16:59 -0700
commit2a871d7fe5257adf5631cfb46f2dfa84cd2d9201 (patch)
tree2eaef80e7ab303bfb3a22fcebb40cb1abcb82906 /planner.c
parentf44a7509b3455492393874fe8a35bb3b564fee86 (diff)
downloadsubsurface-2a871d7fe5257adf5631cfb46f2dfa84cd2d9201.tar.gz
Planner: track gas used even if we don't have a real cylinder
We tracked gas used by simulating a dive with a cylinder - but for that we need a cylinder size and working pressure. If the user just enters a gas but no cylinder data (likely in order to figure out how much gas is used so that she then can pick a big enough cylinder), we didn't show any gas consumption. It kinda sucks to add another member to the cylinder structure, but this seemed far more reasonable then some other, global structure that independently tracks gas usage. This just seemed to make sense. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'planner.c')
-rw-r--r--planner.c19
1 files changed, 9 insertions, 10 deletions
diff --git a/planner.c b/planner.c
index 0e85e62e8..88c7f32f9 100644
--- a/planner.c
+++ b/planner.c
@@ -225,12 +225,15 @@ static void update_cylinder_pressure(struct dive *d, int old_depth, int new_dept
pressure_t delta_p;
depth_t mean_depth;
- if (!cyl || !cyl->type.size.mliter)
+ if (!cyl)
return;
mean_depth.mm = (old_depth + new_depth) / 2;
gas_used.mliter = depth_to_atm(mean_depth.mm, d) * sac / 60 * duration;
- delta_p.mbar = gas_used.mliter * 1000.0 / cyl->type.size.mliter;
- cyl->end.mbar -= delta_p.mbar;
+ cyl->gas_used.mliter += gas_used.mliter;
+ if (!cyl->type.size.mliter) {
+ delta_p.mbar = gas_used.mliter * 1000.0 / cyl->type.size.mliter;
+ cyl->end.mbar -= delta_p.mbar;
+ }
}
static struct dive *create_dive_from_plan(struct diveplan *diveplan, struct dive *master_dive)
@@ -605,19 +608,15 @@ static void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool
break;
len = strlen(buffer);
get_gas_string(get_o2(&cyl->gasmix), get_he(&cyl->gasmix), gas, sizeof(gas));
- if (cyl->type.workingpressure.mbar) {
- int consumed = mbar_to_atm(cyl->start.mbar - cyl->end.mbar) * cyl->type.size.mliter;
- volume = get_volume_units(consumed, NULL, &unit);
+ volume = get_volume_units(cyl->gas_used.mliter, NULL, &unit);
+ if (cyl->type.size.mliter) {
/* Warn if the plan uses more gas than is available in a cylinder
* This only works if we have working pressure for the cylinder
* 10bar is a made up number - but it seemed silly to pretend you could breathe cylinder down to 0 */
if (cyl->end.mbar < 10000)
warning = translate("gettextFromC", "WARNING: this is more gas than available in the specified cylinder!");
- snprintf(buffer + len, sizeof(buffer) - len, translate("gettextFromC", "%.0f%s of %s%s\n"), volume, unit, gas, warning);
- } else {
- fprintf(stderr, "we really should calculate the consumption even without cylinder data\n");
- snprintf(buffer + len, sizeof(buffer) - len, translate("gettextFromC", "did not track volume for %s"), gas);
}
+ snprintf(buffer + len, sizeof(buffer) - len, translate("gettextFromC", "%.0f%s of %s%s\n"), volume, unit, gas, warning);
}
dive->notes = strdup(buffer);
}