Commit graph

9 commits

Author SHA1 Message Date
Berthold Stoeger
12ca172a9e core: add CRTP base class to unit types
The goal here is to add general addition and scalar multiplication
functions to the unit types.

Thereto, we need a CRTP
(https://en.wikipedia.org/wiki/Curiously_recurring_template_pattern)
base class.

However, this breaks compound initialization, so we have to use
named initializers:
	weight_t { 2000 } -> weight_t { .grams = 2000 }
The good thing is that this is exactly how these classes were
supposed to be used: make the unit explicit!

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-09-11 10:23:07 +02:00
Berthold Stoeger
af6201f89c core: simplify default initialization of struct sample
Since the units got default constructors, we don't have to
manually initialize them.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
b56dd13add build: remove extern "C" linkage
No more C source files, no more necessity to use C-linkage.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
03b910ee7f core: remove __cplusplus ifdefs
Since all source files are now C++, this is redundant.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00
Berthold Stoeger
148775f418 core: convert sample.c to C++ and add default constructor
This changes default behavior when creating a sample struct
in C++ code: it is now initialized to default values. If this
ever turns out to be a performance problem, we can either add
additional constructors or use special functions that do
not initialize memory, such as make_unique_for_overwrite.

This removes non-standard (respectively >C++20) constructs,
namely designated initializers.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-03-10 11:01:42 +13:00
Robert C. Helling
e794efaba6 Allow for more O2 sensors
The Divesoft Liberty has four O2 sensors. So far, we had a hard coded
limit of three sensors and crashed with a failed assert when we
encoutered more than three. This allows for up to
MAX_O2_SENSORS which is currently 6. The voting logic is adapted
accordingly: We sort the values and we keep deleting the values that
differ more than 20% by value from the closest. This follows what
Shearwater implements on their computers.

In some of the import/export functions the value is still hard
coded to 6 thanks to explicit field names.

Signed-off-by: Robert C. Helling <helling@lmu.de>
2024-01-23 19:24:53 +01:00
Berthold Stoeger
0c84f369c3 core: use int16_t for sensor-id
The sensor-id in the sample struct was a uint8_t, with all
the known problems of unsigned integers. In the rest of the
code cylinder ids are signed integers. To avoid confusion,
make it a signed int. int8_t should be enough (max. 127
cylinders). To allow for degenerate cases, use an int16_t.
16k cylinders should be enough for everyone.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-07-23 11:16:00 -07:00
Berthold Stoeger
7e11a35371 core: add a special NO_SENSOR value for sample::sensor
The sensor member of sample refers to a cylinder from which
the pressure was read. However, some dives don't even have
a cylinder. Therefore, introduce a special NO_SENSOR value
for these dives. Since the cylinder is given as a uint8_t,
0xff seems to be a sensible choice.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-07-19 10:13:51 -07:00
Berthold Stoeger
0e196310f9 cleanup: split out divecomputer functions from dive.c
Since dive.c is so huge, split out divecomputer-related functions
into divecomputer.[c|h], sample.[c|h] and extradata.[c|h].

This does not give huge compile time improvements, since
struct dive contains a struct divecomputer and therefore
dive.h has to include divecomputer.h. However, it make things
distinctly more clear.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-25 13:59:52 -07:00