Skip to content

Commit e2288b1

Browse files
committed
Implemented 16Bit HD108-Leds in HyperionNG
1 parent 61bfc2e commit e2288b1

File tree

5 files changed

+174
-2
lines changed

5 files changed

+174
-2
lines changed

assets/webconfig/js/content_leds.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ var bottomRight2bottomLeft = null;
1818
var bottomLeft2topLeft = null;
1919
var toggleKeystoneCorrectionArea = false;
2020

21-
var devSPI = ['apa102', 'apa104', 'ws2801', 'lpd6803', 'lpd8806', 'p9813', 'sk6812spi', 'sk6822spi', 'sk9822', 'ws2812spi'];
21+
var devSPI = ['apa102', 'apa104', 'hd108', 'lpd6803', 'lpd8806', 'p9813', 'sk6812spi', 'sk6822spi', 'sk9822', 'ws2801', 'ws2812spi'];
2222
var devFTDI = ['apa102_ftdi', 'sk6812_ftdi', 'ws2812_ftdi'];
2323
var devRPiPWM = ['ws281x'];
2424
var devRPiGPIO = ['piblaster'];
@@ -1115,6 +1115,7 @@ $(document).ready(function () {
11151115
case "ws2812spi":
11161116
case "piblaster":
11171117
case "ws281x":
1118+
case "hd108":
11181119

11191120
//Serial devices
11201121
case "adalight":
@@ -1480,6 +1481,7 @@ $(document).ready(function () {
14801481
case "apa102_ftdi":
14811482
case "sk6812_ftdi":
14821483
case "ws2812_ftdi":
1484+
case "hd108":
14831485
default:
14841486
}
14851487

@@ -1962,6 +1964,7 @@ function saveLedConfig(genDefLayout = false) {
19621964
case "apa102_ftdi":
19631965
case "sk6812_ftdi":
19641966
case "ws2812_ftdi":
1967+
case "hd108":
19651968
default:
19661969
if (genDefLayout === true) {
19671970
ledConfig = {
@@ -2219,6 +2222,7 @@ var updateOutputSelectList = function (ledType, discoveryInfo) {
22192222
case "sk6822spi":
22202223
case "sk9822":
22212224
case "ws2812spi":
2225+
case "hd108":
22222226
case "piblaster":
22232227
for (const device of discoveryInfo.devices) {
22242228
enumVals.push(device.systemLocation);

libsrc/leddevice/LedDeviceSchemas.qrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
<file alias="schema-ws2812_ftdi">schemas/schema-ws2812_ftdi.json</file>
4343
<file alias="schema-apa102_ftdi">schemas/schema-apa102_ftdi.json</file>
4444
<file alias="schema-sk6812_ftdi">schemas/schema-sk6812_ftdi.json</file>
45-
<file alias="schema-skydimo">schemas/schema-skydimo.json</file>
45+
<file alias="schema-skydimo">schemas/schema-skydimo.json</file>
46+
<file alias="schema-hd108">schemas/schema-hd108.json</file>
4647
</qresource>
4748
</RCC>
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#include "LedDeviceHD108.h"
2+
3+
// Constructor
4+
LedDeviceHD108::LedDeviceHD108(const QJsonObject &deviceConfig)
5+
: ProviderSpi(deviceConfig)
6+
{
7+
// Overwrite non supported/required features
8+
_latchTime_ms = 0;
9+
// Initialize _global_brightness
10+
_global_brightness = 0xFFFF;
11+
}
12+
13+
LedDevice* LedDeviceHD108::construct(const QJsonObject &deviceConfig)
14+
{
15+
return new LedDeviceHD108(deviceConfig);
16+
}
17+
18+
// Initialization method
19+
bool LedDeviceHD108::init(const QJsonObject &deviceConfig)
20+
{
21+
bool isInitOK = false;
22+
23+
if ( ProviderSpi::init(deviceConfig) )
24+
{
25+
_brightnessControlMaxLevel = deviceConfig["brightnessControlMaxLevel"].toInt(HD108_BRIGHTNESS_MAX_LEVEL);
26+
Info(_log, "[%s] Setting maximum brightness to [%d] = %d%%", QSTRING_CSTR(_activeDeviceType), _brightnessControlMaxLevel, _brightnessControlMaxLevel * 100 / HD108_BRIGHTNESS_MAX_LEVEL);
27+
28+
// Set the global brightness or control byte based on the provided formula
29+
_global_brightness = (1 << 15) | (_brightnessControlMaxLevel << 10) | (_brightnessControlMaxLevel << 5) | _brightnessControlMaxLevel;
30+
31+
isInitOK = true;
32+
}
33+
34+
return isInitOK;
35+
}
36+
37+
// Write method to update the LED colors
38+
int LedDeviceHD108::write(const std::vector<ColorRgb> & ledValues)
39+
{
40+
std::vector<uint8_t> hd108Data;
41+
42+
// Start frame - 64 bits of 0 (8 bytes of 0)
43+
hd108Data.insert(hd108Data.end(), 8, 0x00);
44+
45+
// Adapted logic from your HD108 library's "show" and "setPixelColor8Bit" methods
46+
for (const ColorRgb &color : ledValues)
47+
{
48+
// Convert 8-bit to 16-bit colors
49+
uint16_t red16 = (color.red << 8) | color.red;
50+
uint16_t green16 = (color.green << 8) | color.green;
51+
uint16_t blue16 = (color.blue << 8) | color.blue;
52+
53+
// Push global and color components into hd108Data
54+
// Brightness
55+
hd108Data.push_back(_global_brightness >> 8);
56+
hd108Data.push_back(_global_brightness & 0xFF);
57+
// Color - Red
58+
hd108Data.push_back(red16 >> 8);
59+
hd108Data.push_back(red16 & 0xFF);
60+
// Color - Green
61+
hd108Data.push_back(green16 >> 8);
62+
hd108Data.push_back(green16 & 0xFF);
63+
// Color - Blue
64+
hd108Data.push_back(blue16 >> 8);
65+
hd108Data.push_back(blue16 & 0xFF);
66+
}
67+
68+
// End frame - write "1"s equal to at least how many pixels are in the string
69+
hd108Data.insert(hd108Data.end(), ledValues.size() / 16 + 1, 0xFF);
70+
71+
// Use ProviderSpi's writeBytes method to send the data
72+
return writeBytes(hd108Data.size(), hd108Data.data());
73+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#ifndef LEDDEVICEHD108_H
2+
#define LEDDEVICEHD108_H
3+
4+
#include "ProviderSpi.h"
5+
6+
/// The maximal level supported by the HD108 brightness control field, 31
7+
const int HD108_BRIGHTNESS_MAX_LEVEL = 31;
8+
9+
10+
class LedDeviceHD108 : public ProviderSpi
11+
{
12+
13+
public:
14+
15+
///
16+
/// @brief Constructs an HD108 LED-device
17+
///
18+
/// @param deviceConfig Device's configuration as JSON-Object
19+
///
20+
explicit LedDeviceHD108(const QJsonObject &deviceConfig);
21+
22+
///
23+
/// @brief Constructs the LED-device
24+
///
25+
/// @param[in] deviceConfig Device's configuration as JSON-Object
26+
/// @return LedDevice constructed
27+
///
28+
static LedDevice* construct(const QJsonObject &deviceConfig);
29+
30+
private:
31+
32+
///
33+
/// @brief Initialise the device's configuration
34+
///
35+
/// @param[in] deviceConfig the JSON device configuration
36+
/// @return True, if success
37+
///
38+
bool init(const QJsonObject &deviceConfig) override;
39+
40+
///
41+
/// @brief Writes the RGB-Color values to the LEDs.
42+
///
43+
/// @param[in] ledValues The RGB-color per LED
44+
/// @return Zero on success, else negative
45+
///
46+
int write(const std::vector<ColorRgb> & ledValues) override;
47+
48+
/// The brighness level. Possibile values 1 .. 31.
49+
int _brightnessControlMaxLevel;
50+
uint16_t _global_brightness;
51+
};
52+
53+
#endif // LEDDEVICEHD108_H
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"type":"object",
3+
"required":true,
4+
"properties":{
5+
"output": {
6+
"type": "string",
7+
"title":"edt_dev_spec_spipath_title",
8+
"propertyOrder" : 1
9+
},
10+
"rate": {
11+
"type": "integer",
12+
"title":"edt_dev_spec_baudrate_title",
13+
"default": 1000000,
14+
"propertyOrder" : 2
15+
},
16+
"invert": {
17+
"type": "boolean",
18+
"title":"edt_dev_spec_invert_title",
19+
"default": false,
20+
"propertyOrder" : 3
21+
},
22+
"brightnessControlMaxLevel": {
23+
"type": "integer",
24+
"title":"edt_conf_color_brightness_title",
25+
"default": 31,
26+
"minimum": 1,
27+
"maximum": 31,
28+
"propertyOrder" : 4
29+
},
30+
"rewriteTime": {
31+
"type": "integer",
32+
"title":"edt_dev_general_rewriteTime_title",
33+
"default": 0,
34+
"append" : "edt_append_ms",
35+
"minimum": 0,
36+
"access" : "expert",
37+
"propertyOrder" : 5
38+
}
39+
},
40+
"additionalProperties": true
41+
}

0 commit comments

Comments
 (0)