From 9bdc74649d339a4a08edc8e90541a3db8d3bc7bc Mon Sep 17 00:00:00 2001 From: Denis Nutiu Date: Sun, 25 Feb 2024 20:55:54 +0200 Subject: [PATCH] add doctest --- src/lib.rs | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 5021c35..910ddda 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,6 +5,62 @@ //! 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 + +//! use crate::*; +//! use core::result; +//! use core::time::Duration; +//! use embedded_hal::delay::DelayNs; +//! use linux_embedded_hal as hal; +//! use linux_embedded_hal::{Delay, I2CError}; +//! use log::info; +//! +//! // Please export RUST_LOG=info in order to see logs in the console. +//! fn main() -> result::Result<(), Error> +//! { +//! env_logger::init(); +//! +//! let i2c = hal::I2cdev::new("/dev/i2c-1").unwrap(); +//! let mut delayer = Delay {}; +//! +//! let mut dev = Bme680::init(i2c, &mut delayer, I2CAddress::Primary)?; +//! let mut delay = Delay {}; +//! +//! 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_temperature_offset(-2.2) +//! .with_run_gas(true) +//! .build(); +//! +//! let profile_dur = dev.get_profile_dur(&settings.0)?; +//! info!("Profile duration {:?}", profile_dur); +//! info!("Setting sensor settings"); +//! dev.set_sensor_settings(&mut delayer, settings)?; +//! info!("Setting forced power modes"); +//! dev.set_sensor_mode(&mut delayer, PowerMode::ForcedMode)?; +//! +//! let sensor_settings = dev.get_sensor_settings(settings.1); +//! info!("Sensor settings: {:?}", sensor_settings); +//! +//! loop { +//! let _ = delay.delay_ms(5000u32); +//! let power_mode = dev.get_sensor_mode(); +//! info!("Sensor power mode: {:?}", power_mode); +//! info!("Setting forced power modes"); +//! dev.set_sensor_mode(&mut delayer, PowerMode::ForcedMode)?; +//! info!("Retrieving sensor data"); +//! let (data, _state) = dev.get_sensor_data(&mut delayer)?; +//! info!("Sensor Data {:?}", data); +//! info!("Temperature {}°C", data.temperature_celsius()); +//! info!("Pressure {}hPa", data.pressure_hpa()); +//! info!("Humidity {}%", data.humidity_percent()); +//! info!("Gas Resistence {}Ω", data.gas_resistance_ohm()); +//! } +//! } + #![no_std] #![forbid(unsafe_code)]