Skip to content

Commit a2266b1

Browse files
authored
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
1 parent e17ce6c commit a2266b1

File tree

8 files changed

+53
-35
lines changed

8 files changed

+53
-35
lines changed

assets/webconfig/js/content_effectsconfigurator.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,9 @@ $(document).ready(function () {
182182

183183
// Disable or enable Delete Effect Button
184184
$('#effectsdellist').off().on('change', function () {
185-
$(this).val() == null ? $('#btn_edit, #btn_delete').prop('disabled', true) : "";
186-
$(this).val().startsWith("int_") ? $('#btn_delete').prop('disabled', true) : $('#btn_delete').prop('disabled', false);
185+
var value = $(this).val();
186+
value == null ? $('#btn_edit, #btn_delete').prop('disabled', true) : "";
187+
value.startsWith("int_") ? $('#btn_delete').prop('disabled', true) : $('#btn_delete').prop('disabled', false);
187188
});
188189

189190
// Load Effect

assets/webconfig/js/content_network.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ $(document).ready(function () {
272272

273273
function updateForwarderServiceSections(type) {
274274

275-
var editorPath = "root.forwarder." + type
275+
var editorPath = "root.forwarder." + type;
276276
var selectedServices = conf_editor_forw.getEditor(editorPath + "select").getValue();
277277

278278
if (jQuery.isEmptyObject(selectedServices) || selectedServices[0] === "NONE") {
@@ -301,7 +301,7 @@ $(document).ready(function () {
301301

302302
function updateForwarderSelectList(type) {
303303

304-
var selectionElement = type + "select"
304+
var selectionElement = type + "select";
305305

306306
var enumVals = [];
307307
var enumTitelVals = [];

assets/webconfig/js/lib/jquery.i18n/CLDRPluralRuleParser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ function pluralRuleParser(rule, number) {
226226
return result;
227227
}
228228

229-
result = parseFloat(number, 10);
229+
result = parseFloat(number, 10); //lgtm [js/superfluous-trailing-arguments]
230230
debug(' -- passed n ', result);
231231

232232
return result;

assets/webconfig/js/ui_utils.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1310,7 +1310,7 @@ function isValidIPv6(value) {
13101310

13111311
function isValidHostname(value) {
13121312
if (value.match(
1313-
'^([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]))*$'
1313+
'^([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]
13141314
))
13151315
return true;
13161316
else
@@ -1319,7 +1319,7 @@ function isValidHostname(value) {
13191319

13201320
function isValidServicename(value) {
13211321
if (value.match(
1322-
'^([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]))*$'
1322+
'^([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]
13231323
))
13241324
return true;
13251325
else

assets/webconfig/js/wizard.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ function startWizardCC() {
466466

467467
$('#wiz_cc_kodiip').off().on('change', function () {
468468

469-
kodiAddress = $(this).val().trim();
469+
kodiAddress = encodeURIComponent($(this).val().trim());
470470

471471
$('#kodi_status').html('');
472472
if (kodiAddress !== "") {

include/hyperion/BGEffectHandler.h

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#pragma once
1+
#ifndef BGEFFECTHANDLER_H
2+
#define BGEFFECTHANDLER_H
23

34
#include <utils/Logger.h>
45
#include <hyperion/Hyperion.h>
@@ -8,18 +9,20 @@
89

910
///
1011
/// @brief Handle the background Effect settings, reacts on runtime to settings changes
11-
///
12+
///
1213
class BGEffectHandler : public QObject
1314
{
1415
Q_OBJECT
1516

1617
public:
1718
BGEffectHandler(Hyperion* hyperion)
18-
: QObject(hyperion)
19-
, _hyperion(hyperion)
20-
, _prioMuxer(_hyperion->getMuxerInstance())
21-
, _isBgEffectConfigured(false)
19+
: QObject(hyperion)
20+
, _hyperion(hyperion)
21+
, _prioMuxer(_hyperion->getMuxerInstance())
22+
, _isBgEffectEnabled(false)
2223
{
24+
QString subComponent = parent()->property("instance").toString();
25+
_log = Logger::getInstance("HYPERION", subComponent);
2326

2427
// listen for config changes
2528
connect(_hyperion, &Hyperion::settingsChanged, this, [=] (settings::type type, const QJsonDocument& config) {
@@ -34,6 +37,12 @@ class BGEffectHandler : public QObject
3437
handleSettingsUpdate(settings::BGEFFECT, _hyperion->getSetting(settings::BGEFFECT));
3538
}
3639

40+
///
41+
/// @brief Check, if background effect processing is enabled.
42+
/// @return True, background effect processing is enabled.
43+
///
44+
bool _isEnabled () const { return _isBgEffectEnabled; }
45+
3746
private slots:
3847
///
3948
/// @brief Handle settings update from Hyperion Settingsmanager emit or this constructor
@@ -44,7 +53,6 @@ private slots:
4453
{
4554
if(type == settings::BGEFFECT)
4655
{
47-
_isBgEffectConfigured = false;
4856
_bgEffectConfig = config;
4957

5058
const QJsonObject& BGEffectConfig = _bgEffectConfig.object();
@@ -54,11 +62,11 @@ private slots:
5462
{
5563
_hyperion->clear(PriorityMuxer::BG_PRIORITY);
5664
}
65+
_isBgEffectEnabled = BGEffectConfig["enable"].toBool(true);
66+
5767
// initial background effect/color
58-
if (BGEffectConfig["enable"].toBool(true))
68+
if (_isBgEffectEnabled)
5969
{
60-
_isBgEffectConfigured = true;
61-
6270
#if defined(ENABLE_EFFECTENGINE)
6371
const QString bgTypeConfig = BGEffectConfig["type"].toString("effect");
6472
const QString bgEffectConfig = BGEffectConfig["effect"].toString("Warm mood blobs");
@@ -69,20 +77,20 @@ private slots:
6977
if (bgTypeConfig.contains("color"))
7078
{
7179
std::vector<ColorRgb> bg_color = {
72-
ColorRgb {
73-
static_cast<uint8_t>(BGCONFIG_ARRAY.at(0).toInt(0)),
74-
static_cast<uint8_t>(BGCONFIG_ARRAY.at(1).toInt(0)),
75-
static_cast<uint8_t>(BGCONFIG_ARRAY.at(2).toInt(0))
76-
}
80+
ColorRgb {
81+
static_cast<uint8_t>(BGCONFIG_ARRAY.at(0).toInt(0)),
82+
static_cast<uint8_t>(BGCONFIG_ARRAY.at(1).toInt(0)),
83+
static_cast<uint8_t>(BGCONFIG_ARRAY.at(2).toInt(0))
84+
}
7785
};
7886
_hyperion->setColor(PriorityMuxer::BG_PRIORITY, bg_color);
79-
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);
87+
Info(_log,"Initial background color set (%d %d %d)",bg_color.at(0).red, bg_color.at(0).green, bg_color.at(0).blue);
8088
}
8189
#if defined(ENABLE_EFFECTENGINE)
8290
else
8391
{
8492
int result = _hyperion->setEffect(bgEffectConfig, PriorityMuxer::BG_PRIORITY, PriorityMuxer::ENDLESS);
85-
Info(Logger::getInstance("HYPERION"),"Initial background effect '%s' %s", QSTRING_CSTR(bgEffectConfig), ((result == 0) ? "started" : "failed"));
93+
Info(_log,"Initial background effect '%s' %s", QSTRING_CSTR(bgEffectConfig), ((result == 0) ? "started" : "failed"));
8694
}
8795
#endif
8896
}
@@ -98,22 +106,26 @@ private slots:
98106
{
99107
if (_prioMuxer->getCurrentPriority() < PriorityMuxer::BG_PRIORITY && _prioMuxer->hasPriority(PriorityMuxer::BG_PRIORITY))
100108
{
101-
Debug(Logger::getInstance("HYPERION"),"Stop background (color-) effect as it moved out of scope");
109+
Debug(_log,"Stop background (color-) effect as it moved out of scope");
102110
_hyperion->clear(PriorityMuxer::BG_PRIORITY);
103111
}
104-
else if (_prioMuxer->getCurrentPriority() == PriorityMuxer::LOWEST_PRIORITY && _isBgEffectConfigured)
112+
else if (_prioMuxer->getCurrentPriority() == PriorityMuxer::LOWEST_PRIORITY && _isBgEffectEnabled)
105113
{
106-
Debug(Logger::getInstance("HYPERION"),"Start background (color-) effect as it moved in scope");
114+
Debug(_log,"Start background (color-) effect as it moved in scope");
107115
emit handleSettingsUpdate (settings::BGEFFECT, _bgEffectConfig);
108116
}
109117
}
110118

111119
private:
112120
/// Hyperion instance pointer
113121
Hyperion* _hyperion;
122+
Logger * _log;
123+
114124
/// priority muxer instance
115125
PriorityMuxer* _prioMuxer;
116126

117127
QJsonDocument _bgEffectConfig;
118-
bool _isBgEffectConfigured;
128+
bool _isBgEffectEnabled;
119129
};
130+
131+
#endif // BGEFFECTHANDLER_H

libsrc/hyperion/Hyperion.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -617,13 +617,18 @@ void Hyperion::handleVisibleComponentChanged(hyperion::Components comp)
617617
}
618618

619619
void Hyperion::handleSourceAvailability(int priority)
620-
{ int previousPriority = _muxer->getPreviousPriority();
620+
{
621+
int previousPriority = _muxer->getPreviousPriority();
621622

622623
if ( priority == PriorityMuxer::LOWEST_PRIORITY)
623624
{
624-
Debug(_log,"No source left -> Pause output processing and switch LED-Device off");
625-
emit _ledDeviceWrapper->switchOff();
626-
emit _deviceSmooth->setPause(true);
625+
// Keep LED-device on, as background effect will kick-in shortly
626+
if (!_BGEffectHandler->_isEnabled())
627+
{
628+
Debug(_log,"No source left -> Pause output processing and switch LED-Device off");
629+
emit _ledDeviceWrapper->switchOff();
630+
emit _deviceSmooth->setPause(true);
631+
}
627632
}
628633
else
629634
{

libsrc/leddevice/LedDeviceWrapper.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ void LedDeviceWrapper::createLedDevice(const QJsonObject& config)
6767
// further signals
6868
connect(this, &LedDeviceWrapper::updateLeds, _ledDevice, &LedDevice::updateLeds, Qt::QueuedConnection);
6969

70-
connect(this, &LedDeviceWrapper::switchOn, _ledDevice, &LedDevice::switchOn);
71-
connect(this, &LedDeviceWrapper::switchOff, _ledDevice, &LedDevice::switchOff);
70+
connect(this, &LedDeviceWrapper::switchOn, _ledDevice, &LedDevice::switchOn, Qt::BlockingQueuedConnection);
71+
connect(this, &LedDeviceWrapper::switchOff, _ledDevice, &LedDevice::switchOff, Qt::BlockingQueuedConnection);
7272

7373
connect(this, &LedDeviceWrapper::stopLedDevice, _ledDevice, &LedDevice::stop, Qt::BlockingQueuedConnection);
7474

0 commit comments

Comments
 (0)