1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
//! no_std driver for the BH1750 / BH1750FVI ambient light sensor.
//!
//! `bh1750-embedded` is a small, `no_std` driver built on top of the
//! [`embedded-hal`](https://crates.io/crates/embedded-hal) traits.
//!
//! This crate is a clean reimplementation based on the existing Rust crate:
//! - `bh1750` by Jona Wilmsmann: <https://github.com/jona-wilmsmann/bh1750-rs>
//!
//! ## What this crate provides
//! - A blocking driver: [`Bh1750`]
//! - Resolution/mode selection via [`Resolution`]
//! - MTreg (measurement time) tuning via [`MeasurementTime`]
//! - Optional async API behind the `async` feature: [`r#async::Bh1750Async`]
//!
//! ## Blocking usage
//!
//! ```
//! use bh1750_embedded::{Address, Bh1750, Error, Resolution};
//!
//! fn example<I2C, D, E>(i2c: I2C, delay: D) -> Result<(), Error<E>>
//! where
//! I2C: embedded_hal::i2c::I2c<Error = E>,
//! D: embedded_hal::delay::DelayNs,
//! E: embedded_hal::i2c::Error,
//! {
//! let mut sensor = Bh1750::new(i2c, delay, Address::Low);
//!
//! // One-shot measurement (driver waits long enough before reading):
//! let _lux = sensor.one_time_measurement(Resolution::High)?;
//! Ok(())
//! }
//! ```
//!
//! ## Continuous mode
//!
//! ```
//! use bh1750_embedded::{Address, Bh1750, Error, Resolution};
//!
//! fn example<I2C, D, E>(i2c: I2C, delay: D) -> Result<(), Error<E>>
//! where
//! I2C: embedded_hal::i2c::I2c<Error = E>,
//! D: embedded_hal::delay::DelayNs,
//! E: embedded_hal::i2c::Error,
//! {
//! let mut sensor = Bh1750::new(i2c, delay, Address::Low);
//! sensor.start_continuous_measurement(Resolution::High)?;
//!
//! // Wait approximately the measurement time before reading.
//! let _ms = sensor.typical_measurement_time_ms(Resolution::High);
//! let _lux = sensor.current_measurement_lux(Resolution::High)?;
//! Ok(())
//! }
//! ```
//!
//! ## Async usage
//!
//! Enable the `async` feature to use the async driver API in [`r#async`].
//!
//! ```
//! # fn main() {}
//! #
//! # #[cfg(feature = "async")]
//! # mod async_example {
//! use bh1750_embedded::{Address, Error, Resolution};
//! use bh1750_embedded::r#async::Bh1750Async;
//!
//! pub async fn example<I2C, D, E>(i2c: I2C, delay: D) -> Result<(), Error<E>>
//! where
//! I2C: embedded_hal_async::i2c::I2c<Error = E>,
//! D: embedded_hal_async::delay::DelayNs,
//! E: embedded_hal::i2c::Error,
//! {
//! let mut sensor = Bh1750Async::new(i2c, delay, Address::Low);
//! let _lux = sensor.one_time_measurement(Resolution::High).await?;
//! Ok(())
//! }
//! # }
//! ```
extern crate std;
pub use Bh1750;
pub use Error;
pub use ;