7#include "MycilaDimmer.h"
8#include <driver/gptimer_types.h>
18 void setPin(gpio_num_t pin) { _pin = pin; }
23 gpio_num_t
getPin()
const {
return _pin; }
29 if (semiPeriod == 0) {
30 ESP_LOGE(
"MycilaDimmerThyristor",
"setSemiPeriod: semiPeriod must be > 0");
32 assert(semiPeriod > 0);
33 _semiPeriod = semiPeriod;
47 uint16_t
getFiringDelay()
const {
return _delay > _semiPeriod ? _semiPeriod : _delay; }
54 float getPhaseAngle()
const {
return _delay >= _semiPeriod ? 180 : 180 * _delay / _semiPeriod; }
71 virtual const char* type()
const {
return "thyristor"; }
83 static void onZeroCross(int16_t delayUntilZero,
void* args);
85#ifdef MYCILA_JSON_SUPPORT
91 void toJson(
const JsonObject& root)
const override {
93 root[
"dimmer_pin"] = _pin;
94 root[
"dimmer_semi_period"] = _semiPeriod;
101 virtual bool _apply() {
102 if (!_online || !_semiPeriod || _dutyCycleFire == 0) {
106 if (_dutyCycleFire == 1) {
110 _delay = (1.0f - _dutyCycleFire) *
static_cast<float>(_semiPeriod);
115 gpio_num_t _pin = GPIO_NUM_NC;
116 uint16_t _delay = UINT16_MAX;
118 static bool _fireTimerISR(gptimer_handle_t timer,
const gptimer_alarm_event_data_t* event,
void* arg);
119 static void _registerDimmer(Mycila::ThyristorDimmer* dimmer);
120 static void _unregisterDimmer(Mycila::ThyristorDimmer* dimmer);
gpio_num_t getPin() const
Get the GPIO pin used for the dimmer.
static void onZeroCross(int16_t delayUntilZero, void *args)
void setPin(gpio_num_t pin)
Set the GPIO pin to use for the dimmer.
uint16_t getSemiPeriod() const
Get the semi-period of the grid frequency in us.
void setSemiPeriod(uint16_t semiPeriod)
Set the semi-period of the grid frequency in us. It cannot be zero and it is required for proper dimm...
virtual void begin()
Enable a dimmer on a specific GPIO pin.
float getPhaseAngle() const
Get the phase angle in degrees (°) of the dimmer in the range [0, 180] At 0% power,...
virtual void end()
Disable the dimmer.
uint16_t getFiringDelay() const
Get the firing delay in us of the dimmer in the range [0, semi-period] At 0% power,...