mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
Threading and more
- webui remove restarts - threading for LedDevice
This commit is contained in:
@@ -14,7 +14,7 @@
|
||||
#include <utils/settings.h>
|
||||
|
||||
class Grabber;
|
||||
class DispmanxFrameGrabber;
|
||||
class GlobalSignals;
|
||||
class QTimer;
|
||||
|
||||
///
|
||||
@@ -60,7 +60,6 @@ public:
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public slots:
|
||||
///
|
||||
/// virtual method, should perform single frame grab and computes the led-colors
|
||||
|
@@ -5,7 +5,7 @@
|
||||
#include <QMap>
|
||||
|
||||
// QT includes
|
||||
#include <QObject>
|
||||
//#include <QObject>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
#include <QSize>
|
||||
@@ -37,11 +37,9 @@
|
||||
|
||||
// Forward class declaration
|
||||
class QTimer;
|
||||
|
||||
class HyperionDaemon;
|
||||
class ImageProcessor;
|
||||
class MessageForwarder;
|
||||
class LedDevice;
|
||||
class LinearColorSmoothing;
|
||||
class EffectEngine;
|
||||
class MultiColorAdjustment;
|
||||
@@ -50,6 +48,7 @@ class SettingsManager;
|
||||
class BGEffectHandler;
|
||||
class CaptureCont;
|
||||
class BoblightServer;
|
||||
class LedDeviceWrapper;
|
||||
|
||||
///
|
||||
/// The main class of Hyperion. This gives other 'users' access to the attached LedDevice through
|
||||
@@ -228,6 +227,13 @@ public:
|
||||
/// @return the state
|
||||
bool sourceAutoSelectEnabled();
|
||||
|
||||
///
|
||||
/// @brief Called from components to update their current state. DO NOT CALL FROM USERS
|
||||
/// @param[in] component The component from enum
|
||||
/// @param[in] state The state of the component [true | false]
|
||||
///
|
||||
void setNewComponentState(const hyperion::Components& component, const bool& state);
|
||||
|
||||
///
|
||||
/// @brief Enable/Disable components during runtime, called from external API (requests)
|
||||
///
|
||||
@@ -432,13 +438,9 @@ signals:
|
||||
void effectListUpdated();
|
||||
|
||||
///
|
||||
/// @brief systemImage from the parent HyperionDaemon SystemCapture
|
||||
/// @brief Emits whenever new data should be pushed to the LedDeviceWrapper which forwards it to the threaded LedDevice
|
||||
///
|
||||
void systemImage(const Image<ColorRgb>& image);
|
||||
///
|
||||
/// @brief v4lImage from the parent HyperionDaemon V4lCapture
|
||||
///
|
||||
void v4lImage(const Image<ColorRgb> & image);
|
||||
void ledDeviceData(const std::vector<ColorRgb>& ledValues);
|
||||
|
||||
///
|
||||
/// @brief Emits whenever new untransformed ledColos data is available, reflects the current visible device
|
||||
@@ -504,8 +506,8 @@ private:
|
||||
/// The adjustment from raw colors to led colors
|
||||
MultiColorAdjustment * _raw2ledAdjustment;
|
||||
|
||||
/// The actual LedDevice
|
||||
LedDevice * _device;
|
||||
/// The actual LedDeviceWrapper
|
||||
LedDeviceWrapper* _ledDeviceWrapper;
|
||||
|
||||
/// The smoothing LedDevice
|
||||
LinearColorSmoothing * _deviceSmooth;
|
||||
@@ -513,7 +515,7 @@ private:
|
||||
/// Effect engine
|
||||
EffectEngine * _effectEngine;
|
||||
|
||||
// proto and json Message forwarder
|
||||
// Message forwarder
|
||||
MessageForwarder * _messageForwarder;
|
||||
|
||||
/// the name of config file
|
||||
|
@@ -34,11 +34,8 @@ class LedDevice : public QObject
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
LedDevice();
|
||||
///
|
||||
/// Empty virtual destructor for pure virtual base class
|
||||
///
|
||||
virtual ~LedDevice() {}
|
||||
LedDevice(const QJsonObject& config = QJsonObject(), QObject* parent = nullptr);
|
||||
virtual ~LedDevice();
|
||||
|
||||
/// Switch the leds off (led hardware disable)
|
||||
virtual int switchOff();
|
||||
@@ -48,33 +45,38 @@ public:
|
||||
|
||||
virtual int setLedValues(const std::vector<ColorRgb>& ledValues);
|
||||
|
||||
///
|
||||
/// Opens and configures the output device
|
||||
///
|
||||
/// @return Zero on succes else negative
|
||||
///
|
||||
virtual int open();
|
||||
|
||||
///
|
||||
/// @brief Get color order of device
|
||||
/// @return The color order
|
||||
///
|
||||
const QString & getColorOrder() { return _colorOrder; };
|
||||
|
||||
static int addToDeviceMap(QString name, LedDeviceCreateFuncType funcPtr);
|
||||
static const LedDeviceRegistry& getDeviceMap();
|
||||
void setActiveDevice(QString dev);
|
||||
const QString & getActiveDevice() { return _activeDevice; };
|
||||
static QJsonObject getLedDeviceSchemas();
|
||||
void setLedCount(int ledCount);
|
||||
int getLedCount() { return _ledCount; }
|
||||
|
||||
void setEnable(bool enable);
|
||||
bool enabled() { return _enabled; };
|
||||
int getLatchTime() { return _latchTime_ms; };
|
||||
const int getLatchTime() { return _latchTime_ms; };
|
||||
|
||||
inline bool componentState() { return enabled(); };
|
||||
|
||||
public slots:
|
||||
///
|
||||
/// Is called on thread start, all construction tasks and init should run here
|
||||
///
|
||||
virtual void start() { _deviceReady = open(); };
|
||||
|
||||
///
|
||||
/// Writes the RGB-Color values to the leds.
|
||||
///
|
||||
/// @param[in] ledValues The RGB-color per led
|
||||
///
|
||||
/// @return Zero on success else negative
|
||||
///
|
||||
virtual int write(const std::vector<ColorRgb>& ledValues) = 0;
|
||||
|
||||
signals:
|
||||
///
|
||||
/// Emits whenever the led device switches between on/off
|
||||
@@ -83,16 +85,18 @@ signals:
|
||||
void enableStateChanged(bool newState);
|
||||
|
||||
protected:
|
||||
///
|
||||
/// Writes the RGB-Color values to the leds.
|
||||
///
|
||||
/// @param[in] ledValues The RGB-color per led
|
||||
///
|
||||
/// @return Zero on success else negative
|
||||
///
|
||||
virtual int write(const std::vector<ColorRgb>& ledValues) = 0;
|
||||
virtual bool init(const QJsonObject &deviceConfig);
|
||||
|
||||
///
|
||||
/// Opens and configures the output device
|
||||
///
|
||||
/// @return Zero on succes else negative
|
||||
///
|
||||
virtual int open();
|
||||
|
||||
// Helper to pipe device config from constructor to start()
|
||||
QJsonObject _devConfig;
|
||||
|
||||
/// The common Logger instance for all LedDevices
|
||||
Logger * _log;
|
||||
|
||||
@@ -102,7 +106,6 @@ protected:
|
||||
bool _deviceReady;
|
||||
|
||||
QString _activeDevice;
|
||||
static LedDeviceRegistry _ledDeviceMap;
|
||||
|
||||
int _ledCount;
|
||||
int _ledRGBCount;
|
||||
|
111
include/leddevice/LedDeviceWrapper.h
Normal file
111
include/leddevice/LedDeviceWrapper.h
Normal file
@@ -0,0 +1,111 @@
|
||||
#pragma once
|
||||
|
||||
// util
|
||||
#include <utils/Logger.h>
|
||||
#include <utils/ColorRgb.h>
|
||||
#include <utils/Components.h>
|
||||
|
||||
class LedDevice;
|
||||
class Hyperion;
|
||||
|
||||
typedef LedDevice* ( *LedDeviceCreateFuncType ) ( const QJsonObject& );
|
||||
typedef std::map<QString,LedDeviceCreateFuncType> LedDeviceRegistry;
|
||||
|
||||
///
|
||||
/// @brief Creates and destroys LedDevice instances with LedDeviceFactory and moves the device to a thread. Pipes all signal/slots and methods to LedDevice instance
|
||||
///
|
||||
class LedDeviceWrapper : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
LedDeviceWrapper(Hyperion* hyperion);
|
||||
~LedDeviceWrapper();
|
||||
///
|
||||
/// @brief Contructs a new LedDevice, moves to thread and starts
|
||||
/// @param config With the given config
|
||||
///
|
||||
void createLedDevice(const QJsonObject& config);
|
||||
|
||||
///
|
||||
/// @brief Get all available device schemas
|
||||
/// @return device schemas
|
||||
///
|
||||
static const QJsonObject getLedDeviceSchemas();
|
||||
|
||||
///
|
||||
/// @brief add all device constrcutors to the map
|
||||
///
|
||||
static int addToDeviceMap(QString name, LedDeviceCreateFuncType funcPtr);
|
||||
|
||||
///
|
||||
/// @brief Return all available device contructors
|
||||
/// @return device constrcutors
|
||||
///
|
||||
static const LedDeviceRegistry& getDeviceMap();
|
||||
|
||||
///
|
||||
/// @brief Get the current latchtime of the ledDevice
|
||||
/// @ return latchtime in ms
|
||||
///
|
||||
int getLatchTime();
|
||||
|
||||
///
|
||||
/// @brief Get the current active ledDevice
|
||||
///
|
||||
const QString & getActiveDevice();
|
||||
|
||||
///
|
||||
/// @brief Return the last enable state
|
||||
///
|
||||
const bool & enabled() { return _enabled; };
|
||||
|
||||
///
|
||||
/// @brief Get the current colorOrder from device
|
||||
///
|
||||
const QString & getColorOrder();
|
||||
|
||||
public slots:
|
||||
///
|
||||
/// @brief Handle new component state request
|
||||
/// @apram component The comp from enum
|
||||
/// @param state The new state
|
||||
///
|
||||
void handleComponentState(const hyperion::Components component, const bool state);
|
||||
|
||||
signals:
|
||||
///
|
||||
/// PIPER signal for Hyperion -> LedDevice
|
||||
///
|
||||
/// @param[in] ledValues The RGB-color per led
|
||||
///
|
||||
/// @return Zero on success else negative
|
||||
///
|
||||
int write(const std::vector<ColorRgb>& ledValues);
|
||||
|
||||
private slots:
|
||||
///
|
||||
/// @brief Is called whenever the led device switches between on/off. The led device can disable it's component state
|
||||
/// The signal comes from the LedDevice
|
||||
/// @param newState The new state of the device
|
||||
///
|
||||
void handleInternalEnableState(bool newState);
|
||||
|
||||
|
||||
protected:
|
||||
/// contains all available led device constrcutors
|
||||
static LedDeviceRegistry _ledDeviceMap;
|
||||
|
||||
private:
|
||||
///
|
||||
/// @brief switchOff() the device and Stops the device thread
|
||||
///
|
||||
void stopDeviceThread();
|
||||
|
||||
private:
|
||||
// parent Hyperion
|
||||
Hyperion* _hyperion;
|
||||
// Pointer of current led device
|
||||
LedDevice* _ledDevice;
|
||||
// the enable state
|
||||
bool _enabled;
|
||||
};
|
41
include/utils/GlobalSignals.h
Normal file
41
include/utils/GlobalSignals.h
Normal file
@@ -0,0 +1,41 @@
|
||||
#pragma once
|
||||
|
||||
// util
|
||||
#include <utils/Image.h>
|
||||
#include <utils/ColorRgb.h>
|
||||
|
||||
// qt
|
||||
#include <QObject>
|
||||
|
||||
///
|
||||
/// Singleton instance for simple signal sharing across threads, should be never used with Qt:DirectConnection!
|
||||
///
|
||||
class GlobalSignals : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
static GlobalSignals* getInstance()
|
||||
{
|
||||
static GlobalSignals instance;
|
||||
return & instance;
|
||||
}
|
||||
private:
|
||||
GlobalSignals() {}
|
||||
|
||||
public:
|
||||
GlobalSignals(GlobalSignals const&) = delete;
|
||||
void operator=(GlobalSignals const&) = delete;
|
||||
|
||||
signals:
|
||||
///
|
||||
/// @brief PIPE SystemCapture images from GrabberWrapper to Hyperion class
|
||||
/// @param image The prepared image
|
||||
///
|
||||
void setSystemImage(const Image<ColorRgb>& image);
|
||||
|
||||
///
|
||||
/// @brief PIPE v4lCapture images from v4lCapture over HyperionDaemon to Hyperion class
|
||||
/// @param image The prepared image
|
||||
///
|
||||
void setV4lImage(const Image<ColorRgb> & image);
|
||||
};
|
Reference in New Issue
Block a user