Skip to content
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

LED Indices / Groups #36

Merged
merged 6 commits into from
Jan 14, 2025
Merged

LED Indices / Groups #36

merged 6 commits into from
Jan 14, 2025

Conversation

dmadison
Copy link
Owner

This PR rewrites the code to use LED indices and channels rather than the raw pointer. That should solve any strange issues caused by violating strict aliasing (i.e. accessing the LED data via memory pointer rather than via the struct members).

I've also added a "grouping" feature, which will distribute LED data if the received amount is a factor of the number of LEDs in the strip. For example, if there are 80 LEDs in the strip and data for 40 LEDs is received, the data will be copied so that the entire strip is lit, with each virtual LED mapped to groups of 2 physical LEDs. Receiving 20 LEDs will map to groups of 4, 10 LEDs to groups of 8, 5 LEDs to groups of 16, etc. etc.

For setups with a lot of LEDs this allows you to send less data to the device, increasing throughput and therefore framerate at the expense of resolution. This is disabled by default, and can be enabled by uncommenting the relevant define.

This also includes a few minor changes to clean up the code a bit: removing a few global variables, some redundant macros, and more flexible timekeeping definitions.

Handling this locally in each function, with a function pointer to simplify changing the timing function.
Makes it easier to change the timebase if the timing function changes.
The Arduino high/low work fine, and are more precise
Cleaner to pass the value of the current byte around rather than saving it persistently
The original implementation violates strict aliasing. It works most of the time but can potentially cause issues.

Note that the LED index counters are 32-bit instead of 16-bit because the LED count provided by the checksum has a +1, so it will not fit in a 16-bit variable.

Similarly, we need to track both the current LED index and the remaining LEDs to write because the size of the LED strip in the code may not match the size of the LED strip as set by the data protocol.
@dmadison dmadison merged commit ef46994 into master Jan 14, 2025
8 checks passed
@dmadison dmadison deleted the groups branch January 14, 2025 23:57
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.

1 participant