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};
130 template<
typename Protocol>
131 void transmit(
const typename Protocol::ProtocolData &data, uint32_t send_times = 1, uint32_t send_wait = 0) {
132 auto call = this->transmit();
133 Protocol().encode(call.get_data(), data);
134 call.set_send_times(send_times);
135 call.set_send_wait(send_wait);
140 void send_(uint32_t send_times, uint32_t send_wait);
141 virtual void send_internal(uint32_t send_times, uint32_t send_wait) = 0;
167 void call_listeners_();
168 void call_dumpers_();
170 this->call_listeners_();
171 this->call_dumpers_();
186 void dump_config()
override;
208 auto res = proto.decode(src);
209 return res.has_value() && *res == this->
data_;
224 auto res = proto.decode(src);
225 if (res.has_value()) {
240 template<
typename Protocol>
241 void transmit_(
const typename Protocol::ProtocolData &data, uint32_t send_times = 1, uint32_t send_wait = 0) {
242 this->transmitter_->transmit<
Protocol>(data, send_times, send_wait);
248 TEMPLATABLE_VALUE(uint32_t, send_times)
249 TEMPLATABLE_VALUE(uint32_t, send_wait)
253 auto call = this->transmitter_->transmit();
254 this->encode(call.get_data(),
x...);
255 call.set_send_times(this->send_times_.value_or(
x..., 1));
256 call.set_send_wait(this->send_wait_.value_or(
x..., 0));
266 auto decoded = proto.decode(src);
267 if (!decoded.has_value())
269 proto.dump(*decoded);
274 #define DECLARE_REMOTE_PROTOCOL_(prefix) \ 275 using prefix##BinarySensor = RemoteReceiverBinarySensor<prefix##Protocol>; \ 276 using prefix##Trigger = RemoteReceiverTrigger<prefix##Protocol>; \ 277 using prefix##Dumper = RemoteReceiverDumper<prefix##Protocol>; 278 #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)