8 namespace remote_transmitter {
10 static const char *
const TAG =
"remote_transmitter";
15 ESP_LOGCONFIG(TAG,
"Remote Transmitter...");
16 ESP_LOGCONFIG(TAG,
" Channel: %d", this->channel_);
17 ESP_LOGCONFIG(TAG,
" RMT memory blocks: %d", this->mem_block_num_);
18 ESP_LOGCONFIG(TAG,
" Clock divider: %u", this->clock_divider_);
19 LOG_PIN(
" Pin: ", this->
pin_);
25 if (this->is_failed()) {
26 ESP_LOGE(TAG,
"Configuring RMT driver failed: %s (%s)", esp_err_to_name(this->
error_code_),
35 c.rmt_mode = RMT_MODE_TX;
37 c.tx_config.loop_en =
false;
40 c.tx_config.carrier_en =
false;
42 c.tx_config.carrier_en =
true;
47 c.tx_config.idle_output_en =
true;
49 c.tx_config.carrier_level = RMT_CARRIER_LEVEL_HIGH;
50 c.tx_config.idle_level = RMT_IDLE_LEVEL_LOW;
52 c.tx_config.carrier_level = RMT_CARRIER_LEVEL_LOW;
53 c.tx_config.idle_level = RMT_IDLE_LEVEL_HIGH;
57 esp_err_t error = rmt_config(&c);
58 if (error != ESP_OK) {
66 error = rmt_driver_install(this->channel_, 0, 0);
67 if (error != ESP_OK) {
69 if (error == ESP_ERR_INVALID_STATE) {
82 if (this->is_failed())
93 rmt_item32_t rmt_item;
96 bool level =
val >= 0;
99 val = this->from_microseconds_(static_cast<uint32_t>(
val));
102 int32_t item = std::min(
val, int32_t(32767));
105 if (rmt_i % 2 == 0) {
106 rmt_item.level0 =
static_cast<uint32_t
>(level ^ this->
inverted_);
107 rmt_item.duration0 =
static_cast<uint32_t
>(item);
109 rmt_item.level1 =
static_cast<uint32_t
>(level ^ this->
inverted_);
110 rmt_item.duration1 =
static_cast<uint32_t
>(item);
117 if (rmt_i % 2 == 1) {
119 rmt_item.duration1 = 0;
124 ESP_LOGE(TAG,
"Empty data");
128 for (uint32_t i = 0; i < send_times; i++) {
129 esp_err_t error = rmt_write_items(this->channel_, this->
rmt_temp_.data(), this->
rmt_temp_.size(),
true);
130 if (error != ESP_OK) {
131 ESP_LOGW(TAG,
"rmt_write_items failed: %s", esp_err_to_name(error));
132 this->status_set_warning();
134 this->status_clear_warning();
136 if (i + 1 < send_times)
RemoteTransmitData temp_
Use same vector for all transmits, avoids many allocations.
Trigger * transmit_trigger_
uint32_t get_carrier_frequency() const
void trigger(Ts... x)
Inform the parent automation that the event has triggered.
virtual uint8_t get_pin() const =0
void dump_config() override
std::string str_sprintf(const char *fmt,...)
void send_internal(uint32_t send_times, uint32_t send_wait) override
uint32_t current_carrier_frequency_
Trigger * complete_trigger_
std::string error_string_
uint8_t carrier_duty_percent_
Implementation of SPI Controller mode.
void IRAM_ATTR HOT delayMicroseconds(uint32_t us)
const RawTimings & get_data() const
virtual bool is_inverted() const =0
std::vector< rmt_item32_t > rmt_temp_