Crate vl53l1x_uld

source ·
Expand description

Port of the STM IMG009 Ultra Lite Driver for the VL53L1X.

Features

This crate has one feature called i2c-iter. This feature changes the communication implementation of the sensor. With this feature enabled the I2C instance is expected to implement the WriteIter and WriteIterRead traits instead of Write and WriteRead traits. The iterator implementation has the advantage that a call to write_bytes is not limited to a slice of 4 bytes.

Example

use vl53l1x_uld::{self, VL53L1X, IOVoltage, RangeStatus};
// Create hardware specific I2C instance.
let i2c = create_i2c();
// Create sensor with default address.
let mut vl = VL53L1X::new(i2c, vl53l1x_uld::DEFAULT_ADDRESS);

const ERR : &str = "Failed to communicate";

// Check if the sensor id is correct.
if (vl.get_sensor_id().expect(ERR) == 0xEACC)
{
    // Initialize the sensor before any usage.
    // Set the voltage of the IO pins to be 2.8 volts
    vl.init(IOVoltage::Volt2_8).expect(ERR);

    // Start a ranging operation, needed to retrieve a distance
    vl.start_ranging().expect(ERR);
     
    // Wait until distance data is ready to be read.
    while !vl.is_data_ready().expect(ERR) {}

    // Check if ditance measurement is valid.
    if (vl.get_range_status().expect(ERR) == RangeStatus::Valid)
    {
        // Retrieve measured distance.
        let distance = vl.get_distance().expect(ERR);
    }
}

Modules

  • Traits and implementations needed for I2C communication.
  • Module containing region of interest definitions.
  • Module containing threshold definitions and implementations.

Structs

Enums

Constants