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::Dimmer Class Reference
Inheritance diagram for Mycila::Dimmer:

Data Structures

struct  Metrics

Public Member Functions

virtual void begin ()
virtual void end ()
virtual const char * type () const
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 (conduction duty cycle) applied to the dimmer in the range [0, 1].
bool calculateHarmonics (float *array, size_t n) const
virtual bool calculateMetrics (Metrics &metrics, float gridVoltage, float loadResistance) const

Protected Member Functions

virtual bool _apply ()
virtual bool _calculateHarmonics (float *array, size_t n) const

Static Protected Member Functions

static uint16_t _lookupFiringDelay (float dutyCycle, uint16_t semiPeriod)
static float _contrain (float amt, float low, float high)
static bool _calculatePhaseControlHarmonics (float dutyCycleFire, float *array, size_t n)
static bool _calculatePhaseControlMetrics (Metrics &metrics, float dutyCycleFire, float gridVoltage, float loadResistance)

Protected Attributes

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 22 of file MycilaDimmer.h.

Constructor & Destructor Documentation

◆ ~Dimmer()

virtual Mycila::Dimmer::~Dimmer ( )
inlinevirtual

Definition at line 35 of file MycilaDimmer.h.

Member Function Documentation

◆ _apply()

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

Definition at line 307 of file MycilaDimmer.h.

◆ _calculateHarmonics()

virtual bool Mycila::Dimmer::_calculateHarmonics ( float * array,
size_t n ) const
inlineprotectedvirtual

Definition at line 308 of file MycilaDimmer.h.

◆ _calculatePhaseControlHarmonics()

bool Mycila::Dimmer::_calculatePhaseControlHarmonics ( float dutyCycleFire,
float * array,
size_t n )
inlinestaticprotected

Definition at line 325 of file MycilaDimmer.h.

◆ _calculatePhaseControlMetrics()

bool Mycila::Dimmer::_calculatePhaseControlMetrics ( Metrics & metrics,
float dutyCycleFire,
float gridVoltage,
float loadResistance )
inlinestaticprotected

Definition at line 364 of file MycilaDimmer.h.

◆ _contrain()

float Mycila::Dimmer::_contrain ( float amt,
float low,
float high )
inlinestaticprotected

Definition at line 321 of file MycilaDimmer.h.

◆ _lookupFiringDelay()

uint16_t Mycila::Dimmer::_lookupFiringDelay ( float dutyCycle,
uint16_t semiPeriod )
staticprotected

Definition at line 218 of file MycilaDimmer.cpp.

◆ begin()

virtual void Mycila::Dimmer::begin ( )
inlinevirtual

◆ calculateHarmonics()

bool Mycila::Dimmer::calculateHarmonics ( float * array,
size_t n ) const
inline

Definition at line 255 of file MycilaDimmer.h.

◆ calculateMetrics()

virtual bool Mycila::Dimmer::calculateMetrics ( Metrics & metrics,
float gridVoltage,
float loadResistance ) const
inlinevirtual

Definition at line 283 of file MycilaDimmer.h.

◆ enablePowerLUT()

void Mycila::Dimmer::enablePowerLUT ( bool enable,
uint16_t semiPeriod = 0 )
inline

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.

Parameters
enable: true to enable, false to disable
semiPeriod: the semi-period of the grid frequency in us (10000 for 50Hz, 8333 for 60Hz).
Note
If false is passed, the semi-period parameter is ignored and the already set semi-period is kept unchanged.
If true is passed, the function validates that a semi-period is set or already exists:
- if a semi-period is provided (>0), it will be used
- if no semi-period is provided (0), the already set semi-period will be used (must be >0)
- if no semi-period is provided and no semi-period was set, an assertion will fail

Definition at line 109 of file MycilaDimmer.h.

◆ end()

virtual void Mycila::Dimmer::end ( )
inlinevirtual

◆ getDutyCycle()

float Mycila::Dimmer::getDutyCycle ( ) const
inline

Get the power duty cycle configured for the dimmer by teh user.

Definition at line 230 of file MycilaDimmer.h.

◆ getDutyCycleFire()

float Mycila::Dimmer::getDutyCycleFire ( ) const
inline

Get the real firing duty cycle (conduction duty cycle) applied to the dimmer in the range [0, 1].

  • At 0% power, the ratio is equal to 0.
  • At 100% power, the ratio is equal to 1.
    Returns
    The duty cycle applied on the hardware, or 0 if the dimmer is offline The firing ratio represents the actual proportion of time the dimmer is conducting power to the load within each AC cycle. It is computed based on the remapped duty cycle and eventually the power LUT if enabled.

Definition at line 245 of file MycilaDimmer.h.

◆ getDutyCycleLimit()

float Mycila::Dimmer::getDutyCycleLimit ( ) const
inline

Get the power duty cycle limit of the dimmer.

Definition at line 81 of file MycilaDimmer.h.

◆ getDutyCycleMapped()

float Mycila::Dimmer::getDutyCycleMapped ( ) const
inline

Get the remapped power duty cycle from the currently user set duty cycle.

Definition at line 235 of file MycilaDimmer.h.

◆ getDutyCycleMax()

