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)
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;
116 explicit RemoteRMTChannel(rmt_channel_t channel, uint8_t mem_block_num = 1);
118 void config_rmt(rmt_config_t &rmt);
123 const uint32_t ticks_per_ten_us = 80000000u / this->clock_divider_ / 100000u;
124 return us * ticks_per_ten_us / 10;
127 const uint32_t ticks_per_ten_us = 80000000u / this->clock_divider_ / 100000u;
128 return (ticks * 10) / ticks_per_ten_us;
131 rmt_channel_t channel_{RMT_CHANNEL_0};
133 uint8_t clock_divider_{80};
146 void perform() { this->parent_->send_(this->send_times_, this->send_wait_); }
150 uint32_t send_times_{1};
151 uint32_t send_wait_{0};
158 template<
typename Protocol>
159 void transmit(
const typename Protocol::ProtocolData &data, uint32_t send_times = 1, uint32_t send_wait = 0) {
160 auto call = this->transmit();
161 Protocol().encode(call.get_data(), data);
162 call.set_send_times(send_times);
163 call.set_send_wait(send_wait);
168 void send_(uint32_t send_times, uint32_t send_wait);
169 virtual void send_internal(uint32_t send_times, uint32_t send_wait) = 0;
193 this->tolerance_ = tolerance;
194 this->tolerance_mode_ = tolerance_mode;
198 void call_listeners_();
199 void call_dumpers_();
201 this->call_listeners_();
202 this->call_dumpers_();
209 uint32_t tolerance_{25};
218 void dump_config()
override;
240 auto res = proto.decode(src);
241 return res.has_value() && *res == this->
data_;
256 auto res = proto.decode(src);
257 if (res.has_value()) {
272 template<
typename Protocol>
273 void transmit_(
const typename Protocol::ProtocolData &data, uint32_t send_times = 1, uint32_t send_wait = 0) {
274 this->transmitter_->transmit<
Protocol>(data, send_times, send_wait);
280 TEMPLATABLE_VALUE(uint32_t, send_times)
281 TEMPLATABLE_VALUE(uint32_t, send_wait)
285 auto call = this->transmitter_->transmit();
286 this->encode(call.get_data(),
x...);
287 call.set_send_times(this->send_times_.value_or(
x..., 1));
288 call.set_send_wait(this->send_wait_.value_or(
x..., 0));
298 auto decoded = proto.decode(src);
299 if (!decoded.has_value())
301 proto.dump(*decoded);
306 #define DECLARE_REMOTE_PROTOCOL_(prefix) \ 307 using prefix##BinarySensor = RemoteReceiverBinarySensor<prefix##Protocol>; \ 308 using prefix##Trigger = RemoteReceiverTrigger<prefix##Protocol>; \ 309 using prefix##Dumper = RemoteReceiverDumper<prefix##Protocol>; 310 #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)
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)
ToleranceMode get_tolerance_mode()
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
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)