summaryrefslogtreecommitdiffstats
path: root/equipment.c
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2014-05-30 09:10:35 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-05-30 09:10:35 -0700
commit4dfe12e508d1abd9a65ce1cb1b32421da0132a05 (patch)
treea8c057474f7617f7956a439645a951b2cf6c32e3 /equipment.c
parent26dd86e4374766a8ba5f0988a442cc51db444b6b (diff)
downloadsubsurface-4dfe12e508d1abd9a65ce1cb1b32421da0132a05.tar.gz
Planner: make sure all cylinders have a sane depth
When copying cylinders from an existing dive, the mod of the cylinder might not be set. Assume a conservative 1.4 pO2 and fill in those data. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'equipment.c')
-rw-r--r--equipment.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/equipment.c b/equipment.c
index fd0d6ee0c..3111ed599 100644
--- a/equipment.c
+++ b/equipment.c
@@ -182,11 +182,20 @@ void remove_weightsystem(struct dive *dive, int idx)
memset(ws + nr, 0, sizeof(*ws));
}
+/* when planning a dive we need to make sure that all cylinders have a sane depth assigned
+ * and that the pressures are reset to start = end = workingpressure */
void reset_cylinders(struct dive *dive)
{
int i;
+ pressure_t pO2 = {.mbar = 1400};
+
for (i = 0; i < MAX_CYLINDERS; i++) {
- if (dive->cylinder[i].type.workingpressure.mbar)
- dive->cylinder[i].start.mbar = dive->cylinder[i].end.mbar = dive->cylinder[i].type.workingpressure.mbar;
+ cylinder_t *cyl = &dive->cylinder[i];
+ if (cylinder_none(cyl))
+ continue;
+ if (cyl->depth.mm == 0) /* if the gas doesn't give a mod, assume conservative pO2 */
+ cyl->depth = gas_mod(&cyl->gasmix, pO2);
+ if (cyl->type.workingpressure.mbar)
+ cyl->start.mbar = cyl->end.mbar = cyl->type.workingpressure.mbar;
}
}