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; }
91 void config_rmt(rmt_config_t &rmt);
96 const uint32_t ticks_per_ten_us = 80000000u / this->clock_divider_ / 100000u;
97 return us * ticks_per_ten_us / 10;
100 const uint32_t ticks_per_ten_us = 80000000u / this->clock_divider_ / 100000u;
101 return (ticks * 10) / ticks_per_ten_us;
104 rmt_channel_t channel_{RMT_CHANNEL_0};
106 uint8_t clock_divider_{80};
119 void perform() { this->parent_->send_(this->send_times_, this->send_wait_); }
123 uint32_t send_times_{1};
124 uint32_t send_wait_{0};
131 template<
typename Protocol>
132 void transmit(
const typename Protocol::ProtocolData &data, uint32_t send_times = 1, uint32_t send_wait = 0) {
133 auto call = this->transmit();
134 Protocol().encode(call.get_data(), data);
135 call.set_send_times(send_times);
136 call.set_send_wait(send_wait);
141 void send_(uint32_t send_times, uint32_t send_wait);
142 virtual void send_internal(uint32_t send_times, uint32_t send_wait) = 0;
168 void call_listeners_();
169 void call_dumpers_();
171 this->call_listeners_();
172 this->call_dumpers_();
187 void dump_config()
override;
209 auto res = proto.decode(src);
210 return res.has_value() && *res == this->
data_;
225 auto res = proto.decode(src);
226 if (res.has_value()) {
241 template<
typename Protocol>
242 void transmit_(
const typename Protocol::ProtocolData &data, uint32_t send_times = 1, uint32_t send_wait = 0) {
243 this->transmitter_->transmit<
Protocol>(data, send_times, send_wait);
249 TEMPLATABLE_VALUE(uint32_t, send_times)
250 TEMPLATABLE_VALUE(uint32_t, send_wait)
254 auto call = this->transmitter_->transmit();
255 this->encode(call.get_data(),
x...);
256 call.set_send_times(this->send_times_.value_or(
x..., 1));
257 call.set_send_wait(this->send_wait_.value_or(
x..., 0));
267 auto decoded = proto.decode(src);
268 if (!decoded.has_value())
270 proto.dump(*decoded);
275 #define DECLARE_REMOTE_PROTOCOL_(prefix) \ 276 using prefix##BinarySensor = RemoteReceiverBinarySensor<prefix##Protocol>; \ 277 using prefix##Trigger = RemoteReceiverTrigger<prefix##Protocol>; \ 278 using prefix##Dumper = RemoteReceiverDumper<prefix##Protocol>; 279 #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 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_
void set_data(typename T::ProtocolData data)
std::vector< RemoteReceiverDumperBase * > secondary_dumpers_
TransmitCall(RemoteTransmitterBase *parent)
void set_transmitter(RemoteTransmitterBase *transmitter)
RemoteComponentBase(InternalGPIOPin *pin)
RemoteTransmitterBase * parent_
RemoteComponentBase * remote_base_
std::vector< int32_t > RawTimings
RemoteReceiverBinarySensorBase()
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_
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)
This is a workaround until we can figure out a way to get the tflite-micro idf component code availab...
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_tolerance(uint8_t tolerance)
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)