Fixed overflow issue with getPixelColor #121
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is an update to fix the issue described here.
Describe the scope of your change:
Added (uint16_t) data type conversion to the brightness correction of the getPixelColor function so that it works properly and avoids overflow.
When the product of a channel's color value and the current brightness level is greater than 215 (i.e. the upper bound of a signed 16-bit type) the output of the function is erratic. When the product drops below 215, either due to a lower input value or a lower brightness level, the function's output behaves normally. The solution is to force an unsigned conversion.
I'm using the Arduino IDE (1.6.9) and I've verified the problem with several compilers. This change appears to fix it entirely. I've tested both the RGB and RGBW functions and haven't found any issues.
Describe any known limitations with your change:
None.
Please run any tests or examples that can exercise your modified code.
I put together a test sketch to demonstrate the problem. You can find the sketch and the output (pre and post fix) here. The test checks both RGB and RGBW strips with three separate input levels and data arrangement.
For the test the sketch was compiled to an Arduino Uno using the 1.6.9 IDE and the AVRISPmkII programmer.