-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
[Neopixel] HSV2RGBW fix #5143
base: mega
Are you sure you want to change the base?
[Neopixel] HSV2RGBW fix #5143
Conversation
} else { | ||
H = H - ANGLE_240_DEG; | ||
order = BRG_ORDER; | ||
order = GBR_ORDER; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this was the only bug? (and line 426 of course)
Why change the defined values ? Are their int values '1' and '2' somewhere else used as integer values? (or stored in settings)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I only changed these values to match the changed order of the rgbw values
To use the RGB scheme for the order is actually a bit misleading in my opinion...
(huh.. now i realized i only had to change the order of the order.. nevermind. hard to explain :) )
Are their int values '1' and '2' somewhere else used as integer values? (or stored in settings)
Good question... I don't think so. Probably unnecessary.
we could also use following to save space. I asked a "friend" to optimize it 😬 (i tested it and it works) void HSV2RGBW(float H, float S, float I, int rgbw[4]) {
constexpr float d = 3.14159f / 180.0f, a = 120.0f * d, z = 240.0f * d, c = 60.0f * d;
H = fmod(H, 360) * d;
S = fmax(0, fmin(S / 100, 1));
I = fmax(0, fmin(I / 100, 1));
int o = (H < a) ? 0 : (H < z ? (H -= a, 1) : (H -= z, 2));
float x = cosf(H), y = cosf(c - H);
int r = S * I * 85 * (1 + x / y), g = S * I * 85 * (1 + (1 - x / y)), b = 0;
rgbw[3] = 255 * (1 - S) * I;
if (!o) rgbw[0] = r, rgbw[1] = g, rgbw[2] = b;
else if (o == 1) rgbw[0] = b, rgbw[1] = r, rgbw[2] = g;
else rgbw[0] = g, rgbw[1] = b, rgbw[2] = r;
} |
Not sure if the second suggested code is better as it is much harder to read and I don't like those comma separated assignment oneliners. |
src/src/Helpers/Misc.cpp
Outdated
rgbw[1] = r; | ||
rgbw[2] = g; | ||
break; | ||
case 2: // GBR_ORDER |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As you can see, removing the defines is not making it better as you literally everywhere have to comment what you mean by it.
So the define is better here as it makes the code better readable.
Some time ago I copied an existing (supposed to do a better conversion) RGB2HSV function to Good that it's now being fixed. 😸 |
I guess it is something that is rarely used by anyone.
It almost did, but as it is not a 1:1 copy, there was a bit of a mix-up. 🙂
You're right, and I agree that the compressed version doesn't really help in terms of readability. |
But i don´t know how i undo the second commit... 🤷♂️ |
With this few changes, I usually just re-edit the file(s) and commit that. |
reverting back to the state of the first commit
Just when I thought that ESPEasy has been running smoothly for quite a while now, I stumbled across this... 🙂
The colourwheel conversion didn't work as expected, because the original code wasn't adapted correctly.