Skip to content

Commit

Permalink
Fix per channel state on/off for lights (#830)
Browse files Browse the repository at this point in the history
  • Loading branch information
xoseperez committed May 13, 2018
1 parent 32ef595 commit bc67e93
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions code/espurna/light.ino
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,14 @@ void _generateBrightness() {
// Scale white channel to match brightness
_light_channel[3].value = constrain(_light_channel[3].value * LIGHT_WHITE_FACTOR, 0, 255);

// For the rest of channels, don't apply brightness, it is already in the inputValue:
// For the rest of channels, don't apply brightness, it is already in the target:
for (unsigned char i=4; i < _light_channel.size(); i++) {
_light_channel[i].value = _light_channel[i].inputValue;
}

} else {

// Don't apply brightness, it is already in the inputValue:
// Don't apply brightness, it is already in the target:
for (unsigned char i=0; i < _light_channel.size(); i++) {
if (_light_has_color & (i<3)) {
_light_channel[i].value = _light_channel[i].inputValue * brightness;
Expand Down Expand Up @@ -389,22 +389,28 @@ unsigned int _toPWM(unsigned char id) {
}

void _shadow() {

// Update transition ticker
_light_steps_left--;
if (_light_steps_left == 0) _light_transition_ticker.detach();

// Transitions
unsigned char target;
for (unsigned int i=0; i < _light_channel.size(); i++) {
target = _light_state ? _light_channel[i].value : 0;

target = _light_state && _light_channel[i].state ? _light_channel[i].value : 0;

if (_light_steps_left == 0) {
_light_channel[i].current = target;
} else {
double difference = (double) (target - _light_channel[i].current) / (_light_steps_left + 1);
_light_channel[i].current = _light_channel[i].current + difference;
}

_light_channel[i].shadow = _light_channel[i].current;

}

}

void _lightProviderUpdate() {
Expand Down

0 comments on commit bc67e93

Please sign in to comment.