12 #include <driver/rmt.h> 16 namespace remote_base {
46 :
data_(data), index_(0), tolerance_(tolerance) {}
52 bool is_valid(uint32_t offset)
const {
return this->index_ + offset < this->
data_.size(); }
53 int32_t
peek(uint32_t offset = 0)
const {
return this->
data_[this->index_ + offset]; }
54 bool peek_mark(uint32_t
length, uint32_t offset = 0)
const;
55 bool peek_space(uint32_t length, uint32_t offset = 0)
const;
56 bool peek_space_at_least(uint32_t length, uint32_t offset = 0)
const;
58 return this->peek_space(space, offset + 1) && this->peek_mark(mark, offset);
61 bool expect_mark(uint32_t length);
62 bool expect_space(uint32_t length);
63 bool expect_item(uint32_t
mark, uint32_t
space);
64 bool expect_pulse_with_gap(uint32_t mark, uint32_t space);
65 void advance(uint32_t amount = 1) { this->index_ += amount; }
66 void reset() { this->index_ = 0; }
69 int32_t
lower_bound_(uint32_t length)
const {
return int32_t(100 - this->tolerance_) * length / 100U; }
70 int32_t
upper_bound_(uint32_t length)
const {
return int32_t(100 + this->tolerance_) * length / 100U; }
90 void config_rmt(rmt_config_t &rmt);
95 const uint32_t ticks_per_ten_us = 80000000u / this->clock_divider_ / 100000u;
96 return us * ticks_per_ten_us / 10;
99 const uint32_t ticks_per_ten_us = 80000000u / this->clock_divider_ / 100000u;
100 return (ticks * 10) / ticks_per_ten_us;
103 rmt_channel_t channel_{RMT_CHANNEL_0};
105 uint8_t clock_divider_{80};
118 void perform() { this->parent_->send_(this->send_times_, this->send_wait_); }
122 uint32_t send_times_{1};
123 uint32_t send_wait_{0};
132 void send_(uint32_t send_times, uint32_t send_wait);
133 virtual void send_internal(uint32_t send_times, uint32_t send_wait) = 0;
159 void call_listeners_();
160 void call_dumpers_();
162 this->call_listeners_();
163 this->call_dumpers_();
178 void dump_config()
override;
189 virtual void dump(
const T &data) = 0;
199 auto res = proto.decode(src);
200 return res.has_value() && *res == this->
data_;
214 auto res = proto.decode(src);
215 if (res.has_value()) {
227 TEMPLATABLE_VALUE(uint32_t, send_times);
228 TEMPLATABLE_VALUE(uint32_t, send_wait);
231 auto call = this->parent_->transmit();
232 this->encode(call.get_data(),
x...);
233 call.set_send_times(this->send_times_.value_or(
x..., 1));
234 call.set_send_wait(this->send_wait_.value_or(
x..., 0));
248 auto decoded = proto.decode(src);
249 if (!decoded.has_value())
251 proto.dump(*decoded);
256 #define DECLARE_REMOTE_PROTOCOL_(prefix) \ 257 using prefix##BinarySensor = RemoteReceiverBinarySensor<prefix##Protocol, prefix##Data>; \ 258 using prefix##Trigger = RemoteReceiverTrigger<prefix##Protocol, prefix##Data>; \ 259 using prefix##Dumper = RemoteReceiverDumper<prefix##Protocol, prefix##Data>; 260 #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
bool on_receive(RemoteReceiveData src) override
bool is_valid(uint32_t offset) const
void item(uint32_t mark, uint32_t space)
RemoteReceiveData(const RawTimings &data, uint8_t tolerance)
void call_listeners_dumpers_()
std::vector< RemoteReceiverDumperBase * > dumpers_
std::vector< RemoteReceiverDumperBase * > secondary_dumpers_
TransmitCall(RemoteTransmitterBase *parent)
RemoteComponentBase(InternalGPIOPin *pin)
RemoteTransmitterBase * parent_
RemoteComponentBase * remote_base_
std::vector< int32_t > RawTimings
RemoteReceiverBinarySensorBase()
bool dump(RemoteReceiveData src) override
RemoteReceiverBinarySensor()
int32_t lower_bound_(uint32_t length) const
void mark(uint32_t length)
int32_t peek(uint32_t offset=0) const
void play(Ts... x) override
RemoteTransmitterBase(InternalGPIOPin *pin)
std::vector< RemoteReceiverListener * > listeners_
uint32_t get_index() const
RemoteTransmitData * get_data()
RemoteReceiverBase(InternalGPIOPin *pin)
void set_send_wait(uint32_t send_wait)
void set_clock_divider(uint8_t clock_divider)
void set_parent(RemoteTransmitterBase *parent)
bool matches(RemoteReceiveData src) override
bool peek_item(uint32_t mark, uint32_t space, uint32_t offset=0) const
void space(uint32_t length)
Implementation of SPI Controller mode.
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_tolerance(uint8_t tolerance)
uint32_t to_microseconds_(uint32_t ticks)
int32_t upper_bound_(uint32_t length) const
uint32_t from_microseconds_(uint32_t us)