M5Unit-INFRARED 0.3.0 git rev:2148adc
Loading...
Searching...
No Matches
m5::unit::UnitAS312 Class Reference

AS312 digital PIR motion sensor unit. More...

#include <unit_AS312.hpp>

Inheritance diagram for m5::unit::UnitAS312:

Classes

struct  config_t
 Settings for begin. More...
 

Public Member Functions

 UnitAS312 ()
 Constructor.
 
config_t config () const
 Gets the config values.
 
void config (const config_t &cfg)
 Set the config values.
 
bool begin () override
 Set the RX pin to input with pull-up and apply the config.
 
void update (const bool force=false) override
 Read the sensor pin and update the detection state.
 
Detection state
bool isDetected () const
 Current detection state.
 
bool wasDetected () const
 Rising edge detection.
 
bool wasReleased () const
 Falling edge detection.
 
Direct reading
bool readDetection (bool &detected)
 Read the sensor pin state directly.
 

Static Public Attributes

static constexpr uint32_t HOLD_TIME_MS {2300}
 AS312 hold time in milliseconds (~2.3s)
 

Detailed Description

AS312 digital PIR motion sensor unit.

The AS312 is a passive infrared (PIR) sensor with digital output. It detects motion by sensing changes in infrared radiation from human bodies or warm objects. The sensor outputs HIGH when motion is detected, LOW otherwise. Timing is fixed internally: ~2.3s hold time, ~2.3s blocking time.

Member Function Documentation

◆ begin()

bool m5::unit::UnitAS312::begin ( )
override

Set the RX pin to input with pull-up and apply the config.

Returns
True if successful, false if config_t::interval >= HOLD_TIME_MS or the pin setup fails

◆ config() [1/2]

config_t m5::unit::UnitAS312::config ( ) const
inline

Gets the config values.

Returns
Copy of the current config

◆ config() [2/2]

void m5::unit::UnitAS312::config ( const config_t & cfg)
inline

Set the config values.

Parameters
cfgConfig to apply on the next begin()

◆ isDetected()

bool m5::unit::UnitAS312::isDetected ( ) const
inline

Current detection state.

Returns
true if motion is currently detected (pin is HIGH)

◆ readDetection()

bool m5::unit::UnitAS312::readDetection ( bool & detected)

Read the sensor pin state directly.

Parameters
[out]detectedtrue if motion is detected
Returns
True if successful

◆ update()

void m5::unit::UnitAS312::update ( const bool force = false)
override

Read the sensor pin and update the detection state.

Parameters
forceRead immediately, ignoring config_t::interval

◆ wasDetected()

bool m5::unit::UnitAS312::wasDetected ( ) const
inline

Rising edge detection.

Returns
true if a new detection occurred since the last update (LOW -> HIGH transition)

◆ wasReleased()

bool m5::unit::UnitAS312::wasReleased ( ) const
inline

Falling edge detection.

Returns
true if detection ended since the last update (HIGH -> LOW transition)