diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2020-11-23 19:19:21 +0100 |
---|---|---|
committer | bstoeger <32835590+bstoeger@users.noreply.github.com> | 2021-01-01 21:10:10 +0100 |
commit | 1270d9470129901215fc2173934602d7cd77836f (patch) | |
tree | bfd442f8149f57f00ac5713a2ba8a3d7ef426b0b /core | |
parent | 1d9392670053c4b4d49f2c7149a2a99e636c6b57 (diff) | |
download | subsurface-1270d9470129901215fc2173934602d7cd77836f.tar.gz |
core: add notion of gas-type to core/gas.c
Create a gastype enum, which describes the type of a gas.
For now: air, nitrox, normoxic, trimix and oxygen.
This probably should be made configurable.
The gas types will be used to bin gasses in the statistics
module.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'core')
-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 } |