ghi-electronics / due-libraries

Demo
https://ghi-electronics.github.io/due-libraries/
0 stars 2 forks source link

Bug in Neo Python API #49

Closed ShahinHussein closed 2 months ago

ShahinHussein commented 10 months ago

Current Behavior: When using the BrainPad.Neo.SetMultiple method with HEX color codes, the colors appear to be incorrectly encoded. For example, setting [0xFF0000] results in green instead of red, and [0x00FF00] results in red instead of green.

Expected Behavior: The colors should be encoded accurately according to the provided HEX codes.

colors = [0xFF0000] * 1
BrainPad.Neo.SetMultiple(0, colors)
# Expected: Red
# Actual: Green
colors = [0x00FF00] * 1
BrainPad.Neo.SetMultiple(0, colors)
# Expected: Green
# Actual: Red
colors = [0x0000FF] * 1
BrainPad.Neo.SetMultiple(0, colors)
# Expected: Blue
# Actual: Blue (as expected)

Proposed Solution: I have identified a potential fix by adjusting the color byte order in the SetMultiplemethod in Neo.py. The modified code snippet is as follows:

for i in range(offset, length + offset):
    data[(i - offset) * 3 + 1] = (color[i] >> 16) & 0xff    # was 3 + 0 
    data[(i - offset) * 3 + 0] = (color[i] >> 8) & 0xff     # was 3 + 1
    data[(i - offset) * 3 + 2] = (color[i] >> 0) & 0xff

I have tested this modification with various HEX colors, and it appears to resolve the issue. However, I'm not sure this is the right solution, So further review and testing by the maintainers are recommended.

Palomino34 commented 10 months ago

Most of Neo matrix on the market they are GRB instead of RGB. So the firmware does swap them already. Try on our brainbot to see, I beleive it is correct on brainbot.

Some still use RGB that why we see green and red are swapped.

Recommend test on our brainbot first.

ShahinHussein commented 10 months ago

Appreciate your input. I tested the proposed fix on BrainBot and BrainClip's ring LED, but the color issue still exists.

To align with BrainPad products, I propose making the framework adaptable to different Neo matrix color orders. Suggestions include dynamic user-configurable settings.

Seeking your guidance on the best way forward.

Best, Hussein

Palomino34 commented 2 months ago

The led panel we have seem correct. User just need to swap them if the color is swapped.