summaryrefslogtreecommitdiffstats
path: root/src/devices/ads1x1x/common.rs
diff options
context:
space:
mode:
authorDiego Barrios Romero <eldruin@gmail.com>2018-11-07 20:22:59 +0100
committerDiego Barrios Romero <eldruin@gmail.com>2018-11-07 20:22:59 +0100
commit483221e740ffaebe406ee428beb59fa136d70c7f (patch)
treef7fee2bbc46b97f1508d4b8bc2fec258695e4239 /src/devices/ads1x1x/common.rs
parentec0ffcaa6d49ae7c6e3256f9742e996d7b0752c4 (diff)
downloadads1x1x-async-483221e740ffaebe406ee428beb59fa136d70c7f.tar.gz
ads1x1x-async-483221e740ffaebe406ee428beb59fa136d70c7f.tar.xz
ads1x1x-async-483221e740ffaebe406ee428beb59fa136d70c7f.zip
Add support for one-shot measurements
Diffstat (limited to 'src/devices/ads1x1x/common.rs')
-rw-r--r--src/devices/ads1x1x/common.rs37
1 files changed, 37 insertions, 0 deletions
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<DI, IC, MODE, E> Ads1x1x<DI, IC, MODE>
+where
+ DI: interface::WriteData<Error = E>
+{
+ pub(super) fn set_operating_mode(&mut self, mode: OperatingMode) -> Result<(), Error<E>> {
+ 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<E>> {
+ 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(())
+ }
+}