From e571469bbb1d91744819a4744ed6a8c7975e7467 Mon Sep 17 00:00:00 2001 From: Diego Barrios Romero Date: Sun, 11 Nov 2018 08:25:45 +0100 Subject: Trigger new measurement if reading a different channel --- src/devices/mode/oneshot.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/devices/mode/oneshot.rs b/src/devices/mode/oneshot.rs index 30958ab..57e72a0 100644 --- a/src/devices/mode/oneshot.rs +++ b/src/devices/mode/oneshot.rs @@ -45,13 +45,19 @@ where { type Error = Error; - /// Request that the ADC begin a conversion on the specified channel + /// Request that the ADC begin a conversion on the specified channel. + /// + /// Returns `nb::Error::WouldBlock` while a measurement is in progress. + /// + /// In case a measurement was requested and after is it is finished a + /// measurement on a different channel is requested, a new measurement on + /// using the new channel selection is triggered. fn read(&mut self, _channel: &mut CH) -> nb::Result { - //TODO for devices with MUX select channel, if it is the wrong one, return AlreadyInProgress or WrongChannel error if self.is_measurement_in_progress().map_err(nb::Error::Other)? { return Err(nb::Error::WouldBlock); } - if self.a_conversion_was_started { + let same_channel = self.config == self.config.with_mux_bits(CH::channel()); + if self.a_conversion_was_started && same_channel { // result is ready let value = self.iface.read_register(Register::CONVERSION).map_err(nb::Error::Other)?; self.a_conversion_was_started = false; -- cgit v1.2.3-54-g00ecf