From 23042ba07cdd017d7d71517496ed70764344e9dd Mon Sep 17 00:00:00 2001 From: Paulchen-Panther Date: Mon, 30 May 2016 22:39:12 +0200 Subject: [PATCH] Update Json Interface (Active LED Color) (#664) * add getCurrentPriority * add getCurrentPriority * Update active led color Former-commit-id: 0e6b828991fdf51d2ec859d3836ce4f976dfd88c --- include/hyperion/Hyperion.h | 8 ++- libsrc/hyperion/Hyperion.cpp | 5 ++ libsrc/jsonserver/JsonClientConnection.cpp | 68 ++++++++++++++++++---- 3 files changed, 69 insertions(+), 12 deletions(-) diff --git a/include/hyperion/Hyperion.h b/include/hyperion/Hyperion.h index aaf5bb87..34b053a5 100644 --- a/include/hyperion/Hyperion.h +++ b/include/hyperion/Hyperion.h @@ -78,7 +78,13 @@ public: /// Returns the number of attached leds /// unsigned getLedCount() const; - + + /// + /// Returns the current priority + /// + /// @return The current priority + /// + int getCurrentPriority() const; /// /// Returns a list of active priorities /// diff --git a/libsrc/hyperion/Hyperion.cpp b/libsrc/hyperion/Hyperion.cpp index 9c871818..aefa0607 100644 --- a/libsrc/hyperion/Hyperion.cpp +++ b/libsrc/hyperion/Hyperion.cpp @@ -819,6 +819,11 @@ void Hyperion::clearall() _effectEngine->allChannelsCleared(); } +int Hyperion::getCurrentPriority() const +{ + return _muxer.getCurrentPriority(); +} + QList Hyperion::getActivePriorities() const { return _muxer.getPriorities(); diff --git a/libsrc/jsonserver/JsonClientConnection.cpp b/libsrc/jsonserver/JsonClientConnection.cpp index b6471355..2f5b13a9 100644 --- a/libsrc/jsonserver/JsonClientConnection.cpp +++ b/libsrc/jsonserver/JsonClientConnection.cpp @@ -1,6 +1,7 @@ // system includes #include #include +#include // stl includes #include @@ -530,19 +531,64 @@ void JsonClientConnection::handleServerInfoCommand(const Json::Value &) activeEffects.append(activeEffect); } - // collect active led colors - Json::Value & activeLedColors = info["activeLedColors"] = Json::Value(Json::arrayValue); - foreach (int priority, activePriorities) { - const Hyperion::InputInfo & priorityInfo = _hyperion->getPriorityInfo(priority); - int i=0; + //////////////////////////////////// + // collect active static led color// + //////////////////////////////////// + + // create New JSON Array Value "activeLEDColor" + Json::Value & activeLedColors = info["activeLedColor"] = Json::Value(Json::arrayValue); + // get current Priority from Hyperion Muxer + const Hyperion::InputInfo & priorityInfo = _hyperion->getPriorityInfo(_hyperion->getCurrentPriority()); + // check if current Priority exist + if (priorityInfo.priority != std::numeric_limits::max()) + { Json::Value LEDcolor; - for (auto it = priorityInfo.ledColors.begin(); it!=priorityInfo.ledColors.end(); ++it, ++i) { - LEDcolor[std::to_string(i)].append(it->red); - LEDcolor[std::to_string(i)].append(it->green); - LEDcolor[std::to_string(i)].append(it->blue); + // check if all LEDs has the same Color + if (std::all_of(priorityInfo.ledColors.begin(), priorityInfo.ledColors.end(), [&](ColorRgb color) + { + return ((color.red == priorityInfo.ledColors.begin()->red) && + (color.green == priorityInfo.ledColors.begin()->green) && + (color.blue == priorityInfo.ledColors.begin()->blue)); + } )) + { + // check if LED Color not Black (0,0,0) + if ((priorityInfo.ledColors.begin()->red != 0) && + (priorityInfo.ledColors.begin()->green != 0) && + (priorityInfo.ledColors.begin()->blue != 0)) + { + // add RGB Value to Array + LEDcolor["RGB Value"].append(priorityInfo.ledColors.begin()->red); + LEDcolor["RGB Value"].append(priorityInfo.ledColors.begin()->green); + LEDcolor["RGB Value"].append(priorityInfo.ledColors.begin()->blue); + + uint16_t Hue; + float Saturation, Luminace; + + // add HSL Value to Array + HslTransform::rgb2hsl(priorityInfo.ledColors.begin()->red, + priorityInfo.ledColors.begin()->green, + priorityInfo.ledColors.begin()->blue, + Hue, Saturation, Luminace); + + LEDcolor["HSL Value"].append(Hue); + LEDcolor["HSL Value"].append(Saturation); + LEDcolor["HSL Value"].append(Luminace); + + // add HEX Value to Array + std::stringstream hex; + hex << "0x" + << std::uppercase << std::setw(2) << std::setfill('0') + << std::hex << unsigned(priorityInfo.ledColors.begin()->red) + << std::uppercase << std::setw(2) << std::setfill('0') + << std::hex << unsigned(priorityInfo.ledColors.begin()->green) + << std::uppercase << std::setw(2) << std::setfill('0') + << std::hex << unsigned(priorityInfo.ledColors.begin()->blue); + + LEDcolor["HEX Value"].append(hex.str()); + + activeLedColors.append(LEDcolor); + } } - - activeLedColors.append(LEDcolor); } // send the result