sinedied / dmx-hue

:traffic_light: Art-Net node to control Philips Hue lights with DMX
MIT License
185 stars 22 forks source link

Hue API Request Randomization #17

Closed Ryan0751 closed 3 years ago

Ryan0751 commented 3 years ago

While using dmx-hue with SoundSwitch (DJ Lighting software), I noticed that for my set of Hue lights the first light in the list was being updated quite frequently, while other lights in the set were not.

I noticed that the code loops over every light by index, and issues a Hue API request to update that light.

Due to the nature of the bridge being unable to update frequently, this results in the first light being treated with priority when many lights are changing at once.

This PR creates a randomly shuffled array of light indexes for each DMX update iteration. This allows each light in the set to have it's Hue API requests processed in a more fair manner.

There must be a more efficient way to implement this (my Javascript skills are quite lacking), but in my testing the responsiveness of the lights is much better.

This is obviously performing a O(n) (n = number of lights) randomization operation per-DMX light update, which is quite poor from an efficiency perspective.

sinedied commented 3 years ago

Thanks for the contribution! I'll merge it and release a new version. 👍 An idea for a more efficient solution may be to simply offset the loop start index each iteration, that way all lights would have an equal chance to get updated over time. But random seems fair too :)