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
This commit is contained in:
LordGrey 2022-08-14 23:02:30 +02:00 committed by GitHub
parent e17ce6cd4e
commit a2266b177f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 54 additions and 36 deletions

View File

@ -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

View File

@ -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 = [];

View File

@ -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;

View File

@ -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

View File

@ -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 !== "") {

View File

@ -1,4 +1,5 @@
#pragma once
#ifndef BGEFFECTHANDLER_H
#define BGEFFECTHANDLER_H
#include <utils/Logger.h>
#include <hyperion/Hyperion.h>
@ -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<ColorRgb> bg_color = {
ColorRgb {
static_cast<uint8_t>(BGCONFIG_ARRAY.at(0).toInt(0)),
static_cast<uint8_t>(BGCONFIG_ARRAY.at(1).toInt(0)),
static_cast<uint8_t>(BGCONFIG_ARRAY.at(2).toInt(0))
}
ColorRgb {
static_cast<uint8_t>(BGCONFIG_ARRAY.at(0).toInt(0)),
static_cast<uint8_t>(BGCONFIG_ARRAY.at(1).toInt(0)),
static_cast<uint8_t>(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

View File

@ -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
{

View File

@ -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);