Skip to content

Commit

Permalink
More dev...
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieucarbou committed Jun 10, 2024
1 parent 2ab821f commit 4aa951b
Show file tree
Hide file tree
Showing 21 changed files with 151 additions and 77 deletions.
6 changes: 3 additions & 3 deletions data/config.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ <h1>YaSolR Configuration</h1>
const supportedConfig = {

"Output 1 Control": "TITLE",
o1_dim_limit: ["Dimmer Limiter (limit dimmer level 0-100)", "percent"],
o1_dim_limit: ["Dimmer Limiter (limit dimmer level 0-10000)", "uint"],
o1_ad_enable: ["Dimmer Automatic Control", "switch"],
o1_ab_enable: ["Bypass Automatic Control", "switch"],
o1_days: ["Bypass Week Days", "string"],
Expand All @@ -73,7 +73,7 @@ <h1>YaSolR Configuration</h1>
o1_temp_stop: ["Bypass Stop Temperature (C)", "uint"],

"Output 2 Control": "TITLE",
o2_dim_limit: ["Dimmer Limiter (limit dimmer level 0-100)", "percent"],
o2_dim_limit: ["Dimmer Limiter (limit dimmer level 0-10000)", "uint"],
o2_ad_enable: ["Dimmer Automatic Control", "switch"],
o2_ab_enable: ["Bypass Automatic Control", "switch"],
o2_days: ["Bypass Week Days", "string"],
Expand Down Expand Up @@ -204,7 +204,7 @@ <h1>YaSolR Configuration</h1>
addInputNumber(cell, key, value, 0, 255);
},
uint: function (cell, key, value, options) {
addInputNumber(cell, key, value, 0, 9999);
addInputNumber(cell, key, value, 0, 999999);
},
percent: function (cell, key, value, options) {
addInputNumber(cell, key, value, 0, 100);
Expand Down
4 changes: 2 additions & 2 deletions include/YaSolRWebsite.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ namespace YaSolR {
Card _output1DS18State = Card(&dashboard, TEMPERATURE_CARD, "Temperature", "°C");
Card _output1DimmerSlider = Card(&dashboard, SLIDER_CARD, "Dimmer Level Manual Control", "", 0, YASOLR_DIMMER_MAX_LEVEL, 1);
Card _output1DimmerSliderRO = Card(&dashboard, PROGRESS_CARD, "Dimmer Level", "", 0, YASOLR_DIMMER_MAX_LEVEL, 1);
Card _output1Bypass = Card(&dashboard, BUTTON_CARD, "Bypass Manual Control");
Card _output1Bypass = Card(&dashboard, BUTTON_CARD, "Bypass");
Card _output1BypassRO = Card(&dashboard, STATUS_CARD, "Bypass");
Card _output1Power = Card(&dashboard, ENERGY_CARD, "Power", "W");
Card _output1ApparentPower = Card(&dashboard, ENERGY_CARD, "Apparent Power", "VA");
Expand All @@ -113,7 +113,7 @@ namespace YaSolR {
Card _output2DS18State = Card(&dashboard, TEMPERATURE_CARD, "Temperature", "°C");
Card _output2DimmerSlider = Card(&dashboard, SLIDER_CARD, "Dimmer Level Manual Control", "", 0, YASOLR_DIMMER_MAX_LEVEL, 1);
Card _output2DimmerSliderRO = Card(&dashboard, PROGRESS_CARD, "Dimmer Level", "", 0, YASOLR_DIMMER_MAX_LEVEL, 1);
Card _output2Bypass = Card(&dashboard, BUTTON_CARD, "Bypass Manual Control");
Card _output2Bypass = Card(&dashboard, BUTTON_CARD, "Bypass");
Card _output2BypassRO = Card(&dashboard, STATUS_CARD, "Bypass");
Card _output2Power = Card(&dashboard, ENERGY_CARD, "Power", "W");
Card _output2ApparentPower = Card(&dashboard, ENERGY_CARD, "Apparent Power", "VA");
Expand Down
43 changes: 18 additions & 25 deletions lib/MycilaDimmer/MycilaDimmer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,14 @@
#include <MycilaLogger.h>

// #include "MycilaDimmerV1.h"
// #include "MycilaDimmerV2.h"
// #include "MycilaDimmerV3.h"

#ifndef MYCILA_DIMMER_NOT_LUT
#if MYCILA_DIMMER_MAX_LEVEL == 100
// #include "MycilaDimmerV1_100_LUT.h"
// #include "MycilaDimmerV2_100_LUT.h"
#include "MycilaDimmerV3_100_LUT.h"
#elif MYCILA_DIMMER_MAX_LEVEL == 255
// #include "MycilaDimmerV1_255_LUT.h"
// #include "MycilaDimmerV2.h"
// #include "MycilaDimmerV2_100_LUT.h"
// #include "MycilaDimmerV2_255_LUT.h"
#include "MycilaDimmerV3_255_LUT.h"
#else
#error "Invalid MYCILA_DIMMER_MAX_LEVEL"
#endif
#endif
// #include "MycilaDimmerV3.h"
#include "MycilaDimmerV3_100_LUT.h"
// #include "MycilaDimmerV3_255_LUT.h"

#define TAG "DIMMER"

Expand Down Expand Up @@ -89,7 +81,7 @@ void Mycila::Dimmer::toJson(const JsonObject& root) const {
root["vrms_230V"] = vrmsF * 230;
}

void Mycila::Dimmer::setLevel(uint8_t newLevel) {
void Mycila::Dimmer::setLevel(uint16_t newLevel) {
if (!_enabled)
return;

Expand All @@ -99,10 +91,11 @@ void Mycila::Dimmer::setLevel(uint8_t newLevel) {
if (_level == newLevel)
return;

const uint8_t oldLevel = _level;
const uint16_t oldLevel = _level;
_level = newLevel;

_dimmer->setDelay(_lookupFiringDelay(_level, Thyristor::getFrequency()));
uint16_t lutLevel = map(newLevel, 0, MYCILA_DIMMER_MAX_LEVEL, 0, MYCILA_DIMMER_LUT_SIZE);
_dimmer->setDelay(_lookupFiringDelay(lutLevel, Thyristor::getFrequency()));

if (_callback && (oldLevel == 0 || oldLevel == MYCILA_DIMMER_MAX_LEVEL || newLevel == 0 || newLevel == MYCILA_DIMMER_MAX_LEVEL))
_callback(newLevel == 0 ? DimmerLevel::OFF : (newLevel == MYCILA_DIMMER_MAX_LEVEL ? DimmerLevel::FULL : DimmerLevel::DIM));
Expand All @@ -114,19 +107,19 @@ float Mycila::Dimmer::getDimmedVoltage(float inputVrms) const {
return _level == 0 ? 0 : (_level == MYCILA_DIMMER_MAX_LEVEL ? inputVrms : inputVrms * _lookupVrmsFactor(_level, Thyristor::getFrequency()));
}

void Mycila::Dimmer::generateLUT(Print& out) {
void Mycila::Dimmer::generateLUT(Print& out, size_t lutSize) {
out.print("static const uint16_t delay50HzLUT[] PROGMEM = {");
for (size_t i = 0; i <= MYCILA_DIMMER_MAX_LEVEL; i++)
out.printf("%" PRIu16 "%s", _lookupFiringDelay(i, 50), i < MYCILA_DIMMER_MAX_LEVEL ? "," : "};\n");
for (size_t i = 0; i <= lutSize; i++)
out.printf("%" PRIu16 "%s", _lookupFiringDelay(i, 50), i < lutSize ? "," : "};\n");
out.print("static const uint16_t delay60HzLUT[] PROGMEM = {");
for (size_t i = 0; i <= MYCILA_DIMMER_MAX_LEVEL; i++)
out.printf("%" PRIu16 "%s", _lookupFiringDelay(i, 60), i < MYCILA_DIMMER_MAX_LEVEL ? "," : "};\n");
for (size_t i = 0; i <= lutSize; i++)
out.printf("%" PRIu16 "%s", _lookupFiringDelay(i, 60), i < lutSize ? "," : "};\n");
out.print("static const float vrms50HzLUT[] PROGMEM = {");
for (size_t i = 0; i <= MYCILA_DIMMER_MAX_LEVEL; i++)
out.printf("%f%s", _lookupVrmsFactor(i, 50), i < MYCILA_DIMMER_MAX_LEVEL ? "," : "};\n");
for (size_t i = 0; i <= lutSize; i++)
out.printf("%f%s", _lookupVrmsFactor(i, 50), i < lutSize ? "," : "};\n");
out.print("static const float vrms60HzLUT[] PROGMEM = {");
for (size_t i = 0; i <= MYCILA_DIMMER_MAX_LEVEL; i++)
out.printf("%f%s", _lookupVrmsFactor(i, 60), i < MYCILA_DIMMER_MAX_LEVEL ? "," : "};\n");
for (size_t i = 0; i <= lutSize; i++)
out.printf("%f%s", _lookupVrmsFactor(i, 60), i < lutSize ? "," : "};\n");
}

float Mycila::Dimmer::_delayToPhaseAngle(uint16_t delay, float frequency) {
Expand Down
11 changes: 6 additions & 5 deletions lib/MycilaDimmer/MycilaDimmer.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@

#include <functional>

#define MYCILA_DIMMER_MAX_LEVEL 100
// Dimmer goes from 0 to 10000
#define MYCILA_DIMMER_MAX_LEVEL 10000

namespace Mycila {
enum class DimmerLevel { OFF,
Expand Down Expand Up @@ -61,12 +62,12 @@ namespace Mycila {
void toJson(const JsonObject& root) const;

// Returns the dimmer level: 0 - MYCILA_DIMMER_MAX_LEVEL
uint8_t getLevel() const { return _level; }
uint16_t getLevel() const { return _level; }

// Set dimmer level: 0 - MYCILA_DIMMER_MAX_LEVEL
// Depending on the implementation, this can be a linear or non-linear dimming curve
// Example: Whether 50% means 50% power or 50% of the firing delay is implementation dependent
void setLevel(uint8_t level);
void setLevel(uint16_t level);

// Returns the current dimmer firing delay in microseconds
// At 0% power, the firing delay is equal to the semi-period (i.e. 10000 us for 50Hz, 8333 us for 60Hz)
Expand All @@ -82,11 +83,11 @@ namespace Mycila {
// This is a theoretical value. In reality, the real Vrms value will be more or less depending on the hardware and software speed.
float getDimmedVoltage(float inputVrms) const;

static void generateLUT(Print& out); // NOLINT
static void generateLUT(Print& out, size_t lutSize); // NOLINT

private:
bool _enabled = false;
uint8_t _level = 0;
uint16_t _level = 0;
gpio_num_t _pin = GPIO_NUM_NC;
DimmerLevelCallback _callback = nullptr;
Thyristor* _dimmer = nullptr;
Expand Down
2 changes: 1 addition & 1 deletion lib/MycilaDimmer/MycilaDimmerV1.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "MycilaDimmer.h"
#include <Arduino.h>

#define MYCILA_DIMMER_NOT_LUT
#define MYCILA_DIMMER_LUT_SIZE MYCILA_DIMMER_MAX_LEVEL

namespace Mycila {
namespace DimmerInternal {
Expand Down
6 changes: 4 additions & 2 deletions lib/MycilaDimmer/MycilaDimmerV1_100_LUT.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include "MycilaDimmer.h"
#include <Arduino.h>

#define MYCILA_DIMMER_LUT_SIZE 100

namespace Mycila {
namespace DimmerInternal {
static const uint16_t delay50HzLUT[] PROGMEM = {10000, 9362, 9096, 8891, 8718, 8564, 8424, 8295, 8174, 8060, 7951, 7847, 7748, 7651, 7558, 7468, 7380, 7294, 7210, 7128, 7048, 6969, 6891, 6815, 6740, 6666, 6593, 6521, 6450, 6379, 6309, 6240, 6172, 6104, 6036, 5969, 5903, 5837, 5771, 5706, 5640, 5576, 5511, 5447, 5382, 5318, 5254, 5191, 5127, 5063, 5000, 4936, 4872, 4808, 4745, 4681, 4617, 4552, 4488, 4423, 4359, 4293, 4228, 4162, 4096, 4030, 3963, 3895, 3827, 3759, 3690, 3620, 3549, 3478, 3406, 3333, 3259, 3184, 3108, 3030, 2951, 2871, 2789, 2705, 2619, 2531, 2441, 2348, 2251, 2152, 2048, 1939, 1825, 1704, 1575, 1435, 1281, 1108, 903, 637, 0};
Expand All @@ -20,7 +22,7 @@ uint16_t Mycila::Dimmer::_lookupFiringDelay(uint8_t level, float frequency) {
if (level == 0)
return 500000 / frequency; // semi-period in microseconds

if (level == MYCILA_DIMMER_MAX_LEVEL)
if (level >= MYCILA_DIMMER_LUT_SIZE)
return 0;

return frequency == 60 ? (uint16_t)pgm_read_word(&Mycila::DimmerInternal::delay60HzLUT[level]) : (uint16_t)pgm_read_word(&Mycila::DimmerInternal::delay50HzLUT[level]);
Expand All @@ -30,7 +32,7 @@ float Mycila::Dimmer::_lookupVrmsFactor(uint8_t level, float frequency) {
if (level == 0)
return 0;

if (level == MYCILA_DIMMER_MAX_LEVEL)
if (level >= MYCILA_DIMMER_LUT_SIZE)
return 1;

return frequency == 60 ? static_cast<float>(pgm_read_float(&Mycila::DimmerInternal::vrms60HzLUT[level])) : static_cast<float>(pgm_read_float(&Mycila::DimmerInternal::vrms50HzLUT[level]));
Expand Down
6 changes: 4 additions & 2 deletions lib/MycilaDimmer/MycilaDimmerV1_255_LUT.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include "MycilaDimmer.h"
#include <Arduino.h>

#define MYCILA_DIMMER_LUT_SIZE 255

namespace Mycila {
namespace DimmerInternal {
static const uint16_t delay50HzLUT[] PROGMEM = {10000, 9601, 9435, 9308, 9200, 9105, 9019, 8940, 8866, 8796, 8730, 8668, 8607, 8550, 8494, 8440, 8388, 8337, 8288, 8239, 8192, 8147, 8102, 8058, 8014, 7972, 7930, 7890, 7849, 7810, 7771, 7732, 7694, 7657, 7620, 7583, 7547, 7512, 7476, 7442, 7407, 7373, 7339, 7306, 7272, 7240, 7207, 7175, 7143, 7111, 7079, 7048, 7017, 6986, 6955, 6925, 6895, 6864, 6835, 6805, 6775, 6746, 6717, 6688, 6659, 6630, 6602, 6573, 6545, 6517, 6489, 6461, 6433, 6405, 6378, 6350, 6323, 6296, 6269, 6242, 6215, 6188, 6161, 6134, 6108, 6081, 6055, 6028, 6002, 5976, 5950, 5924, 5898, 5872, 5846, 5820, 5794, 5768, 5743, 5717, 5691, 5666, 5640, 5615, 5590, 5564, 5539, 5514, 5488, 5463, 5438, 5413, 5387, 5362, 5337, 5312, 5287, 5262, 5237, 5212, 5187, 5162, 5137, 5112, 5087, 5062, 5037, 5012, 4987, 4962, 4937, 4912, 4887, 4862, 4837, 4812, 4787, 4762, 4737, 4712, 4687, 4662, 4637, 4612, 4586, 4561, 4536, 4511, 4485, 4460, 4435, 4409, 4384, 4359, 4333, 4308, 4282, 4256, 4231, 4205, 4179, 4153, 4127, 4101, 4075, 4049, 4023, 3997, 3971, 3944, 3918, 3891, 3865, 3838, 3811, 3784, 3757, 3730, 3703, 3676, 3649, 3621, 3594, 3566, 3538, 3510, 3482, 3454, 3426, 3397, 3369, 3340, 3311, 3282, 3253, 3224, 3194, 3164, 3135, 3104, 3074, 3044, 3013, 2982, 2951, 2920, 2888, 2856, 2824, 2792, 2759, 2727, 2693, 2660, 2626, 2592, 2557, 2523, 2487, 2452, 2416, 2379, 2342, 2305, 2267, 2228, 2189, 2150, 2109, 2069, 2027, 1985, 1941, 1897, 1852, 1807, 1760, 1711, 1662, 1611, 1559, 1505, 1449, 1392, 1331, 1269, 1203, 1133, 1059, 980, 894, 799, 691, 564, 398, 0};
Expand All @@ -20,7 +22,7 @@ uint16_t Mycila::Dimmer::_lookupFiringDelay(uint8_t level, float frequency) {
if (level == 0)
return 500000 / frequency; // semi-period in microseconds

if (level == MYCILA_DIMMER_MAX_LEVEL)
if (level >= MYCILA_DIMMER_LUT_SIZE)
return 0;

return frequency == 60 ? (uint16_t)pgm_read_word(&Mycila::DimmerInternal::delay60HzLUT[level]) : (uint16_t)pgm_read_word(&Mycila::DimmerInternal::delay50HzLUT[level]);
Expand All @@ -30,7 +32,7 @@ float Mycila::Dimmer::_lookupVrmsFactor(uint8_t level, float frequency) {
if (level == 0)
return 0;

if (level == MYCILA_DIMMER_MAX_LEVEL)
if (level >= MYCILA_DIMMER_LUT_SIZE)
return 1;

return frequency == 60 ? static_cast<float>(pgm_read_float(&Mycila::DimmerInternal::vrms60HzLUT[level])) : static_cast<float>(pgm_read_float(&Mycila::DimmerInternal::vrms50HzLUT[level]));
Expand Down
2 changes: 1 addition & 1 deletion lib/MycilaDimmer/MycilaDimmerV2.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "MycilaDimmer.h"
#include <Arduino.h>

#define MYCILA_DIMMER_NOT_LUT
#define MYCILA_DIMMER_LUT_SIZE MYCILA_DIMMER_MAX_LEVEL

// level : | 0| 1| 2| 3| 4| 5| 6| 7| 8| 9| 10| 11| 12| 13| 14| 15| 16| 17| 18| 19| 20| 21| 22| 23| 24| 25| 26| 27| 28| 29| 30| 31| 32| 33| 34| 35| 36| 37| 38| 39| 40| 41| 42| 43| 44| 45| 46| 47| 48| 49| 50| 51| 52| 53| 54| 55| 56| 57| 58| 59| 60| 61| 62| 63| 64| 65| 66| 67| 68| 69| 70| 71| 72| 73| 74| 75| 76| 77| 78| 79| 80| 81| 82| 83| 84| 85| 86| 87| 88| 89| 90| 91| 92| 93| 94| 95| 96| 97| 98| 99| 100| 101| 102| 103| 104| 105| 106| 107| 108| 109| 110| 111| 112| 113| 114| 115| 116| 117| 118| 119| 120| 121| 122| 123| 124| 125| 126| 127| 128| 129| 130| 131| 132| 133| 134| 135| 136| 137| 138| 139| 140| 141| 142| 143| 144| 145| 146| 147| 148| 149| 150| 151| 152| 153| 154| 155| 156| 157| 158| 159| 160| 161| 162| 163| 164| 165| 166| 167| 168| 169| 170| 171| 172| 173| 174| 175| 176| 177| 178| 179| 180| 181| 182| 183| 184| 185| 186| 187| 188| 189| 190| 191| 192| 193| 194| 195| 196| 197| 198| 199| 200| 201| 202| 203| 204| 205| 206| 207| 208| 209| 210| 211| 212| 213| 214| 215| 216| 217| 218| 219| 220| 221| 222| 223| 224| 225| 226| 227| 228| 229| 230| 231| 232| 233| 234| 235| 236| 237| 238| 239| 240| 241| 242| 243| 244| 245| 246| 247| 248| 249| 250| 251| 252| 253| 254| 255|
// dimmable_light : |10000| 9961| 9922| 9883| 9844| 9804| 9765| 9726| 9687| 9648| 9608| 9569| 9530| 9491| 9451| 9412| 9373| 9334| 9295| 9255| 9216| 9177| 9138| 9099| 9059| 9020| 8981| 8942| 8902| 8863| 8824| 8785| 8746| 8706| 8667| 8628| 8589| 8550| 8510| 8471| 8432| 8393| 8353| 8314| 8275| 8236| 8197| 8157| 8118| 8079| 8040| 8000| 7961| 7922| 7883| 7844| 7804| 7765| 7726| 7687| 7648| 7608| 7569| 7530| 7491| 7451| 7412| 7373| 7334| 7295| 7255| 7216| 7177| 7138| 7099| 7059| 7020| 6981| 6942| 6902| 6863| 6824| 6785| 6746| 6706| 6667| 6628| 6589| 6550| 6510| 6471| 6432| 6393| 6353| 6314| 6275| 6236| 6197| 6157| 6118| 6079| 6040| 6000| 5961| 5922| 5883| 5844| 5804| 5765| 5726| 5687| 5648| 5608| 5569| 5530| 5491| 5451| 5412| 5373| 5334| 5295| 5255| 5216| 5177| 5138| 5099| 5059| 5020| 4981| 4942| 4902| 4863| 4824| 4785| 4746| 4706| 4667| 4628| 4589| 4550| 4510| 4471| 4432| 4393| 4353| 4314| 4275| 4236| 4197| 4157| 4118| 4079| 4040| 4000| 3961| 3922| 3883| 3844| 3804| 3765| 3726| 3687| 3648| 3608| 3569| 3530| 3491| 3451| 3412| 3373| 3334| 3295| 3255| 3216| 3177| 3138| 3099| 3059| 3020| 2981| 2942| 2902| 2863| 2824| 2785| 2746| 2706| 2667| 2628| 2589| 2550| 2510| 2471| 2432| 2393| 2353| 2314| 2275| 2236| 2197| 2157| 2118| 2079| 2040| 2000| 1961| 1922| 1883| 1844| 1804| 1765| 1726| 1687| 1648| 1608| 1569| 1530| 1491| 1451| 1412| 1373| 1334| 1295| 1255| 1216| 1177| 1138| 1099| 1059| 1020| 981| 942| 902| 863| 824| 785| 746| 706| 667| 628| 589| 550| 510| 471| 432| 393| 353| 314| 275| 236| 197| 157| 118| 79| 40| 0|
Expand Down
6 changes: 4 additions & 2 deletions lib/MycilaDimmer/MycilaDimmerV2_100_LUT.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include "MycilaDimmer.h"
#include <Arduino.h>

#define MYCILA_DIMMER_LUT_SIZE 100

namespace Mycila {
namespace DimmerInternal {
static const uint16_t delay50HzLUT[] PROGMEM = {10000, 9900, 9800, 9700, 9600, 9500, 9400, 9300, 9200, 9100, 9000, 8900, 8800, 8700, 8600, 8500, 8400, 8300, 8200, 8100, 8000, 7900, 7800, 7700, 7600, 7500, 7400, 7300, 7200, 7100, 7000, 6900, 6800, 6700, 6600, 6500, 6400, 6300, 6200, 6100, 6000, 5900, 5800, 5700, 5600, 5500, 5400, 5300, 5200, 5100, 5000, 4900, 4800, 4700, 4600, 4500, 4400, 4300, 4200, 4100, 4000, 3900, 3800, 3700, 3600, 3500, 3400, 3300, 3200, 3100, 3000, 2900, 2800, 2700, 2600, 2500, 2400, 2300, 2200, 2100, 2000, 1900, 1800, 1700, 1600, 1500, 1400, 1300, 1200, 1100, 1000, 900, 800, 700, 600, 500, 400, 300, 200, 100, 0};
Expand All @@ -20,7 +22,7 @@ uint16_t Mycila::Dimmer::_lookupFiringDelay(uint8_t level, float frequency) {
if (level == 0)
return 500000 / frequency; // semi-period in microseconds

if (level == MYCILA_DIMMER_MAX_LEVEL)
if (level >= MYCILA_DIMMER_LUT_SIZE)
return 0;

return frequency == 60 ? (uint16_t)pgm_read_word(&Mycila::DimmerInternal::delay60HzLUT[level]) : (uint16_t)pgm_read_word(&Mycila::DimmerInternal::delay50HzLUT[level]);
Expand All @@ -30,7 +32,7 @@ float Mycila::Dimmer::_lookupVrmsFactor(uint8_t level, float frequency) {
if (level == 0)
return 0;

if (level == MYCILA_DIMMER_MAX_LEVEL)
if (level >= MYCILA_DIMMER_LUT_SIZE)
return 1;

return frequency == 60 ? static_cast<float>(pgm_read_float(&Mycila::DimmerInternal::vrms60HzLUT[level])) : static_cast<float>(pgm_read_float(&Mycila::DimmerInternal::vrms50HzLUT[level]));
Expand Down
2 changes: 2 additions & 0 deletions lib/MycilaDimmer/MycilaDimmerV2_255_LUT.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include "MycilaDimmer.h"
#include <Arduino.h>

#define MYCILA_DIMMER_LUT_SIZE 255

namespace Mycila {
namespace DimmerInternal {
static const uint16_t delay50HzLUT[] PROGMEM = {10000, 9961, 9922, 9883, 9844, 9804, 9765, 9726, 9687, 9648, 9608, 9569, 9530, 9491, 9451, 9412, 9373, 9334, 9295, 9255, 9216, 9177, 9138, 9099, 9059, 9020, 8981, 8942, 8902, 8863, 8824, 8785, 8746, 8706, 8667, 8628, 8589, 8550, 8510, 8471, 8432, 8393, 8353, 8314, 8275, 8236, 8197, 8157, 8118, 8079, 8040, 8000, 7961, 7922, 7883, 7844, 7804, 7765, 7726, 7687, 7648, 7608, 7569, 7530, 7491, 7451, 7412, 7373, 7334, 7295, 7255, 7216, 7177, 7138, 7099, 7059, 7020, 6981, 6942, 6902, 6863, 6824, 6785, 6746, 6706, 6667, 6628, 6589, 6550, 6510, 6471, 6432, 6393, 6353, 6314, 6275, 6236, 6197, 6157, 6118, 6079, 6040, 6000, 5961, 5922, 5883, 5844, 5804, 5765, 5726, 5687, 5648, 5608, 5569, 5530, 5491, 5451, 5412, 5373, 5334, 5295, 5255, 5216, 5177, 5138, 5099, 5059, 5020, 4981, 4942, 4902, 4863, 4824, 4785, 4746, 4706, 4667, 4628, 4589, 4550, 4510, 4471, 4432, 4393, 4353, 4314, 4275, 4236, 4197, 4157, 4118, 4079, 4040, 4000, 3961, 3922, 3883, 3844, 3804, 3765, 3726, 3687, 3648, 3608, 3569, 3530, 3491, 3451, 3412, 3373, 3334, 3295, 3255, 3216, 3177, 3138, 3099, 3059, 3020, 2981, 2942, 2902, 2863, 2824, 2785, 2746, 2706, 2667, 2628, 2589, 2550, 2510, 2471, 2432, 2393, 2353, 2314, 2275, 2236, 2197, 2157, 2118, 2079, 2040, 2000, 1961, 1922, 1883, 1844, 1804, 1765, 1726, 1687, 1648, 1608, 1569, 1530, 1491, 1451, 1412, 1373, 1334, 1295, 1255, 1216, 1177, 1138, 1099, 1059, 1020, 981, 942, 902, 863, 824, 785, 746, 706, 667, 628, 589, 550, 510, 471, 432, 393, 353, 314, 275, 236, 197, 157, 118, 79, 40, 0};
Expand Down
Loading

0 comments on commit 4aa951b

Please sign in to comment.