mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Remove is_air() and convert its users to gasmix
Also make gasname() and get_gas_string() global functions (which allows us to delete code elsewhere). Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
ee36bf8bf3
commit
28093ae957
5 changed files with 26 additions and 36 deletions
2
dive.c
2
dive.c
|
@ -546,7 +546,7 @@ void sanitize_gasmix(struct gasmix *mix)
|
||||||
if (!o2)
|
if (!o2)
|
||||||
return;
|
return;
|
||||||
/* 20.8% to 21% O2 is just air */
|
/* 20.8% to 21% O2 is just air */
|
||||||
if (is_air(o2, he)) {
|
if (gasmix_is_air(mix)) {
|
||||||
mix->o2.permille = 0;
|
mix->o2.permille = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
12
dive.h
12
dive.h
|
@ -108,14 +108,11 @@ extern void sanitize_gasmix(struct gasmix *mix);
|
||||||
extern int gasmix_distance(const struct gasmix *a, const struct gasmix *b);
|
extern int gasmix_distance(const struct gasmix *a, const struct gasmix *b);
|
||||||
extern struct gasmix *get_gasmix_from_event(struct event *ev);
|
extern struct gasmix *get_gasmix_from_event(struct event *ev);
|
||||||
|
|
||||||
static inline bool is_air(int o2, int he)
|
|
||||||
{
|
|
||||||
return (he == 0) && (o2 == 0 || ((o2 >= O2_IN_AIR - 1) && (o2 <= O2_IN_AIR + 1)));
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline bool gasmix_is_air(const struct gasmix *gasmix)
|
static inline bool gasmix_is_air(const struct gasmix *gasmix)
|
||||||
{
|
{
|
||||||
return is_air(gasmix->o2.permille, gasmix->he.permille);
|
int o2 = gasmix->o2.permille;
|
||||||
|
int he = gasmix->he.permille;
|
||||||
|
return (he == 0) && (o2 == 0 || ((o2 >= O2_IN_AIR - 1) && (o2 <= O2_IN_AIR + 1)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* in the planner we use a null gasmix to indicate that we keep using the gas as before
|
/* in the planner we use a null gasmix to indicate that we keep using the gas as before
|
||||||
|
@ -140,6 +137,9 @@ static inline depth_t gas_mod(struct gasmix *mix, pressure_t po2_limit) {
|
||||||
return depth;
|
return depth;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void get_gas_string(const struct gasmix *gasmix, char *text, int len);
|
||||||
|
const char *gasname(const struct gasmix *gasmix);
|
||||||
|
|
||||||
struct sample {
|
struct sample {
|
||||||
duration_t time;
|
duration_t time;
|
||||||
depth_t depth;
|
depth_t depth;
|
||||||
|
|
18
equipment.c
18
equipment.c
|
@ -97,6 +97,24 @@ bool cylinder_is_used(struct dive *d, cylinder_t *cyl)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void get_gas_string(const struct gasmix *gasmix, char *text, int len)
|
||||||
|
{
|
||||||
|
if (gasmix_is_air(gasmix))
|
||||||
|
snprintf(text, len, "%s", translate("gettextFromC", "air"));
|
||||||
|
else if (get_he(gasmix) == 0)
|
||||||
|
snprintf(text, len, translate("gettextFromC", "EAN%d"), (get_o2(gasmix) + 5) / 10);
|
||||||
|
else
|
||||||
|
snprintf(text, len, "(%d/%d)", (get_o2(gasmix) + 5) / 10, (get_he(gasmix) + 5) / 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Returns a static char buffer - only good for immediate use by printf etc */
|
||||||
|
const char *gasname(const struct gasmix *gasmix)
|
||||||
|
{
|
||||||
|
static char gas[64];
|
||||||
|
get_gas_string(gasmix, gas, sizeof(gas));
|
||||||
|
return gas;
|
||||||
|
}
|
||||||
|
|
||||||
bool weightsystem_none(void *_data)
|
bool weightsystem_none(void *_data)
|
||||||
{
|
{
|
||||||
weightsystem_t *ws = _data;
|
weightsystem_t *ws = _data;
|
||||||
|
|
18
planner.c
18
planner.c
|
@ -93,24 +93,6 @@ int get_gasidx(struct dive *dive, struct gasmix *mix)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void get_gas_string(const struct gasmix *gasmix, char *text, int len)
|
|
||||||
{
|
|
||||||
if (gasmix_is_air(gasmix))
|
|
||||||
snprintf(text, len, "%s", translate("gettextFromC", "air"));
|
|
||||||
else if (get_he(gasmix) == 0)
|
|
||||||
snprintf(text, len, translate("gettextFromC", "EAN%d"), (get_o2(gasmix) + 5) / 10);
|
|
||||||
else
|
|
||||||
snprintf(text, len, "(%d/%d)", (get_o2(gasmix) + 5) / 10, (get_he(gasmix) + 5) / 10);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Returns a static char buffer - only good for immediate use by printf etc */
|
|
||||||
static const char *gasname(const struct gasmix *gasmix)
|
|
||||||
{
|
|
||||||
static char gas[64];
|
|
||||||
get_gas_string(gasmix, gas, sizeof(gas));
|
|
||||||
return gas;
|
|
||||||
}
|
|
||||||
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
int j;
|
int j;
|
||||||
|
|
12
statistics.c
12
statistics.c
|
@ -337,7 +337,6 @@ char *get_gaslist(struct dive *dive)
|
||||||
{
|
{
|
||||||
int idx, offset = 0;
|
int idx, offset = 0;
|
||||||
static char buf[MAXBUF];
|
static char buf[MAXBUF];
|
||||||
int o2, he;
|
|
||||||
|
|
||||||
buf[0] = '\0';
|
buf[0] = '\0';
|
||||||
for (idx = 0; idx < MAX_CYLINDERS; idx++) {
|
for (idx = 0; idx < MAX_CYLINDERS; idx++) {
|
||||||
|
@ -345,20 +344,11 @@ char *get_gaslist(struct dive *dive)
|
||||||
if (!is_gas_used(dive, idx))
|
if (!is_gas_used(dive, idx))
|
||||||
continue;
|
continue;
|
||||||
cyl = &dive->cylinder[idx];
|
cyl = &dive->cylinder[idx];
|
||||||
o2 = get_o2(&cyl->gasmix);
|
|
||||||
he = get_he(&cyl->gasmix);
|
|
||||||
if (offset > 0) {
|
if (offset > 0) {
|
||||||
strncpy(buf + offset, "\n", MAXBUF - offset);
|
strncpy(buf + offset, "\n", MAXBUF - offset);
|
||||||
offset = strlen(buf);
|
offset = strlen(buf);
|
||||||
}
|
}
|
||||||
if (is_air(o2, he))
|
strncpy(buf + offset, gasname(&cyl->gasmix), MAXBUF - offset);
|
||||||
strncpy(buf + offset, translate("gettextFromC", "air"), MAXBUF - offset);
|
|
||||||
else if (he == 0)
|
|
||||||
snprintf(buf + offset, MAXBUF - offset,
|
|
||||||
translate("gettextFromC", "EAN%d"), (o2 + 5) / 10);
|
|
||||||
else
|
|
||||||
snprintf(buf + offset, MAXBUF - offset,
|
|
||||||
"%d/%d", (o2 + 5) / 10, (he + 5) / 10);
|
|
||||||
offset = strlen(buf);
|
offset = strlen(buf);
|
||||||
}
|
}
|
||||||
if (*buf == '\0')
|
if (*buf == '\0')
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue