From bc86fedbd5a299d862f8c81c2054da5b378c6c22 Mon Sep 17 00:00:00 2001 From: David O'Connor Date: Thu, 23 Apr 2020 23:02:20 -0400 Subject: Added type-sig example --- examples/typed.rs | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 examples/typed.rs (limited to 'examples') diff --git a/examples/typed.rs b/examples/typed.rs new file mode 100644 index 0000000..a5a29ca --- /dev/null +++ b/examples/typed.rs @@ -0,0 +1,35 @@ +// This example demonstrates how the `Ads1x1x` struct may +// look in a type signature. + +#[macro_use(block)] +use nb; + +use embedded_hal; +use embedded_hal::adc::OneShot; +use linux_embedded_hal; + +use ads1x1x::{ + channel::SingleA0, + ic::{Ads1115, Resolution16Bit}, + interface::I2cInterface, + Ads1x1x, SlaveAddr, +}; +use linux_embedded_hal::I2cdev; + +type Adc = Ads1x1x, Ads1115, Resolution16Bit, ads1x1x::mode::OneShot>; + +/// Read a single value from channel A +pub fn read(adc: &mut Adc) -> f32 { + block!(adc.read(&mut SingleA0)); +} + +fn main() { + let dev = I2cdev::new("/dev/i2c-1").unwrap(); + let address = SlaveAddr::default(); + let mut adc = Ads1x1x::new_ads1115(dev, address); + + let value = read(&mut adc); + println!("Measurement: {}", value); + // get I2C device back + let _dev = adc.destroy_ads1115(); +} -- cgit v1.2.3-54-g00ecf