float Mycila::Dimmer::getDutyCycleMax ( ) const
inline

Get the remapped "1" of the dimmer duty cycle.

Definition at line 91 of file MycilaDimmer.h.

◆ getDutyCycleMin()

float Mycila::Dimmer::getDutyCycleMin ( ) const
inline

Get the remapped "0" of the dimmer duty cycle.

Definition at line 86 of file MycilaDimmer.h.

◆ getPowerLUTSemiPeriod()

uint16_t Mycila::Dimmer::getPowerLUTSemiPeriod ( ) const
inline

Get the semi-period in us used for the power LUT calculations. If LUT is disabled, returns 0.

Definition at line 136 of file MycilaDimmer.h.

◆ isEnabled()

bool Mycila::Dimmer::isEnabled ( ) const
inline

Check if the dimmer is enabled (if it was able to initialize correctly).

Definition at line 145 of file MycilaDimmer.h.

◆ isOff()

bool Mycila::Dimmer::isOff ( ) const
inline

Check if the dimmer is off.

Definition at line 184 of file MycilaDimmer.h.

◆ isOn()

bool Mycila::Dimmer::isOn ( ) const
inline

Check if the dimmer is on.

Definition at line 189 of file MycilaDimmer.h.

◆ isOnAtFullPower()

bool Mycila::Dimmer::isOnAtFullPower ( ) const
inline

Check if the dimmer is on at full power.

Definition at line 194 of file MycilaDimmer.h.

◆ isOnline()

bool Mycila::Dimmer::isOnline ( ) const
inline

Returns true if the dimmer is marked online.

Definition at line 150 of file MycilaDimmer.h.

◆ isPowerLUTEnabled()

bool Mycila::Dimmer::isPowerLUTEnabled ( ) const
inline

Check if the power LUT is enabled.

Definition at line 131 of file MycilaDimmer.h.

◆ off()

void Mycila::Dimmer::off ( )
inline

Turn off the dimmer.

Definition at line 179 of file MycilaDimmer.h.

◆ on()

void Mycila::Dimmer::on ( )
inline

Turn on the dimmer at full power.

Definition at line 174 of file MycilaDimmer.h.

◆ setDutyCycle()

bool Mycila::Dimmer::setDutyCycle ( float dutyCycle)
inline

Set the power duty.

Parameters
dutyCyclethe power duty cycle in the range [0.0, 1.0]

Definition at line 201 of file MycilaDimmer.h.

◆ setDutyCycleLimit()

void Mycila::Dimmer::setDutyCycleLimit ( float limit)
inline

Set the power duty cycle limit of the dimmer. The duty cycle will be clamped to this limit.

Parameters
limitthe power duty cycle limit in the range [0.0, 1.0]

Definition at line 50 of file MycilaDimmer.h.

◆ setDutyCycleMax()

void Mycila::Dimmer::setDutyCycleMax ( float max)
inline

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.

Parameters
maxSet the new "1" value for the power duty cycle. The duty cycle in the range [0.0, 1.0] will be remapped to [min, max].

Definition at line 73 of file MycilaDimmer.h.

◆ setDutyCycleMin()

void Mycila::Dimmer::setDutyCycleMin ( float min)
inline

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.

Parameters
minSet the new "0" value for the power duty cycle. The duty cycle in the range [0.0, 1.0] will be remapped to [min, max].

Definition at line 62 of file MycilaDimmer.h.

◆ setOnline()

void Mycila::Dimmer::setOnline ( bool online)
inline

Set the online status of the dimmer.

This flag can be used to temporarily disable the dimmer when not connected to the grid

Definition at line 156 of file MycilaDimmer.h.

◆ type()

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

Definition at line 39 of file MycilaDimmer.h.

Field Documentation

◆ _dutyCycle

float Mycila::Dimmer::_dutyCycle = 0.0f
protected

Definition at line 298 of file MycilaDimmer.h.

◆ _dutyCycleFire

float Mycila::Dimmer::_dutyCycleFire = 0.0f
protected

Definition at line 299 of file MycilaDimmer.h.

◆ _dutyCycleLimit

float Mycila::Dimmer::_dutyCycleLimit = 1.0f
protected

Definition at line 300 of file MycilaDimmer.h.

◆ _dutyCycleMax

float Mycila::Dimmer::_dutyCycleMax = 1.0f
protected

Definition at line 302 of file MycilaDimmer.h.

◆ _dutyCycleMin

float Mycila::Dimmer::_dutyCycleMin = 0.0f
protected

Definition at line 301 of file MycilaDimmer.h.

◆ _enabled

bool Mycila::Dimmer::_enabled = false
protected

Definition at line 295 of file MycilaDimmer.h.

◆ _online

bool Mycila::Dimmer::_online = false
protected

Definition at line 296 of file MycilaDimmer.h.

◆ _powerLUTEnabled

bool Mycila::Dimmer::_powerLUTEnabled = false
protected

Definition at line 304 of file MycilaDimmer.h.

◆ _semiPeriod

uint16_t Mycila::Dimmer::_semiPeriod = 0
protected

Definition at line 305 of file MycilaDimmer.h.


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