diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2017-07-28 10:22:17 -0700 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2017-07-28 21:50:15 -0700 |
commit | 1e337518b81fdcd21b9c2e6efac3cc3ad0667439 (patch) | |
tree | 7a816af7c6a15427724dec4a16c9702bd310714d | |
parent | 7e39be436bea6983440a962da8375149166afa92 (diff) | |
download | subsurface-1e337518b81fdcd21b9c2e6efac3cc3ad0667439.tar.gz |
Add "get_gasmix()" helper function to iterate over gas changes
We have a few places that used to get the gasmix by looking at the
sensor index in the plot data, which really doesn't work any more.
To make it easier for those users to convert to the new world order,
this adds a "get_gasmix()" function. The gasmix function takes as its
argument the dive, the dive computer, and the time.
In addition, for good performance (to avoid looping over the event list
over and over and over again) it maintains a pointer to the next gas
switch event, and the previous gas. Those need to be initialized to
NULL by the caller, so the standard use-case pattern basically looks
like this:
struct gasmix *gasmix = NULL;
struct event *ev = NULL;
loop over samples or plot events in increasing time order: {
...
gasmix = get_gasmix(dive, dc, time, &ev, gasmix);
...
}
and then you can see what the currently breathing gas is at that time.
If for some reason you need to walk backwards in time, you can just pass
in a NULL gasmix again, which will reset the event iterator (at the cost
of now having to walk all the events again).
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r-- | core/dive.h | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/core/dive.h b/core/dive.h index eb976f56b..d19ccca4d 100644 --- a/core/dive.h +++ b/core/dive.h @@ -913,6 +913,23 @@ void delete_single_dive(int idx); struct event *get_next_event(struct event *event, const char *name); +static inline struct gasmix *get_gasmix(struct dive *dive, struct divecomputer *dc, int time, struct event **evp, struct gasmix *gasmix) +{ + struct event *ev = *evp; + + if (!gasmix) { + int cyl = explicit_first_cylinder(dive, dc); + gasmix = &dive->cylinder[cyl].gasmix; + ev = dc->events; + } + while (ev && ev->time.seconds < time) { + gasmix = get_gasmix_from_event(dive, ev); + ev = get_next_event(ev->next, "gaschange"); + } + *evp = ev; + return gasmix; +} + /* these structs holds the information that * describes the cylinders / weight systems. |