Crate ltr303

Crate ltr303 

Source
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§

helpers

Macros§

create_register
Defines a standard structure for a 8-bit register.
create_struct_with
Defines a standard structure whose fields all have with_fieldX constructors.

Structs§

ControlRegister
Field
InterruptRegister
LTR303
LTR303Config
MeasRateRegister
Register
Register definitions
StatusRegister

Enums§

DataStatus
DataValidity
Error
All possible errors in this crate
Gain
ISRMode
ISRPol
IntStatus
IntegrationTime
MeasurementRate
Mode
ResetStatus