summaryrefslogtreecommitdiffstats
path: root/profile.c
diff options
context:
space:
mode:
authorGravatar Robert C. Helling <helling@atdotde.de>2014-11-26 14:22:41 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-12-01 14:23:45 -0800
commitfb265c292994d9afa252b5236a805f84cb0d4554 (patch)
treecb03a4d7f76cfa057948db6386fcb8f96780d350 /profile.c
parent96a94f1a19d22fa0432e10495315ce3e98b35c4f (diff)
downloadsubsurface-fb265c292994d9afa252b5236a805f84cb0d4554.tar.gz
Context menu entry to change setpoint
This patch adds a context menu entry to add a setpoint change event. In particular, this can be used to turn a logged dive into a CCR dive. Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'profile.c')
-rw-r--r--profile.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/profile.c b/profile.c
index 849f6b454..20ac03976 100644
--- a/profile.c
+++ b/profile.c
@@ -373,6 +373,18 @@ static int set_cylinder_index(struct plot_info *pi, int i, int cylinderindex, un
return i;
}
+static int set_setpoint(struct plot_info *pi, int i, int setpoint, unsigned int end)
+{
+ while (i < pi->nr) {
+ struct plot_data *entry = pi->entry + i;
+ if (entry->sec > end)
+ break;
+ entry->o2pressure.mbar = setpoint;
+ i++;
+ }
+ return i;
+}
+
/* normally the first cylinder has index 0... if not, we need to fix this up here */
static int set_first_cylinder_index(struct plot_info *pi, int i, int cylinderindex, unsigned int end)
{
@@ -407,6 +419,27 @@ static void check_gas_change_events(struct dive *dive, struct divecomputer *dc,
set_cylinder_index(pi, i, cylinderindex, ~0u);
}
+static void check_setpoint_events(struct dive *dive, struct divecomputer *dc, struct plot_info *pi)
+{
+ int i = 0;
+ pressure_t setpoint;
+
+ setpoint.mbar = 0;
+ struct event *ev = get_next_event(dc->events, "SP change");
+
+ if (!ev)
+ return;
+
+ do {
+ i = set_setpoint(pi, i, setpoint.mbar, ev->time.seconds);
+ setpoint.mbar = ev->value;
+ if(setpoint.mbar)
+ dc->dctype = CCR;
+ ev = get_next_event(ev->next, "SP change");
+ } while (ev);
+ set_setpoint(pi, i, setpoint.mbar, ~0u);
+}
+
struct plot_info calculate_max_limits_new(struct dive *dive, struct divecomputer *dc)
{
@@ -1014,6 +1047,7 @@ void create_plot_info_new(struct dive *dive, struct divecomputer *dc, struct plo
last_pi_entry_new = populate_plot_entries(dive, dc, pi);
check_gas_change_events(dive, dc, pi); /* Populate the gas index from the gas change events */
+ check_setpoint_events(dive, dc, pi); /* Populate setpoints */
setup_gas_sensor_pressure(dive, dc, pi); /* Try to populate our gas pressure knowledge */
populate_pressure_information(dive, dc, pi, false); /* .. calculate missing pressure entries for all gasses except o2 */
if (dc->dctype == CCR) /* For CCR dives.. */