[][src]Crate apds9960

This is a platform agnostic Rust driver for the APDS9960 digital proximity, ambient light, RGB and gesture sensor, based on the embedded-hal traits.

This driver allows you to:

The device

The APDS-9960 device features advanced gesture detection, proximity detection, digital ambient light sense (ALS) and color sense (RGBC).

The communication is done through an I2C bidirectional bus.

Datasheet:

Usage examples (see also examples folder)

To use this driver, import this crate and an embedded_hal implementation, then instantiate the device.

Please find additional examples in this repository: apds9960-examples

Read proximity

extern crate linux_embedded_hal as hal;
#[macro_use]
extern crate nb;
extern crate apds9960;

use hal::I2cdev;
use apds9960::Apds9960;

let dev = I2cdev::new("/dev/i2c-1").unwrap();
let mut sensor = Apds9960::new(dev);
sensor.enable().unwrap();
sensor.enable_proximity().unwrap();
loop {
    let prox = block!(sensor.read_proximity()).unwrap();
    println!("Proximity: {}", prox);
}

Read color / ambient light data

extern crate linux_embedded_hal as hal;
#[macro_use]
extern crate nb;
extern crate apds9960;

use hal::I2cdev;
use apds9960::Apds9960;

let dev = I2cdev::new("/dev/i2c-1").unwrap();
let mut sensor = Apds9960::new(dev);
sensor.enable().unwrap();
sensor.enable_light().unwrap();
loop {
    let data = block!(sensor.read_light()).unwrap();
    println!(
        "Clear: {}, Red: {}, Green: {}, Blue: {}",
        data.clear,
        data.red,
        data.green,
        data.blue
    );
}

Read gesture data

extern crate linux_embedded_hal as hal;
#[macro_use]
extern crate nb;
extern crate apds9960;

use hal::I2cdev;
use apds9960::Apds9960;

let dev = I2cdev::new("/dev/i2c-1").unwrap();
let mut sensor = Apds9960::new(dev);
sensor.enable().unwrap();
sensor.enable_gesture().unwrap();
sensor.enable_gesture_mode().unwrap();
let mut data = [0; 6*4]; // 6 datasets
loop {
    block!(sensor.read_gesture_data(&mut data)).unwrap();
    // interpret gesture data...
}

Structs

Apds9960

APDS9960 device driver.

LightData

Color / ambient light data.

Enums

Error

All possible errors in this crate

GestureDataThreshold

Gesture FIFO data threshold.