pub struct PersonSensor<I2C, INT, MODE> { /* private fields */ }Expand description
Person sensor driver.
The sensor can be used in two modes: continuous capture and standby. In continuous capture mode, the sensor continuously captures frames and sends the results over I2C. In standby mode, the sensor is in a low-power state and only captures a single frame when requested.
To create the sensor, use a PersonSensorBuilder. The builder allows you to set the mode
and interrupt pin.
Example:
let sda = p.PIN_2;
let scl = p.PIN_3;
let i2c = I2c::new_async(p.I2C1, scl, sda, Irqs, Config::default());
let interrupt = p.PIN_4;
let mut person_sensor = PersonSensorBuilder::new_continuous(i2c, true)
.with_interrupt(interrupt)
.build()
.await
.unwrap();
loop {
if let Ok(faces) = person_sensor.get_detections().await {
// Do something with the results
}
}Implementations§
Source§impl<I2C, INT, MODE> PersonSensor<I2C, INT, MODE>where
I2C: I2c,
impl<I2C, INT, MODE> PersonSensor<I2C, INT, MODE>where
I2C: I2c,
Sourcepub async fn set_id_mode(&mut self, mode: IDMode) -> Result<(), I2C::Error>
pub async fn set_id_mode(&mut self, mode: IDMode) -> Result<(), I2C::Error>
Enable / Disable the ID model. Greater performance can be achieved by disabling ID labeling.
Sourcepub async fn enable_id_model(&mut self, enable: bool) -> Result<(), I2C::Error>
👎Deprecated since 0.3.1: Please use set_id_mode instead. This method will be removed in a future release.
pub async fn enable_id_model(&mut self, enable: bool) -> Result<(), I2C::Error>
set_id_mode instead. This method will be removed in a future release.Enable / Disable the ID model.
With this flag set to false, only bounding boxes are captured and the framerate is increased.
Sourcepub fn set_checksum_enabled(&mut self, enable: bool)
pub fn set_checksum_enabled(&mut self, enable: bool)
Validate the checksum of the data received from the sensor. On by default.
Checksum validation may be useful for diagnosing I2C communication issues, but is not necessary for normal operation.
Sourcepub async fn label_next_id(&mut self, id: PersonID) -> Result<(), I2C::Error>
pub async fn label_next_id(&mut self, id: PersonID) -> Result<(), I2C::Error>
Calibrate the next identified frame as person N, from 0 to 7. If two frames pass with no person, this label is discarded.
This will not return the result of the calibration. The only failure is if the I2C write fails. You may wish to follow calibration with a check for detections containing the ID you just attempted to label.
Sourcepub async fn set_persist_ids(&mut self, persist: bool) -> Result<(), I2C::Error>
pub async fn set_persist_ids(&mut self, persist: bool) -> Result<(), I2C::Error>
Store any recognized IDs even when unpowered.
Both current and future IDs will be retained when this is set to true.
Source§impl<I2C, INT> PersonSensor<I2C, INT, StandbyMode>where
I2C: I2c,
impl<I2C, INT> PersonSensor<I2C, INT, StandbyMode>where
I2C: I2c,
Sourcepub async fn capture_once(
&mut self,
) -> Result<Vec<Face, MAX_DETECTIONS>, ReadError<I2C::Error>>
pub async fn capture_once( &mut self, ) -> Result<Vec<Face, MAX_DETECTIONS>, ReadError<I2C::Error>>
Capture a single frame and reads the results
Sourcepub async fn into_continuous_mode(
self,
) -> Result<PersonSensor<I2C, INT, ContinuousCaptureMode>, I2C::Error>
pub async fn into_continuous_mode( self, ) -> Result<PersonSensor<I2C, INT, ContinuousCaptureMode>, I2C::Error>
Switches the sensor to continuous capture mode
Source§impl<I2C, INT> PersonSensor<I2C, INT, ContinuousCaptureMode>where
I2C: I2c,
impl<I2C, INT> PersonSensor<I2C, INT, ContinuousCaptureMode>where
I2C: I2c,
Sourcepub async fn into_standby_mode(
self,
) -> Result<PersonSensor<I2C, INT, StandbyMode>, I2C::Error>
pub async fn into_standby_mode( self, ) -> Result<PersonSensor<I2C, INT, StandbyMode>, I2C::Error>
Switches the sensor into a lower power standby mode. Only single-shot capture is possible in this mode.
Sourcepub async fn get_detections(
&mut self,
) -> Result<Vec<Face, MAX_DETECTIONS>, ReadError<I2C::Error>>
pub async fn get_detections( &mut self, ) -> Result<Vec<Face, MAX_DETECTIONS>, ReadError<I2C::Error>>
Returns the latest results from the sensor.
Depending on the device version and configuration, detections are updated at different rates. This method does not wait for new detections to be available. The last detections will repeatedly read until the device produces new ones.
It is your responsibility to either sensibly rate-limit fetching results to the maximum rate of the sensor or initialize the driver with an interrupt pin to be notified when new results are available.
Source§impl<I2C, INT> PersonSensor<I2C, INT, ContinuousCaptureMode>where
INT: Wait,
impl<I2C, INT> PersonSensor<I2C, INT, ContinuousCaptureMode>where
INT: Wait,
Sourcepub async fn wait_for_person(&mut self) -> Result<(), INT::Error>
pub async fn wait_for_person(&mut self) -> Result<(), INT::Error>
Wait for the person sensor to trigger an interrupt indicating a person has been detected. Returns immediately if a person is currently detected.