ESPHome 2026.5.0-dev
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 {
11namespace rf_bridge {
12
13static const uint8_t RF_MESSAGE_SIZE = 9;
14static const uint8_t RF_CODE_START = 0xAA;
15static const uint8_t RF_CODE_ACK = 0xA0;
16static const uint8_t RF_CODE_LEARN = 0xA1;
17static const uint8_t RF_CODE_LEARN_KO = 0xA2;
18static const uint8_t RF_CODE_LEARN_OK = 0xA3;
19static const uint8_t RF_CODE_RFIN = 0xA4;
20static const uint8_t RF_CODE_RFOUT = 0xA5;
21static const uint8_t RF_CODE_ADVANCED_RFIN = 0xA6;
22static const uint8_t RF_CODE_SNIFFING_ON = 0xA6;
23static const uint8_t RF_CODE_SNIFFING_OFF = 0xA7;
24static const uint8_t RF_CODE_RFOUT_NEW = 0xA8;
25static const uint8_t RF_CODE_LEARN_NEW = 0xA9;
26static const uint8_t RF_CODE_LEARN_KO_NEW = 0xAA;
27static const uint8_t RF_CODE_LEARN_OK_NEW = 0xAB;
28static const uint8_t RF_CODE_RFOUT_BUCKET = 0xB0;
29static const uint8_t RF_CODE_RFIN_BUCKET = 0xB1;
30static const uint8_t RF_CODE_BEEP = 0xC0;
31static const uint8_t RF_CODE_STOP = 0x55;
32static const uint8_t RF_DEBOUNCE = 200;
33static const size_t MAX_RX_BUFFER_SIZE = 512;
34
36 uint16_t sync;
37 uint16_t low;
38 uint16_t high;
40};
41
43 uint8_t length;
44 uint8_t protocol;
45 std::string code;
46};
47
49 public:
50 void loop() override;
51 void dump_config() override;
52 template<typename F> void add_on_code_received_callback(F &&callback) {
53 this->data_callback_.add(std::forward<F>(callback));
54 }
55 template<typename F> void add_on_advanced_code_received_callback(F &&callback) {
56 this->advanced_data_callback_.add(std::forward<F>(callback));
57 }
58 void send_code(RFBridgeData data);
60 void learn();
64 void send_raw(const std::string &code);
65 void beep(uint16_t ms);
66
67 protected:
68 void ack_();
69 void decode_();
70 bool parse_bridge_byte_(uint8_t byte);
71 void write_byte_str_(const std::string &codes);
72
73 std::vector<uint8_t> rx_buffer_;
75
78};
79
80template<typename... Ts> class RFBridgeSendCodeAction : public Action<Ts...> {
81 public:
84 TEMPLATABLE_VALUE(uint16_t, low)
85 TEMPLATABLE_VALUE(uint16_t, high)
87
88 void play(const Ts &...x) {
89 RFBridgeData data{};
90 data.sync = this->sync_.value(x...);
91 data.low = this->low_.value(x...);
92 data.high = this->high_.value(x...);
93 data.code = this->code_.value(x...);
94 this->parent_->send_code(data);
95 }
96
97 protected:
99};
100
101template<typename... Ts> class RFBridgeSendAdvancedCodeAction : public Action<Ts...> {
102 public:
105 TEMPLATABLE_VALUE(uint8_t, protocol)
106 TEMPLATABLE_VALUE(std::string, code)
107
108 void play(const Ts &...x) {
110 data.length = this->length_.value(x...);
111 data.protocol = this->protocol_.value(x...);
112 data.code = this->code_.value(x...);
113 this->parent_->send_advanced_code(data);
114 }
115
116 protected:
118};
119
120template<typename... Ts> class RFBridgeLearnAction : public Action<Ts...> {
121 public:
123
124 void play(const Ts &...x) { this->parent_->learn(); }
125
126 protected:
128};
129
130template<typename... Ts> class RFBridgeStartAdvancedSniffingAction : public Action<Ts...> {
131 public:
133
134 void play(const Ts &...x) { this->parent_->start_advanced_sniffing(); }
135
136 protected:
138};
139
140template<typename... Ts> class RFBridgeStopAdvancedSniffingAction : public Action<Ts...> {
141 public:
143
144 void play(const Ts &...x) { this->parent_->stop_advanced_sniffing(); }
145
146 protected:
148};
149
150template<typename... Ts> class RFBridgeStartBucketSniffingAction : public Action<Ts...> {
151 public:
153
154 void play(const Ts &...x) { this->parent_->start_bucket_sniffing(); }
155
156 protected:
158};
159
160template<typename... Ts> class RFBridgeSendRawAction : public Action<Ts...> {
161 public:
163 TEMPLATABLE_VALUE(std::string, raw)
164
165 void play(const Ts &...x) { this->parent_->send_raw(this->raw_.value(x...)); }
166
167 protected:
169};
170
171template<typename... Ts> class RFBridgeBeepAction : public Action<Ts...> {
172 public:
175
176 void play(const Ts &...x) { this->parent_->beep(this->duration_.value(x...)); }
177
178 protected:
180};
181
182} // namespace rf_bridge
183} // namespace esphome
uint8_t raw[35]
Definition bl0939.h:0
virtual void play(const Ts &...x)=0
RFBridgeBeepAction(RFBridgeComponent *parent)
Definition rf_bridge.h:173
TEMPLATABLE_VALUE(uint16_t, duration) void play(const Ts &...x)
Definition rf_bridge.h:174
void send_raw(const std::string &code)
CallbackManager< void(RFBridgeAdvancedData)> advanced_data_callback_
Definition rf_bridge.h:77
void send_advanced_code(const RFBridgeAdvancedData &data)
CallbackManager< void(RFBridgeData)> data_callback_
Definition rf_bridge.h:76
void write_byte_str_(const std::string &codes)
void add_on_advanced_code_received_callback(F &&callback)
Definition rf_bridge.h:55
void send_code(RFBridgeData data)
std::vector< uint8_t > rx_buffer_
Definition rf_bridge.h:73
void add_on_code_received_callback(F &&callback)
Definition rf_bridge.h:52
RFBridgeLearnAction(RFBridgeComponent *parent)
Definition rf_bridge.h:122
RFBridgeSendAdvancedCodeAction(RFBridgeComponent *parent)
Definition rf_bridge.h:103
TEMPLATABLE_VALUE(uint8_t, length) TEMPLATABLE_VALUE(uint8_t
low code void play(const Ts &...x)
Definition rf_bridge.h:88
TEMPLATABLE_VALUE(uint16_t, sync) TEMPLATABLE_VALUE(uint16_t
RFBridgeSendCodeAction(RFBridgeComponent *parent)
Definition rf_bridge.h:82
TEMPLATABLE_VALUE(std::string, raw) void play(const Ts &...x)
Definition rf_bridge.h:163
RFBridgeSendRawAction(RFBridgeComponent *parent)
Definition rf_bridge.h:162
RFBridgeStartAdvancedSniffingAction(RFBridgeComponent *parent)
Definition rf_bridge.h:132
RFBridgeStartBucketSniffingAction(RFBridgeComponent *parent)
Definition rf_bridge.h:152
RFBridgeStopAdvancedSniffingAction(RFBridgeComponent *parent)
Definition rf_bridge.h:142
uint8_t duration
Definition msa3xx.h:0
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
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