1
0
mirror of https://github.com/esphome/esphome.git synced 2025-10-29 22:24:26 +00:00

rtttl player (#1171)

* rtttl player

* fixes

* Cleanup, add action, condition, etc.

* add test

* updates

* fixes

* Add better error messages

* lint
This commit is contained in:
Guillermo Ruffino
2020-07-25 12:57:11 -03:00
committed by GitHub
parent 4996967c79
commit f6e3070dd8
8 changed files with 356 additions and 6 deletions

View File

@@ -22,7 +22,7 @@ void LEDCOutput::write_state(float state) {
}
void LEDCOutput::setup() {
this->apply_frequency(this->frequency_);
this->update_frequency(this->frequency_);
this->turn_off();
// Attach pin after setting default value
ledcAttachPin(this->pin_->get_pin(), this->channel_);
@@ -50,7 +50,7 @@ optional<uint8_t> ledc_bit_depth_for_frequency(float frequency) {
return {};
}
void LEDCOutput::apply_frequency(float frequency) {
void LEDCOutput::update_frequency(float frequency) {
auto bit_depth_opt = ledc_bit_depth_for_frequency(frequency);
if (!bit_depth_opt.has_value()) {
ESP_LOGW(TAG, "Frequency %f can't be achieved with any bit depth", frequency);

View File

@@ -19,7 +19,7 @@ class LEDCOutput : public output::FloatOutput, public Component {
void set_channel(uint8_t channel) { this->channel_ = channel; }
void set_frequency(float frequency) { this->frequency_ = frequency; }
/// Dynamically change frequency at runtime
void apply_frequency(float frequency);
void update_frequency(float frequency) override;
/// Setup LEDC.
void setup() override;
@@ -45,7 +45,7 @@ template<typename... Ts> class SetFrequencyAction : public Action<Ts...> {
void play(Ts... x) {
float freq = this->frequency_.value(x...);
this->parent_->apply_frequency(freq);
this->parent_->update_frequency(freq);
}
protected: