M5Unit-INFRARED 0.2.0 git rev:76ad9e1
Loading...
Searching...
No Matches
unit_AS312.hpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2026 M5Stack Technology CO LTD
3 *
4 * SPDX-License-Identifier: MIT
5 */
10#ifndef M5_UNIT_INFRARED_UNIT_AS312_HPP
11#define M5_UNIT_INFRARED_UNIT_AS312_HPP
12
13#include <M5UnitComponent.hpp>
14
15namespace m5 {
16namespace unit {
17
26class UnitAS312 : public Component {
27 M5_UNIT_COMPONENT_HPP_BUILDER(UnitAS312, 0x00);
28
29public:
31 static constexpr uint32_t HOLD_TIME_MS{2300};
32
37 struct config_t {
40 uint32_t interval{500};
41 };
42
43 explicit UnitAS312() : Component(0x00)
44 {
45 }
46
49 {
50 return _cfg;
51 }
53 void config(const config_t& cfg)
54 {
55 _cfg = cfg;
56 }
57
58 bool begin() override;
59 void update(const bool force = false) override;
60
63
67 inline bool isDetected() const
68 {
69 return _detected;
70 }
75 inline bool wasDetected() const
76 {
77 return _was_detected;
78 }
83 inline bool wasReleased() const
84 {
85 return _was_released;
86 }
88
91
96 bool readDetection(bool& detected);
98
99private:
100 config_t _cfg{};
101 bool _detected{};
102 bool _prev_detected{};
103 bool _was_detected{};
104 bool _was_released{};
105};
106
107} // namespace unit
108} // namespace m5
109#endif
AS312 digital PIR motion sensor unit.
bool wasDetected() const
Rising edge detection.
Definition unit_AS312.hpp:75
void config(const config_t &cfg)
Set the config values.
Definition unit_AS312.hpp:53
config_t config() const
Gets the config values.
Definition unit_AS312.hpp:48
static constexpr uint32_t HOLD_TIME_MS
AS312 hold time in milliseconds (~2.3s)
Definition unit_AS312.hpp:31
bool readDetection(bool &detected)
Read the sensor pin state directly.
Definition unit_AS312.cpp:71
bool isDetected() const
Current detection state.
Definition unit_AS312.hpp:67
bool wasReleased() const
Falling edge detection.
Definition unit_AS312.hpp:83
Top level namespace of M5Stack.
Unit-related namespace.
Settings for begin.
Definition unit_AS312.hpp:37
uint32_t interval
Definition unit_AS312.hpp:40