summaryrefslogtreecommitdiffstats
path: root/src/devices/ads1x1x/mode/mod.rs
diff options
context:
space:
mode:
authorDiego Barrios Romero <eldruin@gmail.com>2018-11-11 08:04:42 +0100
committerDiego Barrios Romero <eldruin@gmail.com>2018-11-11 08:04:42 +0100
commit3e3a790d9f70bfd6cb4210dfe09560d0385fdf5a (patch)
tree8cf40e43cb93b15a774696c3af639d504addce8c /src/devices/ads1x1x/mode/mod.rs
parent8b9e9ecdb85a30ac1c57fe6b96498cae6ad9f7cc (diff)
downloadads1x1x-async-3e3a790d9f70bfd6cb4210dfe09560d0385fdf5a.tar.gz
ads1x1x-async-3e3a790d9f70bfd6cb4210dfe09560d0385fdf5a.tar.xz
ads1x1x-async-3e3a790d9f70bfd6cb4210dfe09560d0385fdf5a.zip
Reorganize modules
Diffstat (limited to 'src/devices/ads1x1x/mode/mod.rs')
-rw-r--r--src/devices/ads1x1x/mode/mod.rs47
1 files changed, 0 insertions, 47 deletions
diff --git a/src/devices/ads1x1x/mode/mod.rs b/src/devices/ads1x1x/mode/mod.rs
deleted file mode 100644
index 8e0e012..0000000
--- a/src/devices/ads1x1x/mode/mod.rs
+++ /dev/null
@@ -1,47 +0,0 @@
-//! Functions for all devices specific to each operating mode
-
-use ic;
-mod oneshot;
-mod continuous;
-
-fn convert_measurement<IC>(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
- }
-}
-
-
-#[cfg(test)]
-mod tests {
- use super::*;
-
- #[test]
- fn convert_12_bits() {
- assert_eq!( 0, convert_measurement::<ic::Ads1013>(0));
- assert_eq!( 2047, convert_measurement::<ic::Ads1013>(0x7FFF));
- assert_eq!(-2048, convert_measurement::<ic::Ads1013>(0x8000));
- assert_eq!( -1, convert_measurement::<ic::Ads1013>(0xFFFF));
- }
-
- #[test]
- fn convert_16_bits() {
- assert_eq!( 0, convert_measurement::<ic::Ads1113>(0));
- assert_eq!( 32767, convert_measurement::<ic::Ads1113>(0x7FFF));
- assert_eq!(-32768, convert_measurement::<ic::Ads1113>(0x8000));
- assert_eq!( -1, convert_measurement::<ic::Ads1113>(0xFFFF));
- }
-}