From 74ecb924f4831d93d5287db8ea034c5d593c35e9 Mon Sep 17 00:00:00 2001 From: Anton Lundin Date: Mon, 31 Aug 2015 23:23:43 +0200 Subject: [PATCH] Support multiple o2 sensor values from libdc libdivecomputer might call us with DC_SAMPLE_PPO2 multiple times, which means multiple sensors. Signed-off-by: Anton Lundin Signed-off-by: Dirk Hohndel --- libdivecomputer.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/libdivecomputer.c b/libdivecomputer.c index e877e5962..3e4cfada7 100644 --- a/libdivecomputer.c +++ b/libdivecomputer.c @@ -199,6 +199,7 @@ void sample_cb(dc_sample_type_t type, dc_sample_value_t value, void *userdata) { unsigned int mm; + static unsigned int nsensor = 0; struct divecomputer *dc = userdata; struct sample *sample; @@ -217,6 +218,7 @@ sample_cb(dc_sample_type_t type, dc_sample_value_t value, void *userdata) switch (type) { case DC_SAMPLE_TIME: + nsensor = 0; mm = 0; if (sample) { sample->in_deco = in_deco; @@ -269,7 +271,11 @@ sample_cb(dc_sample_type_t type, dc_sample_value_t value, void *userdata) sample->setpoint.mbar = po2 = rint(value.setpoint * 1000); break; case DC_SAMPLE_PPO2: - sample->o2sensor[0].mbar = po2 = rint(value.ppo2 * 1000); + if (nsensor < 3) + sample->o2sensor[nsensor].mbar = po2 = rint(value.ppo2 * 1000); + else + report_error("%d is more o2 sensors than we can handle", nsensor); + nsensor++; break; case DC_SAMPLE_CNS: sample->cns = cns = rint(value.cns * 100);