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
8 changed files with 54 additions and 36 deletions

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