From 80fc153d356b81e326eaf3c2b2675f6426f89a7c Mon Sep 17 00:00:00 2001 From: penfold42 Date: Mon, 11 Jul 2016 21:15:08 +1000 Subject: [PATCH] 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 --- include/udplistener/UDPListener.h | 3 --- libsrc/udplistener/UDPListener.cpp | 11 ++++++----- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/include/udplistener/UDPListener.h b/include/udplistener/UDPListener.h index 457b603b..82020685 100644 --- a/include/udplistener/UDPListener.h +++ b/include/udplistener/UDPListener.h @@ -77,9 +77,6 @@ private: /// hyperion priority int _timeout; - /// The latest led color data - std::vector _ledColors; - /// Logger instance Logger * _log; diff --git a/libsrc/udplistener/UDPListener.cpp b/libsrc/udplistener/UDPListener.cpp index 4b1aa77e..e7b5483e 100644 --- a/libsrc/udplistener/UDPListener.cpp +++ b/libsrc/udplistener/UDPListener.cpp @@ -17,7 +17,6 @@ UDPListener::UDPListener(const int priority, const int timeout, const std::strin _openConnections(), _priority(priority), _timeout(timeout), - _ledColors(Hyperion::getInstance()->getLedCount(), ColorRgb::BLACK), _log(Logger::getInstance("UDPLISTENER")), _isActive(false), _listenPort(listenPort), @@ -104,11 +103,13 @@ void UDPListener::readPendingDatagrams() void UDPListener::processTheDatagram(const QByteArray * datagram) { - int packlen = datagram->size()/3; - int ledlen = _ledColors.size(); - int maxled = std::min(packlen , ledlen); + int packetLedCount = datagram->size()/3; + int hyperionLedCount = Hyperion::getInstance()->getLedCount(); + DebugIf( (packetLedCount != hyperionLedCount), _log, "packetLedCount (%d) != hyperionLedCount (%d)", packetLedCount, hyperionLedCount); - for (int ledIndex=0; ledIndex < maxled; ledIndex++) { + std::vector _ledColors(Hyperion::getInstance()->getLedCount(), ColorRgb::BLACK); + + for (int ledIndex=0; ledIndex < std::min(packetLedCount, hyperionLedCount); ledIndex++) { ColorRgb & rgb = _ledColors[ledIndex]; rgb.red = datagram->at(ledIndex*3+0); rgb.green = datagram->at(ledIndex*3+1);