ESPHome 2026.1.0b1
Loading...
Searching...
No Matches
infrared.h
Go to the documentation of this file.
1#pragma once
2
3// WARNING: This component is EXPERIMENTAL. The API may change at any time
4// without following the normal breaking changes policy. Use at your own risk.
5// Once the API is considered stable, this warning will be removed.
6
10
11#include <vector>
12
13namespace esphome::infrared {
14
16enum InfraredCapability : uint32_t {
17 CAPABILITY_TRANSMITTER = 1 << 0, // Can transmit signals
18 CAPABILITY_RECEIVER = 1 << 1, // Can receive signals
19};
20
22class Infrared;
23
26 public:
27 explicit InfraredCall(Infrared *parent) : parent_(parent) {}
28
33 InfraredCall &set_raw_timings(const std::vector<int32_t> &timings);
36 InfraredCall &set_raw_timings_packed(const uint8_t *data, uint16_t length, uint16_t count);
38 InfraredCall &set_repeat_count(uint32_t count);
39
41 void perform();
42
46 const std::vector<int32_t> &get_raw_timings() const { return *this->raw_timings_; }
48 bool has_raw_timings() const { return this->raw_timings_ != nullptr || this->packed_data_ != nullptr; }
50 bool is_packed() const { return this->packed_data_ != nullptr; }
52 const uint8_t *get_packed_data() const { return this->packed_data_; }
53 uint16_t get_packed_length() const { return this->packed_length_; }
54 uint16_t get_packed_count() const { return this->packed_count_; }
56 uint32_t get_repeat_count() const { return this->repeat_count_; }
57
58 protected:
59 uint32_t repeat_count_{1};
62 // Vector-based timings (for lambdas/automations)
63 const std::vector<int32_t> *raw_timings_{nullptr};
64 // Packed protobuf timings (for API zero-copy)
65 const uint8_t *packed_data_{nullptr};
66 uint16_t packed_length_{0};
67 uint16_t packed_count_{0};
68};
69
72 public:
73 bool get_supports_transmitter() const { return this->supports_transmitter_; }
74 void set_supports_transmitter(bool supports) { this->supports_transmitter_ = supports; }
75
76 bool get_supports_receiver() const { return this->supports_receiver_; }
77 void set_supports_receiver(bool supports) { this->supports_receiver_ = supports; }
78
79 protected:
81 bool supports_receiver_{false};
82};
83
86 public:
87 Infrared() = default;
88
89 void setup() override;
90 void dump_config() override;
91 float get_setup_priority() const override { return setup_priority::AFTER_CONNECTION; }
92
94 void set_receiver(remote_base::RemoteReceiverBase *receiver) { this->receiver_ = receiver; }
96 void set_transmitter(remote_base::RemoteTransmitterBase *transmitter) { this->transmitter_ = transmitter; }
97
99 bool has_transmitter() const { return this->transmitter_ != nullptr; }
101 bool has_receiver() const { return this->receiver_ != nullptr; }
102
104 InfraredTraits &get_traits() { return this->traits_; }
105 const InfraredTraits &get_traits() const { return this->traits_; }
106
109
111 uint32_t get_capability_flags() const;
112
114 bool on_receive(remote_base::RemoteReceiveData data) override;
115
116 protected:
117 friend class InfraredCall;
118
120 virtual void control(const InfraredCall &call);
121
122 // Underlying hardware components
125
126 // Traits describing capabilities
128};
129
130} // namespace esphome::infrared
uint16_le_t frequency
Definition bl0942.h:6
InfraredCall - Builder pattern for transmitting infrared signals.
Definition infrared.h:25
InfraredCall & set_raw_timings(const std::vector< int32_t > &timings)
Set the raw timings (positive = mark, negative = space) Note: The timings vector must outlive the Inf...
Definition infrared.cpp:19
bool is_packed() const
Check if using packed data format.
Definition infrared.h:50
uint32_t get_repeat_count() const
Get the repeat count.
Definition infrared.h:56
InfraredCall & set_carrier_frequency(uint32_t frequency)
Set the carrier frequency in Hz.
Definition infrared.cpp:14
InfraredCall & set_repeat_count(uint32_t count)
Set the number of times to repeat transmission (1 = transmit once, 2 = transmit twice,...
Definition infrared.cpp:33
bool has_raw_timings() const
Check if raw timings have been set (either vector or packed)
Definition infrared.h:48
void perform()
Perform the transmission.
Definition infrared.cpp:38
InfraredCall & set_raw_timings_packed(const uint8_t *data, uint16_t length, uint16_t count)
Set the raw timings from packed protobuf sint32 data (zero-copy from wire) Note: The data must outliv...
Definition infrared.cpp:25
const uint8_t * get_packed_data() const
Get packed data (only valid if set via set_raw_timings_packed)
Definition infrared.h:52
const optional< uint32_t > & get_carrier_frequency() const
Get the carrier frequency.
Definition infrared.h:44
const std::vector< int32_t > & get_raw_timings() const
Get the raw timings (only valid if set via set_raw_timings, not packed)
Definition infrared.h:46
uint16_t get_packed_count() const
Definition infrared.h:54
optional< uint32_t > carrier_frequency_
Definition infrared.h:61
const uint8_t * packed_data_
Definition infrared.h:65
uint16_t get_packed_length() const
Definition infrared.h:53
const std::vector< int32_t > * raw_timings_
Definition infrared.h:63
InfraredCall(Infrared *parent)
Definition infrared.h:27
Infrared - Base class for infrared remote control implementations.
Definition infrared.h:85
void dump_config() override
Definition infrared.cpp:57
remote_base::RemoteReceiverBase * receiver_
Definition infrared.h:123
bool on_receive(remote_base::RemoteReceiveData data) override
Called when IR data is received (from RemoteReceiverListener)
Definition infrared.cpp:123
void set_transmitter(remote_base::RemoteTransmitterBase *transmitter)
Set the remote transmitter component.
Definition infrared.h:96
InfraredCall make_call()
Create a call object for transmitting.
Definition infrared.cpp:66
float get_setup_priority() const override
Definition infrared.h:91
virtual void control(const InfraredCall &call)
Perform the actual transmission (called by InfraredCall)
Definition infrared.cpp:68
remote_base::RemoteTransmitterBase * transmitter_
Definition infrared.h:124
const InfraredTraits & get_traits() const
Definition infrared.h:105
bool has_transmitter() const
Check if this infrared has a transmitter configured.
Definition infrared.h:99
bool has_receiver() const
Check if this infrared has a receiver configured.
Definition infrared.h:101
InfraredTraits & get_traits()
Get the traits for this infrared implementation.
Definition infrared.h:104
uint32_t get_capability_flags() const
Get capability flags for this infrared instance.
Definition infrared.cpp:111
void set_receiver(remote_base::RemoteReceiverBase *receiver)
Set the remote receiver component.
Definition infrared.h:94
InfraredTraits - Describes the capabilities of an infrared implementation.
Definition infrared.h:71
bool get_supports_transmitter() const
Definition infrared.h:73
void set_supports_transmitter(bool supports)
Definition infrared.h:74
void set_supports_receiver(bool supports)
Definition infrared.h:77
InfraredCapability
Capability flags for individual infrared instances.
Definition infrared.h:16
const float AFTER_CONNECTION
For components that should be initialized after a data connection (API/MQTT) is connected.
Definition component.cpp:89
uint16_t length
Definition tt21100.cpp:0