M5Unit-INFRARED 0.3.0 git rev:2148adc
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
44 explicit UnitAS312() : Component(0x00)
45 {
46 }
47
53 {
54 return _cfg;
55 }
60 void config(const config_t& cfg)
61 {
62 _cfg = cfg;
63 }
64
69 bool begin() override;
74 void update(const bool force = false) override;
75
78
82 inline bool isDetected() const
83 {
84 return _detected;
85 }
90 inline bool wasDetected() const
91 {
92 return _was_detected;
93 }
98 inline bool wasReleased() const
99 {
100 return _was_released;
101 }
103
106
111 bool readDetection(bool& detected);
113
114private:
115 config_t _cfg{};
116 bool _detected{};
117 bool _was_detected{};
118 bool _was_released{};
119};
120
121} // namespace unit
122} // namespace m5
123#endif
bool wasDetected() const
Rising edge detection.
Definition unit_AS312.hpp:90
void config(const config_t &cfg)
Set the config values.
Definition unit_AS312.hpp:60
config_t config() const
Gets the config values.
Definition unit_AS312.hpp:52
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:70
bool isDetected() const
Current detection state.
Definition unit_AS312.hpp:82
bool begin() override
Set the RX pin to input with pull-up and apply the config.
Definition unit_AS312.cpp:23
void update(const bool force=false) override
Read the sensor pin and update the detection state.
Definition unit_AS312.cpp:47
bool wasReleased() const
Falling edge detection.
Definition unit_AS312.hpp:98
UnitAS312()
Constructor.
Definition unit_AS312.hpp:44
Top level namespace of M5Stack.
Unit-related namespace.
Settings for begin.
Definition unit_AS312.hpp:37
uint32_t interval
Definition unit_AS312.hpp:40