mirror of
https://github.com/Threnklyn/esphome-dev.git
synced 2026-06-06 21:09:53 +02:00
a62b6548d2
Apparently play()/stop() etc. are not meant to be called directly by users of the class and if they're called directly that would not give the expected result for the classes that have an empty play(). Make all methods except play_complex, stop_comples and is_running protected. While there also make RemoteTransmitterActionBase::encode protected.
52 lines
1.3 KiB
C++
52 lines
1.3 KiB
C++
#pragma once
|
|
|
|
#include "esphome/core/component.h"
|
|
#include "esphome/core/esphal.h"
|
|
#include "esphome/core/automation.h"
|
|
#include "esphome/components/output/float_output.h"
|
|
|
|
namespace esphome {
|
|
namespace esp8266_pwm {
|
|
|
|
class ESP8266PWM : public output::FloatOutput, public Component {
|
|
public:
|
|
void set_pin(GPIOPin *pin) { pin_ = pin; }
|
|
void set_frequency(float frequency) { this->frequency_ = frequency; }
|
|
/// Dynamically update frequency
|
|
void update_frequency(float frequency) {
|
|
this->set_frequency(frequency);
|
|
this->write_state(this->last_output_);
|
|
}
|
|
|
|
/// Initialize pin
|
|
void setup() override;
|
|
void dump_config() override;
|
|
/// HARDWARE setup_priority
|
|
float get_setup_priority() const override { return setup_priority::HARDWARE; }
|
|
|
|
protected:
|
|
void write_state(float state) override;
|
|
|
|
GPIOPin *pin_;
|
|
float frequency_{1000.0};
|
|
/// Cache last output level for dynamic frequency updating
|
|
float last_output_{0.0};
|
|
};
|
|
|
|
template<typename... Ts> class SetFrequencyAction : public Action<Ts...> {
|
|
public:
|
|
SetFrequencyAction(ESP8266PWM *parent) : parent_(parent) {}
|
|
TEMPLATABLE_VALUE(float, frequency);
|
|
|
|
protected:
|
|
void play_(Ts... x) {
|
|
float freq = this->frequency_.value(x...);
|
|
this->parent_->update_frequency(freq);
|
|
}
|
|
|
|
ESP8266PWM *parent_;
|
|
};
|
|
|
|
} // namespace esp8266_pwm
|
|
} // namespace esphome
|