ESPHome 2026.5.0b1
Loading...
Searching...
No Matches
rf_bridge.h
Go to the documentation of this file.
1#pragma once
2
3#include <utility>
4#include <vector>
5
9
10namespace esphome::rf_bridge {
11
12static const uint8_t RF_MESSAGE_SIZE = 9;
13static const uint8_t RF_CODE_START = 0xAA;
14static const uint8_t RF_CODE_ACK = 0xA0;
15static const uint8_t RF_CODE_LEARN = 0xA1;
16static const uint8_t RF_CODE_LEARN_KO = 0xA2;
17static const uint8_t RF_CODE_LEARN_OK = 0xA3;
18static const uint8_t RF_CODE_RFIN = 0xA4;
19static const uint8_t RF_CODE_RFOUT = 0xA5;
20static const uint8_t RF_CODE_ADVANCED_RFIN = 0xA6;
21static const uint8_t RF_CODE_SNIFFING_ON = 0xA6;
22static const uint8_t RF_CODE_SNIFFING_OFF = 0xA7;
23static const uint8_t RF_CODE_RFOUT_NEW = 0xA8;
24static const uint8_t RF_CODE_LEARN_NEW = 0xA9;
25static const uint8_t RF_CODE_LEARN_KO_NEW = 0xAA;
26static const uint8_t RF_CODE_LEARN_OK_NEW = 0xAB;
27static const uint8_t RF_CODE_RFOUT_BUCKET = 0xB0;
28static const uint8_t RF_CODE_RFIN_BUCKET = 0xB1;
29static const uint8_t RF_CODE_BEEP = 0xC0;
30static const uint8_t RF_CODE_STOP = 0x55;
31static const uint8_t RF_DEBOUNCE = 200;
32static const size_t MAX_RX_BUFFER_SIZE = 512;
33
35 uint16_t sync;
36 uint16_t low;
37 uint16_t high;
39};
40
42 uint8_t length;
43 uint8_t protocol;
44 std::string code;
45};
46
48 public:
49 void loop() override;
50 void dump_config() override;
51 template<typename F> void add_on_code_received_callback(F &&callback) {
52 this->data_callback_.add(std::forward<F>(callback));
53 }
54 template<typename F> void add_on_advanced_code_received_callback(F &&callback) {
55 this->advanced_data_callback_.add(std::forward<F>(callback));
56 }
57 void send_code(RFBridgeData data);
59 void learn();
63 void send_raw(const std::string &code);
64 void beep(uint16_t ms);
65
66 protected:
67 void ack_();
68 void decode_();
69 bool parse_bridge_byte_(uint8_t byte);
70 void write_byte_str_(const std::string &codes);
71
72 std::vector<uint8_t> rx_buffer_;
74
77};
78
79template<typename... Ts> class RFBridgeSendCodeAction : public Action<Ts...> {
80 public:
83 TEMPLATABLE_VALUE(uint16_t, low)
84 TEMPLATABLE_VALUE(uint16_t, high)
86
87 void play(const Ts &...x) {
88 RFBridgeData data{};
89 data.sync = this->sync_.value(x...);
90 data.low = this->low_.value(x...);
91 data.high = this->high_.value(x...);
92 data.code = this->code_.value(x...);
93 this->parent_->send_code(data);
94 }
95
96 protected:
98};
99
100template<typename... Ts> class RFBridgeSendAdvancedCodeAction : public Action<Ts...> {
101 public:
104 TEMPLATABLE_VALUE(uint8_t, protocol)
105 TEMPLATABLE_VALUE(std::string, code)
106
107 void play(const Ts &...x) {
109 data.length = this->length_.value(x...);
110 data.protocol = this->protocol_.value(x...);
111 data.code = this->code_.value(x...);
112 this->parent_->send_advanced_code(data);
113 }
114
115 protected:
117};
118
119template<typename... Ts> class RFBridgeLearnAction : public Action<Ts...> {
120 public:
122
123 void play(const Ts &...x) { this->parent_->learn(); }
124
125 protected:
127};
128
129template<typename... Ts> class RFBridgeStartAdvancedSniffingAction : public Action<Ts...> {
130 public:
132
133 void play(const Ts &...x) { this->parent_->start_advanced_sniffing(); }
134
135 protected:
137};
138
139template<typename... Ts> class RFBridgeStopAdvancedSniffingAction : public Action<Ts...> {
140 public:
142
143 void play(const Ts &...x) { this->parent_->stop_advanced_sniffing(); }
144
145 protected:
147};
148
149template<typename... Ts> class RFBridgeStartBucketSniffingAction : public Action<Ts...> {
150 public:
152
153 void play(const Ts &...x) { this->parent_->start_bucket_sniffing(); }
154
155 protected:
157};
158
159template<typename... Ts> class RFBridgeSendRawAction : public Action<Ts...> {
160 public:
162 TEMPLATABLE_VALUE(std::string, raw)
163
164 void play(const Ts &...x) { this->parent_->send_raw(this->raw_.value(x...)); }
165
166 protected:
168};
169
170template<typename... Ts> class RFBridgeBeepAction : public Action<Ts...> {
171 public:
174
175 void play(const Ts &...x) { this->parent_->beep(this->duration_.value(x...)); }
176
177 protected:
179};
180
181} // namespace esphome::rf_bridge
uint8_t raw[35]
Definition bl0939.h:0
virtual void play(const Ts &...x)=0
RFBridgeBeepAction(RFBridgeComponent *parent)
Definition rf_bridge.h:172
TEMPLATABLE_VALUE(uint16_t, duration) void play(const Ts &...x)
Definition rf_bridge.h:173
void send_raw(const std::string &code)
CallbackManager< void(RFBridgeAdvancedData)> advanced_data_callback_
Definition rf_bridge.h:76
void send_advanced_code(const RFBridgeAdvancedData &data)
CallbackManager< void(RFBridgeData)> data_callback_
Definition rf_bridge.h:75
void write_byte_str_(const std::string &codes)
void add_on_advanced_code_received_callback(F &&callback)
Definition rf_bridge.h:54
void send_code(RFBridgeData data)
std::vector< uint8_t > rx_buffer_
Definition rf_bridge.h:72
void add_on_code_received_callback(F &&callback)
Definition rf_bridge.h:51
RFBridgeLearnAction(RFBridgeComponent *parent)
Definition rf_bridge.h:121
RFBridgeSendAdvancedCodeAction(RFBridgeComponent *parent)
Definition rf_bridge.h:102
TEMPLATABLE_VALUE(uint8_t, length) TEMPLATABLE_VALUE(uint8_t
low code void play(const Ts &...x)
Definition rf_bridge.h:87
TEMPLATABLE_VALUE(uint16_t, sync) TEMPLATABLE_VALUE(uint16_t
RFBridgeSendCodeAction(RFBridgeComponent *parent)
Definition rf_bridge.h:81
TEMPLATABLE_VALUE(std::string, raw) void play(const Ts &...x)
Definition rf_bridge.h:162
RFBridgeSendRawAction(RFBridgeComponent *parent)
Definition rf_bridge.h:161
RFBridgeStartAdvancedSniffingAction(RFBridgeComponent *parent)
Definition rf_bridge.h:131
RFBridgeStartBucketSniffingAction(RFBridgeComponent *parent)
Definition rf_bridge.h:151
RFBridgeStopAdvancedSniffingAction(RFBridgeComponent *parent)
Definition rf_bridge.h:141
uint8_t duration
Definition msa3xx.h:0
static void uint32_t
uint16_t sync
Definition sun_gtil2.cpp:0
uint16_t length
Definition tt21100.cpp:0
uint16_t x
Definition tt21100.cpp:5