todbot / blink1-tool

Command-line tools and C library for blink(1) USB RGB LED
https://blink1.thingm.com/
Other
84 stars 15 forks source link

Either hsbtorgb has a problem or I'm completely confused #75

Closed profburke closed 2 months ago

profburke commented 2 months ago

Hi Tod,

I'm finally getting round to making some updates to my Lua bindings for blink1-lib and I was working on wrapping the hsb to rgb conversion. Now as I understand the color model, hue can be any number between 0 and 360. But in the code it's represented as a uint8_t. So unless I'm missing a trick in the algorithm, I think the algorithm is incorrect.

I'm working on adapting some code from https://blog.adafruit.com/2012/03/14/constant-brightness-hsb-to-rgb-algorithm/ that represents hue with a uint16_t. As soon as I get that implemented and tested, I can open up a PR if you'd like.

Regards,

Matt

profburke commented 2 months ago

Ok, after experimenting with the Adafruit algorithm, I see the problem, it doesn't actually use the 0-360, 0-100, 0-100 ranges that the model calls for. I wonder if it might be worth rewriting blink1-tool to map the user supplied values from those ranges to 0-255.

For example, if I run blink1-tool --hsb 0,100,100 I don't get the bright red I'm expecting since the 100% saturation I think I'm specifying is really less than 50%. Similarly blink1-tool --hsb 355,100,100 -- which also should be bright red, is actually giving me dull greenish-blue.

The alternative (simpler) is to add to the help text to clarify what the expected ranges are.