aboutsummaryrefslogtreecommitdiffstats
path: root/core/dive.c
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2020-03-04 19:41:40 +0100
committerGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2020-04-07 00:13:35 +0200
commit9fe1951db29a3470e525c9a4e03612d6f7d5ecbb (patch)
tree91ed50ea68ba68585b68b6c2087ed40079011f66 /core/dive.c
parentb1906dd04f0162619df5710cde9248aa4b342a2b (diff)
downloadsubsurface-9fe1951db29a3470e525c9a4e03612d6f7d5ecbb.tar.gz
core: split out create_gas_change_event() from add_gas_change_event()
For undo, we want to create gas change events without adding them immediately to the dive computer. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'core/dive.c')
-rw-r--r--core/dive.c38
1 files changed, 22 insertions, 16 deletions
diff --git a/core/dive.c b/core/dive.c
index d46f2de1d..849425389 100644
--- a/core/dive.c
+++ b/core/dive.c
@@ -167,6 +167,26 @@ struct event *create_event(unsigned int time, int type, int flags, int value, co
return ev;
}
+/* warning: does not test idx for validity */
+struct event *create_gas_switch_event(struct dive *dive, struct divecomputer *dc, int seconds, int idx)
+{
+ /* 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 = create_event(seconds, he ? SAMPLE_EVENT_GASCHANGE2 : SAMPLE_EVENT_GASCHANGE, 0, value, "gaschange");
+ ev->gas.index = idx;
+ ev->gas.mix = mix;
+ return ev;
+}
+
struct event *clone_event_rename(const struct event *ev, const char *name)
{
return create_event(ev->time.seconds, ev->type, ev->flags, ev->value, name);
@@ -205,22 +225,8 @@ void add_gas_switch_event(struct dive *dive, struct divecomputer *dc, int second
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;
- }
+ struct event *ev = create_gas_switch_event(dive, dc, seconds, idx);
+ add_event_to_dc(dc, ev);
}
/* Substitutes an event in a divecomputer for another. No reordering is performed! */