ESPHome 2025.5.2
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
esp8266_pwm.h
Go to the documentation of this file.
1#pragma once
2
3#ifdef USE_ESP8266
4
6#include "esphome/core/hal.h"
9
10namespace esphome {
11namespace esp8266_pwm {
12
14 public:
15 void set_pin(InternalGPIOPin *pin) { pin_ = pin; }
18 void update_frequency(float frequency) override {
19 this->set_frequency(frequency);
20 this->write_state(this->last_output_);
21 }
22
24 void setup() override;
25 void dump_config() override;
27 float get_setup_priority() const override { return setup_priority::HARDWARE; }
28
29 protected:
30 void write_state(float state) override;
31
33 float frequency_{1000.0};
35 float last_output_{0.0};
36};
37
38template<typename... Ts> class SetFrequencyAction : public Action<Ts...> {
39 public:
42
43 void play(Ts... x) {
44 float freq = this->frequency_.value(x...);
45 this->parent_->update_frequency(freq);
46 }
47
49};
50
51} // namespace esp8266_pwm
52} // namespace esphome
53
54#endif
uint16_le_t frequency
Definition bl0942.h:6
void set_frequency(float frequency)
Definition esp8266_pwm.h:16
float get_setup_priority() const override
HARDWARE setup_priority.
Definition esp8266_pwm.h:27
void set_pin(InternalGPIOPin *pin)
Definition esp8266_pwm.h:15
void update_frequency(float frequency) override
Dynamically update frequency.
Definition esp8266_pwm.h:18
float last_output_
Cache last output level for dynamic frequency updating.
Definition esp8266_pwm.h:35
void write_state(float state) override
void setup() override
Initialize pin.
Base class for all output components that can output a variable level, like PWM.
bool state
Definition fan.h:0
const float HARDWARE
For components that deal with hardware and are very important like GPIO switch.
Definition component.cpp:18
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
uint16_t x
Definition tt21100.cpp:5