hyperion.ng/include/hyperion/Hyperion.h

393 lines
12 KiB
C
Raw Normal View History

#pragma once
// stl includes
#include <list>
#include <QMap>
// QT includes
#include <QObject>
#include <QString>
#include <QStringList>
#include <QTimer>
#include <QSize>
#include <QJsonObject>
#include <QJsonValue>
#include <QJsonArray>
// hyperion-utils includes
#include <utils/Image.h>
#include <utils/ColorRgb.h>
#include <utils/Logger.h>
#include <utils/Components.h>
// Hyperion includes
#include <hyperion/LedString.h>
#include <hyperion/PriorityMuxer.h>
#include <hyperion/ColorAdjustment.h>
#include <hyperion/MessageForwarder.h>
#include <hyperion/ComponentRegister.h>
// Effect engine includes
#include <effectengine/EffectDefinition.h>
#include <effectengine/ActiveEffectDefinition.h>
#include <effectengine/EffectSchema.h>
// KodiVideoChecker includes
#include <kodivideochecker/KODIVideoChecker.h>
#include <bonjour/bonjourservicebrowser.h>
#include <bonjour/bonjourserviceresolver.h>
// Forward class declaration
class LedDevice;
class LinearColorSmoothing;
class RgbTransform;
class EffectEngine;
class RgbChannelAdjustment;
class MultiColorAdjustment;
class KODIVideoChecker;
2013-09-06 21:26:58 +02:00
///
/// The main class of Hyperion. This gives other 'users' access to the attached LedDevice through
/// the priority muxer.
///
class Hyperion : public QObject
{
Q_OBJECT
public:
2013-09-06 21:26:58 +02:00
/// Type definition of the info structure used by the priority muxer
typedef PriorityMuxer::InputInfo InputInfo;
typedef QMap<QString,int> PriorityRegister;
typedef QMap<QString,BonjourRecord> BonjourRegister;
2013-09-06 21:26:58 +02:00
///
/// RGB-Color channel enumeration
///
enum RgbChannel
{
BLACK, WHITE, RED, GREEN, BLUE, CYAN, MAGENTA, YELLOW, INVALID
};
2013-09-06 21:26:58 +02:00
///
/// Destructor; cleans up resources
2013-09-06 21:26:58 +02:00
///
~Hyperion();
///
/// free all alocated objects, should be called only from constructor or before restarting hyperion
///
void freeObjects(bool emitCloseSignal=false);
static Hyperion* initInstance(const QJsonObject& qjsonConfig, const QString configFile);
static Hyperion* getInstance();
2013-09-06 21:26:58 +02:00
///
/// Returns the number of attached leds
///
2013-08-14 10:54:49 +02:00
unsigned getLedCount() const;
QSize getLedGridSize() const { return _ledGridSize; };
///
/// Returns the current priority
///
/// @return The current priority
///
int getCurrentPriority() const;
///
/// Returns a list of active priorities
///
/// @return The list with priorities
///
QList<int> getActivePriorities() const;
///
/// Returns the information of a specific priorrity channel
///
/// @param[in] priority The priority channel
///
/// @return The information of the given
///
/// @throw std::runtime_error when the priority channel does not exist
///
const InputInfo& getPriorityInfo(const int priority) const;
/// Reload the list of available effects
void reloadEffects();
/// Get the list of available effects
/// @return The list of available effects
const std::list<EffectDefinition> &getEffects() const;
/// Get the list of active effects
/// @return The list of active effects
const std::list<ActiveEffectDefinition> &getActiveEffects();
/// Get the list of available effect schema files
/// @return The list of available effect schema files
const std::list<EffectSchema> &getEffectSchemas();
/// gets the current json config object
/// @return json config
const QJsonObject& getQJsonConfig() { return _qjsonConfig; };
/// get filename of configfile
/// @return the current config filename
QString getConfigFileName() { return _configFile; };
/// register a input source to a priority channel
/// @param name uniq name of input source
/// @param origin External setter
/// @param priority priority channel
void registerPriority(const QString &name, const int priority);
/// unregister a input source to a priority channel
/// @param name uniq name of input source
void unRegisterPriority(const QString &name);
/// gets current priority register
/// @return the priority register
const PriorityRegister& getPriorityRegister() { return _priorityRegister; }
/// enable/disable automatic/priorized source selection
/// @param enabled the state
void setSourceAutoSelectEnabled(bool enabled);
/// set current input source to visible
/// @param priority the priority channel which should be vidible
/// @return true if success, false on error
bool setCurrentSourcePriority(int priority );
/// gets current state of automatic/priorized source selection
/// @return the state
bool sourceAutoSelectEnabled() { return _sourceAutoSelectEnabled; };
///
/// Enable/Disable components during runtime
///
/// @param component The component [SMOOTHING, BLACKBORDER, KODICHECKER, FORWARDER, UDPLISTENER, BOBLIGHT_SERVER, GRABBER]
/// @param state The state of the component [true | false]
///
void setComponentState(const hyperion::Components component, const bool state);
ComponentRegister& getComponentRegister() { return _componentRegister; };
bool configModified();
bool configWriteable();
/// gets the methode how image is maped to leds
int getLedMappingType() { return _ledMAppingType; };
int getConfigVersionId() { return _configVersionId; };
public slots:
2013-09-06 21:26:58 +02:00
///
/// Writes a single color to all the leds for the given time and priority
///
/// @param[in] priority The priority of the written color
/// @param[in] ledColor The color to write to the leds
/// @param[in] timeout_ms The time the leds are set to the given color [ms]
///
void setColor(int priority, const ColorRgb &ledColor, const int timeout_ms, bool clearEffects = true);
2013-08-18 13:33:56 +02:00
2013-09-06 21:26:58 +02:00
///
/// Writes the given colors to all leds for the given time and priority
///
/// @param[in] priority The priority of the written colors
/// @param[in] ledColors The colors to write to the leds
/// @param[in] timeout_ms The time the leds are set to the given colors [ms]
/// @param[in] component The current component
/// @param[in] origin Who set it
2013-09-06 21:26:58 +02:00
///
void setColors(int priority, const std::vector<ColorRgb> &ledColors, const int timeout_ms, bool clearEffects = true, hyperion::Components component=hyperion::COMP_INVALID, const QString origin="System");
2013-08-18 13:33:56 +02:00
///
/// Writes the given colors to all leds for the given time and priority
///
/// @param[in] priority The priority of the written colors
/// @param[in] ledColors The colors to write to the leds
/// @param[in] timeout_ms The time the leds are set to the given colors [ms]
///
void setImage(int priority, const Image<ColorRgb> & image, int duration_ms);
///
/// Returns the list with unique adjustment identifiers
/// @return The list with adjustment identifiers
///
const QStringList & getAdjustmentIds() const;
///
/// Returns the ColorAdjustment with the given identifier
/// @return The adjustment with the given identifier (or nullptr if the identifier does not exist)
///
ColorAdjustment * getAdjustment(const QString& id);
///
/// Returns MessageForwarder Object
/// @return instance of message forwarder object
///
MessageForwarder * getForwarder();
/// Tell Hyperion that the corrections have changed and the leds need to be updated
void adjustmentsUpdated();
2013-09-06 21:26:58 +02:00
///
/// Clears the given priority channel. This will switch the led-colors to the colors of the next
/// lower priority channel (or off if no more channels are set)
///
/// @param[in] priority The priority channel
///
2013-08-18 13:33:56 +02:00
void clear(int priority);
2013-09-06 21:26:58 +02:00
///
/// Clears all priority channels. This will switch the leds off until a new priority is written.
///
2013-08-18 13:33:56 +02:00
void clearall();
/// Run the specified effect on the given priority channel and optionally specify a timeout
/// @param effectName Name of the effec to run
/// @param priority The priority channel of the effect
/// @param timeout The timeout of the effect (after the timout, the effect will be cleared)
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
/// @param effectName Name of the effec to run
/// @param args arguments of the effect script
/// @param priority The priority channel of the effect
/// @param timeout The timeout of the effect (after the timout, the effect will be cleared)
int setEffect(const QString & effectName, const QJsonObject & args, int priority,
int timeout = -1, const QString & pythonScript = "", const QString & origin="System");
/// sets the methode how image is maped to leds
void setLedMappingType(int mappingType);
///
Hyperion::BonjourRegister getHyperionSessions();
public:
static Hyperion *_hyperion;
static ColorOrder createColorOrder(const QJsonObject & deviceConfig);
/**
* Construct the 'led-string' with the integration area definition per led and the color
* ordering of the RGB channels
* @param ledsConfig The configuration of the led areas
* @param deviceOrder The default RGB channel ordering
* @return The constructed ledstring
*/
static LedString createLedString(const QJsonValue & ledsConfig, const ColorOrder deviceOrder);
static LedString createLedStringClone(const QJsonValue & ledsConfig, const ColorOrder deviceOrder);
static MultiColorAdjustment * createLedColorsAdjustment(const unsigned ledCnt, const QJsonObject & colorAdjustmentConfig);
static ColorAdjustment * createColorAdjustment(const QJsonObject & adjustmentConfig);
static RgbTransform * createRgbTransform(const QJsonObject& colorConfig);
static RgbChannelAdjustment * createRgbChannelAdjustment(const QJsonObject & colorConfig, const QString channelName, const int defaultR, const int defaultG, const int defaultB);
static LinearColorSmoothing * createColorSmoothing(const QJsonObject & smoothingConfig, LedDevice* leddevice);
static MessageForwarder * createMessageForwarder(const QJsonObject & forwarderConfig);
static QSize getLedLayoutGridSize(const QJsonValue& ledsConfig);
signals:
/// Signal which is emitted when a priority channel is actively cleared
/// This signal will not be emitted when a priority channel time out
void channelCleared(int priority);
/// Signal which is emitted when all priority channels are actively cleared
/// This signal will not be emitted when a priority channel time out
void allChannelsCleared();
void componentStateChanged(const hyperion::Components component, bool enabled);
void imageToLedsMappingChanged(int mappingType);
void emitImage(int priority, const Image<ColorRgb> & image, const int timeout_ms);
void closing();
private slots:
2013-09-06 21:26:58 +02:00
///
/// Updates the priority muxer with the current time and (re)writes the led color with applied
/// transforms.
///
void update();
void currentBonjourRecordsChanged(const QList<BonjourRecord> &list);
void bonjourRecordResolved(const QHostInfo &hostInfo, int port);
void bonjourResolve();
private:
///
/// Constructs the Hyperion instance based on the given Json configuration
///
JsonCpp to QTJson (Final Part) (#273) * Update CMakeLists.txt * Update Hyperion.h * Update LedDevice.h * Update LedDeviceFactory.h * Update Hyperion.cpp * Update LedString.cpp * Update JsonClientConnection.cpp * Update LedDeviceAdalight.cpp * Update LedDeviceAdalight.h * Update LedDeviceAPA102.cpp * Update LedDeviceAdalightApa102.h * Update LedDeviceAdalightApa102.cpp * Update LedDeviceAPA102.h * Update LedDeviceAtmo.cpp * Update LedDeviceAtmo.h * Update LedDeviceAtmoOrb.cpp * Update LedDeviceAtmoOrb.h * Update LedDeviceDMX.cpp * Update LedDeviceDMX.h * Update LedDeviceFactory.cpp * Update LedDeviceFadeCandy.cpp * Update LedDeviceFadeCandy.h * Update LedDeviceFile.cpp * Update LedDeviceFile.h * Update LedDeviceHyperionUsbasp.cpp * Update LedDeviceHyperionUsbasp.h * Update LedDeviceLightpack.cpp * Update LedDeviceLightpack.h * Update LedDeviceLpd6803.cpp * Update LedDeviceLpd6803.h * Update LedDeviceLpd8806.cpp * Update LedDeviceLpd8806.h * Update LedDeviceMultiLightpack.cpp * Update LedDeviceMultiLightpack.h * Update LedDeviceP9813.cpp * Update LedDeviceP9813.h * Update LedDevicePaintpack.cpp * Update LedDevicePaintpack.h * Update LedDevicePhilipsHue.cpp * Update LedDevicePhilipsHue.h * Update LedDevicePiBlaster.cpp * Update LedDevicePiBlaster.h * Update LedDeviceRawHID.cpp * Update LedDeviceRawHID.h * Update LedDeviceSedu.cpp * Update LedDeviceSedu.h * Update LedDeviceSk6812SPI.cpp * Update LedDeviceSk6812SPI.h * Update LedDeviceTinkerforge.cpp * Update LedDeviceTinkerforge.h * Update LedDeviceTpm2.cpp * Update LedDeviceTpm2.h * Update LedDeviceTpm2net.cpp * Update LedDeviceTpm2net.h * Update LedDeviceUdpE131.cpp * Update LedDeviceUdpE131.h * Update LedDeviceUdpH801.cpp * Update LedDeviceUdpH801.h * Update LedDeviceUdpRaw.cpp * Update LedDeviceUdpRaw.h * Update LedDeviceWs2801.cpp * Update LedDeviceWs2801.h * Update LedDeviceWS2812b.cpp * Update LedDeviceWS2812b.h * Update LedDeviceWs2812SPI.cpp * Update LedDeviceWs2812SPI.h * Update LedDeviceWS281x.cpp * Update LedDeviceWS281x.h * Update ProviderHID.cpp * Update ProviderHID.h * Update ProviderRs232.cpp * Update ProviderRs232.h * Update ProviderSpi.cpp * Update ProviderSpi.h * Update ProviderUdp.cpp * Update ProviderUdp.h * Update LedDevice.cpp * Update CMakeLists.txt * Update hyperiond.cpp * Update hyperiond.h * Update TestSpi.cpp * Delete AUTHORS * Delete CMakeLists.txt * Delete LICENSE * Delete json_batchallocator.h * Delete json_internalarray.inl * Delete json_internalmap.inl * Delete json_reader.cpp * Delete json_tool.h * Delete json_value.cpp * Delete json_valueiterator.inl * Delete json_writer.cpp * Delete sconscript * Delete autolink.h * Delete config.h * Delete features.h * Delete forwards.h * Delete json.h * Delete reader.h * Delete value.h * Delete writer.h
2016-10-13 21:59:58 +02:00
/// @param[in] qjsonConfig The Json configuration
///
Hyperion(const QJsonObject& qjsonConfig, const QString configFile);
2013-09-06 21:26:58 +02:00
/// The specifiation of the led frame construction and picture integration
2013-08-18 13:33:56 +02:00
LedString _ledString;
/// specifiation of cloned leds
LedString _ledStringClone;
std::vector<ColorOrder> _ledStringColorOrder;
2013-09-06 21:26:58 +02:00
/// The priority muxer
2013-08-18 13:33:56 +02:00
PriorityMuxer _muxer;
/// The adjustment from raw colors to led colors
MultiColorAdjustment * _raw2ledAdjustment;
2013-09-06 21:26:58 +02:00
/// The actual LedDevice
LedDevice * _device;
/// The smoothing LedDevice
LinearColorSmoothing * _deviceSmooth;
/// Effect engine
EffectEngine * _effectEngine;
// proto and json Message forwarder
MessageForwarder * _messageForwarder;
// json configuration
const QJsonObject& _qjsonConfig;
// the name of config file
QString _configFile;
2013-09-06 21:26:58 +02:00
/// The timer for handling priority channel timeouts
QTimer _timer;
QTimer _timerBonjourResolver;
/// buffer for leds
std::vector<ColorRgb> _ledBuffer;
/// Logger instance
Logger * _log;
/// count of hardware leds
unsigned _hwLedCount;
ComponentRegister _componentRegister;
/// register of input sources and it's prio channel
PriorityRegister _priorityRegister;
/// flag indicates state for autoselection of input source
bool _sourceAutoSelectEnabled;
/// holds the current priority channel that is manualy selected
int _currentSourcePriority;
QByteArray _configHash;
QSize _ledGridSize;
int _ledMAppingType;
int _configVersionId;
hyperion::Components _prevCompId;
BonjourServiceBrowser _bonjourBrowser;
BonjourServiceResolver _bonjourResolver;
BonjourRegister _hyperionSessions;
QString _bonjourCurrentServiceToResolve;
};