1- #pragma once
1+ #ifndef BGEFFECTHANDLER_H
2+ #define BGEFFECTHANDLER_H
23
34#include < utils/Logger.h>
45#include < hyperion/Hyperion.h>
89
910// /
1011// / @brief Handle the background Effect settings, reacts on runtime to settings changes
11- // /
12+ // /
1213class BGEffectHandler : public QObject
1314{
1415 Q_OBJECT
1516
1617public:
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+
3746private 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
111119private:
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
0 commit comments