From 483221e740ffaebe406ee428beb59fa136d70c7f Mon Sep 17 00:00:00 2001 From: Diego Barrios Romero Date: Wed, 7 Nov 2018 20:22:59 +0100 Subject: Add support for one-shot measurements --- src/devices/ads1x1x/common.rs | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/devices/ads1x1x/common.rs (limited to 'src/devices/ads1x1x/common.rs') diff --git a/src/devices/ads1x1x/common.rs b/src/devices/ads1x1x/common.rs new file mode 100644 index 0000000..ce8a67a --- /dev/null +++ b/src/devices/ads1x1x/common.rs @@ -0,0 +1,37 @@ +//! Common functions + +use { Ads1x1x, DataRate, Error, Register, BitFlags, interface }; +use super::OperatingMode; + +impl Ads1x1x +where + DI: interface::WriteData +{ + pub(super) fn set_operating_mode(&mut self, mode: OperatingMode) -> Result<(), Error> { + let config; + match mode { + OperatingMode::OneShot => config = self.config.with_high(BitFlags::OP_MODE), + OperatingMode::Continuous => config = self.config.with_low(BitFlags::OP_MODE), + } + self.iface.write_register(Register::CONFIG, config.bits)?; + self.config = config; + Ok(()) + } + + /// Set data rate + pub fn set_data_rate(&mut self, rate: DataRate) -> Result<(), Error> { + let config; + match rate { + DataRate::Sps128 => config = self.config.with_low( BitFlags::DR2).with_low( BitFlags::DR1).with_low( BitFlags::DR0), + DataRate::Sps250 => config = self.config.with_low( BitFlags::DR2).with_low( BitFlags::DR1).with_high(BitFlags::DR0), + DataRate::Sps490 => config = self.config.with_low( BitFlags::DR2).with_high(BitFlags::DR1).with_low( BitFlags::DR0), + DataRate::Sps920 => config = self.config.with_low( BitFlags::DR2).with_high(BitFlags::DR1).with_high(BitFlags::DR0), + DataRate::Sps1600 => config = self.config.with_high(BitFlags::DR2).with_low( BitFlags::DR1).with_low( BitFlags::DR0), + DataRate::Sps2400 => config = self.config.with_high(BitFlags::DR2).with_low( BitFlags::DR1).with_high(BitFlags::DR0), + DataRate::Sps3300 => config = self.config.with_high(BitFlags::DR2).with_high(BitFlags::DR1).with_low( BitFlags::DR0), + } + self.iface.write_register(Register::CONFIG, config.bits)?; + self.config = config; + Ok(()) + } +} -- cgit v1.2.3-54-g00ecf