-
-
Notifications
You must be signed in to change notification settings - Fork 400
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
Implemented 16Bit HD108-Leds in HyperionNG #1826
base: master
Are you sure you want to change the base?
Conversation
for (const ColorRgb &color : ledValues) | ||
{ | ||
// Convert 8-bit to 16-bit colors | ||
uint16_t red16 = (color.red << 8) | color.red; |
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.
The code coverts the color values into 16 bit and later back to 8 bit. That is not necessary.
In addition, it would be more efficient already allocating the memory before updating the vector.
Potential revised code:
LedDeviceHD108::write(const std::vector &ledValues)
{
const size_t ledCount = ledValues.size();
const size_t frameSize = 8 + ledCount * 8 + (ledCount / 16 + 1);
// Reserve memory to avoid reallocations
std::vector<uint8_t> hd108Data;
hd108Data.reserve(frameSize);
// Start frame (8 bytes of 0)
hd108Data.insert(hd108Data.end(), 8, 0x00);
// Convert colors and populate buffer
for (const ColorRgb &color : ledValues)
{
// Brightness (global)
hd108Data.emplace_back(_global_brightness >> 8);
hd108Data.emplace_back(_global_brightness & 0xFF);
// Color values with proper 8-bit to 16-bit expansion
hd108Data.emplace_back(color.red); // Red
hd108Data.emplace_back(0xFF);
hd108Data.emplace_back(color.green); // Green
hd108Data.emplace_back(0xFF);
hd108Data.emplace_back(color.blue); // Blue
hd108Data.emplace_back(0xFF);
}
// End frame (at least ledCount / 16 + 1 bytes of 0xFF)
hd108Data.insert(hd108Data.end(), ledCount / 16 + 1, 0xFF);
// Send data
return writeBytes(hd108Data.size(), hd108Data.data());
}
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.
Thank you for your suggestion. I understand the intention to simplify the code; however, for the HD108 LEDs, a true 16-bit protocol is actually required. While the documentation is somewhat unclear in certain areas, practical experience has clearly shown that the hardware expects a full 16 bits for each color channel. If I were to simply set the lower 8 bits to 0xFF, I would never achieve true black, and there would always be a baseline brightness on the LEDs. This has been consistently confirmed through our long-term testing over several years.
I do appreciate your suggestion regarding early memory allocation (e.g., using reserve()) and will gladly incorporate it to further optimize the code. However, I will maintain the 16-bit scaling, as it is essential to ensure that black is truly black and to fully utilize the complete color range.
"rate": { | ||
"type": "integer", | ||
"title":"edt_dev_spec_baudrate_title", | ||
"default": 1000000, |
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.
Just to check, is that the standard default Baudrate that gives immediate success?
assets/webconfig/js/content_leds.js
Outdated
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.
Would be nice, if you could maintain the same way of indentions used in the file
@FutureMan0 Thanks for your great contribution! |
I have now implemented the changes. @Lord-Grey, could you please review the updated code? If there’s anything that still needs adjustment, feel free to let me know. The new code has also been thoroughly tested and is working as intended. |
Summary
This PR implements support for 16-bit HD108 LEDs in HyperionNG. It makes it possible to use the highspeed LEDs and adds new configuration options for HD108 LEDs.
What kind of change does this PR introduce? (check at least one)
If changing the UI of web configuration, please provide the before/after screenshot:
N/A
Does this PR introduce a breaking change? (check one)
If yes, please describe the impact and migration path for existing setups:
N/A
The PR fulfills these requirements:
Fixes: #xxx[,#xxx]
, where "xxx" is the issue number)If adding a new feature, the PR's description includes:
PLEASE DON'T FORGET TO ADD YOUR CHANGES TO CHANGELOG.MD
To avoid wasting your time, it's best to open a feature request issue first and wait for approval before working on it.
Other information:
This feature includes the following changes:
LedDeviceHD108.cpp
andLedDeviceHD108.h
for HD108 LED support.schema-hd108.json
).content_leds.js
).