Skip to content

Adding auto_write and show() #15

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

Merged
merged 1 commit into from
Nov 20, 2018
Merged

Adding auto_write and show() #15

merged 1 commit into from
Nov 20, 2018

Conversation

adammhaile
Copy link
Contributor

@kattni As discussed. Works great on my Trellis M4

@adammhaile
Copy link
Contributor Author

Hmm.... hold on this. It's faster then with auto_write, but still not as fast as my hacky implementation... looking.

@adammhaile
Copy link
Contributor Author

Ah.... darn. So the _NeoPixelArray.__setitem__ function adds nearly 10ms to a full matrix update and when I had bypassed that method earlier I of course ignored all the matrix rotation stuff.
At the very least, the changes here speed up a full update by about 5x and improving the speed lost by rotation is simply out of scope for this. But I'm also obsessive about performance for these things... so I may just continue to use my hacked set() method and not worry about it.

@@ -82,8 +83,53 @@ def __setitem__(self, index, value):
raise IndexError("Pixel assignment outside available coordinates.")

self._neopixel[offset] = value
if self._auto_write:
self.show()

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not in this case because the Trellis M4 module turns off auto_write in the Neopixel module when it's initialized. I was trying to keep that the case and therefore implemented the logic at this level.

@@ -125,7 +171,8 @@ def fill(self, color):

"""
self._neopixel.fill(color)
self._neopixel.show()
if self._auto_write:
self._neopixel.show()

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same as comment above.


trellis.pixels.auto_write = True
"""
return self._auto_write

Choose a reason for hiding this comment

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

Why not just have this be a pass thrus to the underlying neopixel object?

return self._neopixel.auto_write

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because it would break _NeoPixelArray.fill(), as noted above I was attempting to make the change with minimal modification to how _NeoPixelArray already worked.


@auto_write.setter
def auto_write(self, val):
self._auto_write = val

Choose a reason for hiding this comment

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

Same here.

self._neopixel.auto_write = val

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same as above.

@caternuson caternuson requested a review from a team November 19, 2018 16:17
@@ -62,6 +62,7 @@ def __init__(self, pin, *, width, height, rotation=0):
width, height = height, width
self._width = width
self._height = height
self._auto_write = True

Copy link

@jerryneedell jerryneedell Nov 19, 2018

Choose a reason for hiding this comment

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

If this is the desired state why not just set auto_write=True in the _init above?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because of the reasons mentioned previously. I can change it to use the Neopixel autowrite instead, I just thought this was cleaner at the time.

@adammhaile
Copy link
Contributor Author

@caternuson @jerryneedell Updated to do it the way you suggested... late last night I swear I had a better reason for not doing it that way, but upon reassessment I can't think of what it was.

@caternuson
Copy link

There may be Reasons™ why it was originally set to False. But I do not know them, so others will have to comment.

@kattni
Copy link
Contributor

kattni commented Nov 19, 2018

The _NeoPixel_Array class is based on original code that was written with this library in mind, but also written to fit an initial project specifically. I assume it was set to improve performance. Given that performance testing was done on this PR, if it performs better this way, then I don't see why we can't change auto_write in init.

@caternuson
Copy link

Thanks, I've gone ahead and signed off for my part. Looks like what I was thinking. Huge caveat though - I don't actually have this HW so can't test. Hopefully I'm not overlooking Reasons™.

@kattni
Copy link
Contributor

kattni commented Nov 19, 2018

I will test it later today. Please wait to merge until I have tested it.

Copy link
Contributor

@kattni kattni left a comment

Choose a reason for hiding this comment

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

Tested successfully! Thank you! I have a couple of suggestions.

Please see my change request below. I updated both docstrings but it was easier to do in one comment. It's a small change to show. And there's no need to explain why your auto_write example could be different.

Copy link
Contributor

@kattni kattni left a comment

Choose a reason for hiding this comment

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

Looks great! Thanks for adding this functionality!

@kattni kattni merged commit 4997633 into adafruit:master Nov 20, 2018
@kattni kattni mentioned this pull request Nov 20, 2018
tannewt pushed a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Nov 21, 2018
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

Successfully merging this pull request may close these issues.

4 participants