PersonSensor

Struct PersonSensor 

Source
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,

Source

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.

Source

pub 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.

Enable / Disable the ID model.

With this flag set to false, only bounding boxes are captured and the framerate is increased.

Source

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.

Source

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.

Source

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

pub async fn erase_ids(&mut self) -> Result<(), I2C::Error>

Wipe any recognized IDs from storage.

Source

pub async fn set_indicator(&mut self, enabled: bool) -> Result<(), I2C::Error>

Whether to enable the LED indicator on the sensor.

Source§

impl<I2C, INT> PersonSensor<I2C, INT, StandbyMode>
where I2C: I2c,

Source

pub async fn capture_once( &mut self, ) -> Result<Vec<Face, MAX_DETECTIONS>, ReadError<I2C::Error>>

Capture a single frame and reads the results

Source

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,

Source

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.

Source

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,

Source

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.

Trait Implementations§

Source§

impl<I2C: Debug, INT: Debug, MODE: Debug> Debug for PersonSensor<I2C, INT, MODE>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<I2C, INT, MODE> Freeze for PersonSensor<I2C, INT, MODE>
where I2C: Freeze, INT: Freeze,

§

impl<I2C, INT, MODE> RefUnwindSafe for PersonSensor<I2C, INT, MODE>
where I2C: RefUnwindSafe, INT: RefUnwindSafe, MODE: RefUnwindSafe,

§

impl<I2C, INT, MODE> Send for PersonSensor<I2C, INT, MODE>
where I2C: Send, INT: Send, MODE: Send,

§

impl<I2C, INT, MODE> Sync for PersonSensor<I2C, INT, MODE>
where I2C: Sync, INT: Sync, MODE: Sync,

§

impl<I2C, INT, MODE> Unpin for PersonSensor<I2C, INT, MODE>
where I2C: Unpin, INT: Unpin, MODE: Unpin,

§

impl<I2C, INT, MODE> UnwindSafe for PersonSensor<I2C, INT, MODE>
where I2C: UnwindSafe, INT: UnwindSafe, MODE: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.