[−][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:
- Enable/disable the sensor. See:
enable()
. - Enable/disable delay between proximity and / or color / ambient light cycles. See:
enable_wait()
. - Enable/disable long delay between proximity and / or color / ambient light cycles. See:
enable_wait_long()
. - Set the waiting time between proximity and / or color / ambient light cycles. See:
set_wait_time()
. - Force an interrupt. See:
force_interrupt()
. - Clear all non-gesture interrupts. See:
clear_interrupts()
. - Read the device ID. See:
read_device_id()
. - Proximity:
- Enable/disable the proximity sensor. See:
enable_proximity()
. - Enable/disable proximity interrupt generation. See:
enable_proximity_interrupts()
. - Enable/disable proximity saturation interrupt generation. See:
enable_proximity_saturation_interrupts()
. - Read the proximity data. See:
read_proximity()
. - Check whether the proximity data is valid. See:
is_proximity_data_valid()
. - Set the proximity interrupt low/high thresholds. See:
set_proximity_low_threshold()
. - Set the proximity offsets. See:
set_proximity_offsets()
. - Clear proximity interrupt. See:
clear_proximity_interrupt()
.
- Enable/disable the proximity sensor. See:
- Color / ambient light:
- Enable/disable the color / ambient light sensor. See:
enable_light()
. - Enable/disable ambient light interrupt generation. See:
enable_light_interrupts()
. - Enable/disable ambient light saturation interrupt generation. See:
enable_light_saturation_interrupts()
. - Check whether the color / ambient light data is valid. See:
is_light_data_valid()
. - Read the color / ambient light data. See:
read_light()
. - Set the color / ambient light integration time. See:
set_light_integration_time()
. - Set the clear light channel interrupt low/high thresholds. See:
set_light_low_threshold()
. - Clear ambient light interrupt. See:
clear_light_interrupt()
.
- Enable/disable the color / ambient light sensor. See:
- Gesture detection:
- Enable/disable gesture detection. See:
enable_gesture()
. - Enable/disable gesture mode. See:
enable_gesture_mode()
. - Enable/disable gesture interrupts. See:
enable_gesture_interrupts()
. - Read whether there is valid gesture data available. See:
is_gesture_data_valid()
. - Read the amount of gesture data available. See:
read_gesture_data_level()
. - Set the threshold of amount of available gesture data. See:
set_gesture_data_level_threshold()
. - Read whether the gesture data has overflown. See:
has_gesture_data_overflown()
. - Read the gesture data. See:
read_gesture_data()
. - Set the gesture proximity entry/exit thresholds. See:
set_gesture_proximity_entry_threshold()
. - Set the gesture offsets. See:
set_gesture_offsets()
.
- Enable/disable gesture detection. See:
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. |