Browse Source

light: configure colortemp limits from settings

master
Maxim Prokhorov 5 years ago
committed by Max Prokhorov
parent
commit
bcd2bf807f
3 changed files with 21 additions and 21 deletions
  1. +0
    -8
      code/espurna/config/general.h
  2. +0
    -8
      code/espurna/light.h
  3. +21
    -5
      code/espurna/light.ino

+ 0
- 8
code/espurna/config/general.h View File

@ -1220,14 +1220,6 @@
#define LIGHT_WARMWHITE_MIRED 500 // Warmwhite Strip, Value must be __ABOVE__ W1!! (Default: 2000 Kelvin/500 MiRed)
#endif
#ifndef LIGHT_COLDWHITE_KELVIN
#define LIGHT_COLDWHITE_KELVIN 6536
#endif
#ifndef LIGHT_WARMWHITE_KELVIN
#define LIGHT_WARMWHITE_KELVIN 2000
#endif
#ifndef LIGHT_STEP
#define LIGHT_STEP 32 // Step size
#endif


+ 0
- 8
code/espurna/light.h View File

@ -11,14 +11,6 @@ namespace Light {
constexpr const long BRIGHTNESS_MIN = LIGHT_MIN_BRIGHTNESS;
constexpr const long BRIGHTNESS_MAX = LIGHT_MAX_BRIGHTNESS;
// Default to the Philips Hue value that HA also use.
// https://developers.meethue.com/documentation/core-concepts
constexpr const long MIREDS_COLDWHITE = LIGHT_COLDWHITE_MIRED;
constexpr const long MIREDS_WARMWHITE = LIGHT_WARMWHITE_MIRED;
constexpr const long KELVIN_WARMWHITE = LIGHT_WARMWHITE_KELVIN;
constexpr const long KELVIN_COLDWHITE = LIGHT_COLDWHITE_KELVIN;
constexpr const long PWM_MIN = LIGHT_MIN_PWM;
constexpr const long PWM_MAX = LIGHT_MAX_PWM;
constexpr const long PWM_LIMIT = LIGHT_LIMIT_PWM;


+ 21
- 5
code/espurna/light.ino View File

@ -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();


Loading…
Cancel
Save