Browse Source

WIP Kelvin

rfm69
Niklas Wagner 6 years ago
parent
commit
04b23cd146
1 changed files with 8 additions and 12 deletions
  1. +8
    -12
      code/espurna/light.ino

+ 8
- 12
code/espurna/light.ino View File

@ -119,6 +119,10 @@ void _setWhite() {
} }
} }
//Return 4 (RGBW) or 3 (RGB)
unsigned char _getRGBChannelWidth() {
return _light_use_white ? 4 : 3;
}
void _fromLong(unsigned long value, bool brightness) { void _fromLong(unsigned long value, bool brightness) {
@ -301,18 +305,12 @@ void _toHSV(char * hsv, size_t len) {
v = 100.0 * max; v = 100.0 * max;
if (v == 0) { if (v == 0) {
h = s = 0; h = s = 0;
} else { } else {
s = 100.0 * (max - min) / max; s = 100.0 * (max - min) / max;
if (s == 0) { if (s == 0) {
h = 0; h = 0;
} else { } else {
if (max == r) { if (max == r) {
if (g >= b) { if (g >= b) {
h = 0.0 + 60.0 * (g - b) / (max - min); h = 0.0 + 60.0 * (g - b) / (max - min);
@ -325,12 +323,10 @@ void _toHSV(char * hsv, size_t len) {
h = 240.0 + 60.0 * (r - g) / (max - min); h = 240.0 + 60.0 * (r - g) / (max - min);
} }
} }
} }
// String // String
snprintf_P(hsv, len, PSTR("%d,%d,%d"), round(h), round(s), round(v)); snprintf_P(hsv, len, PSTR("%d,%d,%d"), round(h), round(s), round(v));
} }
void _toLong(char * color, size_t len, bool applyBrightness) { void _toLong(char * color, size_t len, bool applyBrightness) {
@ -410,7 +406,7 @@ unsigned int _toPWM(unsigned long value, bool gamma, bool reverse) {
// Returns a PWM value for the given channel ID // Returns a PWM value for the given channel ID
unsigned int _toPWM(unsigned char id) { unsigned int _toPWM(unsigned char id) {
bool useGamma = _light_use_gamma && _light_has_color && (id < 3);
bool useGamma = _light_use_gamma && _light_has_color && (id < _getRGBChannelWidth());
return _toPWM(_light_channel[id].shadow, useGamma, _light_channel[id].reverse); return _toPWM(_light_channel[id].shadow, useGamma, _light_channel[id].reverse);
} }
@ -421,7 +417,7 @@ void _shadow() {
if (_light_steps_left == 0) _light_transition_ticker.detach(); if (_light_steps_left == 0) _light_transition_ticker.detach();
// Update 4 Channels if RGBW else 3 // Update 4 Channels if RGBW else 3
char channels = _light_use_white ? 4 : 3;
unsigned char channels = _getRGBChannelWidth();
// Transitions // Transitions
unsigned char target; unsigned char target;
@ -475,7 +471,7 @@ void _lightProviderUpdate() {
void _lightColorSave() { void _lightColorSave() {
//TODO: Remove this once this code was in a stable release
// TODO: Remove this once this code was in a stable release
// This force set ch3 to 0 which could be not zero when you update from a old version // This force set ch3 to 0 which could be not zero when you update from a old version
if (_light_use_white) { if (_light_use_white) {
setSetting("ch", 3, 0); setSetting("ch", 3, 0);
@ -494,7 +490,7 @@ void _lightColorRestore() {
_light_channel[i].value = getSetting("ch", i, i==0 ? 255 : 0).toInt(); _light_channel[i].value = getSetting("ch", i, i==0 ? 255 : 0).toInt();
} }
_setWhite(); _setWhite();
_light_brightness = getSetting("brightness", LIGHT_MAX_BRIGHTNESS).toInt(); _light_brightness = getSetting("brightness", LIGHT_MAX_BRIGHTNESS).toInt();
lightUpdate(false, false); lightUpdate(false, false);
} }


Loading…
Cancel
Save