|
|
@ -56,7 +56,16 @@ unsigned int _light_transition_time = LIGHT_TRANSITION_TIME; |
|
|
|
bool _light_dirty = false; |
|
|
|
bool _light_state = false; |
|
|
|
unsigned char _light_brightness = Light::BRIGHTNESS_MAX; |
|
|
|
unsigned int _light_mireds = lround((Light::MIREDS_COLDWHITE + Light::MIREDS_WARMWHITE) / 2); |
|
|
|
|
|
|
|
// Default to the Philips Hue value that HA also use.
|
|
|
|
// https://developers.meethue.com/documentation/core-concepts
|
|
|
|
long _light_mireds_cold = LIGHT_COLDWHITE_MIRED; |
|
|
|
long _light_mireds_warm = LIGHT_WARMWHITE_MIRED; |
|
|
|
|
|
|
|
long _light_kelvin_cold = (1000000L / _light_mireds_cold); |
|
|
|
long _light_kelvin_warm = (1000000L / _light_mireds_warm); |
|
|
|
|
|
|
|
long _light_mireds = lround((_light_mireds_cold + _light_mireds_warm) / 2L); |
|
|
|
|
|
|
|
using light_brightness_func_t = void(); |
|
|
|
light_brightness_func_t* _light_brightness_func = nullptr; |
|
|
@ -154,7 +163,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::MIREDS_COLDWHITE)/((double) Light::MIREDS_WARMWHITE - (double) Light::MIREDS_COLDWHITE); |
|
|
|
double miredFactor = ((double) _light_mireds - (double) _light_mireds_cold)/((double) _light_mireds_warm - (double) _light_mireds_cold); |
|
|
|
|
|
|
|
// set cold white
|
|
|
|
_light_channel[3].inputValue = 0; |
|
|
@ -320,11 +329,11 @@ void _fromHSV(const char * hsv) { |
|
|
|
// https://github.com/stelgenhof/AiLight
|
|
|
|
// Color temperature is measured in mireds (kelvin = 1e6/mired)
|
|
|
|
long _toKelvin(const long mireds) { |
|
|
|
return constrain(static_cast<long>(1000000L / mireds), Light::KELVIN_WARMWHITE, Light::KELVIN_COLDWHITE); |
|
|
|
return constrain(static_cast<long>(1000000L / mireds), _light_kelvin_warm, _light_kelvin_cold); |
|
|
|
} |
|
|
|
|
|
|
|
long _toMireds(const long kelvin) { |
|
|
|
return constrain(static_cast<long>(lround(1000000L / kelvin)), Light::MIREDS_COLDWHITE, Light::MIREDS_WARMWHITE); |
|
|
|
return constrain(static_cast<long>(lround(1000000L / kelvin)), _light_mireds_cold, _light_mireds_warm); |
|
|
|
} |
|
|
|
|
|
|
|
void _lightMireds(const long kelvin) { |
|
|
@ -335,7 +344,7 @@ void _lightMiredsCCT(const long kelvin) { |
|
|
|
_lightMireds(kelvin); |
|
|
|
|
|
|
|
// This change the range from 153-500 to 0-347 so we get a value between 0 and 1 in the end.
|
|
|
|
const double factor = ((double) _light_mireds - (double) Light::MIREDS_COLDWHITE)/((double) Light::MIREDS_WARMWHITE - (double) Light::MIREDS_COLDWHITE); |
|
|
|
const double factor = ((double) _light_mireds - (double) _light_mireds_cold)/((double) _light_mireds_warm - (double) _light_mireds_cold); |
|
|
|
_setCCTInputValue( |
|
|
|
lround(factor * Light::VALUE_MAX), |
|
|
|
lround(((double) 1.0 - factor) * Light::VALUE_MAX) |
|
|
@ -1270,6 +1279,13 @@ void _lightConfigure() { |
|
|
|
setSetting("useCCT", _light_use_cct); |
|
|
|
} |
|
|
|
|
|
|
|
if (_light_use_cct) { |
|
|
|
_light_mireds_cold = getSetting("lightColdMired", LIGHT_COLDWHITE_MIRED).toInt(); |
|
|
|
_light_mireds_warm = getSetting("lightWarmMired", LIGHT_WARMWHITE_MIRED).toInt(); |
|
|
|
_light_kelvin_cold = (1000000L / _light_mireds_cold); |
|
|
|
_light_kelvin_warm = (1000000L / _light_mireds_warm); |
|
|
|
} |
|
|
|
|
|
|
|
_light_use_gamma = getSetting("useGamma", LIGHT_USE_GAMMA).toInt() == 1; |
|
|
|
_light_use_transitions = getSetting("useTransitions", LIGHT_USE_TRANSITIONS).toInt() == 1; |
|
|
|
_light_transition_time = getSetting("lightTime", LIGHT_TRANSITION_TIME).toInt(); |
|
|
|