hyperion.ng
BGEffectHandler.h
1 #pragma once
2 
3 #include <utils/Logger.h>
4 #include <hyperion/Hyperion.h>
5 #include <utils/settings.h>
6 
10 class BGEffectHandler : public QObject
11 {
12  Q_OBJECT
13 
14 public:
16  : QObject(hyperion)
17  , _hyperion(hyperion)
18  {
19  // listen for config changes
20  connect(_hyperion, &Hyperion::settingsChanged, this, &BGEffectHandler::handleSettingsUpdate);
21 
22  // init
23  handleSettingsUpdate(settings::BGEFFECT, _hyperion->getSetting(settings::BGEFFECT));
24  };
25 
26 private slots:
32  void handleSettingsUpdate(const settings::type& type, const QJsonDocument& config)
33  {
34  if(type == settings::BGEFFECT)
35  {
36  const QJsonObject& BGEffectConfig = config.object();
37 
38  #define BGCONFIG_ARRAY bgColorConfig.toArray()
39  // clear bg prioritiy
40  _hyperion->clear(254);
41  // initial background effect/color
42  if (BGEffectConfig["enable"].toBool(true))
43  {
44  const QString bgTypeConfig = BGEffectConfig["type"].toString("effect");
45  const QString bgEffectConfig = BGEffectConfig["effect"].toString("Warm mood blobs");
46  const QJsonValue bgColorConfig = BGEffectConfig["color"];
47  if (bgTypeConfig.contains("color"))
48  {
49  ColorRgb bg_color = {
50  (uint8_t)BGCONFIG_ARRAY.at(0).toInt(0),
51  (uint8_t)BGCONFIG_ARRAY.at(1).toInt(0),
52  (uint8_t)BGCONFIG_ARRAY.at(2).toInt(0)
53  };
54  _hyperion->setColor(254, bg_color);
55  Info(Logger::getInstance("HYPERION"),"Inital background color set (%d %d %d)",bg_color.red,bg_color.green,bg_color.blue);
56  }
57  else
58  {
59  int result = _hyperion->setEffect(bgEffectConfig, 254);
60  Info(Logger::getInstance("HYPERION"),"Inital background effect '%s' %s", QSTRING_CSTR(bgEffectConfig), ((result == 0) ? "started" : "failed"));
61  }
62  }
63 
64  #undef BGCONFIG_ARRAY
65  }
66  };
67 
68 private:
70  Hyperion* _hyperion;
71 };
The main class of Hyperion.
Definition: Hyperion.h:57
Provide utility methods for Hyperion class.
Definition: BlackBorderDetector.h:7
void setColor(int priority, const ColorRgb &ledColor, const int timeout_ms=-1, const QString &origin="System", bool clearEffects=true)
Writes a single color to all the leds for the given time and priority Registers comp color or provide...
Definition: Hyperion.cpp:422
uint8_t green
The green color channel.
Definition: ColorRgb.h:18
int setEffect(const QString &effectName, int priority, int timeout=-1, const QString &origin="System")
Run the specified effect on the given priority channel and optionally specify a timeout.
Definition: Hyperion.cpp:524
void settingsChanged(const settings::type &type, const QJsonDocument &data)
Emits whenever a config part changed.
bool clear(int priority)
Clears the given priority channel.
Definition: Hyperion.cpp:454
uint8_t blue
The blue color channel.
Definition: ColorRgb.h:20
Handle the background Effect settings, reacts on runtime to settings changes.
Definition: BGEffectHandler.h:10
QJsonDocument getSetting(const settings::type &type)
Get a setting by settings::type from SettingsManager.
Definition: Hyperion.cpp:287
uint8_t red
The red color channel.
Definition: ColorRgb.h:16
Plain-Old-Data structure containing the red-green-blue color specification.
Definition: ColorRgb.h:13