summaryrefslogtreecommitdiffstats
path: root/core/dive.c
diff options
context:
space:
mode:
authorGravatar Willem Ferguson <willemferguson@zoology.up.ac.za>2018-04-03 19:30:27 +0200
committerGravatar Lubomir I. Ivanov <neolit123@gmail.com>2018-05-14 23:47:00 +0300
commit27a0542220ae3766f0a98058c28e86d6c6d43a62 (patch)
treecf5a13544588d53667c2a4272a9053406b32d6a6 /core/dive.c
parentcf377beb2ea13833fa4a867b9c99153ecd9fff22 (diff)
downloadsubsurface-27a0542220ae3766f0a98058c28e86d6c6d43a62.tar.gz
Implement bailout outside of the dive planner
This is the second step for implementing bailout. The indirect calls to fill_pressures through add_segment() (in deco.c) are addressed. Bailout is now fully implemented in the dive log but not in the dive planner. 1) The parameters to add_segment() are changed to take a divemode as the second last parameter, and not a *dive. 2) Call to add_segment() in profile.c and in divelist.c are adapted. In divelist.c some calls to add_segment were left using dc-> divemode instead of possible bailout. This appears tp be the most appropriate route. 3) The functions get_divemode_from_time() and get_next_divemodechange() in dive.c have had some small changes. 4) The calls to get_segment(0 in planner.c were changed to reflect the new parameter list, but not updated to reflect bailout. This is the next step. Signed-off-by: Willem Ferguson <willemferguson@zoology.up.ac.za>
Diffstat (limited to 'core/dive.c')
-rw-r--r--core/dive.c45
1 files changed, 29 insertions, 16 deletions
diff --git a/core/dive.c b/core/dive.c
index 680635e8f..66f05b0b3 100644
--- a/core/dive.c
+++ b/core/dive.c
@@ -244,7 +244,7 @@ void add_extra_data(struct divecomputer *dc, const char *key, const char *value)
struct event *get_next_divemodechange(struct event **evd)
{ /* Starting at the event pointed to by evd, find the next divemode change event and initialise its
* type and divemode. Requires an external pointer (evd) to a divemode change event, usually
- * initialised to dc->events. This function is self-tracking and the value of evd needs no
+ * a copy of dc->events. This function is self-tracking and the value of evd needs no
* setting or manipulation outside of this function. */
struct event *ev = *evd;
while (ev) { // Step through the events.
@@ -277,27 +277,40 @@ struct event *peek_next_divemodechange(struct event *evd)
return (NULL);
}
+/*
+enum dive_comp_type get_divemode_at_time(struct divecomputer *dc, int divetime, struct event **ev_dmc)
+{ // The dummy version of this function, call parameters compatible with self-tracking version.
+ return dc->divemode;
+}
+
+enum dive_comp_type get_divemode_at_time(struct divecomputer *dc, int divetime, struct event **ev_dmc)
+{ // The non-self-tracking version of this function, call parameters compatible with self-tracking version.
+ struct event *ev, *ev_ndc = dc->events;
+ enum dive_comp_type mode = dc->divemode;
+ ev = get_next_divemodechange(&ev_ndc);
+ while (ev && (divetime >= ev->time.seconds)) {
+ mode = ev->divemode;
+ ev = get_next_divemodechange(&ev_ndc);
+ }
+ return mode;
+} */
+
enum dive_comp_type get_divemode_at_time(struct divecomputer *dc, int dtime, struct event **ev_dmc)
{ /* For a particular dive computer and its linked list of events, find the divemode dtime seconds
* into the dive. Requires an external pointer (ev_dmc) to a divemode change event, usually
- * initialised by a call to get_next_divemodechange(dc->events). This function is self-tracking
- * and the value of ev_dmc needs no setting or manipulation outside of this function. */
- enum dive_comp_type mode;
- struct event *ev = *ev_dmc; // ev_dmc points to event initialised by get_next_divemodechange()
- if (!ev)
- mode = dc->divemode; // if there is no divemodechange event, default to dc->divemode
- else {
- mode = ev->divemode; // If there is a starting divemodechange event, use the divemode of that event.
- while (ev && (dtime >= ev->time.seconds)) { // If dtime is AFTER this event time, store divemode
- mode = ev->divemode;
- *ev_dmc = ev;
- ev = peek_next_divemodechange(ev->next); // peek at the time of the following divemode change event
- }
- }
+ * initialised by a call to get_next_divemodechange(&copy-of-dc->events). This function is self-tracking
+ * and the value of ev_dmc needs no manipulation outside of this function. */
+ enum dive_comp_type mode = dc->divemode;
+ struct event *ev_last = *ev_dmc, *ev = *ev_dmc; // ev_dmc points to event initialised by get_next_divemodechange()
+ while (ev && (dtime >= ev->time.seconds)) { // If dtime is AFTER this event time, store divemode
+ mode = ev->divemode;
+ ev_last = ev;
+ ev = peek_next_divemodechange(ev->next); // peek at the time of the following divemode change event
+ }
+ *ev_dmc = ev_last;
return (mode);
}
-
/* this returns a pointer to static variable - so use it right away after calling */
struct gasmix *get_gasmix_from_event(struct dive *dive, struct event *ev)
{