summaryrefslogtreecommitdiffstats
path: root/core/profile.c
diff options
context:
space:
mode:
authorGravatar Linus Torvalds <torvalds@linux-foundation.org>2017-11-16 17:57:37 -0800
committerGravatar Lubomir I. Ivanov <neolit123@gmail.com>2017-11-17 15:25:26 +0100
commit7fa5fcfa1d3917f125d772708ff742f5e4b1758d (patch)
treea456e8b878cd7bd467957dbeb57b1d6b1c05a1fc /core/profile.c
parent2e82a5d2ed6966cb1ac0fb9751278d357ae6346d (diff)
downloadsubsurface-7fa5fcfa1d3917f125d772708ff742f5e4b1758d.tar.gz
Don't show cylinder pressures for other dive computers
Stefan Fuchs points out that sometimes you get cylinder duplication when you merge dives, particularly with a planned dive. For example, if we had different manual pressures in the two different dives, the cylinders will be kept separate. But that also means that we don't want to plot the pressures from those other cylinders that came from another dive and are now associated with another dive computer. Change the "seen" logic for the cylinder to ignore cylinders that are only mentioned by other dive computers than the active one. Reported-by: Stefan Fuchs <sfuchs@gmx.de> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'core/profile.c')
-rw-r--r--core/profile.c42
1 files changed, 36 insertions, 6 deletions
diff --git a/core/profile.c b/core/profile.c
index 4aae8b89e..ac327aee2 100644
--- a/core/profile.c
+++ b/core/profile.c
@@ -802,7 +802,7 @@ static void populate_secondary_sensor_data(struct divecomputer *dc, struct plot_
* This adds a pressure entry to the plot_info based on the gas change
* information and the manually filled in pressures.
*/
-static void add_plot_pressure(struct plot_info *pi, int time, int cyl, int mbar)
+static void add_plot_pressure(struct plot_info *pi, int time, int cyl, pressure_t p)
{
struct plot_data *entry;
for (int i = 0; i < pi->nr; i++) {
@@ -811,14 +811,14 @@ static void add_plot_pressure(struct plot_info *pi, int time, int cyl, int mbar)
if (entry->sec >= time)
break;
}
- SENSOR_PRESSURE(entry, cyl) = mbar;
+ SENSOR_PRESSURE(entry, cyl) = p.mbar;
}
static void setup_gas_sensor_pressure(struct dive *dive, struct divecomputer *dc, struct plot_info *pi)
{
int prev, i;
struct event *ev;
- unsigned int seen[MAX_CYLINDERS] = { 0, };
+ int seen[MAX_CYLINDERS] = { 0, };
unsigned int first[MAX_CYLINDERS] = { 0, };
unsigned int last[MAX_CYLINDERS] = { 0, };
struct divecomputer *secondary;
@@ -847,14 +847,44 @@ static void setup_gas_sensor_pressure(struct dive *dive, struct divecomputer *dc
}
last[prev] = INT_MAX;
+ // Fill in "seen[]" array - mark cylinders we're not interested
+ // in as negative.
for (i = 0; i < MAX_CYLINDERS; i++) {
cylinder_t *cyl = dive->cylinder + i;
int start = cyl->start.mbar;
int end = cyl->end.mbar;
- if (start && end && start != end) {
- add_plot_pressure(pi, first[i], i, start);
- add_plot_pressure(pi, last[i], i, end);
+ /*
+ * Fundamentally uninteresting?
+ *
+ * A dive computer with no pressure data isn't interesting
+ * to plot pressures for even if we've seen it..
+ */
+ if (!start || !end || start == end) {
+ seen[i] = -1;
+ continue;
+ }
+
+ /* If we've seen it, we're definitely interested */
+ if (seen[i])
+ continue;
+
+ /* If it's only mentioned by other dc's, ignore it */
+ for_each_dc(dive, secondary) {
+ if (has_gaschange_event(dive, secondary, i)) {
+ seen[i] = -1;
+ break;
+ }
+ }
+ }
+
+
+ for (i = 0; i < MAX_CYLINDERS; i++) {
+ if (seen[i] >= 0) {
+ cylinder_t *cyl = dive->cylinder + i;
+
+ add_plot_pressure(pi, first[i], i, cyl->start);
+ add_plot_pressure(pi, last[i], i, cyl->end);
}
}