Crates.io | ltr-559 |
lib.rs | ltr-559 |
version | 0.1.1 |
source | src |
created_at | 2020-01-17 01:43:33.209636 |
updated_at | 2020-07-30 15:48:13.871544 |
description | LITEON LTR-559 ligth and proximity sensor |
homepage | https://github.com/iohe/ltr-559 |
repository | https://github.com/iohe/ltr-559.git |
max_upload_size | |
id | 199267 |
size | 57,498 |
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:
get_lux()
.get_als_raw_data()
.get_status()
.get_ps_data()
.get_manufacturer_id()
.get_part_id()
.set_als_contr()
.set_ps_contr()
.set_ps_led()
.set_interrupt_persist()
.set_als_meas_rate()
.set_als_low_limit_raw()
.set_als_high_limit_raw()
.set_ps_low_limit_raw()
.set_ps_high_limit_raw()
.set_ps_meas_rate()
.set_ps_offset()
.set_ps_n_pulses()
.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.
extern crate linux_embedded_hal as hal;
extern crate ltr_559;
use ltr_559::{Ltr559, SlaveAddr};
fn main() {
let dev = hal::I2cdev::new("/dev/i2c-1").unwrap();
let address = SlaveAddr::default();
let sensor = Ltr559::new_device(dev, address);
sensor
.set_als_meas_rate(AlsIntTime::_50ms, AlsMeasRate::_50ms)
.unwrap();
sensor.set_als_contr(AlsGain::Gain4x, false, true).unwrap();
loop {
let status = sensor.get_status().unwrap();
if status.als_data_valid {
let (lux_raw_0, lux_raw_1) = sensor.get_als_raw_data().unwrap();
let lux = sensor.get_lux().unwrap();
println!(
"Raw Lux CH1: 0x{:04x}, CH0: 0x{:04x} Lux = {}, Status.als_data_valid = {}",
lux_raw_0, lux_raw_1, lux, status.als_data_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.