2013-07-26 22:38:34 +02:00
|
|
|
#pragma once
|
|
|
|
|
2013-08-19 20:33:36 +02:00
|
|
|
// stl includes
|
|
|
|
#include <list>
|
|
|
|
|
2013-08-14 17:02:09 +02:00
|
|
|
// QT includes
|
|
|
|
#include <QObject>
|
|
|
|
#include <QTimer>
|
|
|
|
|
2013-07-26 22:38:34 +02:00
|
|
|
// hyperion-utils includes
|
2013-11-11 10:00:37 +01:00
|
|
|
#include <utils/Image.h>
|
2013-07-26 22:38:34 +02:00
|
|
|
|
2013-08-13 11:10:45 +02:00
|
|
|
// Hyperion includes
|
2013-07-26 22:38:34 +02:00
|
|
|
#include <hyperion/LedString.h>
|
|
|
|
#include <hyperion/LedDevice.h>
|
2013-08-13 11:10:45 +02:00
|
|
|
#include <hyperion/PriorityMuxer.h>
|
|
|
|
|
|
|
|
// Forward class declaration
|
2013-08-23 18:24:10 +02:00
|
|
|
class HsvTransform;
|
|
|
|
class ColorTransform;
|
2013-11-24 16:10:48 +01:00
|
|
|
class EffectEngine;
|
2013-07-26 22:38:34 +02:00
|
|
|
|
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.
|
|
|
|
///
|
2013-08-14 17:02:09 +02:00
|
|
|
class Hyperion : public QObject
|
2013-07-26 22:38:34 +02:00
|
|
|
{
|
2013-08-14 17:02:09 +02:00
|
|
|
Q_OBJECT
|
2013-07-26 22:38:34 +02:00
|
|
|
public:
|
2013-09-06 21:26:58 +02:00
|
|
|
/// Type definition of the info structure used by the priority muxer
|
2013-08-19 20:33:36 +02:00
|
|
|
typedef PriorityMuxer::InputInfo InputInfo;
|
|
|
|
|
2013-09-06 21:26:58 +02:00
|
|
|
///
|
|
|
|
/// RGB-Color channel enumeration
|
|
|
|
///
|
2013-08-19 19:57:35 +02:00
|
|
|
enum Color
|
|
|
|
{
|
2013-08-21 21:50:17 +02:00
|
|
|
RED, GREEN, BLUE, INVALID
|
2013-08-19 19:57:35 +02:00
|
|
|
};
|
|
|
|
|
2013-09-06 21:26:58 +02:00
|
|
|
///
|
|
|
|
/// Enumeration of the possible color (color-channel) transforms
|
|
|
|
///
|
2013-08-19 19:57:35 +02:00
|
|
|
enum Transform
|
|
|
|
{
|
2013-08-21 21:50:17 +02:00
|
|
|
SATURATION_GAIN, VALUE_GAIN, THRESHOLD, GAMMA, BLACKLEVEL, WHITELEVEL
|
2013-08-19 19:57:35 +02:00
|
|
|
};
|
|
|
|
|
2013-11-04 20:52:57 +01:00
|
|
|
/// Enumeration containing the possible orders of device color byte data
|
|
|
|
enum ColorOrder
|
|
|
|
{
|
|
|
|
ORDER_RGB, ORDER_RBG, ORDER_GRB, ORDER_BRG, ORDER_GBR, ORDER_BGR
|
|
|
|
};
|
|
|
|
|
2013-09-06 21:26:58 +02:00
|
|
|
///
|
|
|
|
/// Constructs the Hyperion instance based on the given Json configuration
|
|
|
|
///
|
|
|
|
/// @param[in] jsonConfig The Json configuration
|
|
|
|
///
|
2013-07-26 22:38:34 +02:00
|
|
|
Hyperion(const Json::Value& jsonConfig);
|
|
|
|
|
2013-09-06 21:26:58 +02:00
|
|
|
///
|
|
|
|
/// Destructor; cleans up resourcess
|
|
|
|
///
|
2013-07-26 22:38:34 +02:00
|
|
|
~Hyperion();
|
|
|
|
|
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;
|
|
|
|
|
2013-11-29 23:22:49 +01:00
|
|
|
///
|
|
|
|
/// Returns the value of a specific color transform
|
|
|
|
///
|
|
|
|
/// @param[in] transform The type of transform
|
|
|
|
/// @param[in] color The color channel to which the transform applies (only applicable for
|
|
|
|
/// Transform::THRESHOLD, Transform::GAMMA, Transform::BLACKLEVEL,
|
|
|
|
/// Transform::WHITELEVEL)
|
|
|
|
///
|
|
|
|
/// @return The value of the specified color transform
|
|
|
|
///
|
|
|
|
double getTransform(Transform transform, Color color) 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;
|
|
|
|
|
|
|
|
/// Get the list of available effects
|
|
|
|
/// @return The list of available effects
|
|
|
|
std::list<std::string> getEffects() const;
|
|
|
|
|
|
|
|
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]
|
|
|
|
///
|
2013-11-11 10:00:37 +01:00
|
|
|
void setColor(int priority, const ColorRgb &ledColor, const int timeout_ms);
|
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]
|
|
|
|
///
|
2013-11-11 10:00:37 +01:00
|
|
|
void setColors(int priority, const std::vector<ColorRgb> &ledColors, const int timeout_ms);
|
2013-08-18 13:33:56 +02:00
|
|
|
|
2013-09-06 21:26:58 +02:00
|
|
|
///
|
|
|
|
/// Sets/Updates a part of the color transformation.
|
|
|
|
///
|
|
|
|
/// @param[in] transform The type of transform to configure
|
|
|
|
/// @param[in] color The color channel to which the transform applies (only applicable for
|
|
|
|
/// Transform::THRESHOLD, Transform::GAMMA, Transform::BLACKLEVEL,
|
|
|
|
/// Transform::WHITELEVEL)
|
|
|
|
/// @param[in] value The new value for the given transform
|
|
|
|
///
|
2013-08-19 19:57:35 +02:00
|
|
|
void setTransform(Transform transform, Color color, double value);
|
|
|
|
|
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();
|
2013-07-26 22:38:34 +02:00
|
|
|
|
2013-11-24 16:10:48 +01:00
|
|
|
/// 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 timout The timeout of the effect (after the timout, the effect will be cleared)
|
|
|
|
int setEffect(const std::string & effectName, int priority, int timeout = -1);
|
|
|
|
|
|
|
|
public:
|
2013-10-27 18:04:37 +01:00
|
|
|
static LedDevice * createDevice(const Json::Value & deviceConfig);
|
2013-11-04 20:52:57 +01:00
|
|
|
static ColorOrder createColorOrder(const Json::Value & deviceConfig);
|
2013-08-24 11:51:52 +02:00
|
|
|
static LedString createLedString(const Json::Value & ledsConfig);
|
|
|
|
static HsvTransform * createHsvTransform(const Json::Value & hsvConfig);
|
2013-09-06 21:26:58 +02:00
|
|
|
static ColorTransform * createColorTransform(const Json::Value & colorConfig);
|
2013-10-27 18:04:37 +01:00
|
|
|
static LedDevice * createColorSmoothing(const Json::Value & smoothingConfig, LedDevice * ledDevice);
|
2013-08-24 11:51:52 +02:00
|
|
|
|
2013-11-24 16:10:48 +01:00
|
|
|
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();
|
|
|
|
|
2013-08-14 17:02:09 +02:00
|
|
|
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.
|
|
|
|
///
|
2013-08-14 17:02:09 +02:00
|
|
|
void update();
|
|
|
|
|
2013-07-26 22:38:34 +02:00
|
|
|
private:
|
2013-09-06 21:26:58 +02:00
|
|
|
///
|
|
|
|
/// Applies all color transmforms to the given list of colors. The transformation is performed
|
|
|
|
/// in place.
|
|
|
|
///
|
|
|
|
/// @param colors The colors to be transformed
|
|
|
|
///
|
2013-11-11 10:00:37 +01:00
|
|
|
void applyTransform(std::vector<ColorRgb>& colors) const;
|
2013-07-26 22:38:34 +02:00
|
|
|
|
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;
|
2013-07-26 22:38:34 +02:00
|
|
|
|
2013-09-06 21:26:58 +02:00
|
|
|
/// The priority muxer
|
2013-08-18 13:33:56 +02:00
|
|
|
PriorityMuxer _muxer;
|
2013-07-26 22:38:34 +02:00
|
|
|
|
2013-09-06 21:26:58 +02:00
|
|
|
/// The HSV Transform for applying Saturation and Value transforms
|
2013-08-23 18:24:10 +02:00
|
|
|
HsvTransform * _hsvTransform;
|
2013-09-06 21:26:58 +02:00
|
|
|
/// The RED-Channel (RGB) transform
|
2013-08-23 18:24:10 +02:00
|
|
|
ColorTransform * _redTransform;
|
2013-09-06 21:26:58 +02:00
|
|
|
/// The GREEN-Channel (RGB) transform
|
2013-08-23 18:24:10 +02:00
|
|
|
ColorTransform * _greenTransform;
|
2013-09-06 21:26:58 +02:00
|
|
|
/// The BLUE-Channel (RGB) transform
|
2013-08-23 18:24:10 +02:00
|
|
|
ColorTransform * _blueTransform;
|
2013-07-26 22:38:34 +02:00
|
|
|
|
2013-11-04 20:52:57 +01:00
|
|
|
/// Value with the desired color byte order
|
|
|
|
ColorOrder _colorOrder;
|
2013-10-27 10:18:31 +01:00
|
|
|
|
2013-09-06 21:26:58 +02:00
|
|
|
/// The actual LedDevice
|
2013-10-27 18:04:37 +01:00
|
|
|
LedDevice * _device;
|
2013-08-14 17:02:09 +02:00
|
|
|
|
2013-11-24 16:10:48 +01:00
|
|
|
/// Effect engine
|
|
|
|
EffectEngine * _effectEngine;
|
|
|
|
|
2013-09-06 21:26:58 +02:00
|
|
|
/// The timer for handling priority channel timeouts
|
2013-08-14 17:02:09 +02:00
|
|
|
QTimer _timer;
|
2013-07-26 22:38:34 +02:00
|
|
|
};
|