mirror of
https://github.com/esphome/esphome.git
synced 2024-12-04 04:28:19 +01:00
74aca2137b
* Add duty cycle output component * cleanup + tests * format * duty_cycle -> slow_pwm * . * clang-format * ESP_LOGD -> ESPLOGVV Co-Authored-By: Otto Winter <otto@otto-winter.com>
32 lines
790 B
C++
32 lines
790 B
C++
#pragma once
|
|
|
|
#include "esphome/core/component.h"
|
|
#include "esphome/core/esphal.h"
|
|
#include "esphome/components/output/float_output.h"
|
|
|
|
namespace esphome {
|
|
namespace slow_pwm {
|
|
|
|
class SlowPWMOutput : public output::FloatOutput, public Component {
|
|
public:
|
|
void set_pin(GPIOPin *pin) { pin_ = pin; };
|
|
void set_period(unsigned int period) { period_ = period; };
|
|
|
|
/// 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;
|
|
void loop() override;
|
|
|
|
GPIOPin *pin_;
|
|
float state_{0};
|
|
unsigned int period_start_time_{0};
|
|
unsigned int period_{5000};
|
|
};
|
|
|
|
} // namespace slow_pwm
|
|
} // namespace esphome
|