2018-12-27 23:11:32 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <utils/Logger.h>
|
|
|
|
#include <hyperion/Hyperion.h>
|
|
|
|
#include <utils/settings.h>
|
|
|
|
|
|
|
|
///
|
|
|
|
/// @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)
|
|
|
|
{
|
|
|
|
// listen for config changes
|
|
|
|
connect(_hyperion, &Hyperion::settingsChanged, this, &BGEffectHandler::handleSettingsUpdate);
|
|
|
|
|
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
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
const QJsonObject& BGEffectConfig = config.object();
|
|
|
|
|
|
|
|
#define BGCONFIG_ARRAY bgColorConfig.toArray()
|
2020-11-14 17:58:56 +01:00
|
|
|
// clear background priority
|
2018-12-27 23:11:32 +01:00
|
|
|
_hyperion->clear(254);
|
|
|
|
// initial background effect/color
|
|
|
|
if (BGEffectConfig["enable"].toBool(true))
|
|
|
|
{
|
|
|
|
const QString bgTypeConfig = BGEffectConfig["type"].toString("effect");
|
|
|
|
const QString bgEffectConfig = BGEffectConfig["effect"].toString("Warm mood blobs");
|
|
|
|
const QJsonValue bgColorConfig = BGEffectConfig["color"];
|
|
|
|
if (bgTypeConfig.contains("color"))
|
|
|
|
{
|
2020-02-26 18:54:56 +01:00
|
|
|
std::vector<ColorRgb> bg_color = {
|
|
|
|
ColorRgb {
|
2020-11-14 17:58:56 +01:00
|
|
|
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))
|
2020-02-26 18:54:56 +01:00
|
|
|
}
|
2018-12-27 23:11:32 +01:00
|
|
|
};
|
|
|
|
_hyperion->setColor(254, bg_color);
|
2020-11-14 17:58:56 +01:00
|
|
|
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);
|
2018-12-27 23:11:32 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int result = _hyperion->setEffect(bgEffectConfig, 254);
|
2020-11-14 17:58:56 +01:00
|
|
|
Info(Logger::getInstance("HYPERION"),"Initial background effect '%s' %s", QSTRING_CSTR(bgEffectConfig), ((result == 0) ? "started" : "failed"));
|
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
|
|
|
|
|
|
|
private:
|
|
|
|
/// Hyperion instance pointer
|
|
|
|
Hyperion* _hyperion;
|
|
|
|
};
|