From c29456f0bb11f07befc3af66ee7973258b491d20 Mon Sep 17 00:00:00 2001 From: Stefan Fuchs Date: Sun, 8 Oct 2017 05:14:57 +0200 Subject: Used gas in dive planner points: Support for multiple cyl with same gas In the planner if one adds two or more cylinders with the same gasmix (e.g. back gas and bottom stage 18/45) the drop down and data in the used gas column of the planner points table will be filled with a more verbose string mentioning also the cyl number and the cyl type description. Makes it easier in such a case to select the right cylinder. Introduces also a helper function which tells you if there is another cylinder with the same gasmix as the provided cylinder. This also has an option if it should consider unused cylinders or not. Signed-off-by: Stefan Fuchs --- core/dive.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'core/dive.c') diff --git a/core/dive.c b/core/dive.c index 84d476958..59bbef9c8 100644 --- a/core/dive.c +++ b/core/dive.c @@ -1858,7 +1858,7 @@ static int sort_event(struct event *a, struct event *b) static int same_gas(struct event *a, struct event *b) { if (a->type == b->type && a->flags == b->flags && a->value == b->value && !strcmp(a->name, b->name) && - a->gas.mix.o2.permille == b->gas.mix.o2.permille && a->gas.mix.he.permille == b->gas.mix.he.permille) { + same_gasmix(&a->gas.mix, &b->gas.mix)) { return true; } return false; @@ -2078,6 +2078,19 @@ int same_gasmix(struct gasmix *a, struct gasmix *b) return a->o2.permille == b->o2.permille && a->he.permille == b->he.permille; } +int same_gasmix_cylinder(cylinder_t *cyl, int cylid, struct dive *dive, bool check_unused) +{ + struct gasmix *mygas = &cyl->gasmix; + for (int i = 0; i < MAX_CYLINDERS; i++) { + if (i == cylid || cylinder_none(&dive->cylinder[i])) + continue; + struct gasmix *gas2 = &dive->cylinder[i].gasmix; + if (gasmix_distance(mygas, gas2) == 0 && (is_cylinder_used(dive, i) || check_unused)) + return i; + } + return -1; +} + static int pdiff(pressure_t a, pressure_t b) { return a.mbar && b.mbar && a.mbar != b.mbar; -- cgit v1.2.3-70-g09d2