diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2020-03-02 15:34:56 +0100 |
---|---|---|
committer | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2020-04-07 00:13:34 +0200 |
commit | 36754d3399dab9155fac50e9451dcd325c7c73c0 (patch) | |
tree | a501d066806bd78b4e09c7d6f9842ef4c9b9ed42 /core | |
parent | e008b42a591b83eb1304a552fdd950287ddbc375 (diff) | |
download | subsurface-36754d3399dab9155fac50e9451dcd325c7c73c0.tar.gz |
cleanup: move fill_default_cylinder from planner.c to equipment.c
Moreover, move the declaration from dive.h to equipment.h.
The result is a) more consistent and b) more logical.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'core')
-rw-r--r-- | core/dive.h | 1 | ||||
-rw-r--r-- | core/equipment.c | 30 | ||||
-rw-r--r-- | core/equipment.h | 1 | ||||
-rw-r--r-- | core/planner.c | 31 |
4 files changed, 31 insertions, 32 deletions
diff --git a/core/dive.h b/core/dive.h index 1e5ca873d..76eccb5e8 100644 --- a/core/dive.h +++ b/core/dive.h @@ -376,7 +376,6 @@ extern void copy_used_cylinders(const struct dive *s, struct dive *d, bool used_ 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(const struct dive *dive, cylinder_t *cyl); 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/equipment.c b/core/equipment.c index c3b9fa494..24d1d826b 100644 --- a/core/equipment.c +++ b/core/equipment.c @@ -392,6 +392,36 @@ cylinder_t *get_or_create_cylinder(struct dive *d, int idx) return &d->cylinders.cylinders[idx]; } +/* if a default cylinder is set, use that */ +void fill_default_cylinder(const struct dive *dive, cylinder_t *cyl) +{ + const char *cyl_name = prefs.default_cylinder; + struct tank_info_t *ti = tank_info; + pressure_t pO2 = {.mbar = 1600}; + + if (!cyl_name) + return; + while (ti->name != NULL && ti < tank_info + MAX_TANK_INFO) { + if (strcmp(ti->name, cyl_name) == 0) + break; + ti++; + } + if (ti->name == NULL) + /* didn't find it */ + return; + cyl->type.description = strdup(ti->name); + if (ti->ml) { + cyl->type.size.mliter = ti->ml; + cyl->type.workingpressure.mbar = ti->bar * 1000; + } else { + cyl->type.workingpressure.mbar = psi_to_mbar(ti->psi); + if (ti->psi) + 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, dive, 1); +} + cylinder_t create_new_cylinder(const struct dive *d) { cylinder_t cyl = empty_cylinder; diff --git a/core/equipment.h b/core/equipment.h index 289eb75a1..494f8dc2b 100644 --- a/core/equipment.h +++ b/core/equipment.h @@ -92,6 +92,7 @@ extern void set_weightsystem(struct dive *dive, int idx, weightsystem_t ws); extern void reset_cylinders(struct dive *dive, bool track_gas); extern int gas_volume(const cylinder_t *cyl, pressure_t p); /* Volume in mliter of a cylinder at pressure 'p' */ extern int find_best_gasmix_match(struct gasmix mix, const struct cylinder_table *cylinders); +extern void fill_default_cylinder(const struct dive *dive, cylinder_t *cyl); /* dive is needed to fill out MOD, which depends on salinity. */ extern cylinder_t create_new_cylinder(const struct dive *dive); /* dive is needed to fill out MOD, which depends on salinity. */ #ifdef DEBUG_CYL extern void dump_cylinders(struct dive *dive, bool verbose); diff --git a/core/planner.c b/core/planner.c index 0e26a9a57..204958a7e 100644 --- a/core/planner.c +++ b/core/planner.c @@ -175,37 +175,6 @@ static int tissue_at_end(struct deco_state *ds, struct dive *dive, struct deco_s return surface_interval; } - -/* if a default cylinder is set, use that */ -void fill_default_cylinder(const struct dive *dive, cylinder_t *cyl) -{ - const char *cyl_name = prefs.default_cylinder; - struct tank_info_t *ti = tank_info; - pressure_t pO2 = {.mbar = 1600}; - - if (!cyl_name) - return; - while (ti->name != NULL && ti < tank_info + MAX_TANK_INFO) { - if (strcmp(ti->name, cyl_name) == 0) - break; - ti++; - } - if (ti->name == NULL) - /* didn't find it */ - return; - cyl->type.description = strdup(ti->name); - if (ti->ml) { - cyl->type.size.mliter = ti->ml; - cyl->type.workingpressure.mbar = ti->bar * 1000; - } else { - cyl->type.workingpressure.mbar = psi_to_mbar(ti->psi); - if (ti->psi) - 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, dive, 1); -} - /* calculate the new end pressure of the cylinder, based on its current end pressure and the * latest segment. */ static void update_cylinder_pressure(struct dive *d, int old_depth, int new_depth, int duration, int sac, cylinder_t *cyl, bool in_deco, enum divemode_t divemode) |