diff --git a/include/api/JsonAPI.h b/include/api/JsonAPI.h index 6346ce72..3880fc42 100644 --- a/include/api/JsonAPI.h +++ b/include/api/JsonAPI.h @@ -88,6 +88,11 @@ private slots: /// void handleInstanceStateChange(InstanceState state, quint8 instance, const QString &name = QString()); + /// + /// @brief Stream a new LED Colors update + /// + void streamLedColorsUpdate(); + signals: /// /// Signal emits with the reply message provided with handleMessage() diff --git a/libsrc/api/JsonAPI.cpp b/libsrc/api/JsonAPI.cpp index d3e401a9..75863ca2 100644 --- a/libsrc/api/JsonAPI.cpp +++ b/libsrc/api/JsonAPI.cpp @@ -140,6 +140,8 @@ void JsonAPI::initialize() connect(this, &JsonAPI::toggleSuspendAll, _instanceManager, &HyperionIManager::triggerToggleSuspend); connect(this, &JsonAPI::idleAll, _instanceManager, &HyperionIManager::triggerIdle); connect(this, &JsonAPI::toggleIdleAll, _instanceManager, &HyperionIManager::triggerToggleIdle); + + connect(_ledStreamTimer, &QTimer::timeout, this, &JsonAPI::streamLedColorsUpdate, Qt::UniqueConnection); } bool JsonAPI::handleInstanceSwitch(quint8 inst, bool forced) @@ -1139,6 +1141,11 @@ void JsonAPI::handleComponentStateCommand(const QJsonObject &message, const QStr sendSuccessReply(command, tan); } +void JsonAPI::streamLedColorsUpdate() +{ + emit streamLedcolorsUpdate(_currentLedValues); +} + void JsonAPI::handleLedColorsCommand(const QJsonObject &message, const QString &command, int tan) { // create result @@ -1154,21 +1161,21 @@ void JsonAPI::handleLedColorsCommand(const QJsonObject &message, const QString & _streaming_leds_reply["tan"] = tan; connect(_hyperion, &Hyperion::rawLedColors, this, [=](const std::vector &ledValues) { - _currentLedValues = ledValues; - // necessary because Qt::UniqueConnection for lambdas does not work until 5.9 - // see: https://bugreports.qt.io/browse/QTBUG-52438 - if (!_ledStreamConnection) - _ledStreamConnection = connect(_ledStreamTimer, &QTimer::timeout, this, [=]() { - emit streamLedcolorsUpdate(_currentLedValues); - }, - Qt::UniqueConnection); + if (ledValues != _currentLedValues) + { + _currentLedValues = ledValues; + if (!_ledStreamTimer->isActive() || _ledStreamTimer->interval() != streaming_interval) + { + _ledStreamTimer->start(streaming_interval); + } + } + else + { + _ledStreamTimer->stop(); + } + }); - // start the timer - if (!_ledStreamTimer->isActive() || _ledStreamTimer->interval() != streaming_interval) - _ledStreamTimer->start(streaming_interval); - }, - Qt::UniqueConnection); // push once _hyperion->update(); }