From 83051543d25a95a0ba739f7351dc165b48dab669 Mon Sep 17 00:00:00 2001 From: johan Date: Thu, 12 Dec 2013 23:12:22 +0100 Subject: [PATCH] Boblight server: Added a sync after writing led N-1. Added clipping to a parsed RGB value instead of the modulo Former-commit-id: 9080c04a0f09f536587867912231b29565a31b5d --- .../boblightserver/BoblightClientConnection.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/libsrc/boblightserver/BoblightClientConnection.cpp b/libsrc/boblightserver/BoblightClientConnection.cpp index 75e61451..de254803 100644 --- a/libsrc/boblightserver/BoblightClientConnection.cpp +++ b/libsrc/boblightserver/BoblightClientConnection.cpp @@ -133,7 +133,8 @@ void BoblightClientConnection::handleMessage(const QString & message) if (messageParts[3] == "rgb" && messageParts.size() == 7) { bool rc1, rc2, rc3; - uint8_t red = 255 * messageParts[4].toFloat(&rc1); + uint8_t red = qMax(0, qMin(255, int(255 * messageParts[4].toFloat(&rc1)))); + if (!rc1) { // maybe a locale issue. switch to a locale with a comma instead of a dot as decimal seperator (or vice versa) @@ -141,11 +142,11 @@ void BoblightClientConnection::handleMessage(const QString & message) _locale.setNumberOptions(QLocale::OmitGroupSeparator | QLocale::RejectGroupSeparator); // try again - red = 255 * messageParts[4].toFloat(&rc1); + red = qMax(0, qMin(255, int(255 * messageParts[4].toFloat(&rc1)))); } - uint8_t green = 255 * messageParts[5].toFloat(&rc2); - uint8_t blue = 255 * messageParts[6].toFloat(&rc3); + uint8_t green = qMax(0, qMin(255, 255 * int(messageParts[5].toFloat(&rc2)))); + uint8_t blue = qMax(0, qMin(255, 255 * int(messageParts[6].toFloat(&rc3)))); if (rc1 && rc2 && rc3) { @@ -153,6 +154,13 @@ void BoblightClientConnection::handleMessage(const QString & message) rgb.red = red; rgb.green = green; rgb.blue = blue; + + // send current color values to hyperion if this is the last led assuming leds values are send in order of id + if ((ledIndex == _ledColors.size() -1) && _priority < 255) + { + _hyperion->setColors(_priority, _ledColors, -1); + } + return; } }