Closed rhooper closed 4 years ago
Why do we want this? Usually we only have buffers passed in if the object is short lived. Neopixel is long lived so it seems like we don't need this.
I don't know if we do. There might be something about #65 and what @sta-c0000 is doing that's worth supporting directly in NeoPixel, or if we should document how to use _pixelbuf with neopixel_write directly instead? This PR can be discarded if we don't want to support direct .buf updates (and the https://github.com/adafruit/circuitpython/issues/2502 can also be closed).
Hey @rhooper fwiw I tried this patch on my local and i still get the error:
Traceback (most recent call last):
File "zzz.py", line 6, in <module>
pixels[0] = (255, 0, 0)
File "/home/pi/.local/lib/python3.7/site-packages/adafruit_pypixelbuf.py", line 260, in __setitem__
self.show()
File "/home/pi/.local/lib/python3.7/site-packages/neopixel.py", line 163, in show
neopixel_write(self.pin, self.buf)
AttributeError: 'NeoPixel' object has no attribute 'buf'
My code:
import board
import neopixel
pixels = neopixel.NeoPixel(board.D18, 8)
pixels[0] = (255, 0, 0)
pixels.fill((0, 255, 0))
Shouldn't you warn the users when you make these kind of changes? Im having the same problem as @thanpolas, I also tried to use the optional_buffer but it says that the init function has no optional_buffer parameter so i don't know what to do. I really wanted to change the color of a certain number of pixels not all like the fill function and I don't know how to do it now. Can you guys help ?
@Maxternight making things break wasn't intentional. You probably don't want this PR.
You can change arbitrary pixels with something like:
import board
import neopixel
pixels = neopixel.NeoPixel(board.NEOPIXEL, 10)
pixels[0] = (255, 0, 0)
pixels[3:6] = [(255, 0, 0), (0, 0, 255), (255,255,255)]
print(pixels)
which would set the first and 4th, 5th, and 6th pixels
@Maxternight @thanpolas hi i just pushed a fix, please reinstall adafruit-circuitpython-pypixelbuf (uninstall and reinstall thru pip)
@rhooper im sorry for my comment, i know you guys work hard and sometimes some bugs can appear. It all works fine now, thank you @rhooper and @ladyada.
…in own buffers
Workaround for Issue #65