diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2019-08-06 11:19:32 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2019-08-08 16:26:31 -0700 |
commit | 00944f7a02c98bd281778218bccc592896386f14 (patch) | |
tree | ff0ac130a72c9e1be48d28aafc9afa5a21b022ab | |
parent | 6ce4aeb04ee4a01af43f18ef8b76224402cb5c3b (diff) | |
download | subsurface-00944f7a02c98bd281778218bccc592896386f14.tar.gz |
Core: pass dive, cylinder-id to fill_default_cylinder
The fill_default_cylinder() function calculated the MOD based
on the currently displayed dive. This does not seem to make sense:
- When importing dives, why would we care about the altitude and
salinity of the currently displayed dive, possibly from a different
trip.
- The planner is supposed to be thread-safe and should not touch
global variables.
Of course this means that the importing-functions have to fill
out altitude and salinity before creating the default cylinder,
but this is their problem. For a freshly created dive they will
get the default values, which still seems less random than the
values from the displayed dive.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
-rw-r--r-- | core/cochran.c | 6 | ||||
-rw-r--r-- | core/dive.h | 2 | ||||
-rw-r--r-- | core/libdivecomputer.c | 2 | ||||
-rw-r--r-- | core/liquivision.c | 2 | ||||
-rw-r--r-- | core/planner.c | 5 | ||||
-rw-r--r-- | qt-models/cylindermodel.cpp | 2 | ||||
-rw-r--r-- | qt-models/diveplannermodel.cpp | 2 |
7 files changed, 11 insertions, 10 deletions
diff --git a/core/cochran.c b/core/cochran.c index 14ee65fcb..9cbc51113 100644 --- a/core/cochran.c +++ b/core/cochran.c @@ -677,7 +677,7 @@ static void cochran_parse_dive(const unsigned char *decode, unsigned mod, if (config.type == TYPE_GEMINI) { dc->model = "Gemini"; dc->deviceid = buf[0x18c] * 256 + buf[0x18d]; // serial no - fill_default_cylinder(&dive->cylinder[0]); + fill_default_cylinder(dive, 0); dive->cylinder[0].gasmix.o2.permille = (log[CMD_O2_PERCENT] / 256 + log[CMD_O2_PERCENT + 1]) * 10; dive->cylinder[0].gasmix.he.permille = 0; @@ -685,7 +685,7 @@ static void cochran_parse_dive(const unsigned char *decode, unsigned mod, dc->model = "Commander"; dc->deviceid = array_uint32_le(buf + 0x31e); // serial no for (g = 0; g < 2; g++) { - fill_default_cylinder(&dive->cylinder[g]); + fill_default_cylinder(dive, g); dive->cylinder[g].gasmix.o2.permille = (log[CMD_O2_PERCENT + g * 2] / 256 + log[CMD_O2_PERCENT + g * 2 + 1]) * 10; dive->cylinder[g].gasmix.he.permille = 0; @@ -727,7 +727,7 @@ static void cochran_parse_dive(const unsigned char *decode, unsigned mod, dc->model = "EMC"; dc->deviceid = array_uint32_le(buf + 0x31e); // serial no for (g = 0; g < 4; g++) { - fill_default_cylinder(&dive->cylinder[g]); + fill_default_cylinder(dive , g); dive->cylinder[g].gasmix.o2.permille = (log[EMC_O2_PERCENT + g * 2] / 256 + log[EMC_O2_PERCENT + g * 2 + 1]) * 10; diff --git a/core/dive.h b/core/dive.h index 1509e51c2..72928c5ec 100644 --- a/core/dive.h +++ b/core/dive.h @@ -362,7 +362,7 @@ extern void copy_cylinders(const struct dive *s, struct dive *d, bool used_only) extern void copy_samples(const struct divecomputer *s, struct divecomputer *d); extern bool is_cylinder_used(const struct dive *dive, int idx); extern bool is_cylinder_prot(const struct dive *dive, int idx); -extern void fill_default_cylinder(cylinder_t *cyl); +extern void fill_default_cylinder(struct dive *dive, int idx); extern void add_gas_switch_event(struct dive *dive, struct divecomputer *dc, int time, int idx); extern struct event *add_event(struct divecomputer *dc, unsigned int time, int type, int flags, int value, const char *name); extern void remove_event(struct event *event); diff --git a/core/libdivecomputer.c b/core/libdivecomputer.c index 63567ba56..2e4441933 100644 --- a/core/libdivecomputer.c +++ b/core/libdivecomputer.c @@ -224,7 +224,7 @@ static int parse_gasmixes(device_data_t *devdata, struct dive *dive, dc_parser_t if (no_volume) { /* for the first tank, if there is no tanksize available from the * dive computer, fill in the default tank information (if set) */ - fill_default_cylinder(&dive->cylinder[i]); + fill_default_cylinder(dive, i); } /* whatever happens, make sure there is a name for the cylinder */ if (empty_string(dive->cylinder[i].type.description)) diff --git a/core/liquivision.c b/core/liquivision.c index e5b3ea48b..1e430bcf1 100644 --- a/core/liquivision.c +++ b/core/liquivision.c @@ -149,7 +149,7 @@ static void parse_dives(int log_version, const unsigned char *buf, unsigned int /* Just the main cylinder until we can handle the buddy cylinder porperly */ for (i = 0; i < 1; i++) - fill_default_cylinder(&dive->cylinder[i]); + fill_default_cylinder(dive, i); // Model 0=Xen, 1,2=Xeo, 4=Lynx, other=Liquivision model = *(buf + ptr); diff --git a/core/planner.c b/core/planner.c index 407418553..9cf4fc6ec 100644 --- a/core/planner.c +++ b/core/planner.c @@ -178,9 +178,10 @@ static int tissue_at_end(struct deco_state *ds, struct dive *dive, struct deco_s /* if a default cylinder is set, use that */ -void fill_default_cylinder(cylinder_t *cyl) +void fill_default_cylinder(struct dive *dive, int idx) { const char *cyl_name = prefs.default_cylinder; + cylinder_t *cyl = &dive->cylinder[idx]; struct tank_info_t *ti = tank_info; pressure_t pO2 = {.mbar = 1600}; @@ -204,7 +205,7 @@ void fill_default_cylinder(cylinder_t *cyl) cyl->type.size.mliter = lrint(cuft_to_l(ti->cuft) * 1000 / bar_to_atm(psi_to_bar(ti->psi))); } // MOD of air - cyl->depth = gas_mod(cyl->gasmix, pO2, &displayed_dive, 1); + cyl->depth = gas_mod(cyl->gasmix, pO2, dive, 1); } /* calculate the new end pressure of the cylinder, based on its current end pressure and the diff --git a/qt-models/cylindermodel.cpp b/qt-models/cylindermodel.cpp index 448a86e2d..95c6aace2 100644 --- a/qt-models/cylindermodel.cpp +++ b/qt-models/cylindermodel.cpp @@ -426,7 +426,7 @@ void CylindersModel::add() } int row = rows; - fill_default_cylinder(&displayed_dive.cylinder[row]); + fill_default_cylinder(&displayed_dive, row); displayed_dive.cylinder[row].start = displayed_dive.cylinder[row].type.workingpressure; displayed_dive.cylinder[row].manually_added = true; displayed_dive.cylinder[row].cylinder_use = OC_GAS; diff --git a/qt-models/diveplannermodel.cpp b/qt-models/diveplannermodel.cpp index 47d2bf275..c2bbdf084 100644 --- a/qt-models/diveplannermodel.cpp +++ b/qt-models/diveplannermodel.cpp @@ -165,7 +165,7 @@ void DivePlannerPointsModel::setupCylinders() return; // We have at least one cylinder } if (!empty_string(prefs.default_cylinder)) { - fill_default_cylinder(&displayed_dive.cylinder[0]); + fill_default_cylinder(&displayed_dive, 0); displayed_dive.cylinder[0].start = displayed_dive.cylinder[0].type.workingpressure; } if (cylinder_none(&displayed_dive.cylinder[0])) { |