ESPHome 2025.12.0-dev
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 {
10namespace remote_base {
11
13 public:
14 bool matches(RemoteReceiveData src) override {
15 for (size_t i = 0; i < this->len_; i++) {
16 auto val = this->data_[i];
17 if (val < 0) {
18 if (!src.expect_space(static_cast<uint32_t>(-val)))
19 return false;
20 } else {
21 if (!src.expect_mark(static_cast<uint32_t>(val)))
22 return false;
23 }
24 }
25 return true;
26 }
27 void set_data(const int32_t *data) { data_ = data; }
28 void set_len(size_t len) { len_ = len; }
29
30 protected:
31 const int32_t *data_;
32 size_t len_;
33};
34
35class RawTrigger : public Trigger<RawTimings>, public Component, public RemoteReceiverListener {
36 protected:
37 bool on_receive(RemoteReceiveData src) override {
38 this->trigger(src.get_raw_data());
39 return false;
40 }
41};
42
43template<typename... Ts> class RawAction : public RemoteTransmitterActionBase<Ts...> {
44 public:
45 void set_code_template(RawTimings (*func)(Ts...)) {
46 this->code_.func = func;
47 this->len_ = -1; // Sentinel value indicates template mode
48 }
49 void set_code_static(const int32_t *code, size_t len) {
50 this->code_.data = code;
51 this->len_ = len; // Length >= 0 indicates static mode
52 }
53 TEMPLATABLE_VALUE(uint32_t, carrier_frequency);
54
55 void encode(RemoteTransmitData *dst, Ts... x) override {
56 if (this->len_ >= 0) {
57 for (size_t i = 0; i < static_cast<size_t>(this->len_); i++) {
58 auto val = this->code_.data[i];
59 if (val < 0) {
60 dst->space(static_cast<uint32_t>(-val));
61 } else {
62 dst->mark(static_cast<uint32_t>(val));
63 }
64 }
65 } else {
66 dst->set_data(this->code_.func(x...));
67 }
68 dst->set_carrier_frequency(this->carrier_frequency_.value(x...));
69 }
70
71 protected:
72 ssize_t len_{-1}; // -1 = template mode, >=0 = static mode with length
73 union Code {
74 RawTimings (*func)(Ts...);
75 const int32_t *data;
77};
78
80 public:
81 bool dump(RemoteReceiveData src) override;
82 bool is_secondary() override { return true; }
83};
84
85} // namespace remote_base
86} // namespace esphome
void trigger(const Ts &...x)
Definition automation.h:169
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:49
void set_carrier_frequency(uint32_t carrier_frequency)
Definition remote_base.h:30
void set_data(const RawTimings &data)
Definition remote_base.h:33
__int64 ssize_t
Definition httplib.h:178
mopeka_std_values val[4]
std::vector< int32_t > RawTimings
Definition remote_base.h:19
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
std::string size_t len
Definition helpers.h:500
uint16_t x
Definition tt21100.cpp:5