2019-01-01 19:47:07 +01:00
# 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 :
2020-02-10 15:21:58 +01:00
explicit LedDeviceWrapper ( Hyperion * hyperion ) ;
2019-01-01 19:47:07 +01:00
~ 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 ( ) ;
///
2019-12-08 13:12:01 +01:00
/// @brief Get the current active ledDevice type
2019-01-01 19:47:07 +01:00
///
2019-12-08 13:12:01 +01:00
const QString & getActiveDeviceType ( ) ;
2019-01-01 19:47:07 +01:00
///
/// @brief Return the last enable state
///
2020-02-10 15:21:58 +01:00
const bool & enabled ( ) { return _enabled ; }
2019-01-01 19:47:07 +01:00
///
/// @brief Get the current colorOrder from device
///
const QString & getColorOrder ( ) ;
2020-02-10 15:21:58 +01:00
///
/// @brief Get the number of Leds from device
///
unsigned int getLedCount ( ) const ;
2019-01-01 19:47:07 +01:00
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
///
2020-02-10 15:21:58 +01:00
int updateLeds ( const std : : vector < ColorRgb > & ledValues ) ;
void setEnable ( bool enable ) ;
void closeLedDevice ( ) ;
2019-01-01 19:47:07 +01:00
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 ;
} ;