diff options
author | Diego Barrios Romero <eldruin@gmail.com> | 2018-11-20 18:45:32 +0100 |
---|---|---|
committer | Diego Barrios Romero <eldruin@gmail.com> | 2018-11-20 18:45:32 +0100 |
commit | ea48b456d5045cd136c08829d40708eef1cab67a (patch) | |
tree | b01cbefeb66b2a7f45950dd953fbec31ab4aa9a8 | |
parent | 23f62d84d1232b7ef5ec02483a8090aa5c336fa6 (diff) | |
download | ads1x1x-async-ea48b456d5045cd136c08829d40708eef1cab67a.tar.gz ads1x1x-async-ea48b456d5045cd136c08829d40708eef1cab67a.tar.xz ads1x1x-async-ea48b456d5045cd136c08829d40708eef1cab67a.zip |
Add method to start continuous conversions
-rw-r--r-- | src/devices/mode/continuous.rs | 7 | ||||
-rw-r--r-- | src/devices/mode/oneshot.rs | 4 | ||||
-rw-r--r-- | tests/tier1_i2c.rs | 18 |
3 files changed, 20 insertions, 9 deletions
diff --git a/src/devices/mode/continuous.rs b/src/devices/mode/continuous.rs index cb62f8d..6bf5201 100644 --- a/src/devices/mode/continuous.rs +++ b/src/devices/mode/continuous.rs @@ -21,4 +21,11 @@ where _mode: PhantomData }) } + + /// Start continuous conversions + pub fn start(&mut self) -> Result<(), Error<E>> { + self.set_operating_mode(OperatingMode::Continuous)?; + self.a_conversion_was_started = true; + Ok(()) + } } diff --git a/src/devices/mode/oneshot.rs b/src/devices/mode/oneshot.rs index fc4a5ed..41a9f26 100644 --- a/src/devices/mode/oneshot.rs +++ b/src/devices/mode/oneshot.rs @@ -3,7 +3,6 @@ use core::marker::PhantomData; use { Ads1x1x, mode, Error, Register, BitFlags, Config }; use { interface, conversion, hal, nb }; -use devices::OperatingMode; use channels::ChannelSelection; impl<DI, IC, CONV, E> Ads1x1x<DI, IC, CONV, mode::OneShot> @@ -12,8 +11,7 @@ where CONV: conversion::ConvertMeasurement { /// Change operating mode to Continuous - pub fn into_continuous(mut self) -> Result<Ads1x1x<DI, IC, CONV, mode::Continuous>, Error<E>> { - self.set_operating_mode(OperatingMode::Continuous)?; + pub fn into_continuous(self) -> Result<Ads1x1x<DI, IC, CONV, mode::Continuous>, Error<E>> { Ok(Ads1x1x { iface: self.iface, config: self.config, diff --git a/tests/tier1_i2c.rs b/tests/tier1_i2c.rs index 5ffff60..9437487 100644 --- a/tests/tier1_i2c.rs +++ b/tests/tier1_i2c.rs @@ -100,21 +100,27 @@ mod data_rate_16bit { #[test] fn can_convert_to_continuous() { - let config = Config::default().with_low(BitFlags::OP_MODE); - let transactions = [ I2cTrans::write(DEV_ADDR, vec![Register::CONFIG, config.msb(), config.lsb()]) ]; - let dev = new_ads1013(&transactions); + let dev = new_ads1013(&[]); let dev = dev.into_continuous().unwrap(); destroy_ads1013(dev); } #[test] fn can_convert_to_one_shot() { - let config_cont = Config::default().with_low(BitFlags::OP_MODE); let config_os = Config::default(); - let transactions = [ I2cTrans::write(DEV_ADDR, vec![Register::CONFIG, config_cont.msb(), config_cont.lsb()]), - I2cTrans::write(DEV_ADDR, vec![Register::CONFIG, config_os.msb(), config_os.lsb()]) ]; + let transactions = [ I2cTrans::write(DEV_ADDR, vec![Register::CONFIG, config_os.msb(), config_os.lsb()]) ]; let dev = new_ads1013(&transactions); let dev = dev.into_continuous().unwrap(); let dev = dev.into_one_shot().unwrap(); destroy_ads1013(dev); } + +#[test] +fn can_start_in_continuous() { + let config = Config::default().with_low(BitFlags::OP_MODE); + let transactions = [ I2cTrans::write(DEV_ADDR, vec![Register::CONFIG, config.msb(), config.lsb()]) ]; + let dev = new_ads1013(&transactions); + let mut dev = dev.into_continuous().unwrap(); + dev.start().unwrap(); + destroy_ads1013(dev); +} |