This is a platform agnostic Rust driver for the APDS9960 digital proximity, ambient light, RGB
and gesture sensor using 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 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:
Please find additional examples using hardware in this repository: driver-examples
extern crate embedded_hal;
extern crate linux_embedded_hal;
#[macro_use]
extern crate nb;
extern crate apds9960;
use apds9960::Apds9960;
use linux_embedded_hal::I2cdev;
fn main() {
let dev = I2cdev::new("/dev/i2c-1").unwrap();
let mut sensor = Apds9960::new(dev);
sensor.enable().unwrap();
sensor.enable_proximity().unwrap();
loop {
let p = block!(sensor.read_proximity()).unwrap();
println!("Proximity: {}", p);
}
}
For questions, issues, feature requests, and other changes, please file an issue in the github project.
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
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.