udplistener will now set remaining LEDs to black. (#99)

eg: configure 42 leds, but a udp packet only contains 10 leds, the remaining 32 are now set to black
This commit is contained in:
penfold42 2016-07-11 21:15:08 +10:00 committed by brindosch
parent 2013304130
commit 80fc153d35
2 changed files with 6 additions and 8 deletions

View File

@ -77,9 +77,6 @@ private:
/// hyperion priority /// hyperion priority
int _timeout; int _timeout;
/// The latest led color data
std::vector<ColorRgb> _ledColors;
/// Logger instance /// Logger instance
Logger * _log; Logger * _log;

View File

@ -17,7 +17,6 @@ UDPListener::UDPListener(const int priority, const int timeout, const std::strin
_openConnections(), _openConnections(),
_priority(priority), _priority(priority),
_timeout(timeout), _timeout(timeout),
_ledColors(Hyperion::getInstance()->getLedCount(), ColorRgb::BLACK),
_log(Logger::getInstance("UDPLISTENER")), _log(Logger::getInstance("UDPLISTENER")),
_isActive(false), _isActive(false),
_listenPort(listenPort), _listenPort(listenPort),
@ -104,11 +103,13 @@ void UDPListener::readPendingDatagrams()
void UDPListener::processTheDatagram(const QByteArray * datagram) void UDPListener::processTheDatagram(const QByteArray * datagram)
{ {
int packlen = datagram->size()/3; int packetLedCount = datagram->size()/3;
int ledlen = _ledColors.size(); int hyperionLedCount = Hyperion::getInstance()->getLedCount();
int maxled = std::min(packlen , ledlen); DebugIf( (packetLedCount != hyperionLedCount), _log, "packetLedCount (%d) != hyperionLedCount (%d)", packetLedCount, hyperionLedCount);
for (int ledIndex=0; ledIndex < maxled; ledIndex++) { std::vector<ColorRgb> _ledColors(Hyperion::getInstance()->getLedCount(), ColorRgb::BLACK);
for (int ledIndex=0; ledIndex < std::min(packetLedCount, hyperionLedCount); ledIndex++) {
ColorRgb & rgb = _ledColors[ledIndex]; ColorRgb & rgb = _ledColors[ledIndex];
rgb.red = datagram->at(ledIndex*3+0); rgb.red = datagram->at(ledIndex*3+0);
rgb.green = datagram->at(ledIndex*3+1); rgb.green = datagram->at(ledIndex*3+1);