MycilaJSY 13.0.0
Arduino / ESP32 library for the JSY1031, JSY-MK-163, JSY-MK-193, JSY-MK-194, JSY-MK-227, JSY-MK-229, JSY-MK-333 families single-phase and three-phase AC bidirectional meters from Shenzhen Jiansiyan Technologies Co, Ltd.
Loading...
Searching...
No Matches
Mycila::ZeroCrossDimmer Class Reference
Inheritance diagram for Mycila::ZeroCrossDimmer:
Collaboration diagram for Mycila::ZeroCrossDimmer:

Public Member Functions

void setPin (gpio_num_t pin)
 Set the GPIO pin to use for the dimmer.
gpio_num_t getPin () const
 Get the GPIO pin used for the dimmer.
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 dimmer operation.
uint16_t getSemiPeriod () const
 Get the semi-period of the grid frequency in us.
uint16_t getFiringDelay () const
 Get the firing delay in us of the dimmer in the range [0, semi-period] At 0% power, delay is equal to the semi-period: the dimmer is kept off At 100% power, the delay is 0 us: the dimmer is kept on This value is mostly used for TRIAC based dimmers but also in order to derive metrics based on the phase angle.
float getPhaseAngle () const
 Get the phase angle in degrees (°) of the dimmer in the range [0, 180] At 0% power, the phase angle is equal to 180 At 100% power, the phase angle is equal to 0.
virtual void begin ()
 Enable a dimmer on a specific GPIO pin.
virtual void end ()
 Disable the dimmer.
virtual const char * type () const
Public Member Functions inherited from Mycila::Dimmer
void setDutyCycleLimit (float limit)
 Set the power duty cycle limit of the dimmer. The duty cycle will be clamped to this limit.
void setDutyCycleMin (float min)
 Duty remapping (equivalent to Shelly Dimmer remapping feature). Useful to calibrate the dimmer when using for example a PWM signal to 0-10V analog convertor connected to a voltage regulator which is only working in a specific voltage range like 1-8V.
void setDutyCycleMax (float max)
 Duty remapping (equivalent to Shelly Dimmer remapping feature). Useful to calibrate the dimmer when using for example a PWM signal to 0-10V analog convertor connected to a voltage regulator which is only working in a specific voltage range like 1-8V.
float getDutyCycleLimit () const
 Get the power duty cycle limit of the dimmer.
float getDutyCycleMin () const
 Get the remapped "0" of the dimmer duty cycle.
float getDutyCycleMax () const
 Get the remapped "1" of the dimmer duty cycle.
void enablePowerLUT (bool enable, uint16_t semiPeriod=0)
 Enable or disable the use of power LUT for dimmer curve The power LUT provides a non-linear dimming curve that is more aligned with human perception of brightness. If disabled, a linear dimming curve will be used.
bool isPowerLUTEnabled () const
 Check if the power LUT is enabled.
uint16_t getPowerLUTSemiPeriod () const
 Get the semi-period in us used for the power LUT calculations. If LUT is disabled, returns 0.
bool isEnabled () const
 Check if the dimmer is enabled (if it was able to initialize correctly)
bool isOnline () const
 Returns true if the dimmer is marked online.
void setOnline (bool online)
 Set the online status of the dimmer.
void on ()
 Turn on the dimmer at full power.
void off ()
 Turn off the dimmer.
bool isOff () const
 Check if the dimmer is off.
bool isOn () const
 Check if the dimmer is on.
bool isOnAtFullPower () const
 Check if the dimmer is on at full power.
bool setDutyCycle (float dutyCycle)
 Set the power duty.
float getDutyCycle () const
 Get the power duty cycle configured for the dimmer by teh user.
float getDutyCycleMapped () const
 Get the remapped power duty cycle from the currently user set duty cycle.
float getDutyCycleFire () const
 Get the real firing duty cycle applied to the dimmer in the range [0, 1].

Static Public Member Functions

static void onZeroCross (int16_t delayUntilZero, void *args)

Protected Member Functions

virtual bool _apply ()

Additional Inherited Members

Static Protected Member Functions inherited from Mycila::Dimmer
static uint16_t _lookupFiringDelay (float dutyCycle, uint16_t semiPeriod)
static float _contrain (float amt, float low, float high)
Protected Attributes inherited from Mycila::Dimmer
bool _enabled = false
bool _online = false
float _dutyCycle = 0.0f
float _dutyCycleFire = 0.0f
float _dutyCycleLimit = 1.0f
float _dutyCycleMin = 0.0f
float _dutyCycleMax = 1.0f
bool _powerLUTEnabled = false
uint16_t _semiPeriod = 0

