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/gas.c | |
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/gas.c')
-rw-r--r-- | core/gas.c | 30 |
1 files changed, 30 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]); +} |