From eb0c438e9dbad47a9cf2c24610233b0224f7e269 Mon Sep 17 00:00:00 2001 From: Diego Barrios Romero Date: Wed, 21 Nov 2018 08:11:15 +0100 Subject: Make function to read if a measurement is in progress public --- README.md | 1 + src/devices/common.rs | 10 +++++++++- src/devices/mode/oneshot.rs | 7 ------- src/lib.rs | 2 ++ tests/tier1_i2c.rs | 18 ++++++++++++++++++ 5 files changed, 30 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index ea4699f..90b6d6d 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,7 @@ This driver allows you to: - Read the last measurement made in continuous conversion mode. See: `read()`. - Set the data rate. See: `set_data_rate()`. - Set the full-scale range (gain amplifier). See `set_full_scale_range()`. +- Read whether a measurement is in progress. See: `is_measurement_in_progress()`. - Set the low and high thresholds. See: `set_high_threshold_raw()`. - Set the comparator mode. See: `set_comparator_mode()`. - Set the comparator polarity. See: `set_comparator_polarity()`. diff --git a/src/devices/common.rs b/src/devices/common.rs index 1121265..92b4f9e 100644 --- a/src/devices/common.rs +++ b/src/devices/common.rs @@ -5,7 +5,7 @@ use super::OperatingMode; impl Ads1x1x where - DI: interface::WriteData + DI: interface::WriteData + interface::ReadData, { pub(super) fn set_operating_mode(&mut self, mode: OperatingMode) -> Result<(), Error> { let config; @@ -18,6 +18,14 @@ where Ok(()) } + /// Read whether a measurement is currently in progress. + pub fn is_measurement_in_progress(&mut self) -> Result> { + let config = Config { + bits: self.iface.read_register(Register::CONFIG)? + }; + Ok(!config.is_high(BitFlags::OS)) + } + /// Reset the internal state of this driver to the default values. /// /// *Note:* This does not alter the state or configuration of the device. diff --git a/src/devices/mode/oneshot.rs b/src/devices/mode/oneshot.rs index 41a9f26..a03d8d2 100644 --- a/src/devices/mode/oneshot.rs +++ b/src/devices/mode/oneshot.rs @@ -23,13 +23,6 @@ where }) } - fn is_measurement_in_progress(&mut self) -> Result> { - let config = Config { - bits: self.iface.read_register(Register::CONFIG)? - }; - Ok(!config.is_high(BitFlags::OS)) - } - fn trigger_measurement(&mut self, config: &Config) -> Result<(), Error> { let config = config.with_high(BitFlags::OS); self.iface.write_register(Register::CONFIG, config.bits) diff --git a/src/lib.rs b/src/lib.rs index 976fd23..20f5857 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -12,6 +12,7 @@ //! - Set the data rate. See: [`set_data_rate()`]. //! - Set the full-scale range (gain amplifier). See [`set_full_scale_range()`]. //! - Set the low and high thresholds. See: [`set_high_threshold_raw()`]. +//! - Read whether a measurement is in progress. See: [`is_measurement_in_progress()`]. //! - Set the comparator mode. See: [`set_comparator_mode()`]. //! - Set the comparator polarity. See: [`set_comparator_polarity()`]. //! - Set the comparator latching. See: [`set_comparator_latching()`]. @@ -25,6 +26,7 @@ //! [read_cont]: struct.Ads1x1x.html#impl-OneShot%3CAds1x1x%3CDI%2C%20IC%2C%20CONV%2C%20OneShot%3E%2C%20i16%2C%20CH%3E //! [`set_data_rate()`]: struct.Ads1x1x.html#method.set_data_rate //! [`set_full_scale_range()`]: struct.Ads1x1x.html#method.set_full_scale_range +//! [`is_measurement_in_progress()`]: struct.Ads1x1x.html#method.is_measurement_in_progress //! [`set_high_threshold_raw()`]: struct.Ads1x1x.html#method.set_high_threshold_raw //! [`set_comparator_mode()`]: struct.Ads1x1x.html#method.set_comparator_mode //! [`set_comparator_polarity()`]: struct.Ads1x1x.html#method.set_comparator_polarity diff --git a/tests/tier1_i2c.rs b/tests/tier1_i2c.rs index b26312f..b91575e 100644 --- a/tests/tier1_i2c.rs +++ b/tests/tier1_i2c.rs @@ -111,6 +111,24 @@ mod data_rate_16bit { test!(sps860, Sps860, Config::default().with_high(BitFlags::DR2).with_high(BitFlags::DR1).with_high(BitFlags::DR0)); } +#[test] +fn can_read_measurement_in_progress() { + let config_os = Config::default().with_low(BitFlags::OS); + let transactions = [ I2cTrans::write_read(DEV_ADDR, vec![Register::CONFIG], vec![config_os.msb(), config_os.lsb()]) ]; + let mut dev = new_ads1013(&transactions); + assert!(dev.is_measurement_in_progress().unwrap()); + destroy_ads1013(dev); +} + +#[test] +fn can_read_measurement_not_in_progress() { + let config_os = Config::default().with_high(BitFlags::OS); + let transactions = [ I2cTrans::write_read(DEV_ADDR, vec![Register::CONFIG], vec![config_os.msb(), config_os.lsb()]) ]; + let mut dev = new_ads1013(&transactions); + assert!(!dev.is_measurement_in_progress().unwrap()); + destroy_ads1013(dev); +} + #[test] fn can_convert_to_continuous() { let dev = new_ads1013(&[]); -- cgit v1.2.3-54-g00ecf