diff options
author | Diego Barrios Romero <eldruin@gmail.com> | 2018-11-11 17:32:52 +0100 |
---|---|---|
committer | Diego Barrios Romero <eldruin@gmail.com> | 2018-11-11 17:32:52 +0100 |
commit | fce3d8546bd619964ec5dd1594cd93e744a99521 (patch) | |
tree | 7bc17d465652c86b25b9fb34ccd7ed3bf0218b56 /src/devices/mode/mod.rs | |
parent | b9b5349b4b78a5d59be4a7e4a11f712e2f6a8256 (diff) | |
download | ads1x1x-async-fce3d8546bd619964ec5dd1594cd93e744a99521.tar.gz ads1x1x-async-fce3d8546bd619964ec5dd1594cd93e744a99521.tar.xz ads1x1x-async-fce3d8546bd619964ec5dd1594cd93e744a99521.zip |
Implement value conversions over type parameter
Diffstat (limited to 'src/devices/mode/mod.rs')
-rw-r--r-- | src/devices/mode/mod.rs | 43 |
1 files changed, 0 insertions, 43 deletions
diff --git a/src/devices/mode/mod.rs b/src/devices/mode/mod.rs index 8e0e012..9625465 100644 --- a/src/devices/mode/mod.rs +++ b/src/devices/mode/mod.rs @@ -1,47 +1,4 @@ //! 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)); - } -} |