summaryrefslogtreecommitdiffstats
path: root/src/devices/mode/continuous.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/devices/mode/continuous.rs')
-rw-r--r--src/devices/mode/continuous.rs35
1 files changed, 7 insertions, 28 deletions
diff --git a/src/devices/mode/continuous.rs b/src/devices/mode/continuous.rs
index 66951dd..29471de 100644
--- a/src/devices/mode/continuous.rs
+++ b/src/devices/mode/continuous.rs
@@ -3,7 +3,7 @@
use super::super::OperatingMode;
use channels::ChannelSelection;
use core::marker::PhantomData;
-use {conversion, hal, interface, mode, Ads1x1x, Error, Register};
+use {conversion, hal, interface, mode, Ads1x1x, Error, ModeChangeError, Register};
impl<DI, IC, CONV, E> Ads1x1x<DI, IC, CONV, mode::Continuous>
where
@@ -11,8 +11,12 @@ where
CONV: conversion::ConvertMeasurement,
{
/// Change operating mode to OneShot
- pub fn into_one_shot(mut self) -> Result<Ads1x1x<DI, IC, CONV, mode::OneShot>, Error<E>> {
- self.set_operating_mode(OperatingMode::OneShot)?;
+ pub fn into_one_shot(
+ mut self,
+ ) -> Result<Ads1x1x<DI, IC, CONV, mode::OneShot>, ModeChangeError<E, Self>> {
+ if let Err(Error::I2C(e)) = self.set_operating_mode(OperatingMode::OneShot) {
+ return Err(ModeChangeError::I2C(e, self));
+ }
Ok(Ads1x1x {
iface: self.iface,
config: self.config,
@@ -24,37 +28,12 @@ where
})
}
- /// Start continuous conversions
- ///
- /// _Note:_ this method is only available in continuous mode.
- pub fn start(&mut self) -> Result<(), Error<E>> {
- self.set_operating_mode(OperatingMode::Continuous)?;
- self.a_conversion_was_started = true;
- Ok(())
- }
-
/// Read the most recent measurement
- ///
- /// The continuous measurement must be started with [`start()`] before
- /// calling this method. Otherwise, `Error::NotStarted` will be returned.
- ///
- /// _Note:_ this method is only available in continuous mode.
- ///
- /// [`start()`]: struct.Ads1x1x.html#method.start
pub fn read(&mut self) -> Result<i16, Error<E>> {
- if !self.a_conversion_was_started {
- return Err(Error::NotStarted);
- }
let value = self.iface.read_register(Register::CONVERSION)?;
Ok(CONV::convert_measurement(value))
}
-}
-impl<DI, IC, CONV, E> Ads1x1x<DI, IC, CONV, mode::Continuous>
-where
- DI: interface::ReadData<Error = E> + interface::WriteData<Error = E>,
- CONV: conversion::ConvertMeasurement,
-{
/// Select the channel for measurements.
///
/// Note that when changing the channel in continuous conversion mode, the