Expand description
§Introduction
This is a platform-agnostic Rust driver for the LTR-303 Ambient Light Sensor using embedded-hal traits.
§Supported devices
Tested with the following sensor(s):
§Usage
§Setup
Instantiate a new driver instance using a blocking I²C HAL
implementation.
For example, using linux-embedded-hal and an LTR303 sensor:
use linux_embedded_hal::{I2cdev};
use ltr303;
let dev = I2cdev::new("/dev/i2c-1").unwrap();
let mut sensor = ltr303::LTR303::init(dev);
let config = ltr303::LTR303Config::default();§Device Info
Then, you can query information about the sensor:
let part_id = sensor.get_part_id().unwrap();
let mfc_id = sensor.get_mfc_id().unwrap();§Measurements
For measuring the illuminance, simply start a measurement and wait for a result:
use linux_embedded_hal::{Delay, I2cdev};
let config = ltr303::LTR303Config::default();
sensor.start_measurement(&config).unwrap();
while sensor.data_ready().unwrap() != true {}
let lux_val = sensor.get_lux_data().unwrap();
println!("LTR303 current lux phys: {}", lux_val.lux_phys);Modules§
Macros§
- create_
register - Defines a standard structure for a 8-bit register.
- create_
struct_ with - Defines a standard structure whose fields all have
with_fieldXconstructors.
Structs§
- Control
Register - Field
- Interrupt
Register - LTR303
- LTR303
Config - Meas
Rate Register - Register
- Register definitions
- Status
Register
Enums§
- Data
Status - Data
Validity - Error
- All possible errors in this crate
- Gain
- ISRMode
- ISRPol
- IntStatus
- Integration
Time - Measurement
Rate - Mode
- Reset
Status