Skip to content

Add first and count params to fill #13

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

igrek-xavier
Copy link

  • allows fill to control all or part of a led strip
  • inspired from Adafruit Dotstar Arduino library

Xavier Carcelle added 5 commits April 11, 2025 16:15
- allows fill to control all or part of a led strip
- inspired from Adafruit Dotstar Arduino library
@dhalbert
Copy link

Thanks for your PR. This sort of functionality is available via Python array slices. Would this meet your needs? For example:

import neopixel
np = neopixel.NeoPixel(board.NEOPIXEL, 10)
np[0:7] = ((20,30,40)) *7

Any changes in the adafruit_pixelbuf API must also be made to the C version of this library, implemented in https://github.com/adafruit/circuitpython/tree/main/shared-bindings/adafruit_pixelbuf and https://github.com/adafruit/circuitpython/tree/main/shared-module/adafruit_pixelbuf. So we are careful to limit the API changes.

@igrek-xavier
Copy link
Author

Thanks for your PR. This sort of functionality is available via Python array slices. Would this meet your needs? For example:

Dear @dhalbert thanks for your prompt reply and your pointer.
Actually I am using Dotstar 144 LEDs strip controlled with Adafruit_CircuitPython_Dotstar library.
Adafruit_CircuitPython_Dotstar calls Pixelbuf class where fill function is limited.
By exposing fisrt and count directly in Pixelbuf, it allows simple access to this feature like in the Arduino Pixelbuf library.

import neopixel
np = neopixel.NeoPixel(board.NEOPIXEL, 10)
np[0:7] = ((20,30,40)) *7

Any changes in the adafruit_pixelbuf API must also be made to the C version of this library, implemented in https://github.com/adafruit/circuitpython/tree/main/shared-bindings/adafruit_pixelbuf and https://github.com/adafruit/circuitpython/tree/main/shared-module/adafruit_pixelbuf. So we are careful to limit the API changes.

I have been using the same logic than in the Arduino C++ library to be exactly similar to the existing API so I was hoping it should not impact too much the API ?

Much thanks for your support.

@igrek-xavier
Copy link
Author

Dear @dhalbert in order to accept my PR, do you need also to modify the API CPP pixelbuf shared and bindings modules ? Can I help on this one if necessary ? Much thanks

@dhalbert
Copy link

dhalbert commented Apr 15, 2025

@igrek-xavier Yes, adding to the C API would be necessary, and there may or may not be room for the additional C API on some boards that include the C version.

Suppose you just added this function to your code (choose whatever name you want):

def fancy_fill(pixelbuf, value, start, count):
    pixelbuf[start: start+count] = (value,) * count

Would that be sufficiently convenient? Default args could be added.

I don't mean to sound negative, but this particular library (and the corresponding C library) we try to keep small so it can run on many boards, even those with minimal RAM and firmware space.

@igrek-xavier
Copy link
Author

igrek-xavier commented Apr 15, 2025

@dhalbert thanks for your reply and you have a better vision of the whole CircuitPython support for all boards than I have.
I was trying to help to unify the fill feature for Arduino (C) and the CircuitPython one to have the same support when driving LED strips as I observed a difference of performance if using fill or making my own fill with the kind of own function you proposed.
I will live with the hack of the Pixelbuf class which is the simplest and most efficient in term of performances here.
Keeping many boards support is important and firmware/RAM space also but allowing new features in the hand of users and developers look great to allow more and more people to use CircuitPython. If you feel I can help to add this support with help in the C API, I will be willing to help.

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.

2 participants