summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2014-11-17 00:09:59 +0000
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-11-17 00:09:59 +0000
commit3e5cb7e2aa00a13542ac6d02af3ef8ab639112d7 (patch)
tree57392a7b3270df9e84a4c9b1c9117b73abca0507
parentee7dd4307a442148598299db1152461b6cbf8270 (diff)
downloadsubsurface-3e5cb7e2aa00a13542ac6d02af3ef8ab639112d7.tar.gz
Fix per_cylinder_mean_depth calculation for CCR
This patch is bigger than necessary because I also renamed the get_cylinder_use() function to the much more accurate get_cylinder_idx_by_use(). If we have no gas changes (except for a possible explicit first gas), (which in the CCR case also means no bailout), this code will give you correct per cylinder depth and duration for oxygen and diluent and therefore create more reasonable gas consumption data for CCR dives. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--dive.c24
-rw-r--r--dive.h2
2 files changed, 17 insertions, 9 deletions
diff --git a/dive.c b/dive.c
index e1d6bb3d8..3e938c516 100644
--- a/dive.c
+++ b/dive.c
@@ -698,10 +698,18 @@ void per_cylinder_mean_depth(struct dive *dive, struct divecomputer *dc, int *me
for (i = 0; i < MAX_CYLINDERS; i++)
mean[i] = duration[i] = 0;
struct event *ev = get_next_event(dc->events, "gaschange");
- if (!ev) {
- // special case - no gas changes
- mean[0] = dc->meandepth.mm;
- duration[0] = dc->duration.seconds;
+ if (!ev || (dc && dc->sample && ev->time.seconds == dc->sample[0].time.seconds && get_next_event(ev->next, "gaschange") == NULL)) {
+ // we have either no gas change or only one gas change and that's setting an explicit first cylinder
+ if (dc->dctype == CCR) {
+ int o2_cyl = get_cylinder_idx_by_use(dive, OXYGEN);
+ int diluent_cyl = get_cylinder_idx_by_use(dive, DILUENT);
+ mean[o2_cyl] = mean[diluent_cyl] = dc->meandepth.mm;
+ duration[o2_cyl] = duration[diluent_cyl] = dc->duration.seconds;
+ } else {
+ // OC, no real gas changes, it's all the first cylinder
+ mean[explicit_first_cylinder(dive, dc)] = dc->meandepth.mm;
+ duration[explicit_first_cylinder(dive, dc)] = dc->duration.seconds;
+ }
return;
}
if (!dc->samples)
@@ -1066,8 +1074,8 @@ unsigned int dc_airtemp(struct divecomputer *dc)
static void fixup_cylinder_use(struct dive *dive) // for CCR dives, store the indices
{ // of the oxygen and diluent cylinders
- dive->oxygen_cylinder_index = get_cylinder_use(dive, OXYGEN);
- dive->diluent_cylinder_index = get_cylinder_use(dive, DILUENT);
+ dive->oxygen_cylinder_index = get_cylinder_idx_by_use(dive, OXYGEN);
+ dive->diluent_cylinder_index = get_cylinder_idx_by_use(dive, DILUENT);
}
static void fixup_airtemp(struct dive *dive)
@@ -1543,13 +1551,13 @@ static void merge_weightsystem_info(weightsystem_t *res, weightsystem_t *a, weig
*res = *a;
}
-/* get_cylinder_use(): Find the index of the first cylinder with a particular CCR use type.
+/* get_cylinder_idx_by_use(): Find the index of the first cylinder with a particular CCR use type.
* The index returned corresponds to that of the first cylinder with a cylinder_use that
* equals the appropriate enum value [oxygen, diluent, bailout] given by cylinder_use_type.
* A negative number returned indicates that a match could not be found.
* Call parameters: dive = the dive being processed
* cylinder_use_type = an enum, one of {oxygen, diluent, bailout} */
-extern int get_cylinder_use(struct dive *dive, enum cylinderuse cylinder_use_type)
+extern int get_cylinder_idx_by_use(struct dive *dive, enum cylinderuse cylinder_use_type)
{
int cylinder_index;
for (cylinder_index = 0; cylinder_index < MAX_CYLINDERS; cylinder_index++) {
diff --git a/dive.h b/dive.h
index f687d2868..9a6242fa9 100644
--- a/dive.h
+++ b/dive.h
@@ -341,7 +341,7 @@ struct dive {
int oxygen_cylinder_index, diluent_cylinder_index; // CCR dive cylinder indices
};
-extern int get_cylinder_use(struct dive *dive, enum cylinderuse cylinder_use_type);
+extern int get_cylinder_idx_by_use(struct dive *dive, enum cylinderuse cylinder_use_type);
/* when selectively copying dive information, which parts should be copied? */
struct dive_components {