summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorDavid O'Connor <david.alan.oconnor@gmail.com>2020-04-23 23:02:20 -0400
committerDavid O'Connor <david.alan.oconnor@gmail.com>2020-04-23 23:02:20 -0400
commitbc86fedbd5a299d862f8c81c2054da5b378c6c22 (patch)
treee2a8771e9810fa2fc472219ceff07ca6cd849bc5 /examples
parent7fd6e72ef5258f791127cfbf436a0dfaee22b063 (diff)
downloadads1x1x-async-bc86fedbd5a299d862f8c81c2054da5b378c6c22.tar.gz
ads1x1x-async-bc86fedbd5a299d862f8c81c2054da5b378c6c22.tar.xz
ads1x1x-async-bc86fedbd5a299d862f8c81c2054da5b378c6c22.zip
Added type-sig example
Diffstat (limited to 'examples')
-rw-r--r--examples/typed.rs35
1 files changed, 35 insertions, 0 deletions
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<I2cInterface<I2cdev>, 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();
+}