M5Unit-RF433 0.1.0 git rev:5415b86
Loading...
Searching...
No Matches
unit_SYN531R.hpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD
3 *
4 * SPDX-License-Identifier: MIT
5 */
10#ifndef M5_UNIT_RF433_UNIT_SYN531R_HPP
11#define M5_UNIT_RF433_UNIT_SYN531R_HPP
12
13#include <M5UnitComponent.hpp>
14#include <memory>
15#include <vector>
16#include "codec/m5_codec.hpp"
17
18namespace m5 {
19namespace unit {
20
26class UnitSYN531R : public Component {
27 M5_UNIT_COMPONENT_HPP_BUILDER(UnitSYN531R, 0x00);
28
29public:
30 using container_type = rf433::container_type;
31
36 struct config_t {
48 {
49#if defined(M5_UNIT_UNIFIED_USING_RMT_V2)
50 255
51#else
52 23
53#endif
54 };
55 };
56
59
61 {
62 return _cfg;
63 }
65 inline void config(const config_t& cfg)
66 {
67 _cfg = cfg;
68 }
70
71 UnitSYN531R() : Component(DEFAULT_ADDRESS)
72 {
73 }
74 virtual ~UnitSYN531R()
75 {
76 }
77
79 virtual bool begin() override;
81 virtual void update(const bool force = false) override;
82
86 inline size_t available() const
87 {
88 return _data.size();
89 }
91 inline bool empty() const
92 {
93 return _data.empty();
94 }
96 inline uint8_t oldest() const
97 {
98 return !_data.empty() ? _data.front() : 0;
99 }
101 inline uint8_t latest() const
102 {
103 return !_data.empty() ? _data.back() : 0;
104 }
106 inline void discard()
107 {
108 if (!_data.empty()) {
109 _data.erase(_data.begin());
110 }
111 }
113 inline void flush()
114 {
115 _data.clear();
116 }
117
119 inline const container_type& container() const
120 {
121 return _data;
122 }
124
126 inline std::shared_ptr<rf433::ProtocolCodec> codec()
127 {
128 return _codec;
129 }
131 void setCodec(std::shared_ptr<rf433::ProtocolCodec> codec)
132 {
133 _codec = codec;
134 }
135
136protected:
137 bool read_data();
138
139private:
140 struct FreeDeleter {
141 void operator()(uint8_t* p) const
142 {
143 free(p);
144 }
145 };
146 std::shared_ptr<rf433::ProtocolCodec> _codec{std::make_shared<rf433::M5Codec>()};
147 container_type _data{};
148 std::unique_ptr<uint8_t[], FreeDeleter> _rx_buffer{};
149 size_t _rx_buffer_size{};
150 config_t _cfg{};
151};
152
153} // namespace unit
154} // namespace m5
155#endif
config_t config()
Gets the configuration.
Definition unit_SYN531R.hpp:60
virtual bool begin() override
Initialize the receiver unit.
Definition unit_SYN531R.cpp:37
void config(const config_t &cfg)
Set the configuration.
Definition unit_SYN531R.hpp:65
size_t available() const
Gets the number of stored data.
Definition unit_SYN531R.hpp:86
const container_type & container() const
Gets the received container reference.
Definition unit_SYN531R.hpp:119
void discard()
Discard the oldest data accumulated.
Definition unit_SYN531R.hpp:106
bool empty() const
Is empty stored data?
Definition unit_SYN531R.hpp:91
std::shared_ptr< rf433::ProtocolCodec > codec()
Get codec (for codec-specific configuration)
Definition unit_SYN531R.hpp:126
virtual void update(const bool force=false) override
Update the receiver unit.
Definition unit_SYN531R.cpp:112
uint8_t latest() const
Retrieve latest stored data.
Definition unit_SYN531R.hpp:101
uint8_t oldest() const
Retrieve oldest stored data.
Definition unit_SYN531R.hpp:96
void setCodec(std::shared_ptr< rf433::ProtocolCodec > codec)
Set protocol codec (default: M5Codec)
Definition unit_SYN531R.hpp:131
void flush()
Discard all data.
Definition unit_SYN531R.hpp:113
M5Unit-RF433 original protocol codec.
Top level namespace of M5Stack.
Unit-related namespace.
Settings for begin.
Definition unit_SYN531R.hpp:36
uint8_t max_payload_size
Definition unit_SYN531R.hpp:48