Skip to content

Commit

Permalink
WIP Kelvin
Browse files Browse the repository at this point in the history
  • Loading branch information
Skaronator committed Apr 6, 2018
1 parent 9e1352f commit 04b23cd
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions code/espurna/light.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Expand Down Expand Up @@ -301,18 +305,12 @@ void _toHSV(char * hsv, size_t len) {

v = 100.0 * max;
if (v == 0) {

h = s = 0;

} else {

s = 100.0 * (max - min) / max;
if (s == 0) {

h = 0;

} else {

if (max == r) {
if (g >= b) {
h = 0.0 + 60.0 * (g - b) / (max - min);
Expand All @@ -325,12 +323,10 @@ void _toHSV(char * hsv, size_t len) {
h = 240.0 + 60.0 * (r - g) / (max - min);
}
}

}

// String
snprintf_P(hsv, len, PSTR("%d,%d,%d"), round(h), round(s), round(v));

}

void _toLong(char * color, size_t len, bool applyBrightness) {
Expand Down Expand Up @@ -410,7 +406,7 @@ unsigned int _toPWM(unsigned long value, bool gamma, bool reverse) {

// Returns a PWM value for the given channel 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);
}

Expand All @@ -421,7 +417,7 @@ void _shadow() {
if (_light_steps_left == 0) _light_transition_ticker.detach();

// Update 4 Channels if RGBW else 3
char channels = _light_use_white ? 4 : 3;
unsigned char channels = _getRGBChannelWidth();

// Transitions
unsigned char target;
Expand Down Expand Up @@ -475,7 +471,7 @@ void _lightProviderUpdate() {

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
if (_light_use_white) {
setSetting("ch", 3, 0);
Expand All @@ -494,7 +490,7 @@ void _lightColorRestore() {
_light_channel[i].value = getSetting("ch", i, i==0 ? 255 : 0).toInt();
}
_setWhite();

_light_brightness = getSetting("brightness", LIGHT_MAX_BRIGHTNESS).toInt();
lightUpdate(false, false);
}
Expand Down

0 comments on commit 04b23cd

Please sign in to comment.