From ceed9e844ba5818368a2e0558418a47dae3f09ee Mon Sep 17 00:00:00 2001 From: marcelbuesing Date: Thu, 31 May 2018 12:28:07 +0200 Subject: [PATCH] Add example to crate documentation --- src/lib.rs | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 72f9926..8187e7f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,6 +3,43 @@ //! //! The library uses the embedded-hal crate to abstract reading and writing via I²C. //! In the examples you can find a demo how to use the library in Linux using the linux-embedded-hal crate (e.g. on a RPI). +//! ```no_run + +//! extern crate bme680; +//! extern crate embedded_hal; +//! extern crate linux_embedded_hal as hal; +//! +//! use bme680::*; +//! use embedded_hal::blocking::i2c; +//! use hal::*; +//! use std::result; +//! use std::time::Duration; +//! +//! fn main() -> result::Result<(), Error<::Error, ::Error>> +//! { +//! // Initialize device +//! let i2c = I2cdev::new("/dev/i2c-1").unwrap(); +//! let mut dev = Bme680::init(i2c, Delay {}, I2CAddress::Primary)?; +//! let settings = SettingsBuilder::new() +//! .with_humidity_oversampling(OversamplingSetting::OS2x) +//! .with_pressure_oversampling(OversamplingSetting::OS4x) +//! .with_temperature_oversampling(OversamplingSetting::OS8x) +//! .with_temperature_filter(IIRFilterSize::Size3) +//! .with_gas_measurement(Duration::from_millis(1500), 320, 25) +//! .with_run_gas(true) +//! .build(); +//! dev.set_sensor_settings(settings)?; +//! +//! // Read sensor data +//! dev.set_sensor_mode(PowerMode::ForcedMode)?; +//! let (data, _state) = dev.get_sensor_data()?; +//! +//! println!("Temperature {}°C", data.temperature_celsius()); +//! println!("Pressure {}hPa", data.pressure_hpa()); +//! println!("Humidity {}%", data.humidity_percent()); +//! println!("Gas Resistence {}Ω", data.gas_resistance_ohm()); +//! } +//! ``` #![no_std]