From a2266b177fb7bb732d77e13d3f62573293537e09 Mon Sep 17 00:00:00 2001 From: LordGrey <48840279+Lord-Grey@users.noreply.github.com> Date: Sun, 14 Aug 2022 23:02:30 +0200 Subject: [PATCH] Improve Led Device on/off and background effect (#1502) * Queue On-Off calls * Do not switch-off LED-device when Background effect is enabled * Fix LGTM Warnings * Address LGTM findings --- .../js/content_effectsconfigurator.js | 5 +- assets/webconfig/js/content_network.js | 4 +- .../lib/jquery.i18n/CLDRPluralRuleParser.js | 2 +- assets/webconfig/js/ui_utils.js | 4 +- assets/webconfig/js/wizard.js | 2 +- include/hyperion/BGEffectHandler.h | 56 +++++++++++-------- libsrc/hyperion/Hyperion.cpp | 13 +++-- libsrc/leddevice/LedDeviceWrapper.cpp | 4 +- 8 files changed, 54 insertions(+), 36 deletions(-) diff --git a/assets/webconfig/js/content_effectsconfigurator.js b/assets/webconfig/js/content_effectsconfigurator.js index 33dbfdbd..34564539 100644 --- a/assets/webconfig/js/content_effectsconfigurator.js +++ b/assets/webconfig/js/content_effectsconfigurator.js @@ -182,8 +182,9 @@ $(document).ready(function () { // Disable or enable Delete Effect Button $('#effectsdellist').off().on('change', function () { - $(this).val() == null ? $('#btn_edit, #btn_delete').prop('disabled', true) : ""; - $(this).val().startsWith("int_") ? $('#btn_delete').prop('disabled', true) : $('#btn_delete').prop('disabled', false); + var value = $(this).val(); + value == null ? $('#btn_edit, #btn_delete').prop('disabled', true) : ""; + value.startsWith("int_") ? $('#btn_delete').prop('disabled', true) : $('#btn_delete').prop('disabled', false); }); // Load Effect diff --git a/assets/webconfig/js/content_network.js b/assets/webconfig/js/content_network.js index 1e497975..26fec2c8 100644 --- a/assets/webconfig/js/content_network.js +++ b/assets/webconfig/js/content_network.js @@ -272,7 +272,7 @@ $(document).ready(function () { function updateForwarderServiceSections(type) { - var editorPath = "root.forwarder." + type + var editorPath = "root.forwarder." + type; var selectedServices = conf_editor_forw.getEditor(editorPath + "select").getValue(); if (jQuery.isEmptyObject(selectedServices) || selectedServices[0] === "NONE") { @@ -301,7 +301,7 @@ $(document).ready(function () { function updateForwarderSelectList(type) { - var selectionElement = type + "select" + var selectionElement = type + "select"; var enumVals = []; var enumTitelVals = []; diff --git a/assets/webconfig/js/lib/jquery.i18n/CLDRPluralRuleParser.js b/assets/webconfig/js/lib/jquery.i18n/CLDRPluralRuleParser.js index f76459e5..2194fa50 100644 --- a/assets/webconfig/js/lib/jquery.i18n/CLDRPluralRuleParser.js +++ b/assets/webconfig/js/lib/jquery.i18n/CLDRPluralRuleParser.js @@ -226,7 +226,7 @@ function pluralRuleParser(rule, number) { return result; } - result = parseFloat(number, 10); + result = parseFloat(number, 10); //lgtm [js/superfluous-trailing-arguments] debug(' -- passed n ', result); return result; diff --git a/assets/webconfig/js/ui_utils.js b/assets/webconfig/js/ui_utils.js index 36df6eff..8fa72726 100644 --- a/assets/webconfig/js/ui_utils.js +++ b/assets/webconfig/js/ui_utils.js @@ -1310,7 +1310,7 @@ function isValidIPv6(value) { function isValidHostname(value) { if (value.match( - '^([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])(\.([a-zA-Z0-9]|[_a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9]))*$' + '^([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]{0,61}[a-zA-Z0-9])(.([a-zA-Z0-9]|[_a-zA-Z0-9][a-zA-Z0-9-]{0,61}[a-zA-Z0-9]))*$' //lgtm [js/redos] )) return true; else @@ -1319,7 +1319,7 @@ function isValidHostname(value) { function isValidServicename(value) { if (value.match( - '^([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9 \-]{0,61}[a-zA-Z0-9])(\.([a-zA-Z0-9]|[_a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9]))*$' + '^([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9 -]{0,61}[a-zA-Z0-9])(.([a-zA-Z0-9]|[_a-zA-Z0-9][a-zA-Z0-9-]{0,61}[a-zA-Z0-9]))*$' //lgtm [js/redos] )) return true; else diff --git a/assets/webconfig/js/wizard.js b/assets/webconfig/js/wizard.js index 12b966b6..dedd50ed 100755 --- a/assets/webconfig/js/wizard.js +++ b/assets/webconfig/js/wizard.js @@ -466,7 +466,7 @@ function startWizardCC() { $('#wiz_cc_kodiip').off().on('change', function () { - kodiAddress = $(this).val().trim(); + kodiAddress = encodeURIComponent($(this).val().trim()); $('#kodi_status').html(''); if (kodiAddress !== "") { diff --git a/include/hyperion/BGEffectHandler.h b/include/hyperion/BGEffectHandler.h index 8d91a3fd..1dc0b1ef 100644 --- a/include/hyperion/BGEffectHandler.h +++ b/include/hyperion/BGEffectHandler.h @@ -1,4 +1,5 @@ -#pragma once +#ifndef BGEFFECTHANDLER_H +#define BGEFFECTHANDLER_H #include #include @@ -8,18 +9,20 @@ /// /// @brief Handle the background Effect settings, reacts on runtime to settings changes -/// +/// class BGEffectHandler : public QObject { Q_OBJECT public: BGEffectHandler(Hyperion* hyperion) - : QObject(hyperion) - , _hyperion(hyperion) - , _prioMuxer(_hyperion->getMuxerInstance()) - , _isBgEffectConfigured(false) + : QObject(hyperion) + , _hyperion(hyperion) + , _prioMuxer(_hyperion->getMuxerInstance()) + , _isBgEffectEnabled(false) { + QString subComponent = parent()->property("instance").toString(); + _log = Logger::getInstance("HYPERION", subComponent); // listen for config changes connect(_hyperion, &Hyperion::settingsChanged, this, [=] (settings::type type, const QJsonDocument& config) { @@ -34,6 +37,12 @@ public: handleSettingsUpdate(settings::BGEFFECT, _hyperion->getSetting(settings::BGEFFECT)); } + /// + /// @brief Check, if background effect processing is enabled. + /// @return True, background effect processing is enabled. + /// + bool _isEnabled () const { return _isBgEffectEnabled; } + private slots: /// /// @brief Handle settings update from Hyperion Settingsmanager emit or this constructor @@ -44,7 +53,6 @@ private slots: { if(type == settings::BGEFFECT) { - _isBgEffectConfigured = false; _bgEffectConfig = config; const QJsonObject& BGEffectConfig = _bgEffectConfig.object(); @@ -54,11 +62,11 @@ private slots: { _hyperion->clear(PriorityMuxer::BG_PRIORITY); } - // initial background effect/color - if (BGEffectConfig["enable"].toBool(true)) - { - _isBgEffectConfigured = true; + _isBgEffectEnabled = BGEffectConfig["enable"].toBool(true); + // initial background effect/color + if (_isBgEffectEnabled) + { #if defined(ENABLE_EFFECTENGINE) const QString bgTypeConfig = BGEffectConfig["type"].toString("effect"); const QString bgEffectConfig = BGEffectConfig["effect"].toString("Warm mood blobs"); @@ -69,20 +77,20 @@ private slots: if (bgTypeConfig.contains("color")) { std::vector bg_color = { - ColorRgb { - static_cast(BGCONFIG_ARRAY.at(0).toInt(0)), - static_cast(BGCONFIG_ARRAY.at(1).toInt(0)), - static_cast(BGCONFIG_ARRAY.at(2).toInt(0)) - } + ColorRgb { + static_cast(BGCONFIG_ARRAY.at(0).toInt(0)), + static_cast(BGCONFIG_ARRAY.at(1).toInt(0)), + static_cast(BGCONFIG_ARRAY.at(2).toInt(0)) + } }; _hyperion->setColor(PriorityMuxer::BG_PRIORITY, bg_color); - Info(Logger::getInstance("HYPERION"),"Initial background color set (%d %d %d)",bg_color.at(0).red, bg_color.at(0).green, bg_color.at(0).blue); + Info(_log,"Initial background color set (%d %d %d)",bg_color.at(0).red, bg_color.at(0).green, bg_color.at(0).blue); } #if defined(ENABLE_EFFECTENGINE) else { int result = _hyperion->setEffect(bgEffectConfig, PriorityMuxer::BG_PRIORITY, PriorityMuxer::ENDLESS); - Info(Logger::getInstance("HYPERION"),"Initial background effect '%s' %s", QSTRING_CSTR(bgEffectConfig), ((result == 0) ? "started" : "failed")); + Info(_log,"Initial background effect '%s' %s", QSTRING_CSTR(bgEffectConfig), ((result == 0) ? "started" : "failed")); } #endif } @@ -98,12 +106,12 @@ private slots: { if (_prioMuxer->getCurrentPriority() < PriorityMuxer::BG_PRIORITY && _prioMuxer->hasPriority(PriorityMuxer::BG_PRIORITY)) { - Debug(Logger::getInstance("HYPERION"),"Stop background (color-) effect as it moved out of scope"); + Debug(_log,"Stop background (color-) effect as it moved out of scope"); _hyperion->clear(PriorityMuxer::BG_PRIORITY); } - else if (_prioMuxer->getCurrentPriority() == PriorityMuxer::LOWEST_PRIORITY && _isBgEffectConfigured) + else if (_prioMuxer->getCurrentPriority() == PriorityMuxer::LOWEST_PRIORITY && _isBgEffectEnabled) { - Debug(Logger::getInstance("HYPERION"),"Start background (color-) effect as it moved in scope"); + Debug(_log,"Start background (color-) effect as it moved in scope"); emit handleSettingsUpdate (settings::BGEFFECT, _bgEffectConfig); } } @@ -111,9 +119,13 @@ private slots: private: /// Hyperion instance pointer Hyperion* _hyperion; + Logger * _log; + /// priority muxer instance PriorityMuxer* _prioMuxer; QJsonDocument _bgEffectConfig; - bool _isBgEffectConfigured; + bool _isBgEffectEnabled; }; + +#endif // BGEFFECTHANDLER_H diff --git a/libsrc/hyperion/Hyperion.cpp b/libsrc/hyperion/Hyperion.cpp index 35b3c236..d112d928 100644 --- a/libsrc/hyperion/Hyperion.cpp +++ b/libsrc/hyperion/Hyperion.cpp @@ -617,13 +617,18 @@ void Hyperion::handleVisibleComponentChanged(hyperion::Components comp) } void Hyperion::handleSourceAvailability(int priority) -{ int previousPriority = _muxer->getPreviousPriority(); +{ + int previousPriority = _muxer->getPreviousPriority(); if ( priority == PriorityMuxer::LOWEST_PRIORITY) { - Debug(_log,"No source left -> Pause output processing and switch LED-Device off"); - emit _ledDeviceWrapper->switchOff(); - emit _deviceSmooth->setPause(true); + // Keep LED-device on, as background effect will kick-in shortly + if (!_BGEffectHandler->_isEnabled()) + { + Debug(_log,"No source left -> Pause output processing and switch LED-Device off"); + emit _ledDeviceWrapper->switchOff(); + emit _deviceSmooth->setPause(true); + } } else { diff --git a/libsrc/leddevice/LedDeviceWrapper.cpp b/libsrc/leddevice/LedDeviceWrapper.cpp index 5cba7af9..cc8177fb 100644 --- a/libsrc/leddevice/LedDeviceWrapper.cpp +++ b/libsrc/leddevice/LedDeviceWrapper.cpp @@ -67,8 +67,8 @@ void LedDeviceWrapper::createLedDevice(const QJsonObject& config) // further signals connect(this, &LedDeviceWrapper::updateLeds, _ledDevice, &LedDevice::updateLeds, Qt::QueuedConnection); - connect(this, &LedDeviceWrapper::switchOn, _ledDevice, &LedDevice::switchOn); - connect(this, &LedDeviceWrapper::switchOff, _ledDevice, &LedDevice::switchOff); + connect(this, &LedDeviceWrapper::switchOn, _ledDevice, &LedDevice::switchOn, Qt::BlockingQueuedConnection); + connect(this, &LedDeviceWrapper::switchOff, _ledDevice, &LedDevice::switchOff, Qt::BlockingQueuedConnection); connect(this, &LedDeviceWrapper::stopLedDevice, _ledDevice, &LedDevice::stop, Qt::BlockingQueuedConnection);