11 #if defined(USE_ESP32) && ESP_IDF_VERSION_MAJOR < 5 12 #include <driver/rmt.h> 16 namespace remote_base {
51 :
data_(data), index_(0), tolerance_(tolerance), tolerance_mode_(tolerance_mode) {}
57 bool is_valid(uint32_t offset = 0)
const {
return this->index_ + offset < this->
data_.size(); }
58 int32_t
peek(uint32_t offset = 0)
const {
return this->
data_[this->index_ + offset]; }
59 bool peek_mark(uint32_t
length, uint32_t offset = 0)
const;
60 bool peek_space(uint32_t length, uint32_t offset = 0)
const;
61 bool peek_space_at_least(uint32_t length, uint32_t offset = 0)
const;
63 return this->peek_space(space, offset + 1) && this->peek_mark(mark, offset);
66 bool expect_mark(uint32_t length);
67 bool expect_space(uint32_t length);
68 bool expect_item(uint32_t
mark, uint32_t
space);
69 bool expect_pulse_with_gap(uint32_t mark, uint32_t space);
70 void advance(uint32_t amount = 1) { this->index_ += amount; }
71 void reset() { this->index_ = 0; }
74 this->tolerance_ = tolerance;
75 this->tolerance_mode_ = tolerance_mode;
83 return int32_t(length - this->tolerance_);
85 return int32_t(100 - this->tolerance_) * length / 100U;
91 return int32_t(length + this->tolerance_);
93 return int32_t(100 + this->tolerance_) * length / 100U;
115 #if ESP_IDF_VERSION_MAJOR >= 5 120 explicit RemoteRMTChannel(rmt_channel_t channel, uint8_t mem_block_num = 1);
122 void config_rmt(rmt_config_t &rmt);
128 #if ESP_IDF_VERSION_MAJOR >= 5 129 const uint32_t ticks_per_ten_us = this->clock_resolution_ / 100000u;
131 const uint32_t ticks_per_ten_us = 80000000u / this->clock_divider_ / 100000u;
133 return us * ticks_per_ten_us / 10;
136 #if ESP_IDF_VERSION_MAJOR >= 5 137 const uint32_t ticks_per_ten_us = this->clock_resolution_ / 100000u;
139 const uint32_t ticks_per_ten_us = 80000000u / this->clock_divider_ / 100000u;
141 return (ticks * 10) / ticks_per_ten_us;
144 #if ESP_IDF_VERSION_MAJOR >= 5 145 uint32_t clock_resolution_{1000000};
148 rmt_channel_t channel_{RMT_CHANNEL_0};
150 uint8_t clock_divider_{80};
164 void perform() { this->parent_->send_(this->send_times_, this->send_wait_); }
168 uint32_t send_times_{1};
169 uint32_t send_wait_{0};
176 template<
typename Protocol>
177 void transmit(
const typename Protocol::ProtocolData &data, uint32_t send_times = 1, uint32_t send_wait = 0) {
178 auto call = this->transmit();
179 Protocol().encode(call.get_data(), data);
180 call.set_send_times(send_times);
181 call.set_send_wait(send_wait);
186 void send_(uint32_t send_times, uint32_t send_wait);
187 virtual void send_internal(uint32_t send_times, uint32_t send_wait) = 0;
211 this->tolerance_ = tolerance;
212 this->tolerance_mode_ = tolerance_mode;
216 void call_listeners_();
217 void call_dumpers_();
219 this->call_listeners_();
220 this->call_dumpers_();
227 uint32_t tolerance_{25};
236 void dump_config()
override;
258 auto res = proto.decode(src);
259 return res.has_value() && *res == this->
data_;
274 auto res = proto.decode(src);
275 if (res.has_value()) {
290 template<
typename Protocol>
291 void transmit_(
const typename Protocol::ProtocolData &data, uint32_t send_times = 1, uint32_t send_wait = 0) {
292 this->transmitter_->transmit<
Protocol>(data, send_times, send_wait);
298 TEMPLATABLE_VALUE(uint32_t, send_times)
299 TEMPLATABLE_VALUE(uint32_t, send_wait)
303 auto call = this->transmitter_->transmit();
304 this->encode(call.get_data(),
x...);
305 call.set_send_times(this->send_times_.value_or(
x..., 1));
306 call.set_send_wait(this->send_wait_.value_or(
x..., 0));
316 auto decoded = proto.decode(src);
317 if (!decoded.has_value())
319 proto.dump(*decoded);
324 #define DECLARE_REMOTE_PROTOCOL_(prefix) \ 325 using prefix##BinarySensor = RemoteReceiverBinarySensor<prefix##Protocol>; \ 326 using prefix##Trigger = RemoteReceiverTrigger<prefix##Protocol>; \ 327 using prefix##Dumper = RemoteReceiverDumper<prefix##Protocol>; 328 #define DECLARE_REMOTE_PROTOCOL(prefix) DECLARE_REMOTE_PROTOCOL_(prefix)
uint32_t carrier_frequency_
void register_listener(RemoteReceiverListener *listener)
void set_data(const RawTimings &data)
RemoteTransmitData temp_
Use same vector for all transmits, avoids many allocations.
int32_t operator[](uint32_t index) const
const RawTimings & get_raw_data() const
void set_carrier_frequency(uint32_t carrier_frequency)
uint32_t get_carrier_frequency() const
void item(uint32_t mark, uint32_t space)
void call_listeners_dumpers_()
std::vector< RemoteReceiverDumperBase * > dumpers_
void set_data(typename T::ProtocolData data)
std::vector< RemoteReceiverDumperBase * > secondary_dumpers_
bool is_valid(uint32_t offset=0) const
TransmitCall(RemoteTransmitterBase *parent)
void set_transmitter(RemoteTransmitterBase *transmitter)
ToleranceMode get_tolerance_mode()
void set_clock_resolution(uint32_t clock_resolution)
RemoteComponentBase(InternalGPIOPin *pin)
RemoteTransmitterBase * parent_
RemoteComponentBase * remote_base_
std::vector< int32_t > RawTimings
RemoteReceiverBinarySensorBase()
RemoteReceiveData(const RawTimings &data, uint32_t tolerance, ToleranceMode tolerance_mode)
void set_tolerance(uint32_t tolerance, ToleranceMode tolerance_mode)
RemoteTransmitterBase * transmitter_
int32_t lower_bound_(uint32_t length) const
void mark(uint32_t length)
int32_t peek(uint32_t offset=0) const
RemoteReceiverBinarySensor()
void play(Ts... x) override
RemoteTransmitterBase(InternalGPIOPin *pin)
std::vector< RemoteReceiverListener * > listeners_
void set_tolerance(uint32_t tolerance, ToleranceMode tolerance_mode)
uint32_t get_index() const
void transmit(const typename Protocol::ProtocolData &data, uint32_t send_times=1, uint32_t send_wait=0)
RemoteTransmitData * get_data()
RemoteReceiverBase(InternalGPIOPin *pin)
bool on_receive(RemoteReceiveData src) override
void set_send_wait(uint32_t send_wait)
bool dump(RemoteReceiveData src) override
void set_clock_divider(uint8_t clock_divider)
void transmit_(const typename Protocol::ProtocolData &data, uint32_t send_times=1, uint32_t send_wait=0)
bool peek_item(uint32_t mark, uint32_t space, uint32_t offset=0) const
void space(uint32_t length)
Implementation of SPI Controller mode.
ToleranceMode tolerance_mode_
bool matches(RemoteReceiveData src) override
void reserve(uint32_t len)
virtual bool is_secondary()
void set_send_times(uint32_t send_times)
void advance(uint32_t amount=1)
const RawTimings & get_data() const
void set_rmt_symbols(uint32_t rmt_symbols)
uint32_t to_microseconds_(uint32_t ticks)
RemoteTransmittable(RemoteTransmitterBase *transmitter)
int32_t upper_bound_(uint32_t length) const
uint32_t from_microseconds_(uint32_t us)