Skip to content

Make buf be the same #68

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
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions neopixel.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,11 @@ def __init__(self, pin, n, *, bpp=3, brightness=1.0, auto_write=True, pixel_orde
order[pixel_order] = order_chars[char_no]
pixel_order = ''.join(order)

super().__init__(n, bytearray(self.n * bpp),
self._buf = bytearray(self.n * bpp)
Copy link
Member

Choose a reason for hiding this comment

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

ideally we would not allocate two buffers if they are not needed - the original code only alloc'd a new buffer when brightness was < 1

self._rawbuf = bytearray(self.n * bpp)
super().__init__(n, self._buf,
brightness=brightness,
rawbuf=bytearray(self.n * bpp),
rawbuf=self._rawbuf,
byteorder=pixel_order,
auto_write=auto_write)

Expand Down Expand Up @@ -148,8 +150,23 @@ def show(self):

The colors may or may not be showing after this function returns because
it may be done asynchronously."""
neopixel_write(self.pin, self.buf)
neopixel_write(self.pin, self._buf)

def fill(self, color):
"""Colors all pixels the given ***color***."""
_pixelbuf.fill(self, color)

@property
def buf(self):
"""
Get or set the unadjusted buffer.
"""
return self._rawbuf

@buf.setter
Copy link
Member

Choose a reason for hiding this comment

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

Please don't support setting. NeoPixel_SPI and users shouldn't be doing this.

def buf(self, value):
"""
Update the unadjusted buffer.
"""
self._rawbuf[:] = value[:]
self.brightness = self.brightness # pylint: disable=attribute-defined-outside-init