-
-
Notifications
You must be signed in to change notification settings - Fork 403
Implemented 16Bit HD108-Leds in HyperionNG #1826
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#include "LedDeviceHD108.h" | ||
|
||
// Constructor | ||
LedDeviceHD108::LedDeviceHD108(const QJsonObject &deviceConfig) | ||
: ProviderSpi(deviceConfig) | ||
{ | ||
// Overwrite non supported/required features | ||
_latchTime_ms = 0; | ||
// Initialize _global_brightness | ||
_global_brightness = 0xFFFF; | ||
} | ||
|
||
LedDevice* LedDeviceHD108::construct(const QJsonObject &deviceConfig) | ||
{ | ||
return new LedDeviceHD108(deviceConfig); | ||
} | ||
|
||
// Initialization method | ||
bool LedDeviceHD108::init(const QJsonObject &deviceConfig) | ||
{ | ||
bool isInitOK = false; | ||
|
||
if ( ProviderSpi::init(deviceConfig) ) | ||
{ | ||
_brightnessControlMaxLevel = deviceConfig["brightnessControlMaxLevel"].toInt(HD108_BRIGHTNESS_MAX_LEVEL); | ||
Info(_log, "[%s] Setting maximum brightness to [%d] = %d%%", QSTRING_CSTR(_activeDeviceType), _brightnessControlMaxLevel, _brightnessControlMaxLevel * 100 / HD108_BRIGHTNESS_MAX_LEVEL); | ||
|
||
// Set the global brightness or control byte based on the provided formula | ||
_global_brightness = (1 << 15) | (_brightnessControlMaxLevel << 10) | (_brightnessControlMaxLevel << 5) | _brightnessControlMaxLevel; | ||
|
||
isInitOK = true; | ||
} | ||
|
||
return isInitOK; | ||
} | ||
|
||
// Write method to update the LED colors | ||
int LedDeviceHD108::write(const std::vector<ColorRgb> & ledValues) | ||
{ | ||
std::vector<uint8_t> hd108Data; | ||
|
||
// Start frame - 64 bits of 0 (8 bytes of 0) | ||
hd108Data.insert(hd108Data.end(), 8, 0x00); | ||
|
||
// Adapted logic from your HD108 library's "show" and "setPixelColor8Bit" methods | ||
for (const ColorRgb &color : ledValues) | ||
{ | ||
// Convert 8-bit to 16-bit colors | ||
uint16_t red16 = (color.red << 8) | color.red; | ||
Lord-Grey marked this conversation as resolved.
Show resolved
Hide resolved
|
||
uint16_t green16 = (color.green << 8) | color.green; | ||
uint16_t blue16 = (color.blue << 8) | color.blue; | ||
|
||
// Push global and color components into hd108Data | ||
// Brightness | ||
hd108Data.push_back(_global_brightness >> 8); | ||
hd108Data.push_back(_global_brightness & 0xFF); | ||
// Color - Red | ||
hd108Data.push_back(red16 >> 8); | ||
hd108Data.push_back(red16 & 0xFF); | ||
// Color - Green | ||
hd108Data.push_back(green16 >> 8); | ||
hd108Data.push_back(green16 & 0xFF); | ||
// Color - Blue | ||
hd108Data.push_back(blue16 >> 8); | ||
hd108Data.push_back(blue16 & 0xFF); | ||
} | ||
|
||
// End frame - write "1"s equal to at least how many pixels are in the string | ||
hd108Data.insert(hd108Data.end(), ledValues.size() / 16 + 1, 0xFF); | ||
|
||
// Use ProviderSpi's writeBytes method to send the data | ||
return writeBytes(hd108Data.size(), hd108Data.data()); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#ifndef LEDDEVICEHD108_H | ||
#define LEDDEVICEHD108_H | ||
|
||
#include "ProviderSpi.h" | ||
|
||
/// The maximal level supported by the HD108 brightness control field, 31 | ||
const int HD108_BRIGHTNESS_MAX_LEVEL = 31; | ||
|
||
|
||
class LedDeviceHD108 : public ProviderSpi | ||
{ | ||
|
||
public: | ||
|
||
/// | ||
/// @brief Constructs an HD108 LED-device | ||
/// | ||
/// @param deviceConfig Device's configuration as JSON-Object | ||
/// | ||
explicit LedDeviceHD108(const QJsonObject &deviceConfig); | ||
|
||
/// | ||
/// @brief Constructs the LED-device | ||
/// | ||
/// @param[in] deviceConfig Device's configuration as JSON-Object | ||
/// @return LedDevice constructed | ||
/// | ||
static LedDevice* construct(const QJsonObject &deviceConfig); | ||
|
||
private: | ||
|
||
/// | ||
/// @brief Initialise the device's configuration | ||
/// | ||
/// @param[in] deviceConfig the JSON device configuration | ||
/// @return True, if success | ||
/// | ||
bool init(const QJsonObject &deviceConfig) override; | ||
|
||
/// | ||
/// @brief Writes the RGB-Color values to the LEDs. | ||
/// | ||
/// @param[in] ledValues The RGB-color per LED | ||
/// @return Zero on success, else negative | ||
/// | ||
int write(const std::vector<ColorRgb> & ledValues) override; | ||
|
||
/// The brighness level. Possibile values 1 .. 31. | ||
int _brightnessControlMaxLevel; | ||
uint16_t _global_brightness; | ||
}; | ||
|
||
#endif // LEDDEVICEHD108_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
{ | ||
"type":"object", | ||
"required":true, | ||
"properties":{ | ||
"output": { | ||
"type": "string", | ||
"title":"edt_dev_spec_spipath_title", | ||
"propertyOrder" : 1 | ||
}, | ||
"rate": { | ||
"type": "integer", | ||
"title":"edt_dev_spec_baudrate_title", | ||
"default": 1000000, | ||
Lord-Grey marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"propertyOrder" : 2 | ||
}, | ||
"invert": { | ||
"type": "boolean", | ||
"title":"edt_dev_spec_invert_title", | ||
"default": false, | ||
"propertyOrder" : 3 | ||
}, | ||
"brightnessControlMaxLevel": { | ||
"type": "integer", | ||
"title":"edt_conf_color_brightness_title", | ||
"default": 31, | ||
"minimum": 1, | ||
"maximum": 31, | ||
"propertyOrder" : 4 | ||
}, | ||
"rewriteTime": { | ||
"type": "integer", | ||
"title":"edt_dev_general_rewriteTime_title", | ||
"default": 0, | ||
"append" : "edt_append_ms", | ||
"minimum": 0, | ||
"access" : "expert", | ||
"propertyOrder" : 5 | ||
} | ||
}, | ||
"additionalProperties": true | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.