diff options
-rw-r--r-- | core/gas.c | 30 | ||||
-rw-r--r-- | core/gas.h | 12 |
2 files changed, 42 insertions, 0 deletions
diff --git a/core/gas.c b/core/gas.c index 128305e12..d37b614fb 100644 --- a/core/gas.c +++ b/core/gas.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 #include "gas.h" #include "pref.h" +#include "gettext.h" #include <stdio.h> #include <string.h> @@ -139,3 +140,32 @@ void fill_pressures(struct gas_pressures *pressures, const double amb_pressure, } } } + +enum gastype gasmix_to_type(struct gasmix mix) +{ + if (gasmix_is_air(mix)) + return GASTYPE_AIR; + if (mix.o2.permille >= 980) + return GASTYPE_OXYGEN; + if (mix.he.permille == 0) + return mix.o2.permille >= 230 ? GASTYPE_NITROX : GASTYPE_AIR; + if (mix.o2.permille <= 180) + return GASTYPE_HYPOXIC_TRIMIX; + return mix.o2.permille <= 230 ? GASTYPE_NORMOXIC_TRIMIX : GASTYPE_HYPEROXIC_TRIMIX; +} + +static const char *gastype_names[] = { + QT_TRANSLATE_NOOP("gettextFromC", "Air"), + QT_TRANSLATE_NOOP("gettextFromC", "Nitrox"), + QT_TRANSLATE_NOOP("gettextFromC", "Hypoxic Trimix"), + QT_TRANSLATE_NOOP("gettextFromC", "Normoxic Trimix"), + QT_TRANSLATE_NOOP("gettextFromC", "Hyperoxic Trimix"), + QT_TRANSLATE_NOOP("gettextFromC", "Oxygen") +}; + +const char *gastype_name(enum gastype type) +{ + if (type < 0 || type >= GASTYPE_COUNT) + return ""; + return translate("gettextFromC", gastype_names[type]); +} diff --git a/core/gas.h b/core/gas.h index 014eaca4b..5e0f4675f 100644 --- a/core/gas.h +++ b/core/gas.h @@ -22,6 +22,16 @@ struct gasmix { static const struct gasmix gasmix_invalid = { { -1 }, { -1 } }; static const struct gasmix gasmix_air = { { 0 }, { 0 } }; +enum gastype { + GASTYPE_AIR, + GASTYPE_NITROX, + GASTYPE_HYPOXIC_TRIMIX, + GASTYPE_NORMOXIC_TRIMIX, + GASTYPE_HYPEROXIC_TRIMIX, + GASTYPE_OXYGEN, + GASTYPE_COUNT +}; + struct icd_data { // This structure provides communication between function isobaric_counterdiffusion() and the calling software. int dN2; // The change in fraction (permille) of nitrogen during the change int dHe; // The change in fraction (permille) of helium during the change @@ -59,6 +69,8 @@ extern fraction_t get_gas_component_fraction(struct gasmix mix, enum gas_compone extern void fill_pressures(struct gas_pressures *pressures, double amb_pressure, struct gasmix mix, double po2, enum divemode_t dctype); extern bool gasmix_is_air(struct gasmix gasmix); +extern enum gastype gasmix_to_type(struct gasmix mix); +extern const char *gastype_name(enum gastype type); #ifdef __cplusplus } |