summaryrefslogtreecommitdiffstats
path: root/divelist.c
diff options
context:
space:
mode:
authorGravatar Linus Torvalds <torvalds@linux-foundation.org>2012-12-30 20:00:51 -0800
committerGravatar Dirk Hohndel <dirk@hohndel.org>2012-12-30 20:44:47 -0800
commitd720e133d84d6d468ffab48698d5105849f7d14c (patch)
tree78b531ab868c901f8077a49d5d8304422698f6a0 /divelist.c
parentdf0ea072920668de4517ad85c742c7169bd24f22 (diff)
downloadsubsurface-d720e133d84d6d468ffab48698d5105849f7d14c.tar.gz
First step in cleaning up cylinder pressure sensor logic
This clarifies/changes the meaning of our "cylinderindex" entry in our samples. It has been rather confused, because different dive computers have done things differently, and the naming really hasn't helped. There are two totally different - and independent - cylinder "indexes": - the pressure sensor index, which indicates which cylinder the sensor data is from. - the "active cylinder" index, which indicates which cylinder we actually breathe from. These two values really are totally independent, and have nothing what-so-ever to do with each other. The sensor index may well be fixed: many dive computers only support a single pressure sensor (whether wireless or wired), and the sensor index is thus always zero. Other dive computers may support multiple pressure sensors, and the gas switch event may - or may not - indicate that the sensor changed too. A dive computer might give the sensor data for *all* cylinders it can read, regardless of which one is the one we're actively breathing. In fact, some dive computers might give sensor data for not just *your* cylinder, but your buddies. This patch renames "cylinderindex" in the samples as "sensor", making it quite clear that it's about which sensor index the pressure data in the sample is about. The way we figure out which is the currently active gas is with an explicit has change event. If a computer (like the Uemis Zurich) joins the two concepts together, then a sensor change should also create a gas switch event. This patch also changes the Uemis importer to do that. Finally, it should be noted that the plot info works totally separately from the sample data, and is about what we actually *display*, not about the sample pressures etc. In the plot info, the "cylinderindex" does in fact mean the currently active cylinder, and while it is initially set to match the sensor information from the samples, we then walk the gas change events and fix it up - and if the active cylinder differs from the sensor cylinder, we clear the sensor data. [Dirk Hohndel: this conflicted with some of my recent changes - I think I merged things correctly...] Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'divelist.c')
-rw-r--r--divelist.c22
1 files changed, 19 insertions, 3 deletions
diff --git a/divelist.c b/divelist.c
index 316c4d547..2a6829e27 100644
--- a/divelist.c
+++ b/divelist.c
@@ -715,6 +715,24 @@ static void cns_data_func(GtkTreeViewColumn *col,
g_object_set(renderer, "text", buffer, NULL);
}
+static int active_o2(struct dive *dive, struct divecomputer *dc, duration_t time)
+{
+ int o2permille = dive->cylinder[0].gasmix.o2.permille;
+ struct event *event = dc->events;
+
+ if (!o2permille)
+ o2permille = AIR_PERMILLE;
+
+ for (event = dc->events; event; event = event->next) {
+ if (event->time.seconds > time.seconds)
+ break;
+ if (strcmp(event->name, "gaschange"))
+ continue;
+ o2permille = 10*(event->value & 0xffff);
+ }
+ return o2permille;
+}
+
/* calculate OTU for a dive */
static int calculate_otu(struct dive *dive, struct divecomputer *dc)
{
@@ -730,9 +748,7 @@ static int calculate_otu(struct dive *dive, struct divecomputer *dc)
if (sample->po2) {
po2 = sample->po2;
} else {
- int o2 = dive->cylinder[sample->cylinderindex].gasmix.o2.permille;
- if (!o2)
- o2 = AIR_PERMILLE;
+ int o2 = active_o2(dive, dc, sample->time);
po2 = o2 / 1000.0 * depth_to_mbar(sample->depth.mm, dive) / 1000.0;
}
if (po2 >= 0.5)