7#include "MycilaDimmer.h"
9#define MYCILA_DIMMER_PWM_RESOLUTION 12
10#define MYCILA_DIMMER_PWM_FREQUENCY 1000
23 void setPin(gpio_num_t pin) { _pin = pin; }
28 gpio_num_t
getPin()
const {
return _pin; }
33 void setFrequency(uint32_t frequency) { this->_frequency = frequency; }
43 void setResolution(uint8_t resolution) { this->_resolution = resolution; }
65 virtual const char* type()
const {
return "pwm"; }
67#ifdef MYCILA_JSON_SUPPORT
73 void toJson(
const JsonObject& root)
const override {
75 root[
"pwm_pin"] =
static_cast<int>(_pin);
76 root[
"pwm_frequency"] = _frequency;
77 root[
"pwm_resolution"] = _resolution;
82 virtual bool _apply()
override {
84 return ledcWrite(_pin, 0);
86 uint32_t duty = _dutyCycleFire * ((1 << _resolution) - 1);
87 return ledcWrite(_pin, duty);
90 virtual bool _calculateHarmonics(
float* array,
size_t n)
const override {
91 return _calculatePhaseControlHarmonics(_dutyCycleFire, array, n);
95 gpio_num_t _pin = GPIO_NUM_NC;
96 uint32_t _frequency = MYCILA_DIMMER_PWM_FREQUENCY;
97 uint8_t _resolution = MYCILA_DIMMER_PWM_RESOLUTION;
PWM based dimmer implementation for voltage regulators controlled by a PWM signal to 0-10V analog con...
void setPin(gpio_num_t pin)
Set the GPIO pin to use for the dimmer.
void setResolution(uint8_t resolution)
Set the PWM resolution in bits.
void setFrequency(uint32_t frequency)
Set the PWM frequency in Hz.
virtual void begin()
Enable a dimmer on a specific GPIO pin.
uint8_t getResolution() const
Get the PWM resolution in bits.
gpio_num_t getPin() const
Get the GPIO pin used for the dimmer.
virtual void end()
Disable the dimmer.
uint32_t getFrequency() const
Get the PWM frequency in Hz.