diff options
Diffstat (limited to 'src/devices/mode/oneshot.rs')
-rw-r--r-- | src/devices/mode/oneshot.rs | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/src/devices/mode/oneshot.rs b/src/devices/mode/oneshot.rs index 665ce33..fa4d3b8 100644 --- a/src/devices/mode/oneshot.rs +++ b/src/devices/mode/oneshot.rs @@ -1,7 +1,7 @@ //! Common functions use crate::{ - channels::ChannelSelection, conversion, devices::OperatingMode, interface, mode, Ads1x1x, - BitFlags, Config, Error, ModeChangeError, Register, + conversion, devices::OperatingMode, interface, mode, Ads1x1x, BitFlags, ChannelSelection, + Config, DynamicOneShot, Error, ModeChangeError, Register, }; use core::marker::PhantomData; use embedded_hal::adc; @@ -58,13 +58,25 @@ where /// 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> { + <Self as DynamicOneShot>::read(self, CH::channel()) + } +} + +impl<DI, IC, CONV, E> DynamicOneShot for Ads1x1x<DI, IC, CONV, mode::OneShot> +where + DI: interface::ReadData<Error = E> + interface::WriteData<Error = E>, + CONV: conversion::ConvertMeasurement, +{ + type Error = Error<E>; + + fn read(&mut self, channel: ChannelSelection) -> nb::Result<i16, Self::Error> { if self .is_measurement_in_progress() .map_err(nb::Error::Other)? { return Err(nb::Error::WouldBlock); } - let same_channel = self.config == self.config.with_mux_bits(CH::channel()); + let same_channel = self.config == self.config.with_mux_bits(channel); if self.a_conversion_was_started && same_channel { // result is ready let value = self @@ -74,7 +86,7 @@ where self.a_conversion_was_started = false; return Ok(CONV::convert_measurement(value)); } - let config = self.config.with_mux_bits(CH::channel()); + let config = self.config.with_mux_bits(channel); self.trigger_measurement(&config) .map_err(nb::Error::Other)?; self.config = config; |