mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Switch more functions to use gasmix type
This time it's get_gas_string(). Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
f1d67cfbac
commit
fece3f321f
2 changed files with 17 additions and 18 deletions
1
dive.h
1
dive.h
|
@ -652,7 +652,6 @@ struct diveplan {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct divedatapoint *plan_add_segment(struct diveplan *diveplan, int duration, int depth, struct gasmix gasmix, int po2, bool entered);
|
struct divedatapoint *plan_add_segment(struct diveplan *diveplan, int duration, int depth, struct gasmix gasmix, int po2, bool entered);
|
||||||
void get_gas_string(int o2, int he, char *buf, int len);
|
|
||||||
struct divedatapoint *create_dp(int time_incr, int depth, struct gasmix gasmix, int po2);
|
struct divedatapoint *create_dp(int time_incr, int depth, struct gasmix gasmix, int po2);
|
||||||
#if DEBUG_PLAN
|
#if DEBUG_PLAN
|
||||||
void dump_plan(struct diveplan *diveplan);
|
void dump_plan(struct diveplan *diveplan);
|
||||||
|
|
34
planner.c
34
planner.c
|
@ -93,14 +93,14 @@ int get_gasidx(struct dive *dive, struct gasmix *mix)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void get_gas_string(int o2, int he, char *text, int len)
|
static void get_gas_string(const struct gasmix *gasmix, char *text, int len)
|
||||||
{
|
{
|
||||||
if (is_air(o2, he))
|
if (gasmix_is_air(gasmix))
|
||||||
snprintf(text, len, "%s", translate("gettextFromC", "air"));
|
snprintf(text, len, "%s", translate("gettextFromC", "air"));
|
||||||
else if (he == 0)
|
else if (get_he(gasmix) == 0)
|
||||||
snprintf(text, len, translate("gettextFromC", "EAN%d"), (o2 + 5) / 10);
|
snprintf(text, len, translate("gettextFromC", "EAN%d"), (get_o2(gasmix) + 5) / 10);
|
||||||
else
|
else
|
||||||
snprintf(text, len, "(%d/%d)", (o2 + 5) / 10, (he + 5) / 10);
|
snprintf(text, len, "(%d/%d)", (get_o2(gasmix) + 5) / 10, (get_he(gasmix) + 5) / 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
double interpolate_transition(struct dive *dive, int t0, int t1, int d0, int d1, const struct gasmix *gasmix, int ppo2)
|
double interpolate_transition(struct dive *dive, int t0, int t1, int d0, int d1, const struct gasmix *gasmix, int ppo2)
|
||||||
|
@ -144,7 +144,7 @@ double tissue_at_end(struct dive *dive, char **cached_datap)
|
||||||
get_gas_from_events(&dive->dc, t0, &gas);
|
get_gas_from_events(&dive->dc, t0, &gas);
|
||||||
if ((gasidx = get_gasidx(dive, &gas)) == -1) {
|
if ((gasidx = get_gasidx(dive, &gas)) == -1) {
|
||||||
char gas_string[50];
|
char gas_string[50];
|
||||||
get_gas_string(gas.o2.permille, gas.he.permille, gas_string, sizeof(gas_string));
|
get_gas_string(&gas, gas_string, sizeof(gas_string));
|
||||||
report_error(translate("gettextFromC", "Can't find gas %s"), gas_string);
|
report_error(translate("gettextFromC", "Can't find gas %s"), gas_string);
|
||||||
gasidx = 0;
|
gasidx = 0;
|
||||||
}
|
}
|
||||||
|
@ -532,7 +532,7 @@ static void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool
|
||||||
translate("gettextFromC", "%s\nSubsurface dive plan\nbased on GFlow = %d and GFhigh = %d\n\n"),
|
translate("gettextFromC", "%s\nSubsurface dive plan\nbased on GFlow = %d and GFhigh = %d\n\n"),
|
||||||
disclaimer, diveplan->gflow, diveplan->gfhigh);
|
disclaimer, diveplan->gflow, diveplan->gfhigh);
|
||||||
do {
|
do {
|
||||||
struct gasmix gasmix;
|
struct gasmix gasmix, newgasmix;
|
||||||
const char *depth_unit;
|
const char *depth_unit;
|
||||||
char gas[64];
|
char gas[64];
|
||||||
double depthvalue;
|
double depthvalue;
|
||||||
|
@ -542,16 +542,18 @@ static void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool
|
||||||
|
|
||||||
if (dp->time == 0)
|
if (dp->time == 0)
|
||||||
continue;
|
continue;
|
||||||
o2 = get_o2(&dp->gasmix);
|
gasmix = dp->gasmix;
|
||||||
he = get_he(&dp->gasmix);
|
o2 = get_o2(&gasmix);
|
||||||
|
he = get_he(&gasmix);
|
||||||
depthvalue = get_depth_units(dp->depth, &decimals, &depth_unit);
|
depthvalue = get_depth_units(dp->depth, &decimals, &depth_unit);
|
||||||
/* analyze the dive points ahead */
|
/* analyze the dive points ahead */
|
||||||
nextdp = dp->next;
|
nextdp = dp->next;
|
||||||
while (nextdp && nextdp->time == 0)
|
while (nextdp && nextdp->time == 0)
|
||||||
nextdp = nextdp->next;
|
nextdp = nextdp->next;
|
||||||
if (nextdp) {
|
if (nextdp) {
|
||||||
newo2 = get_o2(&nextdp->gasmix);
|
newgasmix = nextdp->gasmix;
|
||||||
newhe = get_he(&nextdp->gasmix);
|
newo2 = get_o2(&newgasmix);
|
||||||
|
newhe = get_he(&newgasmix);
|
||||||
if (newhe == 0 && newo2 == 0) {
|
if (newhe == 0 && newo2 == 0) {
|
||||||
/* same as last segment */
|
/* same as last segment */
|
||||||
newo2 = o2;
|
newo2 = o2;
|
||||||
|
@ -561,9 +563,7 @@ static void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool
|
||||||
/* do we want to skip this leg as it is devoid of anything useful? */
|
/* do we want to skip this leg as it is devoid of anything useful? */
|
||||||
if (!dp->entered && o2 == newo2 && he == newhe && nextdp && dp->depth != lastdepth && nextdp->depth != dp->depth)
|
if (!dp->entered && o2 == newo2 && he == newhe && nextdp && dp->depth != lastdepth && nextdp->depth != dp->depth)
|
||||||
continue;
|
continue;
|
||||||
get_gas_string(o2, he, gas, sizeof(gas));
|
get_gas_string(&gasmix, gas, sizeof(gas));
|
||||||
gasmix.he.permille = he;
|
|
||||||
gasmix.o2.permille = o2;
|
|
||||||
gasidx = get_gasidx(dive, &gasmix);
|
gasidx = get_gasidx(dive, &gasmix);
|
||||||
len = strlen(buffer);
|
len = strlen(buffer);
|
||||||
if (dp->depth != lastdepth)
|
if (dp->depth != lastdepth)
|
||||||
|
@ -580,7 +580,7 @@ static void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool
|
||||||
gas);
|
gas);
|
||||||
if (nextdp && (o2 != newo2 || he != newhe) ) {
|
if (nextdp && (o2 != newo2 || he != newhe) ) {
|
||||||
// gas switch at this waypoint
|
// gas switch at this waypoint
|
||||||
get_gas_string(newo2, newhe, gas, sizeof(gas));
|
get_gas_string(&newgasmix, gas, sizeof(gas));
|
||||||
len = strlen(buffer);
|
len = strlen(buffer);
|
||||||
snprintf(buffer + len, sizeof(buffer) - len, translate("gettextFromC", "Switch gas to %s\n"), gas);
|
snprintf(buffer + len, sizeof(buffer) - len, translate("gettextFromC", "Switch gas to %s\n"), gas);
|
||||||
o2 = newo2;
|
o2 = newo2;
|
||||||
|
@ -600,7 +600,7 @@ static void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool
|
||||||
if (cylinder_none(cyl))
|
if (cylinder_none(cyl))
|
||||||
break;
|
break;
|
||||||
len = strlen(buffer);
|
len = strlen(buffer);
|
||||||
get_gas_string(get_o2(&cyl->gasmix), get_he(&cyl->gasmix), gas, sizeof(gas));
|
get_gas_string(&cyl->gasmix, gas, sizeof(gas));
|
||||||
volume = get_volume_units(cyl->gas_used.mliter, NULL, &unit);
|
volume = get_volume_units(cyl->gas_used.mliter, NULL, &unit);
|
||||||
if (cyl->type.size.mliter) {
|
if (cyl->type.size.mliter) {
|
||||||
/* Warn if the plan uses more gas than is available in a cylinder
|
/* Warn if the plan uses more gas than is available in a cylinder
|
||||||
|
@ -672,7 +672,7 @@ void plan(struct diveplan *diveplan, char **cached_datap, struct dive **divep, s
|
||||||
po2 = dive->dc.sample[dive->dc.samples - 1].po2;
|
po2 = dive->dc.sample[dive->dc.samples - 1].po2;
|
||||||
if ((current_cylinder = get_gasidx(dive, &gas)) == -1) {
|
if ((current_cylinder = get_gasidx(dive, &gas)) == -1) {
|
||||||
char gas_string[50];
|
char gas_string[50];
|
||||||
get_gas_string(gas.o2.permille, gas.he.permille, gas_string, sizeof(gas_string));
|
get_gas_string(&gas, gas_string, sizeof(gas_string));
|
||||||
report_error(translate("gettextFromC", "Can't find gas %s"), gas_string);
|
report_error(translate("gettextFromC", "Can't find gas %s"), gas_string);
|
||||||
current_cylinder = 0;
|
current_cylinder = 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue