Skip to content

Silently accepting mismatched color tuples. #34

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

Closed
caternuson opened this issue Oct 21, 2018 · 9 comments
Closed

Silently accepting mismatched color tuples. #34

caternuson opened this issue Oct 21, 2018 · 9 comments
Assignees

Comments

@caternuson
Copy link
Contributor

Should we be silently accepting color tuples that don't match pixel order?
Give an RGB a 4 tuple, no errors:

Adafruit CircuitPython 3.0.3 on 2018-10-10; Adafruit Gemma M0 with samd21e18
>>> import board, neopixel
>>> pixels = neopixel.NeoPixel(board.A2, 8, pixel_order=neopixel.RGB)
>>> pixels[0] = (255,0,0,255)
>>> pixels.fill((255,0,0,255))

Give a RGBW a 3 tuple, no errors:

Adafruit CircuitPython 3.0.3 on 2018-10-10; Adafruit Gemma M0 with samd21e18
>>> import board, neopixel
>>> pixels = neopixel.NeoPixel(board.A2, 8, pixel_order=neopixel.RGBW)
>>> pixels[0] = (255,0,0)
>>> pixels.fill((255,0,0))

In both cases, all zeros get sent out instead. See here:
https://github.com/adafruit/Adafruit_CircuitPython_NeoPixel/blob/master/neopixel.py#L145

@kattni
Copy link
Contributor

kattni commented Oct 21, 2018

No, we should not. Seems like having that be caught and return an error would be super helpful.

@caternuson
Copy link
Contributor Author

The possible combinations can be summarized as:

Input RGB NeoPixels RGBW NeoPixels
24 bit int OK automagic
32 bit int ? ?
3 tuple OK ?
4 tuple ? OK

We need to decide what the behavior should be for the ?. The OK entries have obvious behavior. Nothing is currently done for 32 bit int, adding it here for completeness.

@jerryneedell
Copy link
Contributor

its a bit hard to distinguish a 32 bit int from a 24 bit int with the 8 upper bit 0.
0x00123456
vs
0x123456

@jerryneedell
Copy link
Contributor

jerryneedell commented Oct 29, 2018

so I guess you just want to reject a value with the upper nibble set for an RGB
that is
0xXX123456
will be rejected if XX non zero for the RGB case.
Is that what you have in mind?

@jerryneedell
Copy link
Contributor

never mind -- clearly I'm confused about how the ints are used.
apparently the upper 8 bits are never used. is that correct?
Should they be used for an RGBW to set W ?

@jerryneedell
Copy link
Contributor

Discussed in weekly -- plan forward:
Throw ValueError if 4-tuple fed to RGB
Throw ValueError if any bits above bit 23 are set in integer mode

If 3-tuple sent to RGBW -- set RGB values.

@caternuson
Copy link
Contributor Author

Yep. In table form:

Input RGB NeoPixels RGBW NeoPixels
24 bit int OK automagic
>24bit int ValueError ValueError
3 tuple OK W=0
4 tuple ValueError OK

@jerryneedell
Copy link
Contributor

jerryneedell commented Oct 29, 2018

Thanks! -- hopefully this is accomplished by #37 Let me know if I missed something.

@caternuson
Copy link
Contributor Author

Closing. Fixed by #37. Thanks @jerryneedell.

Possible future solution - make things super simple here, just support a 3 or 4 tuple. Move all the logic and other things to some external helper that can take various inputs/flags/etc and return the required 3 or 4 tuple.

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

No branches or pull requests

3 participants