M5Unit-RF433 0.2.0 git rev:ed9ef39
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
130 {
131 if (_codec) {
132 return *_codec;
133 }
134 return _default_codec;
135 }
137 inline const rf433::ProtocolCodec& codec() const
138 {
139 if (_codec) {
140 return *_codec;
141 }
142 return _default_codec;
143 }
150 {
151 _codec = (&codec == &_default_codec) ? nullptr : &codec;
152 }
155 {
156 _codec = nullptr;
157 }
158
159protected:
160 bool read_data();
161
162private:
163 struct FreeDeleter {
164 void operator()(uint8_t* p) const
165 {
166 free(p);
167 }
168 };
169 rf433::M5Codec _default_codec{};
170 rf433::ProtocolCodec* _codec{}; // nullptr: use _default_codec
171 container_type _data{};
172 std::unique_ptr<uint8_t[], FreeDeleter> _rx_buffer{};
173 size_t _rx_buffer_size{};
174 config_t _cfg{};
175};
176
177} // namespace unit
178} // namespace m5
179#endif
config_t config()
Gets the configuration.
Definition unit_SYN531R.hpp:60
virtual bool begin() override
Initialize the receiver unit.
Definition unit_SYN531R.cpp:41
void config(const config_t &cfg)
Set the configuration.
Definition unit_SYN531R.hpp:65
rf433::ProtocolCodec & codec()
Get codec (for codec-specific configuration)
Definition unit_SYN531R.hpp:129
const rf433::ProtocolCodec & codec() const
Get codec (for codec-specific configuration)
Definition unit_SYN531R.hpp:137
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
void resetCodec()
Reset to default M5Codec.
Definition unit_SYN531R.hpp:154
bool empty() const
Is empty stored data?
Definition unit_SYN531R.hpp:91
virtual void update(const bool force=false) override
Update the receiver unit.
Definition unit_SYN531R.cpp:117
void setCodec(rf433::ProtocolCodec &codec)
Set protocol codec.
Definition unit_SYN531R.hpp:149
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 flush()
Discard all data.
Definition unit_SYN531R.hpp:113
Abstract base class for RF433 protocol encoding/decoding.
Definition protocol_codec.hpp:49
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