ESPHome 2026.5.1
Loading...
Searching...
No Matches
raw_protocol.h
Go to the documentation of this file.
1#pragma once
2
4#include "remote_base.h"
5
6#include <cinttypes>
7#include <vector>
8
9namespace esphome::remote_base {
10
12 public:
13 bool matches(RemoteReceiveData src) override {
14 for (size_t i = 0; i < this->len_; i++) {
15 auto val = this->data_[i];
16 if (val < 0) {
17 if (!src.expect_space(static_cast<uint32_t>(-val)))
18 return false;
19 } else {
20 if (!src.expect_mark(static_cast<uint32_t>(val)))
21 return false;
22 }
23 }
24 return true;
25 }
26 void set_data(const int32_t *data) { data_ = data; }
27 void set_len(size_t len) { len_ = len; }
28
29 protected:
30 const int32_t *data_;
31 size_t len_;
32};
33
34class RawTrigger : public Trigger<RawTimings>, public Component, public RemoteReceiverListener {
35 protected:
36 bool on_receive(RemoteReceiveData src) override {
37 this->trigger(src.get_raw_data());
38 return false;
39 }
40};
41
42template<typename... Ts> class RawAction : public RemoteTransmitterActionBase<Ts...> {
43 public:
44 void set_code_template(RawTimings (*func)(Ts...)) {
45 this->code_.func = func;
46 this->len_ = -1; // Sentinel value indicates template mode
47 }
48 void set_code_static(const int32_t *code, size_t len) {
49 this->code_.data = code;
50 this->len_ = len; // Length >= 0 indicates static mode
51 }
52 TEMPLATABLE_VALUE(uint32_t, carrier_frequency);
53
54 void encode(RemoteTransmitData *dst, Ts... x) override {
55 if (this->len_ >= 0) {
56 for (size_t i = 0; i < static_cast<size_t>(this->len_); i++) {
57 auto val = this->code_.data[i];
58 if (val < 0) {
59 dst->space(static_cast<uint32_t>(-val));
60 } else {
61 dst->mark(static_cast<uint32_t>(val));
62 }
63 }
64 } else {
65 dst->set_data(this->code_.func(x...));
66 }
67 dst->set_carrier_frequency(this->carrier_frequency_.value(x...));
68 }
69
70 protected:
71 ssize_t len_{-1}; // -1 = template mode, >=0 = static mode with length
72 union Code {
73 RawTimings (*func)(Ts...);
74 const int32_t *data;
76};
77
79 public:
80 bool dump(RemoteReceiveData src) override;
81 bool is_secondary() override { return true; }
82};
83
84} // namespace esphome::remote_base
void trigger(const Ts &...x) ESPHOME_ALWAYS_INLINE
Definition automation.h:482
union esphome::remote_base::RawAction::Code code_
TEMPLATABLE_VALUE(uint32_t, carrier_frequency)
void set_code_static(const int32_t *code, size_t len)
void set_code_template(RawTimings(*func)(Ts...))
void encode(RemoteTransmitData *dst, Ts... x) override
void set_data(const int32_t *data)
bool matches(RemoteReceiveData src) override
bool dump(RemoteReceiveData src) override
bool on_receive(RemoteReceiveData src) override
const RawTimings & get_raw_data() const
Definition remote_base.h:58
void set_carrier_frequency(uint32_t carrier_frequency)
Definition remote_base.h:29
void set_data(const RawTimings &data)
Definition remote_base.h:32
__int64 ssize_t
Definition httplib.h:178
mopeka_std_values val[3]
std::vector< int32_t > RawTimings
Definition remote_base.h:18
std::string size_t len
static void uint32_t
uint16_t x
Definition tt21100.cpp:5