Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add brightness control #14

Merged
merged 5 commits into from
Jan 4, 2015
Merged

Add brightness control #14

merged 5 commits into from
Jan 4, 2015

Conversation

TwP
Copy link
Contributor

@TwP TwP commented Dec 19, 2014

The arduino library for neo pixels is quite nice in that it has a brightness control. This is a simple scaling that is applied to each pixel to control the overall luminosity of the pixel. This is an implementation of brightness for the raspberry pi library.

The leds array for the channel is unaffected by these changes. The brightness scaling is applied to each led as the colors are rendered to the PWM channel.

(channel->leds[i] >> 0) & 0xff, // blue
(((channel->leds[i] >> 8) & 0xff) * scale) >> 8, // green
(((channel->leds[i] >> 16) & 0xff) * scale) >> 8, // red
(((channel->leds[i] >> 0) & 0xff) * scale) >> 8, // blue
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI - this is an adaptation of the python scaling code which is, in turn, an adaptation of the original Adafruit arduino scaling code. So I'm merely standing on the shoulders of my predecessors.

@jgarff
Copy link
Owner

jgarff commented Dec 20, 2014

Looks good. I like the algorithm, it's clever. I'm only really concerned with users that assume full brightness as the default. I think the python examples would do this if not changed. If I understand the changeset correctly, the LEDs will most likely remain dark if they didn't initialize the brightness.

@TwP
Copy link
Contributor Author

TwP commented Dec 20, 2014

Correct, the LEDs will be dark unless the brightness is explicitly set to a value other than zero. This is a backwards incompatible change; existing code will need to be updated in order to continue functioning properly.

Unfortunately there is not a good work around for this scenario. If the ws2811_init method sets the brightness to 255, then it could very well overwrite a value the user set when they initially configured the ws2811_channel_t structure.

@TwP
Copy link
Contributor Author

TwP commented Dec 20, 2014

Another note. I did not update the python code at all. Let me do that before merging in this PR.

@jgarff
Copy link
Owner

jgarff commented Dec 29, 2014

Looks good. I'll do some testing, and get this merged in. Thanks.

jgarff added a commit that referenced this pull request Jan 4, 2015
@jgarff jgarff merged commit de5a765 into jgarff:master Jan 4, 2015
Gadgetoid added a commit that referenced this pull request Jul 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants