ltr-559 0.1.1

LITEON LTR-559 ligth and proximity sensor
Documentation

Rust LTR-559 ALS and PS Driver

crates.io Build Status

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 device

The LTR-559 is a an integrated low voltage I2C digital light sensor[ALS] and proximity sensor[PS]

Datasheet: LTR-559

Usage

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
            );
        }
    }
}

Support

For questions, issues, feature requests, and other changes, please file an issue in the github project.

License

Licensed under either of

at your option.

Contributing

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.