This is a platform agnostic Rust driver for LTR-559 Ambient light sensor and
Proximity sensor using the [embedded-hal
] traits.
This driver allows you to:
- Read the measurement in lux. See: get_lux()
.
- Read the measurement in raw. See: get_als_raw_data()
.
- Read the conversion status. See: get_status()
.
- Read PS Data. See: get_ps_data()
.
- Get the manufacturer ID. See: get_manufacturer_id()
.
- Get the part ID. See: get_part_id()
.
- Set ALS Enable, Gain and SW Reset. See: set_als_contr()
.
- Set PS Mode and Saturation. See: set_ps_contr()
.
- Set PS LED Pulse, DutyCycle and PeakCurrent. See: set_ps_led()
.
- Set Interrupt Persist. See: set_interrupt_persist()
.
- Set ALS Meas Rate. See: set_als_meas_rate()
.
- Set ALS Low Limit. See: set_als_low_limit_raw()
.
- Set ALS High Limit. See: set_als_high_limit_raw()
.
- Set PS Low Limit. See: set_ps_low_limit_raw()
.
- Set PS High Limit. See: set_ps_high_limit_raw()
.
- Set PS Meas Rate. See: set_ps_meas_rate()
.
- Set PS Offset. See: set_ps_offset()
.
- Set PS N Pulses. See: set_ps_n_pulses()
.
- Set Interrupt Mode and Polarity. See: set_interrupt()
.
The LTR-559 is a an integrated low voltage I2C digital light sensor[ALS] and proximity sensor[PS]
Datasheet: LTR-559
To use this driver, import this crate and an embedded_hal
implementation,
then instantiate the device.
```rust extern crate linuxembeddedhal as hal;
extern crate ltr559; use ltr559::{Ltr559, SlaveAddr};
fn main() { let dev = hal::I2cdev::new("/dev/i2c-1").unwrap(); let address = SlaveAddr::default(); let sensor = Ltr559::newdevice(dev, address); sensor .setalsmeasrate(AlsIntTime::50ms, AlsMeasRate::50ms) .unwrap(); sensor.setalscontr(AlsGain::Gain4x, false, true).unwrap(); loop { let status = sensor.getstatus().unwrap(); if status.alsdatavalid { let (luxraw0, luxraw1) = sensor.getalsrawdata().unwrap(); let lux = sensor.getlux().unwrap(); println!( "Raw Lux CH1: 0x{:04x}, CH0: 0x{:04x} Lux = {}, Status.alsdatavalid = {}", luxraw0, luxraw1, lux, status.alsdata_valid ); } } } ```
For questions, issues, feature requests, and other changes, please file an issue in the github project.
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.