diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2020-03-04 19:29:59 +0100 |
---|---|---|
committer | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2020-04-07 00:13:35 +0200 |
commit | b1906dd04f0162619df5710cde9248aa4b342a2b (patch) | |
tree | 89d60aa1982f776c2e68cbde5f3121ef5507ea42 /core | |
parent | 3d511b069f5e2c659ed5af039485b1c72c348b8a (diff) | |
download | subsurface-b1906dd04f0162619df5710cde9248aa4b342a2b.tar.gz |
cleanup: move add_gas_switch_event to dive.c
Since all the other event-functions are also defined there.
Ultimately, we should probably move them to their own
event.c translation unit.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'core')
-rw-r--r-- | core/dive.c | 26 | ||||
-rw-r--r-- | core/parse-xml.c | 25 |
2 files changed, 26 insertions, 25 deletions
diff --git a/core/dive.c b/core/dive.c index 6d2645cef..d46f2de1d 100644 --- a/core/dive.c +++ b/core/dive.c @@ -11,6 +11,7 @@ #include "device.h" #include "divelist.h" #include "divesite.h" +#include "errorhelper.h" #include "qthelper.h" #include "metadata.h" #include "membuffer.h" @@ -197,6 +198,31 @@ struct event *add_event(struct divecomputer *dc, unsigned int time, int type, in return ev; } +void add_gas_switch_event(struct dive *dive, struct divecomputer *dc, int seconds, int idx) +{ + /* sanity check so we don't crash */ + if (idx < 0 || idx >= dive->cylinders.nr) { + report_error("Unknown cylinder index: %d", idx); + return; + } + /* The gas switch event format is insane for historical reasons */ + struct gasmix mix = get_cylinder(dive, idx)->gasmix; + int o2 = get_o2(mix); + int he = get_he(mix); + struct event *ev; + int value; + + o2 = (o2 + 5) / 10; + he = (he + 5) / 10; + value = o2 + (he << 16); + + ev = add_event(dc, seconds, he ? SAMPLE_EVENT_GASCHANGE2 : SAMPLE_EVENT_GASCHANGE, 0, value, "gaschange"); + if (ev) { + ev->gas.index = idx; + ev->gas.mix = mix; + } +} + /* Substitutes an event in a divecomputer for another. No reordering is performed! */ void swap_event(struct divecomputer *dc, struct event *from, struct event *to) { diff --git a/core/parse-xml.c b/core/parse-xml.c index 6218fc74d..2f3d7a283 100644 --- a/core/parse-xml.c +++ b/core/parse-xml.c @@ -697,31 +697,6 @@ static void try_to_match_autogroup(const char *name, char *buf) nonmatch("autogroup", name, buf); } -void add_gas_switch_event(struct dive *dive, struct divecomputer *dc, int seconds, int idx) -{ - /* sanity check so we don't crash */ - if (idx < 0 || idx >= dive->cylinders.nr) { - report_error("Unknown cylinder index: %d", idx); - return; - } - /* The gas switch event format is insane for historical reasons */ - struct gasmix mix = get_cylinder(dive, idx)->gasmix; - int o2 = get_o2(mix); - int he = get_he(mix); - struct event *ev; - int value; - - o2 = (o2 + 5) / 10; - he = (he + 5) / 10; - value = o2 + (he << 16); - - ev = add_event(dc, seconds, he ? SAMPLE_EVENT_GASCHANGE2 : SAMPLE_EVENT_GASCHANGE, 0, value, "gaschange"); - if (ev) { - ev->gas.index = idx; - ev->gas.mix = mix; - } -} - static void get_cylinderindex(char *buffer, uint8_t *i, struct parser_state *state) { *i = atoi(buffer); |