-
-
Notifications
You must be signed in to change notification settings - Fork 406
rgbw e131 support #1888
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
base: master
Are you sure you want to change the base?
rgbw e131 support #1888
Changes from 3 commits
20ad969
b7334ad
e60fa6f
b146a10
4359ea9
9f49c4d
e46db70
a535db3
1510899
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,6 +39,7 @@ const int DMX_MAX = 512; // 512 usable slots | |
|
|
||
| LedDeviceUdpE131::LedDeviceUdpE131(const QJsonObject &deviceConfig) | ||
| : ProviderUdp(deviceConfig) | ||
| , _whiteAlgorithm(RGBW::WhiteAlgorithm::INVALID) | ||
| { | ||
| } | ||
|
|
||
|
|
@@ -58,9 +59,21 @@ bool LedDeviceUdpE131::init(const QJsonObject &deviceConfig) | |
| _port = deviceConfig[CONFIG_PORT].toInt(E131_DEFAULT_PORT); | ||
|
|
||
| _e131_universe = deviceConfig["universe"].toInt(1); | ||
| _e131_dmx_max = deviceConfig["dmx-max"].toInt(DMX_MAX); | ||
| _e131_source_name = deviceConfig["source-name"].toString("hyperion on "+QHostInfo::localHostName()); | ||
| QString _json_cid = deviceConfig["cid"].toString(""); | ||
|
|
||
| // Initialize white algorithm | ||
| QString whiteAlgorithmStr = deviceConfig["whiteAlgorithm"].toString("white_off"); | ||
| _whiteAlgorithm = RGBW::stringToWhiteAlgorithm(whiteAlgorithmStr); | ||
| if (_whiteAlgorithm == RGBW::WhiteAlgorithm::INVALID) | ||
| { | ||
| QString errortext = QString("unknown whiteAlgorithm: %1").arg(whiteAlgorithmStr); | ||
| this->setInError(errortext); | ||
| return false; | ||
| } | ||
| Debug(_log, "whiteAlgorithm : %s", QSTRING_CSTR(whiteAlgorithmStr)); | ||
|
|
||
| if (_json_cid.isEmpty()) | ||
| { | ||
| _e131_cid = QUuid::createUuid(); | ||
|
|
@@ -138,35 +151,57 @@ void LedDeviceUdpE131::prepare(unsigned this_universe, unsigned this_dmxChannelC | |
|
|
||
| int LedDeviceUdpE131::write(const std::vector<ColorRgb> &ledValues) | ||
| { | ||
| int retVal = 0; | ||
| int retVal = 0; | ||
| int thisChannelCount = 0; | ||
| int dmxChannelCount = _ledRGBCount; | ||
| const uint8_t * rawdata = reinterpret_cast<const uint8_t *>(ledValues.data()); | ||
| int dmxChannelCount = (_whiteAlgorithm == RGBW::WhiteAlgorithm::WHITE_OFF) ? _ledRGBCount : _ledRGBWCount; // if white_off we expect 3 channels per LED otherwise 4 | ||
Lord-Grey marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| // Create a temporary buffer for RGB or RGBW data | ||
| std::vector<uint8_t> tempBuffer(dmxChannelCount); | ||
|
||
| uint8_t* rawDataPtr = tempBuffer.data(); | ||
|
|
||
| int currentChannel = 0; | ||
| for (const ColorRgb& color : ledValues) | ||
| { | ||
| if (_whiteAlgorithm == RGBW::WhiteAlgorithm::WHITE_OFF) | ||
| { | ||
| rawDataPtr[currentChannel++] = color.red; | ||
| rawDataPtr[currentChannel++] = color.green; | ||
| rawDataPtr[currentChannel++] = color.blue; | ||
| } | ||
| else | ||
| { | ||
| RGBW::Rgb_to_Rgbw(color, &_temp_rgbw, _whiteAlgorithm); | ||
| rawDataPtr[currentChannel++] = _temp_rgbw.red; | ||
| rawDataPtr[currentChannel++] = _temp_rgbw.green; | ||
| rawDataPtr[currentChannel++] = _temp_rgbw.blue; | ||
| rawDataPtr[currentChannel++] = _temp_rgbw.white; | ||
| } | ||
| } | ||
|
|
||
| _e131_seq++; | ||
|
|
||
| for (int rawIdx = 0; rawIdx < dmxChannelCount; rawIdx++) | ||
| { | ||
| if (rawIdx % DMX_MAX == 0) // start of new packet | ||
| if (rawIdx % _e131_dmx_max == 0) // start of new packet | ||
| { | ||
| thisChannelCount = (dmxChannelCount - rawIdx < DMX_MAX) ? dmxChannelCount % DMX_MAX : DMX_MAX; | ||
| // is this the last packet? ? ^^ last packet : ^^ earlier packets | ||
| thisChannelCount = (dmxChannelCount - rawIdx < _e131_dmx_max) ? dmxChannelCount % _e131_dmx_max : _e131_dmx_max; | ||
| // is this the last packet? ? ^^ last packet : ^^ earlier packets | ||
|
|
||
| prepare(_e131_universe + rawIdx / DMX_MAX, thisChannelCount); | ||
| prepare(_e131_universe + rawIdx / _e131_dmx_max, thisChannelCount); | ||
| e131_packet.sequence_number = _e131_seq; | ||
| } | ||
|
|
||
| e131_packet.property_values[1 + rawIdx%DMX_MAX] = rawdata[rawIdx]; | ||
| e131_packet.property_values[1 + rawIdx % _e131_dmx_max] = rawDataPtr[rawIdx]; | ||
|
|
||
| // is this the last byte of last packet || last byte of other packets | ||
| if ( (rawIdx == dmxChannelCount-1) || (rawIdx %DMX_MAX == DMX_MAX-1) ) | ||
| // is this the last byte of last packet || last byte of other packets | ||
| if ((rawIdx == dmxChannelCount - 1) || (rawIdx % _e131_dmx_max == _e131_dmx_max - 1)) | ||
| { | ||
| #undef e131debug | ||
| #if e131debug | ||
| Debug (_log, "send packet: rawidx %d dmxchannelcount %d universe: %d, packetsz %d" | ||
| , rawIdx | ||
| , dmxChannelCount | ||
| , _e131_universe + rawIdx / DMX_MAX | ||
| , _e131_universe + rawIdx / _e131_dmx_max | ||
| , E131_DMP_DATA + 1 + thisChannelCount | ||
| ); | ||
| #endif | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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 assume that _e131_dmx_max must be always <= DMX_MAX?
The ensure that _e131_dmx_max = DMX_MAX, if greater