hyperion.ng
Hyperion.h
1 #pragma once
2 
3 // stl includes
4 #include <list>
5 #include <QMap>
6 
7 // QT includes
8 #include <QString>
9 #include <QStringList>
10 #include <QSize>
11 #include <QJsonObject>
12 #include <QJsonValue>
13 #include <QJsonArray>
14 #include <QFileSystemWatcher>
15 #include <QMutex>
16 
17 // hyperion-utils includes
18 #include <utils/Image.h>
19 #include <utils/ColorRgb.h>
20 #include <utils/Logger.h>
21 #include <utils/Components.h>
22 #include <utils/VideoMode.h>
23 
24 // Hyperion includes
25 #include <hyperion/LedString.h>
26 #include <hyperion/PriorityMuxer.h>
27 #include <hyperion/ColorAdjustment.h>
28 #include <hyperion/ComponentRegister.h>
29 
30 // Effect engine includes
31 #include <effectengine/EffectDefinition.h>
32 #include <effectengine/ActiveEffectDefinition.h>
33 #include <effectengine/EffectSchema.h>
34 
35 // settings utils
36 #include <utils/settings.h>
37 
38 // Forward class declaration
39 class QTimer;
40 class HyperionDaemon;
41 class ImageProcessor;
42 class MessageForwarder;
44 class EffectEngine;
46 class ColorAdjustment;
47 class SettingsManager;
48 class BGEffectHandler;
49 class CaptureCont;
50 class BoblightServer;
51 class LedDeviceWrapper;
52 
57 class Hyperion : public QObject
58 {
59  Q_OBJECT
60 public:
67  {
68  BLACK, WHITE, RED, GREEN, BLUE, CYAN, MAGENTA, YELLOW, INVALID
69  };
70 
74  ~Hyperion();
75 
79  void freeObjects(bool emitCloseSignal=false);
80 
88  static Hyperion* initInstance(HyperionDaemon* daemon, const quint8& instance, const QString configFile, const QString rootPath);
89 
94  static Hyperion* getInstance();
95 
100  EffectEngine* getEffectEngineInstance() { return _effectEngine; };
101 
106  PriorityMuxer* getMuxerInstance() { return &_muxer; };
107 
108  ImageProcessor* getImageProcessor() { return _imageProcessor; };
109 
115  QJsonDocument getSetting(const settings::type& type);
116 
123  bool saveSettings(QJsonObject config, const bool& correct = false);
124 
128  unsigned getLedCount() const;
129 
133  QSize getLedGridSize() const { return _ledGridSize; };
134 
140  int getCurrentPriority() const;
141 
147  bool isCurrentPriority(const int priority) const;
148 
154  QList<int> getActivePriorities() const;
155 
163  const InputInfo getPriorityInfo(const int priority) const;
164 
171  bool saveEffect(const QJsonObject& obj, QString& resultMsg);
172 
179  bool deleteEffect(const QString& effectName, QString& resultMsg);
180 
183  const std::list<EffectDefinition> &getEffects() const;
184 
187  const std::list<ActiveEffectDefinition> &getActiveEffects();
188 
191  const std::list<EffectSchema> &getEffectSchemas();
192 
195  const QJsonObject& getQJsonConfig();
196 
199  QString getConfigFilePath() { return _configFile; };
200 
203  QString getConfigFileName() const;
204 
214  void registerInput(const int priority, const hyperion::Components& component, const QString& origin = "System", const QString& owner = "", unsigned smooth_cfg = 0);
215 
216 
219  void setSourceAutoSelectEnabled(bool enabled);
220 
224  bool setCurrentSourcePriority(int priority );
225 
229 
235  void setNewComponentState(const hyperion::Components& component, const bool& state);
236 
243  void setComponentState(const hyperion::Components component, const bool state);
244 
245  ComponentRegister& getComponentRegister() { return _componentRegister; };
246 
247  bool configModified() { return _configMod; };
248 
249  bool configWriteable() { return _configWrite; };
250 
252  const int & getLedMappingType();
253 
255  const QString &getRootPath() { return _rootPath; };
256 
258  const QString &getId(){ return _id; };
260  void setId(QString id){ _id = id; };
261 
262  int getLatchTime() const;
263 
265  unsigned addSmoothingConfig(int settlingTime_ms, double ledUpdateFrequency_hz=25.0, unsigned updateDelay=0);
266 
267  const VideoMode & getCurrentVideoMode();
268 
273  const QString & getActiveDevice();
274 
275 public slots:
285  bool setInput(const int priority, const std::vector<ColorRgb>& ledColors, const int timeout_ms = -1, const bool& clearEffect = true);
286 
296  bool setInputImage(const int priority, const Image<ColorRgb>& image, int64_t timeout_ms = -1, const bool& clearEffect = true);
297 
303  bool setInputInactive(const quint8& priority);
304 
315  void setColor(int priority, const ColorRgb &ledColor, const int timeout_ms = -1, const QString& origin = "System" ,bool clearEffects = true);
316 
321  const QStringList & getAdjustmentIds() const;
322 
327  ColorAdjustment * getAdjustment(const QString& id);
328 
330  void adjustmentsUpdated();
331 
339  bool clear(int priority);
340 
344  void clearall(bool forceClearAll=false);
345 
350  int setEffect(const QString & effectName, int priority, int timeout = -1, const QString & origin="System");
351 
357  int setEffect(const QString &effectName
358  , const QJsonObject &args
359  , int priority
360  , int timeout = -1
361  , const QString &pythonScript = ""
362  , const QString &origin="System"
363  , const QString &imageData = ""
364  );
365 
367  void setLedMappingType(const int& mappingType);
368 
373  void setVideoMode(const VideoMode& mode);
374 
375 public:
376  static Hyperion *_hyperion;
377 
378 signals:
381  void channelCleared(int priority);
382 
385  void allChannelsCleared();
386 
393  void componentStateChanged(const hyperion::Components component, bool enabled);
394 
399  void imageToLedsMappingChanged(const int& mappingType);
400 
406  void currentImage(const Image<ColorRgb> & image);
407 
408  void closing();
409 
411  void forwardJsonMessage(QJsonObject);
412 
414  void forwardSystemProtoMessage(const QString, const Image<ColorRgb>);
415 
417  void forwardV4lProtoMessage(const QString, const Image<ColorRgb>);
418 
422  void videoMode(const VideoMode& mode);
423 
427  void newVideoMode(const VideoMode& mode);
428 
434  void settingsChanged(const settings::type& type, const QJsonDocument& data);
435 
439  void adjustmentChanged();
440 
444  void effectListUpdated();
445 
449  void ledDeviceData(const std::vector<ColorRgb>& ledValues);
450 
454  void rawLedColors(const std::vector<ColorRgb>& ledValues);
455 
456 private slots:
461  void update();
462 
464  void checkConfigState(QString cfile = NULL);
465 
471  void updatedComponentState(const hyperion::Components comp, const bool state);
472 
478  void handleSettingsUpdate(const settings::type& type, const QJsonDocument& config);
479 
480 private:
481 
487  Hyperion(HyperionDaemon* daemon, const quint8& instance, const QString configFile, const QString rootPath);
488 
490  HyperionDaemon* _daemon;
491 
493  SettingsManager* _settingsManager;
494 
496  ComponentRegister _componentRegister;
497 
499  LedString _ledString;
500 
502  LedString _ledStringClone;
503 
505  ImageProcessor* _imageProcessor;
506 
507  std::vector<ColorOrder> _ledStringColorOrder;
508 
510  PriorityMuxer _muxer;
511 
513  MultiColorAdjustment * _raw2ledAdjustment;
514 
516  LedDeviceWrapper* _ledDeviceWrapper;
517 
519  LinearColorSmoothing * _deviceSmooth;
520 
522  EffectEngine * _effectEngine;
523 
524  // Message forwarder
525  MessageForwarder * _messageForwarder;
526 
528  QString _configFile;
529 
531  QString _rootPath;
532 
534  QString _id;
535 
537  Logger * _log;
538 
540  unsigned _hwLedCount;
541 
542  QByteArray _configHash;
543 
544  QSize _ledGridSize;
545 
547  hyperion::Components _prevCompId;
548 
550  QFileSystemWatcher _fsWatcher;
551  QTimer* _cTimer;
552 
554  bool _prevConfigMod = false;
555  bool _prevConfigWrite = true;
556 
558  bool _configMod = false;
559  bool _configWrite = true;
560 
562  BGEffectHandler* _BGEffectHandler;
564  CaptureCont* _captureCont;
565 
567  std::vector<ColorRgb> _ledBuffer;
568 
570  BoblightServer* _boblightServer;
571 
573  QMutex _changes;
574 };
Definition: Logger.h:32
bool setInputInactive(const quint8 &priority)
Set the given priority to inactive.
Definition: Hyperion.cpp:417
bool sourceAutoSelectEnabled()
gets current state of automatic/priorized source selection
Definition: Hyperion.cpp:363
The component register reflects and manages the current state of all components and Hyperion as a who...
Definition: ComponentRegister.h:17
void setVideoMode(const VideoMode &mode)
Set the video mode (2D/3D)
Definition: Hyperion.cpp:548
const int & getLedMappingType()
gets the methode how image is maped to leds
Definition: Hyperion.cpp:543
QString getConfigFilePath()
get path+filename of configfile
Definition: Hyperion.h:199
const std::list< ActiveEffectDefinition > & getActiveEffects()
Get the list of active effects.
Definition: Hyperion.cpp:509
void forwardV4lProtoMessage(const QString, const Image< ColorRgb >)
Signal which is emitted, when a new V4l proto image should be forwarded.
Definition: ColorAdjustment.h:10
The main class of Hyperion.
Definition: Hyperion.h:57
void setId(QString id)
set unique id
Definition: Hyperion.h:260
The LedColorTransform is responsible for performing color transformation from &#39;raw&#39; colors received a...
Definition: MultiColorAdjustment.h:16
PriorityMuxer * getMuxerInstance()
Get a pointer to the priorityMuxer instance.
Definition: Hyperion.h:106
void setComponentState(const hyperion::Components component, const bool state)
Enable/Disable components during runtime, called from external API (requests)
Definition: Hyperion.cpp:373
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
Capture Control class which is a interface to the HyperionDaemon native capture classes.
Definition: CaptureCont.h:15
static Hyperion * getInstance()
Get a pointer of this Hyperion instance.
Definition: Hyperion.cpp:64
const QString & getActiveDevice()
Get the current active led device.
Definition: Hyperion.cpp:558
void adjustmentsUpdated()
Tell Hyperion that the corrections have changed and the leds need to be updated.
Definition: Hyperion.cpp:448
void clearall(bool forceClearAll=false)
Clears all priority channels.
Definition: Hyperion.cpp:466
void forwardJsonMessage(QJsonObject)
Signal which is emitted, when a new json message should be forwarded.
void ledDeviceData(const std::vector< ColorRgb > &ledValues)
Emits whenever new data should be pushed to the LedDeviceWrapper which forwards it to the threaded Le...
void currentImage(const Image< ColorRgb > &image)
Emits whenever the visible priority delivers a image which is applied in update() priorities with led...
unsigned addSmoothingConfig(int settlingTime_ms, double ledUpdateFrequency_hz=25.0, unsigned updateDelay=0)
forward smoothing config
Definition: Hyperion.cpp:308
void videoMode(const VideoMode &mode)
Is emitted from clients who request a videoMode change.
void registerInput(const int priority, const hyperion::Components &component, const QString &origin="System", const QString &owner="", unsigned smooth_cfg=0)
Register a new input by priority, the priority is not active (timeout -100 isn&#39;t muxer recognized) un...
Definition: Hyperion.cpp:378
QList< int > getActivePriorities() const
Returns a list of all registered priorities.
Definition: Hyperion.cpp:484
RgbChannel
RGB-Color channel enumeration.
Definition: Hyperion.h:66
The information structure for a single priority channel.
Definition: PriorityMuxer.h:37
QString getConfigFileName() const
get filename of configfile
Definition: Hyperion.cpp:297
bool isCurrentPriority(const int priority) const
Returns true if current priority is given priority.
Definition: Hyperion.cpp:479
const std::list< EffectDefinition > & getEffects() const
Get the list of available effects.
Definition: Hyperion.cpp:504
void imageToLedsMappingChanged(const int &mappingType)
Emits whenever the imageToLedsMapping has changed.
EffectEngine * getEffectEngineInstance()
Get a pointer to the effect engine.
Definition: Hyperion.h:100
void freeObjects(bool emitCloseSignal=false)
free all alocated objects, should be called only from constructor or before restarting hyperion ...
Definition: Hyperion.cpp:172
void channelCleared(int priority)
Signal which is emitted when a priority channel is actively cleared This signal will not be emitted w...
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
bool setInput(const int priority, const std::vector< ColorRgb > &ledColors, const int timeout_ms=-1, const bool &clearEffect=true)
Update the current color of a priority (prev registered with registerInput()) DO NOT use this togethe...
Definition: Hyperion.cpp:383
The PriorityMuxer handles the priority channels.
Definition: PriorityMuxer.h:30
const QStringList & getAdjustmentIds() const
Returns the list with unique adjustment identifiers.
Definition: Hyperion.cpp:438
Creates and destroys LedDevice instances with LedDeviceFactory and moves the device to a thread...
Definition: LedDeviceWrapper.h:17
void allChannelsCleared()
Signal which is emitted when all priority channels are actively cleared This signal will not be emitt...
bool setInputImage(const int priority, const Image< ColorRgb > &image, int64_t timeout_ms=-1, const bool &clearEffect=true)
Update the current image of a priority (prev registered with registerInput()) DO NOT use this togethe...
Definition: Hyperion.cpp:400
void setSourceAutoSelectEnabled(bool enabled)
enable/disable automatic/priorized source selection
Definition: Hyperion.cpp:352
const std::list< EffectSchema > & getEffectSchemas()
Get the list of available effect schema files.
Definition: Hyperion.cpp:514
int getCurrentPriority() const
Returns the current priority.
Definition: Hyperion.cpp:474
void settingsChanged(const settings::type &type, const QJsonDocument &data)
Emits whenever a config part changed.
Components
Enumeration of components in Hyperion.
Definition: Components.h:10
bool setCurrentSourcePriority(int priority)
set current input source to visible
Definition: Hyperion.cpp:358
bool clear(int priority)
Clears the given priority channel.
Definition: Hyperion.cpp:454
void componentStateChanged(const hyperion::Components component, bool enabled)
Emits whenever a user request a component state change, it&#39;s up the component to listen and update th...
The ImageProcessor translates an RGB-image to RGB-values for the leds.
Definition: ImageProcessor.h:26
Definition: MessageForwarder.h:32
Definition: EffectEngine.h:24
Linear Smooting class.
Definition: LinearColorSmoothing.h:24
const QString & getId()
get unique id per instance
Definition: Hyperion.h:258
ColorAdjustment * getAdjustment(const QString &id)
Returns the ColorAdjustment with the given identifier.
Definition: Hyperion.cpp:443
bool saveEffect(const QJsonObject &obj, QString &resultMsg)
Save an effect.
Definition: Hyperion.cpp:494
void adjustmentChanged()
Emits whenever the adjustments have been updated.
Definition: hyperiond.h:67
Manage the settings read write from/to config file, on settings changed will emit a signal to update ...
Definition: SettingsManager.h:14
void newVideoMode(const VideoMode &mode)
A new videoMode was requested (called from Daemon!)
Handle the background Effect settings, reacts on runtime to settings changes.
Definition: BGEffectHandler.h:10
const QJsonObject & getQJsonConfig()
gets the current json config object from SettingsManager
Definition: Hyperion.cpp:519
void forwardSystemProtoMessage(const QString, const Image< ColorRgb >)
Signal which is emitted, when a new system proto image should be forwarded.
unsigned getLedCount() const
Returns the number of attached leds.
Definition: Hyperion.cpp:313
QJsonDocument getSetting(const settings::type &type)
Get a setting by settings::type from SettingsManager.
Definition: Hyperion.cpp:287
~Hyperion()
Destructor; cleans up resources.
Definition: Hyperion.cpp:167
void rawLedColors(const std::vector< ColorRgb > &ledValues)
Emits whenever new untransformed ledColos data is available, reflects the current visible device...
const InputInfo getPriorityInfo(const int priority) const
Returns the information of a specific priorrity channel.
Definition: Hyperion.cpp:489
This class creates a TCP server which accepts connections from boblight clients.
Definition: BoblightServer.h:24
bool saveSettings(QJsonObject config, const bool &correct=false)
Save a complete json config.
Definition: Hyperion.cpp:292
QSize getLedGridSize() const
Return the size of led grid.
Definition: Hyperion.h:133
const QString & getRootPath()
get the root path for all hyperion user data files
Definition: Hyperion.h:255
The LedString contains the image integration information of the leds.
Definition: LedString.h:111
bool deleteEffect(const QString &effectName, QString &resultMsg)
Delete an effect by name.
Definition: Hyperion.cpp:499
PriorityMuxer::InputInfo InputInfo
Type definition of the info structure used by the priority muxer.
Definition: Hyperion.h:62
void setLedMappingType(const int &mappingType)
sets the methode how image is maped to leds at ImageProcessor
Definition: Hyperion.cpp:534
void effectListUpdated()
Signal pipe from EffectEngine to external, emits when effect list has been updated.
Plain-Old-Data structure containing the red-green-blue color specification.
Definition: ColorRgb.h:13
void setNewComponentState(const hyperion::Components &component, const bool &state)
Called from components to update their current state.
Definition: Hyperion.cpp:368
static Hyperion * initInstance(HyperionDaemon *daemon, const quint8 &instance, const QString configFile, const QString rootPath)
creates a new Hyperion instance, usually called from the Hyperion Daemon
Definition: Hyperion.cpp:55