Detailed Description

Definition at line 11 of file MycilaDimmerZeroCross.h.

Constructor & Destructor Documentation

◆ ~ZeroCrossDimmer()

virtual Mycila::ZeroCrossDimmer::~ZeroCrossDimmer ( )
inlinevirtual

Definition at line 13 of file MycilaDimmerZeroCross.h.

Member Function Documentation

◆ _apply()

virtual bool Mycila::ZeroCrossDimmer::_apply ( )
inlineprotectedvirtual

Implements Mycila::Dimmer.

Definition at line 101 of file MycilaDimmerZeroCross.h.

◆ begin()

void Mycila::ZeroCrossDimmer::begin ( )
virtual

Enable a dimmer on a specific GPIO pin.

Warning
Dimmer won't be enabled if pin is invalid
Dimmer won't be activated until the ZCD is enabled

Implements Mycila::Dimmer.

Definition at line 70 of file MycilaDimmerZeroCross.cpp.

◆ end()

void Mycila::ZeroCrossDimmer::end ( )
virtual

Disable the dimmer.

Warning
Dimmer won't be destroyed but won't turn on anymore even is a duty cycle is set.

Implements Mycila::Dimmer.

Definition at line 90 of file MycilaDimmerZeroCross.cpp.

◆ getFiringDelay()

uint16_t Mycila::ZeroCrossDimmer::getFiringDelay ( ) const
inline

Get the firing delay in us of the dimmer in the range [0, semi-period] At 0% power, delay is equal to the semi-period: the dimmer is kept off At 100% power, the delay is 0 us: the dimmer is kept on This value is mostly used for TRIAC based dimmers but also in order to derive metrics based on the phase angle.

Definition at line 47 of file MycilaDimmerZeroCross.h.

◆ getPhaseAngle()

float Mycila::ZeroCrossDimmer::getPhaseAngle ( ) const
inline

Get the phase angle in degrees (°) of the dimmer in the range [0, 180] At 0% power, the phase angle is equal to 180 At 100% power, the phase angle is equal to 0.

Definition at line 54 of file MycilaDimmerZeroCross.h.

◆ getPin()

gpio_num_t Mycila::ZeroCrossDimmer::getPin ( ) const
inline

Get the GPIO pin used for the dimmer.

Definition at line 23 of file MycilaDimmerZeroCross.h.

◆ getSemiPeriod()

uint16_t Mycila::ZeroCrossDimmer::getSemiPeriod ( ) const
inline

Get the semi-period of the grid frequency in us.

Definition at line 39 of file MycilaDimmerZeroCross.h.

◆ onZeroCross()

void ARDUINO_ISR_ATTR Mycila::ZeroCrossDimmer::onZeroCross ( int16_t delayUntilZero,
void * args )
static

Callback to be called when a zero-crossing event is detected.

  • When using MycilaPulseAnalyzer library, this callback can be registered like this:

pulseAnalyzer.onZeroCross(Mycila::Dimmer::onZeroCross);

  • When using your own ISR with the RobotDyn ZCD, you can call this method with delayUntilZero == 200 since the length of the ZCD pulse is about 400 us.
  • When using your own ISR with the ZCd from Daniel S, you can call this method with delayUntilZero == 550 since the length of the ZCD pulse is about 1100 us.

Definition at line 101 of file MycilaDimmerZeroCross.cpp.

◆ setPin()

void Mycila::ZeroCrossDimmer::setPin ( gpio_num_t pin)
inline

Set the GPIO pin to use for the dimmer.

Definition at line 18 of file MycilaDimmerZeroCross.h.

◆ setSemiPeriod()

void Mycila::ZeroCrossDimmer::setSemiPeriod ( uint16_t semiPeriod)
inline

Set the semi-period of the grid frequency in us. It cannot be zero and it is required for proper dimmer operation.

Definition at line 28 of file MycilaDimmerZeroCross.h.

◆ type()

virtual const char * Mycila::ZeroCrossDimmer::type ( ) const
inlinevirtual

Implements Mycila::Dimmer.

Definition at line 71 of file MycilaDimmerZeroCross.h.


The documentation for this class was generated from the following files: