2022-08-14 23:02:30 +02:00
|
|
|
#ifndef BGEFFECTHANDLER_H
|
|
|
|
#define BGEFFECTHANDLER_H
|
2018-12-27 23:11:32 +01:00
|
|
|
|
|
|
|
#include <utils/Logger.h>
|
|
|
|
#include <hyperion/Hyperion.h>
|
|
|
|
#include <utils/settings.h>
|
2021-03-19 22:52:41 +01:00
|
|
|
#include <effectengine/Effect.h>
|
2021-04-25 16:50:27 +02:00
|
|
|
#include <hyperion/PriorityMuxer.h>
|
2018-12-27 23:11:32 +01:00
|
|
|
|
|
|
|
///
|
|
|
|
/// @brief Handle the background Effect settings, reacts on runtime to settings changes
|
2022-08-14 23:02:30 +02:00
|
|
|
///
|
2018-12-27 23:11:32 +01:00
|
|
|
class BGEffectHandler : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
BGEffectHandler(Hyperion* hyperion)
|
2022-08-14 23:02:30 +02:00
|
|
|
: QObject(hyperion)
|
|
|
|
, _hyperion(hyperion)
|
|
|
|
, _prioMuxer(_hyperion->getMuxerInstance())
|
|
|
|
, _isBgEffectEnabled(false)
|
2022-12-22 12:40:39 +01:00
|
|
|
, _isSuspended(false)
|
2018-12-27 23:11:32 +01:00
|
|
|
{
|
2022-08-14 23:02:30 +02:00
|
|
|
QString subComponent = parent()->property("instance").toString();
|
|
|
|
_log = Logger::getInstance("HYPERION", subComponent);
|
2022-02-22 20:58:59 +01:00
|
|
|
|
2018-12-27 23:11:32 +01:00
|
|
|
// listen for config changes
|
2022-02-22 20:58:59 +01:00
|
|
|
connect(_hyperion, &Hyperion::settingsChanged, this, [=] (settings::type type, const QJsonDocument& config) {
|
|
|
|
this->handleSettingsUpdate(type, config);
|
|
|
|
});
|
2021-04-25 16:50:27 +02:00
|
|
|
|
2022-02-22 20:58:59 +01:00
|
|
|
connect(_prioMuxer, &PriorityMuxer::prioritiesChanged, this, [=] {
|
|
|
|
this->handlePriorityUpdate();
|
|
|
|
});
|
2018-12-27 23:11:32 +01:00
|
|
|
|
2022-12-22 12:40:39 +01:00
|
|
|
// listen for suspend/resume requests, to not start a background effect when system goes into suspend mode
|
|
|
|
connect(_hyperion, &Hyperion::suspendRequest, this, [=] (bool isSuspended) {
|
|
|
|
_isSuspended = isSuspended;
|
|
|
|
});
|
|
|
|
|
2020-11-14 17:58:56 +01:00
|
|
|
// initialization
|
2018-12-27 23:11:32 +01:00
|
|
|
handleSettingsUpdate(settings::BGEFFECT, _hyperion->getSetting(settings::BGEFFECT));
|
2020-11-14 17:58:56 +01:00
|
|
|
}
|
2018-12-27 23:11:32 +01:00
|
|
|
|
2022-08-14 23:02:30 +02:00
|
|
|
///
|
|
|
|
/// @brief Check, if background effect processing is enabled.
|
|
|
|
/// @return True, background effect processing is enabled.
|
|
|
|
///
|
|
|
|
bool _isEnabled () const { return _isBgEffectEnabled; }
|
|
|
|
|
2018-12-27 23:11:32 +01:00
|
|
|
private slots:
|
|
|
|
///
|
|
|
|
/// @brief Handle settings update from Hyperion Settingsmanager emit or this constructor
|
2020-11-14 17:58:56 +01:00
|
|
|
/// @param type settingType from enum
|
2018-12-27 23:11:32 +01:00
|
|
|
/// @param config configuration object
|
|
|
|
///
|
2020-08-08 13:09:15 +02:00
|
|
|
void handleSettingsUpdate(settings::type type, const QJsonDocument& config)
|
2018-12-27 23:11:32 +01:00
|
|
|
{
|
|
|
|
if(type == settings::BGEFFECT)
|
|
|
|
{
|
2021-04-25 16:50:27 +02:00
|
|
|
_bgEffectConfig = config;
|
2018-12-27 23:11:32 +01:00
|
|
|
|
2021-04-25 16:50:27 +02:00
|
|
|
const QJsonObject& BGEffectConfig = _bgEffectConfig.object();
|
2018-12-27 23:11:32 +01:00
|
|
|
#define BGCONFIG_ARRAY bgColorConfig.toArray()
|
2020-11-14 17:58:56 +01:00
|
|
|
// clear background priority
|
2022-02-22 20:58:59 +01:00
|
|
|
if (_hyperion->getCurrentPriority() == PriorityMuxer::BG_PRIORITY)
|
|
|
|
{
|
|
|
|
_hyperion->clear(PriorityMuxer::BG_PRIORITY);
|
|
|
|
}
|
2022-08-14 23:02:30 +02:00
|
|
|
_isBgEffectEnabled = BGEffectConfig["enable"].toBool(true);
|
|
|
|
|
2018-12-27 23:11:32 +01:00
|
|
|
// initial background effect/color
|
2022-08-14 23:02:30 +02:00
|
|
|
if (_isBgEffectEnabled)
|
2018-12-27 23:11:32 +01:00
|
|
|
{
|
2022-02-11 20:36:15 +01:00
|
|
|
#if defined(ENABLE_EFFECTENGINE)
|
2018-12-27 23:11:32 +01:00
|
|
|
const QString bgTypeConfig = BGEffectConfig["type"].toString("effect");
|
|
|
|
const QString bgEffectConfig = BGEffectConfig["effect"].toString("Warm mood blobs");
|
2022-02-11 20:36:15 +01:00
|
|
|
#else
|
|
|
|
const QString bgTypeConfig = "color";
|
|
|
|
#endif
|
2018-12-27 23:11:32 +01:00
|
|
|
const QJsonValue bgColorConfig = BGEffectConfig["color"];
|
|
|
|
if (bgTypeConfig.contains("color"))
|
|
|
|
{
|
2020-02-26 18:54:56 +01:00
|
|
|
std::vector<ColorRgb> bg_color = {
|
2022-08-14 23:02:30 +02:00
|
|
|
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))
|
|
|
|
}
|
2018-12-27 23:11:32 +01:00
|
|
|
};
|
2021-03-19 22:52:41 +01:00
|
|
|
_hyperion->setColor(PriorityMuxer::BG_PRIORITY, bg_color);
|
2022-08-14 23:02:30 +02:00
|
|
|
Info(_log,"Initial background color set (%d %d %d)",bg_color.at(0).red, bg_color.at(0).green, bg_color.at(0).blue);
|
2018-12-27 23:11:32 +01:00
|
|
|
}
|
2022-02-11 20:36:15 +01:00
|
|
|
#if defined(ENABLE_EFFECTENGINE)
|
2018-12-27 23:11:32 +01:00
|
|
|
else
|
|
|
|
{
|
2022-02-11 20:36:15 +01:00
|
|
|
int result = _hyperion->setEffect(bgEffectConfig, PriorityMuxer::BG_PRIORITY, PriorityMuxer::ENDLESS);
|
2022-08-14 23:02:30 +02:00
|
|
|
Info(_log,"Initial background effect '%s' %s", QSTRING_CSTR(bgEffectConfig), ((result == 0) ? "started" : "failed"));
|
2018-12-27 23:11:32 +01:00
|
|
|
}
|
2022-02-11 20:36:15 +01:00
|
|
|
#endif
|
2018-12-27 23:11:32 +01:00
|
|
|
}
|
|
|
|
#undef BGCONFIG_ARRAY
|
|
|
|
}
|
2020-11-14 17:58:56 +01:00
|
|
|
}
|
2018-12-27 23:11:32 +01:00
|
|
|
|
2021-04-25 16:50:27 +02:00
|
|
|
///
|
|
|
|
/// @brief Handle priority updates.
|
|
|
|
/// In case the background effect is not current priority, stop BG-effect to save resources; otherwise start effect again.
|
|
|
|
///
|
|
|
|
void handlePriorityUpdate()
|
|
|
|
{
|
2022-02-22 20:58:59 +01:00
|
|
|
if (_prioMuxer->getCurrentPriority() < PriorityMuxer::BG_PRIORITY && _prioMuxer->hasPriority(PriorityMuxer::BG_PRIORITY))
|
2021-04-25 16:50:27 +02:00
|
|
|
{
|
2022-08-14 23:02:30 +02:00
|
|
|
Debug(_log,"Stop background (color-) effect as it moved out of scope");
|
2021-04-25 16:50:27 +02:00
|
|
|
_hyperion->clear(PriorityMuxer::BG_PRIORITY);
|
|
|
|
}
|
2022-12-22 12:40:39 +01:00
|
|
|
else if (!_isSuspended && _prioMuxer->getCurrentPriority() == PriorityMuxer::LOWEST_PRIORITY && _isBgEffectEnabled)
|
2021-04-25 16:50:27 +02:00
|
|
|
{
|
2022-08-14 23:02:30 +02:00
|
|
|
Debug(_log,"Start background (color-) effect as it moved in scope");
|
2021-04-25 16:50:27 +02:00
|
|
|
emit handleSettingsUpdate (settings::BGEFFECT, _bgEffectConfig);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-27 23:11:32 +01:00
|
|
|
private:
|
|
|
|
/// Hyperion instance pointer
|
|
|
|
Hyperion* _hyperion;
|
2022-08-14 23:02:30 +02:00
|
|
|
Logger * _log;
|
|
|
|
|
2021-04-25 16:50:27 +02:00
|
|
|
/// priority muxer instance
|
|
|
|
PriorityMuxer* _prioMuxer;
|
|
|
|
|
|
|
|
QJsonDocument _bgEffectConfig;
|
2022-08-14 23:02:30 +02:00
|
|
|
bool _isBgEffectEnabled;
|
2022-12-22 12:40:39 +01:00
|
|
|
|
|
|
|
bool _isSuspended;
|
2018-12-27 23:11:32 +01:00
|
|
|
};
|
2022-08-14 23:02:30 +02:00
|
|
|
|
|
|
|
#endif // BGEFFECTHANDLER_H
|