mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-30 22:20:21 +00:00
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>
This commit is contained in:
parent
b1906dd04f
commit
9fe1951db2
2 changed files with 23 additions and 16 deletions
38
core/dive.c
38
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! */
|
||||
|
|
|
@ -378,6 +378,7 @@ extern bool is_cylinder_used(const struct dive *dive, int idx);
|
|||
extern bool is_cylinder_prot(const struct dive *dive, int idx);
|
||||
extern void add_gas_switch_event(struct dive *dive, struct divecomputer *dc, int time, int idx);
|
||||
extern struct event *create_event(unsigned int time, int type, int flags, int value, const char *name);
|
||||
extern struct event *create_gas_switch_event(struct dive *dive, struct divecomputer *dc, int seconds, int idx);
|
||||
extern struct event *clone_event_rename(const struct event *ev, const char *name);
|
||||
extern void add_event_to_dc(struct divecomputer *dc, struct event *ev);
|
||||
extern void swap_event(struct divecomputer *dc, struct event *from, struct event *to);
|
||||
|
|
Loading…
Reference in a new issue