Skip to content

Commit

Permalink
Improve error messages on ESP32 RMT receiver/transmitter
Browse files Browse the repository at this point in the history
  • Loading branch information
Mat931 committed May 8, 2024
1 parent 7764ab2 commit 268b1e3
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions esphome/components/remote_receiver/remote_receiver.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class RemoteReceiverComponent : public remote_base::RemoteReceiverBase,
void decode_rmt_(rmt_item32_t *item, size_t len);
RingbufHandle_t ringbuf_;
esp_err_t error_code_{ESP_OK};
std::string error_string_{""};
#endif

#if defined(USE_ESP8266) || defined(USE_LIBRETINY)
Expand Down
10 changes: 9 additions & 1 deletion esphome/components/remote_receiver/remote_receiver_esp32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,33 @@ void RemoteReceiverComponent::setup() {
esp_err_t error = rmt_config(&rmt);
if (error != ESP_OK) {
this->error_code_ = error;
this->error_string_ = "in rmt_config";
this->mark_failed();
return;
}

error = rmt_driver_install(this->channel_, this->buffer_size_, 0);
if (error != ESP_OK) {
this->error_code_ = error;
if (error == ESP_ERR_INVALID_STATE) {
this->error_string_ = str_sprintf("RMT channel %i is already in use by another component", this->channel_);
} else {
this->error_string_ = "in rmt_driver_install";
}
this->mark_failed();
return;
}
error = rmt_get_ringbuf_handle(this->channel_, &this->ringbuf_);
if (error != ESP_OK) {
this->error_code_ = error;
this->error_string_ = "in rmt_get_ringbuf_handle";
this->mark_failed();
return;
}
error = rmt_rx_start(this->channel_, true);
if (error != ESP_OK) {
this->error_code_ = error;
this->error_string_ = "in rmt_rx_start";
this->mark_failed();
return;
}
Expand All @@ -67,7 +75,7 @@ void RemoteReceiverComponent::dump_config() {
ESP_LOGCONFIG(TAG, " Filter out pulses shorter than: %" PRIu32 " us", this->filter_us_);
ESP_LOGCONFIG(TAG, " Signal is done after %" PRIu32 " us of no changes", this->idle_us_);
if (this->is_failed()) {
ESP_LOGE(TAG, "Configuring RMT driver failed: %s", esp_err_to_name(this->error_code_));
ESP_LOGE(TAG, "Configuring RMT driver failed: %s (%s)", esp_err_to_name(this->error_code_), this->error_string_.c_str());
}
}

Expand Down
1 change: 1 addition & 0 deletions esphome/components/remote_transmitter/remote_transmitter.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class RemoteTransmitterComponent : public remote_base::RemoteTransmitterBase,
bool initialized_{false};
std::vector<rmt_item32_t> rmt_temp_;
esp_err_t error_code_{ESP_OK};
std::string error_string_{""};
bool inverted_{false};
#endif
uint8_t carrier_duty_percent_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ void RemoteTransmitterComponent::dump_config() {
}

if (this->is_failed()) {
ESP_LOGE(TAG, "Configuring RMT driver failed: %s", esp_err_to_name(this->error_code_));
ESP_LOGE(TAG, "Configuring RMT driver failed: %s (%s)", esp_err_to_name(this->error_code_), this->error_string_.c_str());
}
}

Expand Down Expand Up @@ -56,6 +56,7 @@ void RemoteTransmitterComponent::configure_rmt_() {
esp_err_t error = rmt_config(&c);
if (error != ESP_OK) {
this->error_code_ = error;
this->error_string_ = "in rmt_config";
this->mark_failed();
return;
}
Expand All @@ -64,6 +65,11 @@ void RemoteTransmitterComponent::configure_rmt_() {
error = rmt_driver_install(this->channel_, 0, 0);
if (error != ESP_OK) {
this->error_code_ = error;
if (error == ESP_ERR_INVALID_STATE) {
this->error_string_ = str_sprintf("RMT channel %i is already in use by another component", this->channel_);
} else {
this->error_string_ = "in rmt_driver_install";
}
this->mark_failed();
return;
}
Expand Down

0 comments on commit 268b1e3

Please sign in to comment.