From 054a9a5ea7b02e596d1835e7097f2e0df41fa121 Mon Sep 17 00:00:00 2001 From: Max Prokhorov Date: Sat, 7 Sep 2019 13:07:36 +0300 Subject: [PATCH] lights: fix kelvin/mired const naming --- code/espurna/config/general.h | 23 ++++++++++------------- code/espurna/light.h | 8 ++++---- code/espurna/light.ino | 14 +++++++------- 3 files changed, 21 insertions(+), 24 deletions(-) diff --git a/code/espurna/config/general.h b/code/espurna/config/general.h index 41480d64..592ecc32 100644 --- a/code/espurna/config/general.h +++ b/code/espurna/config/general.h @@ -1188,20 +1188,22 @@ // Home Assistant also uses these, see Light::min_mireds, Light::max_mireds // https://github.com/home-assistant/home-assistant/blob/dev/homeassistant/components/light/__init__.py -#ifndef LIGHT_MIN_KELVIN -#define LIGHT_MIN_KELVIN 2000 +// Used when LIGHT_USE_WHITE AND LIGHT_USE_CCT is 1 - (1000000/Kelvin = MiReds) +// Warning! Don't change this yet, NOT FULLY IMPLEMENTED! +#ifndef LIGHT_COLDWHITE_MIRED +#define LIGHT_COLDWHITE_MIRED 153 // Coldwhite Strip, Value must be __BELOW__ W2!! (Default: 6535 Kelvin/153 MiRed) #endif -#ifndef LIGHT_MAX_KELVIN -#define LIGHT_MAX_KELVIN 6536 +#ifndef LIGHT_WARMWHITE_MIRED +#define LIGHT_WARMWHITE_MIRED 500 // Warmwhite Strip, Value must be __ABOVE__ W1!! (Default: 2000 Kelvin/500 MiRed) #endif -#ifndef LIGHT_MIN_MIREDS -#define LIGHT_MIN_MIREDS 153 +#ifndef LIGHT_COLDWHITE_KELVIN +#define LIGHT_COLDWHITE_KELVIN 6536 #endif -#ifndef LIGHT_MAX_MIREDS -#define LIGHT_MAX_MIREDS 500 +#ifndef LIGHT_WARMWHITE_KELVIN +#define LIGHT_WARMWHITE_KELVIN 2000 #endif #ifndef LIGHT_STEP @@ -1220,11 +1222,6 @@ #define LIGHT_USE_CCT 0 // Use the 5th channel as Coldwhite LEDs, LIGHT_USE_WHITE must be 1. #endif -// Used when LIGHT_USE_WHITE AND LIGHT_USE_CCT is 1 - (1000000/Kelvin = MiReds) -// Warning! Don't change this yet, NOT FULLY IMPLEMENTED! -#define LIGHT_COLDWHITE_MIRED 153 // Coldwhite Strip, Value must be __BELOW__ W2!! (Default: 6535 Kelvin/153 MiRed) -#define LIGHT_WARMWHITE_MIRED 500 // Warmwhite Strip, Value must be __ABOVE__ W1!! (Default: 2000 Kelvin/500 MiRed) - #ifndef LIGHT_USE_GAMMA #define LIGHT_USE_GAMMA 0 // Use gamma correction for color channels #endif diff --git a/code/espurna/light.h b/code/espurna/light.h index 2ba4f94d..464a791d 100644 --- a/code/espurna/light.h +++ b/code/espurna/light.h @@ -13,11 +13,11 @@ namespace Light { // Default to the Philips Hue value that HA also use. // https://developers.meethue.com/documentation/core-concepts - constexpr const unsigned int MIREDS_MIN = LIGHT_MIN_MIREDS; - constexpr const unsigned int MIREDS_MAX = LIGHT_MAX_MIREDS; + constexpr const unsigned int MIREDS_COLDWHITE = LIGHT_COLDWHITE_MIRED; + constexpr const unsigned int MIREDS_WARMWHITE = LIGHT_WARMWHITE_MIRED; - constexpr const unsigned int KELVIN_MIN = LIGHT_MIN_KELVIN; - constexpr const unsigned int KELVIN_MAX = LIGHT_MAX_KELVIN; + constexpr const unsigned int KELVIN_WARMWHITE = LIGHT_WARMWHITE_KELVIN; + constexpr const unsigned int KELVIN_COLDWHITE = LIGHT_COLDWHITE_KELVIN; constexpr const unsigned int PWM_MIN = LIGHT_MIN_PWM; constexpr const unsigned int PWM_MAX = LIGHT_MAX_PWM; diff --git a/code/espurna/light.ino b/code/espurna/light.ino index 264be0b8..f2144ac2 100644 --- a/code/espurna/light.ino +++ b/code/espurna/light.ino @@ -51,7 +51,7 @@ bool _light_use_cct = false; bool _light_use_gamma = false; unsigned long _light_steps_left = 1; unsigned char _light_brightness = Light::BRIGHTNESS_MAX; -unsigned int _light_mireds = lround((LIGHT_COLDWHITE_MIRED+LIGHT_WARMWHITE_MIRED)/2); +unsigned int _light_mireds = lround((Light::MIREDS_COLDWHITE + Light::MIREDS_WARMWHITE) / 2); using light_brightness_func_t = void(); light_brightness_func_t* _light_brightness_func = nullptr; @@ -135,7 +135,7 @@ void _lightApplyBrightnessColor() { if (_light_use_cct) { // This change the range from 153-500 to 0-347 so we get a value between 0 and 1 in the end. - double miredFactor = ((double) _light_mireds - (double) LIGHT_COLDWHITE_MIRED)/((double) LIGHT_WARMWHITE_MIRED - (double) LIGHT_COLDWHITE_MIRED); + double miredFactor = ((double) _light_mireds - (double) Light::MIREDS_COLDWHITE)/((double) Light::MIREDS_WARMWHITE - (double) Light::MIREDS_COLDWHITE); // set cold white _light_channel[3].inputValue = 0; @@ -281,7 +281,7 @@ void _fromHSV(const char * hsv) { double f = (h - floor(h)); double s = (double) value[1] / 100.0; - _light_brightness = lround((double) value[2] * (static_cast(Light::BRIGHTNESS_MAX) / 100.0)); // (255/100) + _light_brightness = lround((double) value[2] * (static_cast(Light::BRIGHTNESS_MAX) / 100.0)); // (default 255/100) unsigned char p = lround(Light::VALUE_MAX * (1.0 - s)); unsigned char q = lround(Light::VALUE_MAX * (1.0 - s * f)); unsigned char t = lround(Light::VALUE_MAX * (1.0 - s * (1.0 - f))); @@ -319,10 +319,10 @@ void _fromKelvin(unsigned long kelvin) { if(!_light_use_cct) return; - _light_mireds = constrain(static_cast(lround(1000000UL / kelvin)), Light::MIREDS_MIN, Light::MIREDS_MAX); + _light_mireds = constrain(static_cast(lround(1000000UL / kelvin)), Light::MIREDS_COLDWHITE, Light::MIREDS_WARMWHITE); // This change the range from 153-500 to 0-347 so we get a value between 0 and 1 in the end. - double factor = ((double) _light_mireds - (double) LIGHT_COLDWHITE_MIRED)/((double) LIGHT_WARMWHITE_MIRED - (double) LIGHT_COLDWHITE_MIRED); + double factor = ((double) _light_mireds - (double) Light::MIREDS_COLDWHITE)/((double) Light::MIREDS_WARMWHITE - (double) Light::MIREDS_COLDWHITE); unsigned char warm = lround(factor * Light::VALUE_MAX); unsigned char cold = lround(((double) 1.0 - factor) * Light::VALUE_MAX); @@ -331,7 +331,7 @@ void _fromKelvin(unsigned long kelvin) { return; } - _light_mireds = constrain(static_cast(lround(1000000UL / kelvin)), Light::MIREDS_MIN, Light::MIREDS_MAX); + _light_mireds = constrain(static_cast(lround(1000000UL / kelvin)), Light::MIREDS_COLDWHITE, Light::MIREDS_WARMWHITE); if (_light_use_cct) { _setRGBInputValue(Light::VALUE_MAX, Light::VALUE_MAX, Light::VALUE_MAX); @@ -358,7 +358,7 @@ void _fromKelvin(unsigned long kelvin) { // Color temperature is measured in mireds (kelvin = 1e6/mired) void _fromMireds(unsigned long mireds) { - unsigned long kelvin = constrain(static_cast(1000000UL / mireds), Light::KELVIN_MIN, Light::KELVIN_MAX); + unsigned long kelvin = constrain(static_cast(1000000UL / mireds), Light::KELVIN_WARMWHITE, Light::KELVIN_COLDWHITE); _fromKelvin(kelvin); }