summaryrefslogtreecommitdiffstats
path: root/src/devices/mode
diff options
context:
space:
mode:
authorDiego Barrios Romero <eldruin@gmail.com>2018-11-11 08:25:45 +0100
committerDiego Barrios Romero <eldruin@gmail.com>2018-11-11 08:25:45 +0100
commite571469bbb1d91744819a4744ed6a8c7975e7467 (patch)
tree0f6d9deee2286925d23612b3286f4616bd52a2ed /src/devices/mode
parentd6ec443c2ed0f609cd9b66df4239f22ab87468a6 (diff)
downloadads1x1x-async-e571469bbb1d91744819a4744ed6a8c7975e7467.tar.gz
ads1x1x-async-e571469bbb1d91744819a4744ed6a8c7975e7467.tar.xz
ads1x1x-async-e571469bbb1d91744819a4744ed6a8c7975e7467.zip
Trigger new measurement if reading a different channel
Diffstat (limited to 'src/devices/mode')
-rw-r--r--src/devices/mode/oneshot.rs12
1 files changed, 9 insertions, 3 deletions
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<E>;
- /// 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<i16, Self::Error> {
- //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;