summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Robert C. Helling <helling@atdotde.de>2015-01-16 13:49:12 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2015-01-17 08:18:08 +1300
commit881803441e3c0a24004a25e84197280c4722b679 (patch)
treea285649894f5a4dc390aea1caed92b9f7fa9d573
parentf2939dd991f5f9cd40501d419e7a816492857311 (diff)
downloadsubsurface-881803441e3c0a24004a25e84197280c4722b679.tar.gz
Save predefined SAC
When planning a dive, the gas consumption is based on a user configured SAC. Thus we should use that SAC and not try to recompute it from samples. Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--dive.h1
-rw-r--r--planner.c3
-rw-r--r--profile.c13
3 files changed, 13 insertions, 4 deletions
diff --git a/dive.h b/dive.h
index 46b3d399b..327598b7c 100644
--- a/dive.h
+++ b/dive.h
@@ -191,6 +191,7 @@ struct sample // BASE TYPE BYTES UNITS RANGE DE
uint8_t sensor; // uint8_t 1 sensorID (0-255) ID of cylinder pressure sensor
uint8_t cns; // uint8_t 1 % (0-255 %) cns% accumulated
uint8_t heartbeat; // uint8_t 1 beats/m (0-255) heart rate measurement
+ volume_t sac; // 4 ml/min predefined SAC
bool in_deco; // bool 1 y/n y/n this sample is part of deco
bool manually_entered; // bool 1 y/n y/n this sample was entered by the user,
// not calculated when planning a dive
diff --git a/planner.c b/planner.c
index e6bd088c9..d7f80b407 100644
--- a/planner.c
+++ b/planner.c
@@ -278,6 +278,7 @@ static void create_dive_from_plan(struct diveplan *diveplan, bool track_gas)
oldgasmix = cyl->gasmix;
sample = prepare_sample(dc);
sample->setpoint.mbar = dp->setpoint;
+ sample->sac.mliter = prefs.bottomsac;
oldpo2 = dp->setpoint;
if (track_gas && cyl->type.workingpressure.mbar)
sample->cylinderpressure.mbar = cyl->end.mbar;
@@ -323,6 +324,7 @@ static void create_dive_from_plan(struct diveplan *diveplan, bool track_gas)
sample->time.seconds = lasttime + 1;
sample->depth.mm = lastdepth;
sample->manually_entered = dp->entered;
+ sample->sac.mliter = dp->entered ? prefs.bottomsac : prefs.decosac;
if (track_gas && cyl->type.workingpressure.mbar)
sample->cylinderpressure.mbar = cyl->sample_end.mbar;
finish_sample(dc);
@@ -337,6 +339,7 @@ static void create_dive_from_plan(struct diveplan *diveplan, bool track_gas)
sample->time.seconds = lasttime = time;
sample->depth.mm = lastdepth = depth;
sample->manually_entered = dp->entered;
+ sample->sac.mliter = dp->entered ? prefs.bottomsac : prefs.decosac;
if (track_gas && !sample[-1].setpoint.mbar) { /* Don't track gas usage for CCR legs of dive */
update_cylinder_pressure(&displayed_dive, sample[-1].depth.mm, depth, time - sample[-1].time.seconds,
dp->entered ? diveplan->bottomsac : diveplan->decosac, cyl, !dp->entered);
diff --git a/profile.c b/profile.c
index 205663b0a..05e84cd73 100644
--- a/profile.c
+++ b/profile.c
@@ -518,12 +518,13 @@ struct plot_info calculate_max_limits_new(struct dive *dive, struct divecomputer
/* copy the previous entry (we know this exists), update time and depth
* and zero out the sensor pressure (since this is a synthetic entry)
* increment the entry pointer and the count of synthetic entries. */
-#define INSERT_ENTRY(_time, _depth) \
+#define INSERT_ENTRY(_time, _depth, _sac) \
*entry = entry[-1]; \
entry->sec = _time; \
entry->depth = _depth; \
entry->running_sum = (entry - 1)->running_sum + (_time - (entry - 1)->sec) * (_depth + (entry - 1)->depth) / 2; \
SENSOR_PRESSURE(entry) = 0; \
+ entry->sac = _sac; \
entry++; \
idx++
@@ -562,6 +563,7 @@ struct plot_data *populate_plot_entries(struct dive *dive, struct divecomputer *
int time = sample->time.seconds;
int offset, delta;
int depth = sample->depth.mm;
+ int sac = sample->sac.mliter;
/* Add intermediate plot entries if required */
delta = time - lasttime;
@@ -575,12 +577,12 @@ struct plot_data *populate_plot_entries(struct dive *dive, struct divecomputer *
/* Add events if they are between plot entries */
while (ev && ev->time.seconds < lasttime + offset) {
- INSERT_ENTRY(ev->time.seconds, interpolate(lastdepth, depth, ev->time.seconds - lasttime, delta));
+ INSERT_ENTRY(ev->time.seconds, interpolate(lastdepth, depth, ev->time.seconds - lasttime, delta), sac);
ev = ev->next;
}
/* now insert the time interpolated entry */
- INSERT_ENTRY(lasttime + offset, interpolate(lastdepth, depth, offset, delta));
+ INSERT_ENTRY(lasttime + offset, interpolate(lastdepth, depth, offset, delta), sac);
/* skip events that happened at this time */
while (ev && ev->time.seconds == lasttime + offset)
@@ -589,7 +591,7 @@ struct plot_data *populate_plot_entries(struct dive *dive, struct divecomputer *
/* Add events if they are between plot entries */
while (ev && ev->time.seconds < time) {
- INSERT_ENTRY(ev->time.seconds, interpolate(lastdepth, depth, ev->time.seconds - lasttime, delta));
+ INSERT_ENTRY(ev->time.seconds, interpolate(lastdepth, depth, ev->time.seconds - lasttime, delta), sac);
ev = ev->next;
}
@@ -625,6 +627,7 @@ struct plot_data *populate_plot_entries(struct dive *dive, struct divecomputer *
entry->temperature = lasttemp;
entry->heartbeat = sample->heartbeat;
entry->bearing = sample->bearing.degrees;
+ entry->sac = sample->sac.mliter;
/* skip events that happened at this time */
while (ev && ev->time.seconds == time)
@@ -689,6 +692,8 @@ static void calculate_sac(struct dive *dive, struct plot_info *pi)
for (i = 0; i < pi->nr; i++) {
struct plot_data *entry = pi->entry + i;
+ if (entry->sac)
+ continue;
if (!last_entry || last_entry->cylinderindex != entry->cylinderindex) {
last = i;
last_entry = entry;