Makuna / NeoPixelBus

An Arduino NeoPixel support library supporting a large variety of individually addressable LEDs. Please refer to the Wiki for more details. Please use the GitHub Discussions to ask questions as the GitHub Issues feature is used for bug tracking.
GNU Lesser General Public License v3.0
1.17k stars 255 forks source link

"Loop Sends" for repeating output stream on low memory builds. #771

Open sparkplug23 opened 4 months ago

sparkplug23 commented 4 months ago

Is your feature request related to a problem? Please describe. As discussed on Discord, sending the data stream multiple times to replicate the output. This would be particularly useful in low memory applications.

Describe the solution you'd like An optional parameter to enable repeating pixel buffer multiple times. Perhaps with optional arg on begin, or simply a function that should be called during runtime (similar to usage settings). Runtime config would be easier than setting it when the class is defined. Since this is an optional feature, it may just be easier (memory efficient) to keep it as a build/template option.

In my personal use of this library, when I need to maintain FPS and have large data outputs (1000+ pixels) I have introduced a "decimate" feature. For example, if I had 1000 LEDs physically connected but the effect running only calculated the first 100 internal pixels then repeated this in sequence, instead of regenerating the internal colours from the effect/palette code, I would replicate the first 100 pixels 10 times (with SetPixelColour). This case would be decimate of 10% (ie only 10% of the output needs to be calculated). You could perhaps introduce this type of feature natively in NeoPixelBus as my repeated output is essentially this feature.

Makuna commented 2 months ago

BTW, what platform are you using? I might have an alpha branch up shortly for AVR that supports this. ESP32 is next on the list.

sparkplug23 commented 2 months ago

I am mostly using esp32 these days as I work on my code, though will eventually compiling again on esp8266. I have added my own colour type into your library so it takes me some time to merge with your latest releases.

I will be able to test on the attiny85, this is what sparked this original conversation.

Makuna commented 2 months ago

This branch contains the current alpha version that builds only for AVR platforms. It should be fully compatible API; except for several things.

1) For the NeoPixelBusLg, the GetPixelColor() will return the same exact value that you called SetPixelColor() with. Most would call this an improvement.
2) The data that Pixels() points to is an array of RgbColors (or whatever the color object the feature you use). Most again would call this an improvement. 3) Most buffers will also work only in DIB (device independent bits).

The new work that addresses this issue/request, is the ability to define a "repeated pixel count" and the strip pixel count; such that the repeated pixel count will repeat across the transmitted set or truncated if its longer than the strip pixel count.

If you don't want the repeated count, you would still instance your NeoPixelBus the same old way like...

NeoPixelBusLg<NeoRgbFeature, NeoWs2812xMethod> strip(PixelCount, PixelPin);

And when you call strip.GetPixelCount() it will return PixelCount.

If you do want a repeated count, you would pass two counts bracketed in curly braces like...

NeoPixelBusLg<NeoRgbFeature, NeoWs2812xMethod> strip({RepeatedCount, PixelCount}, PixelPin);

And when you call strip.GetPixelCount() it will return RepeatedCount; while still sending out the bus a total of PixelCount.

Let me know how it works for you. I am actively working on expanding this to all supported platforms.