mirror of
https://github.com/esphome/esphome.git
synced 2025-10-08 12:53:45 +01:00
[remote_receiver] Add signal demodulation support on ESP32 (#8711)
Co-authored-by: Jonathan Swoboda <154711427+swoboda1337@users.noreply.github.com>
This commit is contained in:
@@ -5,6 +5,8 @@ from esphome.config_helpers import filter_source_files_from_platform
|
||||
import esphome.config_validation as cv
|
||||
from esphome.const import (
|
||||
CONF_BUFFER_SIZE,
|
||||
CONF_CARRIER_DUTY_PERCENT,
|
||||
CONF_CARRIER_FREQUENCY,
|
||||
CONF_CLOCK_RESOLUTION,
|
||||
CONF_DUMP,
|
||||
CONF_FILTER,
|
||||
@@ -149,6 +151,14 @@ CONFIG_SCHEMA = remote_base.validate_triggers(
|
||||
),
|
||||
cv.boolean,
|
||||
),
|
||||
cv.SplitDefault(CONF_CARRIER_DUTY_PERCENT, esp32=100): cv.All(
|
||||
cv.only_on_esp32,
|
||||
cv.percentage_int,
|
||||
cv.Range(min=1, max=100),
|
||||
),
|
||||
cv.SplitDefault(CONF_CARRIER_FREQUENCY, esp32="0Hz"): cv.All(
|
||||
cv.only_on_esp32, cv.frequency, cv.int_
|
||||
),
|
||||
}
|
||||
)
|
||||
.extend(cv.COMPONENT_SCHEMA)
|
||||
@@ -168,6 +178,8 @@ async def to_code(config):
|
||||
cg.add(var.set_clock_resolution(config[CONF_CLOCK_RESOLUTION]))
|
||||
if CONF_FILTER_SYMBOLS in config:
|
||||
cg.add(var.set_filter_symbols(config[CONF_FILTER_SYMBOLS]))
|
||||
cg.add(var.set_carrier_duty_percent(config[CONF_CARRIER_DUTY_PERCENT]))
|
||||
cg.add(var.set_carrier_frequency(config[CONF_CARRIER_FREQUENCY]))
|
||||
else:
|
||||
var = cg.new_Pvariable(config[CONF_ID], pin)
|
||||
|
||||
|
@@ -64,6 +64,8 @@ class RemoteReceiverComponent : public remote_base::RemoteReceiverBase,
|
||||
void set_filter_symbols(uint32_t filter_symbols) { this->filter_symbols_ = filter_symbols; }
|
||||
void set_receive_symbols(uint32_t receive_symbols) { this->receive_symbols_ = receive_symbols; }
|
||||
void set_with_dma(bool with_dma) { this->with_dma_ = with_dma; }
|
||||
void set_carrier_duty_percent(uint8_t carrier_duty_percent) { this->carrier_duty_percent_ = carrier_duty_percent; }
|
||||
void set_carrier_frequency(uint32_t carrier_frequency) { this->carrier_frequency_ = carrier_frequency; }
|
||||
#endif
|
||||
void set_buffer_size(uint32_t buffer_size) { this->buffer_size_ = buffer_size; }
|
||||
void set_filter_us(uint32_t filter_us) { this->filter_us_ = filter_us; }
|
||||
@@ -76,6 +78,8 @@ class RemoteReceiverComponent : public remote_base::RemoteReceiverBase,
|
||||
uint32_t filter_symbols_{0};
|
||||
uint32_t receive_symbols_{0};
|
||||
bool with_dma_{false};
|
||||
uint32_t carrier_frequency_{0};
|
||||
uint8_t carrier_duty_percent_{100};
|
||||
esp_err_t error_code_{ESP_OK};
|
||||
std::string error_string_{""};
|
||||
#endif
|
||||
|
@@ -72,6 +72,21 @@ void RemoteReceiverComponent::setup() {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this->carrier_frequency_ > 0 && 0 < this->carrier_duty_percent_ && this->carrier_duty_percent_ < 100) {
|
||||
rmt_carrier_config_t carrier;
|
||||
memset(&carrier, 0, sizeof(carrier));
|
||||
carrier.frequency_hz = this->carrier_frequency_;
|
||||
carrier.duty_cycle = (float) this->carrier_duty_percent_ / 100.0f;
|
||||
carrier.flags.polarity_active_low = this->pin_->is_inverted();
|
||||
error = rmt_apply_carrier(this->channel_, &carrier);
|
||||
if (error != ESP_OK) {
|
||||
this->error_code_ = error;
|
||||
this->error_string_ = "in rmt_apply_carrier";
|
||||
this->mark_failed();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
rmt_rx_event_callbacks_t callbacks;
|
||||
memset(&callbacks, 0, sizeof(callbacks));
|
||||
callbacks.on_recv_done = rmt_callback;
|
||||
@@ -111,11 +126,13 @@ void RemoteReceiverComponent::dump_config() {
|
||||
" Filter symbols: %" PRIu32 "\n"
|
||||
" Receive symbols: %" PRIu32 "\n"
|
||||
" Tolerance: %" PRIu32 "%s\n"
|
||||
" Carrier frequency: %" PRIu32 " hz\n"
|
||||
" Carrier duty: %u%%\n"
|
||||
" Filter out pulses shorter than: %" PRIu32 " us\n"
|
||||
" Signal is done after %" PRIu32 " us of no changes",
|
||||
this->clock_resolution_, this->rmt_symbols_, this->filter_symbols_, this->receive_symbols_,
|
||||
this->tolerance_, (this->tolerance_mode_ == remote_base::TOLERANCE_MODE_TIME) ? " us" : "%",
|
||||
this->filter_us_, this->idle_us_);
|
||||
this->carrier_frequency_, this->carrier_duty_percent_, this->filter_us_, this->idle_us_);
|
||||
if (this->is_failed()) {
|
||||
ESP_LOGE(TAG, "Configuring RMT driver failed: %s (%s)", esp_err_to_name(this->error_code_),
|
||||
this->error_string_.c_str());
|
||||
|
@@ -1,6 +1,8 @@
|
||||
substitutions:
|
||||
pin: GPIO2
|
||||
clock_resolution: "2000000"
|
||||
carrier_duty_percent: "25"
|
||||
carrier_frequency: "30000"
|
||||
filter_symbols: "2"
|
||||
receive_symbols: "4"
|
||||
rmt_symbols: "64"
|
||||
|
Reference in New Issue
Block a user