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/mode/mod.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/devices/ads1x1x/mode/mod.rs (limited to 'src/devices/ads1x1x/mode/mod.rs') diff --git a/src/devices/ads1x1x/mode/mod.rs b/src/devices/ads1x1x/mode/mod.rs new file mode 100644 index 0000000..1a01d27 --- /dev/null +++ b/src/devices/ads1x1x/mode/mod.rs @@ -0,0 +1,26 @@ +//! Functions for all devices specific to each operating mode + +use ic; + +fn convert_measurement(register_data: u16) -> i16 +where + IC: ic::Resolution +{ + let value = register_data; + if IC::BITS == ic::ResolutionBits::_12 { + let is_negative = (value & 0b1000_0000_0000_0000) != 0; + if is_negative { + let value = 0b1111_0000_0000_0000 | (value >> 4); + value as i16 + } + else { + (value >> 4) as i16 + } + } + else { + value as i16 + } +} + +mod oneshot; +mod continuous; -- cgit v1.2.3-54-g00ecf