Added/Updated/Fixed doxygen comments

This commit is contained in:
T. van der Zwan 2013-09-09 02:54:13 +00:00
parent d2d7265f02
commit 8441dd51cc
13 changed files with 385 additions and 74 deletions

View File

@ -23,27 +23,27 @@ class JsonServer : public QObject
public: public:
/// ///
/// \brief JsonServer constructor /// JsonServer constructor
/// \param hyperion Hyperion instance /// @param hyperion Hyperion instance
/// \param port port number on which to start listening for connections /// @param port port number on which to start listening for connections
/// ///
JsonServer(Hyperion * hyperion, uint16_t port = 19444); JsonServer(Hyperion * hyperion, uint16_t port = 19444);
~JsonServer(); ~JsonServer();
/// ///
/// \return the port number on which this TCP listens for incoming connections /// @return the port number on which this TCP listens for incoming connections
/// ///
uint16_t getPort() const; uint16_t getPort() const;
private slots: private slots:
/// ///
/// \brief Slot which is called when a client tries to create a new connection /// Slot which is called when a client tries to create a new connection
/// ///
void newConnection(); void newConnection();
/// ///
/// \brief Slot which is called when a client closes a connection /// Slot which is called when a client closes a connection
/// \param The Connection object which is being closed /// @param The Connection object which is being closed
/// ///
void closedConnection(JsonClientConnection * connection); void closedConnection(JsonClientConnection * connection);

View File

@ -15,17 +15,17 @@
class ColorTransform class ColorTransform
{ {
public: public:
/// @brief Default constructor /// Default constructor
ColorTransform(); ColorTransform();
/// @brief Constructor /// Constructor
/// @param threshold /// @param threshold
/// @param gamma /// @param gamma
/// @param blacklevel /// @param blacklevel
/// @param whitelevel /// @param whitelevel
ColorTransform(double threshold, double gamma, double blacklevel, double whitelevel); ColorTransform(double threshold, double gamma, double blacklevel, double whitelevel);
/// @brief Destructor /// Destructor
~ColorTransform(); ~ColorTransform();
/// @return The current threshold value /// @return The current threshold value
@ -52,7 +52,7 @@ public:
/// @param whitelevel New whitelevel value /// @param whitelevel New whitelevel value
void setWhitelevel(double whitelevel); void setWhitelevel(double whitelevel);
/// @brief Transform the given byte value /// Transform the given byte value
/// @param input The input color byte /// @param input The input color byte
/// @return The transformed byte value /// @return The transformed byte value
uint8_t transform(uint8_t input) const uint8_t transform(uint8_t input) const
@ -61,14 +61,19 @@ public:
} }
private: private:
/// @brief (re)-initilize the color mapping /// (re)-initilize the color mapping
void initializeMapping(); void initializeMapping();
private: private:
/// The threshold value
double _threshold; double _threshold;
/// The gamma value
double _gamma; double _gamma;
/// The blacklevel
double _blacklevel; double _blacklevel;
/// The whitelevel
double _whitelevel; double _whitelevel;
/// The mapping from input color to output color
uint8_t _mapping[256]; uint8_t _mapping[256];
}; };

View File

@ -4,48 +4,79 @@
#include <cstdint> #include <cstdint>
/// ///
/// \brief Color transformation to adjust the saturation and value of a RGB color value /// Color transformation to adjust the saturation and value of a RGB color value
/// ///
class HsvTransform class HsvTransform
{ {
public: public:
///
/// Default constructor /// Default constructor
///
HsvTransform(); HsvTransform();
/// @brief Constructor ///
/// @param saturationGain /// Constructor
/// @param valueGain ///
/// @param saturationGain The used saturation gain
/// @param valueGain The used value gain
///
HsvTransform(double saturationGain, double valueGain); HsvTransform(double saturationGain, double valueGain);
///
/// Destructor /// Destructor
///
~HsvTransform(); ~HsvTransform();
///
/// Updates the saturation gain
///
/// @param saturationGain New saturationGain /// @param saturationGain New saturationGain
///
void setSaturationGain(double saturationGain); void setSaturationGain(double saturationGain);
///
/// Returns the saturation gain
///
/// @return The current Saturation gain /// @return The current Saturation gain
///
double getSaturationGain() const; double getSaturationGain() const;
/// @param valueGain New Value gain ///
/// Updates the value gain
///
/// @param valueGain New value gain
///
void setValueGain(double valueGain); void setValueGain(double valueGain);
///
/// Returns the value gain
///
/// @return The current value gain /// @return The current value gain
///
double getValueGain() const; double getValueGain() const;
/// @brief Apply the transform the the given RGB values. ///
/// Apply the transform the the given RGB values.
///
/// @param red The red color component /// @param red The red color component
/// @param green The green color component /// @param green The green color component
/// @param blue The blue color component /// @param blue The blue color component
///
/// @note The values are updated in place. /// @note The values are updated in place.
///
void transform(uint8_t & red, uint8_t & green, uint8_t & blue) const; void transform(uint8_t & red, uint8_t & green, uint8_t & blue) const;
///
/// integer version of the conversion are faster, but a little less accurate /// integer version of the conversion are faster, but a little less accurate
/// all values are unsigned 8 bit values and scaled between 0 and 255 except /// all values are unsigned 8 bit values and scaled between 0 and 255 except
/// for the hue which is a 16 bit number and scaled between 0 and 360 /// for the hue which is a 16 bit number and scaled between 0 and 360
///
static void rgb2hsv(uint8_t red, uint8_t green, uint8_t blue, uint16_t & hue, uint8_t & saturation, uint8_t & value); static void rgb2hsv(uint8_t red, uint8_t green, uint8_t blue, uint16_t & hue, uint8_t & saturation, uint8_t & value);
static void hsv2rgb(uint16_t hue, uint8_t saturation, uint8_t value, uint8_t & red, uint8_t & green, uint8_t & blue); static void hsv2rgb(uint16_t hue, uint8_t saturation, uint8_t value, uint8_t & red, uint8_t & green, uint8_t & blue);
private: private:
/// The saturation gain
double _saturationGain; double _saturationGain;
/// The value gain
double _valueGain; double _valueGain;
}; };

View File

@ -8,31 +8,57 @@
// Forward class declaration // Forward class declaration
struct RgbColor; struct RgbColor;
///
/// Plain-Old-Data structure containing the red-green-blue color specification. Size of the
/// structure is exactly 3-bytes for easy writing to led-device
///
struct RgbColor struct RgbColor
{ {
/// The red color channel
uint8_t red; uint8_t red;
/// The green color channel
uint8_t green; uint8_t green;
/// The blue color channel
uint8_t blue; uint8_t blue;
/// 'Black' RgbColor (0, 0, 0)
static RgbColor BLACK; static RgbColor BLACK;
/// 'Red' RgbColor (255, 0, 0)
static RgbColor RED; static RgbColor RED;
/// 'Green' RgbColor (0, 255, 0)
static RgbColor GREEN; static RgbColor GREEN;
/// 'Blue' RgbColor (0, 0, 255)
static RgbColor BLUE; static RgbColor BLUE;
/// 'Yellow' RgbColor (255, 255, 0)
static RgbColor YELLOW; static RgbColor YELLOW;
/// 'White' RgbColor (255, 255, 255)
static RgbColor WHITE; static RgbColor WHITE;
///
/// Checks is this exactly matches another color
///
/// @param other The other color
///
/// @return True if the colors are identical
///
inline bool operator==(const RgbColor& other) const inline bool operator==(const RgbColor& other) const
{ {
return red == other.red && green == other.green && blue == other.blue; return red == other.red && green == other.green && blue == other.blue;
} }
}; };
/// Assert to ensure that the size of the structure is 'only' 3 bytes
static_assert(sizeof(RgbColor) == 3, "Incorrect size of RgbColor"); static_assert(sizeof(RgbColor) == 3, "Incorrect size of RgbColor");
///
/// Stream operator to write RgbColor to an outputstream (format "'{'[red]','[green]','[blue]'}'")
///
/// @param os The output stream
/// @param color The color to write
/// @return The output stream (with the color written to it)
///
inline std::ostream& operator<<(std::ostream& os, const RgbColor& color) inline std::ostream& operator<<(std::ostream& os, const RgbColor& color)
{ {
os << "{" << unsigned(color.red) << "," << unsigned(color.green) << "," << unsigned(color.blue) << "}"; os << "{" << unsigned(color.red) << "," << unsigned(color.green) << "," << unsigned(color.blue) << "}";
return os; return os;
} }

View File

@ -8,57 +8,127 @@
// Local includes // Local includes
#include "RgbColor.h" #include "RgbColor.h"
///
/// The RgbImage holds a 2D matrix of RgbColors's (or image). Width and height of the image are
/// fixed at construction.
///
class RgbImage class RgbImage
{ {
public: public:
///
/// Constructor for an image with specified width and height
///
/// @param width The width of the image
/// @param height The height of the image
/// @param background The color of the image (default = BLACK)
///
RgbImage(const unsigned width, const unsigned height, const RgbColor background = RgbColor::BLACK); RgbImage(const unsigned width, const unsigned height, const RgbColor background = RgbColor::BLACK);
///
/// Destructor
///
~RgbImage(); ~RgbImage();
///
/// Returns the width of the image
///
/// @return The width of the image
///
inline unsigned width() const inline unsigned width() const
{ {
return mWidth; return _width;
} }
///
/// Returns the height of the image
///
/// @return The height of the image
///
inline unsigned height() const inline unsigned height() const
{ {
return mHeight; return _height;
} }
///
/// Sets the color of a specific pixel in the image
///
/// @param x The x index
/// @param y The y index
/// @param color The new color
///
void setPixel(const unsigned x, const unsigned y, const RgbColor color); void setPixel(const unsigned x, const unsigned y, const RgbColor color);
///
/// Returns a const reference to a specified pixel in the image
///
/// @param x The x index
/// @param y The y index
///
/// @return const reference to specified pixel
///
const RgbColor& operator()(const unsigned x, const unsigned y) const; const RgbColor& operator()(const unsigned x, const unsigned y) const;
///
/// Returns a reference to a specified pixel in the image
///
/// @param x The x index
/// @param y The y index
///
/// @return reference to specified pixel
///
RgbColor& operator()(const unsigned x, const unsigned y); RgbColor& operator()(const unsigned x, const unsigned y);
///
/// Copies another image into this image. The images should have exactly the same size.
///
/// @param other The image to copy into this
///
inline void copy(const RgbImage& other) inline void copy(const RgbImage& other)
{ {
assert(other.mWidth == mWidth); assert(other._width == _width);
assert(other.mHeight == mHeight); assert(other._height == _height);
memcpy(mColors, other.mColors, mWidth*mHeight*sizeof(RgbColor)); memcpy(mColors, other.mColors, _width*_height*sizeof(RgbColor));
} }
///
/// Returns a memory pointer to the first pixel in the image
/// @return The memory pointer to the first pixel
///
RgbColor* memptr() RgbColor* memptr()
{ {
return mColors; return mColors;
} }
///
/// Returns a const memory pointer to the first pixel in the image
/// @return The const memory pointer to the first pixel
///
const RgbColor* memptr() const const RgbColor* memptr() const
{ {
return mColors; return mColors;
} }
private: private:
///
/// Translate x and y coordinate to index of the underlying vector
///
/// @param x The x index
/// @param y The y index
///
/// @return The index into the underlying data-vector
///
inline unsigned toIndex(const unsigned x, const unsigned y) const inline unsigned toIndex(const unsigned x, const unsigned y) const
{ {
return y*mWidth + x; return y*_width + x;
} }
private: private:
const unsigned mWidth; /// The width of the image
const unsigned mHeight; const unsigned _width;
/// The height of the image
const unsigned _height;
/** The colors of the image */ /** The colors of the image */
RgbColor* mColors; RgbColor* mColors;

View File

@ -14,46 +14,63 @@
// Hyperion includes // Hyperion includes
#include <hyperion/Hyperion.h> #include <hyperion/Hyperion.h>
///
/// This class will check if XBMC is playing something. When it does not, this class will send all black data to Hyperion. /// This class will check if XBMC is playing something. When it does not, this class will send all black data to Hyperion.
/// This allows grabbed screen data to be overriden while in the XBMC menus. /// This allows grabbed screen data to be overriden while in the XBMC menus.
/// ///
/// Note: The json TCP server needs to be enabled manually in XBMC in System/Settings/Network/Services /// Note: The json TCP server needs to be enabled manually in XBMC in System/Settings/Network/Services
///
class XBMCVideoChecker : public QObject class XBMCVideoChecker : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
/// @Constructor ///
/// @param address Netwrok address of the XBMC instance /// Constructor
///
/// @param address Network address of the XBMC instance
/// @param port Port number to use (XBMC default = 9090) /// @param port Port number to use (XBMC default = 9090)
/// @param interval The interval at which XBMC is polled /// @param interval The interval at which XBMC is polled
/// @param hyperion The Hyperion instance /// @param hyperion The Hyperion instance
/// @param priority The priority at which to send the all black data /// @param priority The priority at which to send the all black data
///
XBMCVideoChecker(const std::string & address, uint16_t port, uint64_t interval, Hyperion * hyperion, int priority); XBMCVideoChecker(const std::string & address, uint16_t port, uint64_t interval, Hyperion * hyperion, int priority);
/// \brief Start polling XBMC ///
/// Start polling XBMC
///
void start(); void start();
private slots: private slots:
/// \brief Send a request to XBMC ///
/// Send a request to XBMC
///
void sendRequest(); void sendRequest();
/// @brief receive a reply from XBMC ///
/// Receive a reply from XBMC
///
void receiveReply(); void receiveReply();
private: private:
/// The network address of the XBMC instance
const QString _address; const QString _address;
/// The port number of XBMC
const uint16_t _port; const uint16_t _port;
/// The JSON-RPC request message
const QByteArray _request; const QByteArray _request;
/// The timer that schedules XBMC queries
QTimer _timer; QTimer _timer;
/// The QT TCP Socket with connection to XBMC
QTcpSocket _socket; QTcpSocket _socket;
/// The Hyperion instance to switch leds to black if in XBMC menu
Hyperion * _hyperion; Hyperion * _hyperion;
/// The priority of the BLACK led value when in XBMC menu
const int _priority; const int _priority;
}; };

View File

@ -6,32 +6,65 @@
namespace hyperion namespace hyperion
{ {
///
/// The BlackBorder processor is a wrapper around the black-border detector for keeping track of
/// detected borders and count of the type and size of detected borders.
///
class BlackBorderProcessor class BlackBorderProcessor
{ {
public: public:
///
/// Constructor for the BlackBorderProcessor
/// @param unknownFrameCnt The number of frames(images) that need to contain an unknown
/// border before the current border is set to unknown
/// @param borderFrameCnt The number of frames(images) that need to contain a vertical or
/// horizontal border becomes the current border
/// @param blurRemoveCnt The size to add to a horizontal or vertical border (because the
/// outer pixels is blurred (black and color combined))
///
BlackBorderProcessor( BlackBorderProcessor(
const unsigned unknownFrameCnt, const unsigned unknownFrameCnt,
const unsigned borderFrameCnt, const unsigned borderFrameCnt,
const unsigned blurRemoveCnt); const unsigned blurRemoveCnt);
///
/// Return the current (detected) border
/// @return The current border
///
BlackBorder getCurrentBorder() const; BlackBorder getCurrentBorder() const;
///
/// Processes the image. This performs detecion of black-border on the given image and
/// updates the current border accordingly. If the current border is updated the method call
/// will return true else false
///
/// @param image The image to process
///
/// @return True if a different border was detected than the current else false
///
bool process(const RgbImage& image); bool process(const RgbImage& image);
private: private:
/// The number of unknown-borders detected before it becomes the current border
const unsigned _unknownSwitchCnt; const unsigned _unknownSwitchCnt;
/// The number of horizontal/vertical borders detected before it becomes the current border
const unsigned _borderSwitchCnt; const unsigned _borderSwitchCnt;
/// The number of pixels to increase a detected border for removing blury pixels
unsigned _blurRemoveCnt; unsigned _blurRemoveCnt;
/// The blackborder detector
BlackBorderDetector _detector; BlackBorderDetector _detector;
/// The current detected border
BlackBorder _currentBorder; BlackBorder _currentBorder;
/// The border detected in the previous frame
BlackBorder _previousDetectedBorder; BlackBorder _previousDetectedBorder;
/// The number of frame the previous detected border matched the incomming border
unsigned _consistentCnt; unsigned _consistentCnt;
}; };
} // end namespace hyperion } // end namespace hyperion

View File

@ -6,14 +6,33 @@
// Hyperion includes // Hyperion includes
#include <hyperion/LedDevice.h> #include <hyperion/LedDevice.h>
///
/// Implementation of the LedDevice that write the led-colors to an
/// ASCII-textfile('/home/pi/LedDevice.out')
///
class LedDeviceTest : public LedDevice class LedDeviceTest : public LedDevice
{ {
public: public:
///
/// Constructs the test-device, which opens an output stream to the file
///
LedDeviceTest(); LedDeviceTest();
///
/// Destructor of this test-device
///
virtual ~LedDeviceTest(); virtual ~LedDeviceTest();
///
/// Writes the given led-color values to the output stream
///
/// @param ledValues The color-value per led
///
/// @return Zero on success else negative
///
virtual int write(const std::vector<RgbColor> & ledValues); virtual int write(const std::vector<RgbColor> & ledValues);
private: private:
/// The outputstream
std::ofstream _ofs; std::ofstream _ofs;
}; };

View File

@ -11,9 +11,7 @@
// hyperion local includes // hyperion local includes
#include "LedDeviceWs2801.h" #include "LedDeviceWs2801.h"
LedDeviceWs2801::LedDeviceWs2801(const std::string& name, LedDeviceWs2801::LedDeviceWs2801(const std::string& outputDevice,
const std::string& outputDevice,
const unsigned interval,
const unsigned baudrate) : const unsigned baudrate) :
mDeviceName(outputDevice), mDeviceName(outputDevice),
mBaudRate_Hz(baudrate), mBaudRate_Hz(baudrate),

View File

@ -9,25 +9,51 @@
// hyperion incluse // hyperion incluse
#include <hyperion/LedDevice.h> #include <hyperion/LedDevice.h>
///
/// Implementation of the LedDevice interface for writing to Ws2801 led device.
///
class LedDeviceWs2801 : public LedDevice class LedDeviceWs2801 : public LedDevice
{ {
public: public:
LedDeviceWs2801(const std::string& name, ///
const std::string& outputDevice, /// Constructs the LedDevice for a string containing leds of the type Ws2801
const unsigned interval, ///
/// @param outputDevice The name of the output device (eg '/etc/SpiDev.0.0')
/// @param baudrate The used baudrate for writing to the output device
///
LedDeviceWs2801(const std::string& outputDevice,
const unsigned baudrate); const unsigned baudrate);
///
/// Destructor of the LedDevice; closes the output device if it is open
///
virtual ~LedDeviceWs2801(); virtual ~LedDeviceWs2801();
///
/// Opens and configures the output device
///
/// @return Zero on succes else negative
///
int open(); int open();
///
/// Writes the led color values to the led-device
///
/// @param ledValues The color-value per led
/// @return Zero on succes else negative
///
virtual int write(const std::vector<RgbColor> &ledValues); virtual int write(const std::vector<RgbColor> &ledValues);
private: private:
/// The name of the output device
const std::string mDeviceName; const std::string mDeviceName;
/// The used baudrate of the output device
const int mBaudRate_Hz; const int mBaudRate_Hz;
/// The File Identifier of the opened output device (or -1 if not opened)
int mFid; int mFid;
/// The transfer structure for writing to the spi-device
spi_ioc_transfer spi; spi_ioc_transfer spi;
/// The 'latch' time for latching the shifted-value into the leds
timespec latchTime; timespec latchTime;
}; };

View File

@ -18,91 +18,142 @@
class ImageProcessor; class ImageProcessor;
/// @brief The Connection object created by \a JsonServer when a new connection is establshed ///
/// The Connection object created by \a JsonServer when a new connection is establshed
/// ///
class JsonClientConnection : public QObject class JsonClientConnection : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
/// @brief Constructor ///
/// Constructor
/// @param socket The Socket object for this connection /// @param socket The Socket object for this connection
/// @param hyperion The Hyperion server /// @param hyperion The Hyperion server
///
JsonClientConnection(QTcpSocket * socket, Hyperion * hyperion); JsonClientConnection(QTcpSocket * socket, Hyperion * hyperion);
/// @brief Destructor ///
/// Destructor
///
~JsonClientConnection(); ~JsonClientConnection();
signals: signals:
/// @brief Signal which is emitted when the connection is being closed ///
/// Signal which is emitted when the connection is being closed
/// @param connection This connection object /// @param connection This connection object
///
void connectionClosed(JsonClientConnection * connection); void connectionClosed(JsonClientConnection * connection);
private slots: private slots:
/// @brief Slot called when new data has arrived ///
/// Slot called when new data has arrived
///
void readData(); void readData();
/// @brief Slot called when this connection is being closed ///
/// Slot called when this connection is being closed
///
void socketClosed(); void socketClosed();
private: private:
/// @brief Handle an incoming JSON message ///
/// Handle an incoming JSON message
///
/// @param message the incoming message as string /// @param message the incoming message as string
///
void handleMessage(const std::string & message); void handleMessage(const std::string & message);
/// @brief Handle an incoming JSON Color message ///
/// Handle an incoming JSON Color message
///
/// @param message the incoming message /// @param message the incoming message
///
void handleColorCommand(const Json::Value & message); void handleColorCommand(const Json::Value & message);
/// @brief Handle an incoming JSON Image message ///
/// Handle an incoming JSON Image message
///
/// @param message the incoming message /// @param message the incoming message
///
void handleImageCommand(const Json::Value & message); void handleImageCommand(const Json::Value & message);
/// @brief Handle an incoming JSON Server info message ///
/// Handle an incoming JSON Server info message
///
/// @param message the incoming message /// @param message the incoming message
///
void handleServerInfoCommand(const Json::Value & message); void handleServerInfoCommand(const Json::Value & message);
/// @brief Handle an incoming JSON Clear message ///
/// Handle an incoming JSON Clear message
///
/// @param message the incoming message /// @param message the incoming message
///
void handleClearCommand(const Json::Value & message); void handleClearCommand(const Json::Value & message);
/// @brief Handle an incoming JSON Clearall message ///
/// Handle an incoming JSON Clearall message
///
/// @param message the incoming message /// @param message the incoming message
///
void handleClearallCommand(const Json::Value & message); void handleClearallCommand(const Json::Value & message);
/// @brief Handle an incoming JSON Transform message ///
/// Handle an incoming JSON Transform message
///
/// @param message the incoming message /// @param message the incoming message
///
void handleTransformCommand(const Json::Value & message); void handleTransformCommand(const Json::Value & message);
/// @brief Handle an incoming JSON message of unknown type ///
/// Handle an incoming JSON message of unknown type
///
/// @param message the incoming message /// @param message the incoming message
///
void handleNotImplemented(); void handleNotImplemented();
/// @brief Send a message to the connected client ///
/// Send a message to the connected client
///
/// @param message The JSON message to send /// @param message The JSON message to send
///
void sendMessage(const Json::Value & message); void sendMessage(const Json::Value & message);
/// @brief Send a standard reply indicating success ///
/// Send a standard reply indicating success
///
void sendSuccessReply(); void sendSuccessReply();
/// @brief Send an error message back to the client ///
/// Send an error message back to the client
///
/// @param error String describing the error /// @param error String describing the error
///
void sendErrorReply(const std::string & error); void sendErrorReply(const std::string & error);
private: private:
/// @brief Check if a JSON messag is valid according to a given JSON schema ///
/// Check if a JSON messag is valid according to a given JSON schema
///
/// @param message JSON message which need to be checked /// @param message JSON message which need to be checked
/// @param schemaResource Qt esource identifier with the JSON schema /// @param schemaResource Qt esource identifier with the JSON schema
/// @param errors Output error message /// @param errors Output error message
///
/// @return true if message conforms the given JSON schema /// @return true if message conforms the given JSON schema
///
bool checkJson(const Json::Value & message, const QString &schemaResource, std::string & errors); bool checkJson(const Json::Value & message, const QString &schemaResource, std::string & errors);
private: private:
/// The TCP-Socket that is connected tot the Json-client
QTcpSocket * _socket; QTcpSocket * _socket;
/// The processor for translating images to led-values
ImageProcessor * _imageProcessor; ImageProcessor * _imageProcessor;
/// Link to Hyperion for writing led-values to a priority channel
Hyperion * _hyperion; Hyperion * _hyperion;
/// The buffer used for reading data from the socket
QByteArray _receiveBuffer; QByteArray _receiveBuffer;
}; };

View File

@ -8,8 +8,8 @@
RgbImage::RgbImage(const unsigned width, const unsigned height, const RgbColor background) : RgbImage::RgbImage(const unsigned width, const unsigned height, const RgbColor background) :
mWidth(width), _width(width),
mHeight(height), _height(height),
mColors(new RgbColor[width*height]) mColors(new RgbColor[width*height])
{ {
for (unsigned i=0; i<width*height; ++i) for (unsigned i=0; i<width*height; ++i)
@ -32,8 +32,8 @@ void RgbImage::setPixel(const unsigned x, const unsigned y, const RgbColor color
const RgbColor& RgbImage::operator()(const unsigned x, const unsigned y) const const RgbColor& RgbImage::operator()(const unsigned x, const unsigned y) const
{ {
// Debug-mode sanity check on given index // Debug-mode sanity check on given index
assert(x < mWidth); assert(x < _width);
assert(y < mHeight); assert(y < _height);
const unsigned index = toIndex(x, y); const unsigned index = toIndex(x, y);
return mColors[index]; return mColors[index];
@ -42,8 +42,8 @@ const RgbColor& RgbImage::operator()(const unsigned x, const unsigned y) const
RgbColor& RgbImage::operator()(const unsigned x, const unsigned y) RgbColor& RgbImage::operator()(const unsigned x, const unsigned y)
{ {
// Debug-mode sanity check on given index // Debug-mode sanity check on given index
assert(x < mWidth); assert(x < _width);
assert(y < mHeight); assert(y < _height);
const unsigned index = toIndex(x, y); const unsigned index = toIndex(x, y);
return mColors[index]; return mColors[index];

View File

@ -15,48 +15,73 @@
// hyperion-remote includes // hyperion-remote includes
#include "ColorTransformValues.h" #include "ColorTransformValues.h"
///
/// Connection class to setup an connection to the hyperion server and execute commands /// Connection class to setup an connection to the hyperion server and execute commands
///
class JsonConnection class JsonConnection
{ {
public: public:
/// @brief COnstructor ///
/// Constructor
///
/// @param address The address of the Hyperion server (for example "192.168.0.32:19444) /// @param address The address of the Hyperion server (for example "192.168.0.32:19444)
/// @param printJson Boolean indicating if the sent and received json is written to stdout /// @param printJson Boolean indicating if the sent and received json is written to stdout
///
JsonConnection(const std::string & address, bool printJson); JsonConnection(const std::string & address, bool printJson);
/// @brief Destructor ///
/// Destructor
///
~JsonConnection(); ~JsonConnection();
/// @brief Set all leds to the specified color ///
/// Set all leds to the specified color
///
/// @param color The color /// @param color The color
/// @param priority The priority /// @param priority The priority
/// @param duration The duration in milliseconds /// @param duration The duration in milliseconds
///
void setColor(QColor color, int priority, int duration); void setColor(QColor color, int priority, int duration);
/// @brief Set the leds according to the given image (assume the image is stretched to the display size) ///
/// Set the leds according to the given image (assume the image is stretched to the display size)
///
/// @param image The image /// @param image The image
/// @param priority The priority /// @param priority The priority
/// @param duration The duration in milliseconds /// @param duration The duration in milliseconds
///
void setImage(QImage image, int priority, int duration); void setImage(QImage image, int priority, int duration);
/// @brief Retrieve a list of all occupied priority channels ///
/// Retrieve a list of all occupied priority channels
///
/// @return String with the server info /// @return String with the server info
///
QString getServerInfo(); QString getServerInfo();
/// @brief Clear the given priority channel ///
/// Clear the given priority channel
///
/// @param priority The priority /// @param priority The priority
///
void clear(int priority); void clear(int priority);
/// @brief Clear all priority channels ///
/// Clear all priority channels
///
void clearAll(); void clearAll();
/// @brief Set the color transform of the leds ///
/// Set the color transform of the leds
///
/// @note Note that providing a NULL will leave the settings on the server unchanged /// @note Note that providing a NULL will leave the settings on the server unchanged
///
/// @param saturation The HSV saturation gain /// @param saturation The HSV saturation gain
/// @param value The HSV value gain /// @param value The HSV value gain
/// @param threshold The threshold /// @param threshold The threshold
/// @param blacklevel The blacklevel /// @param blacklevel The blacklevel
/// @param whitelevel The whitelevel /// @param whitelevel The whitelevel
///
void setTransform( void setTransform(
double * saturation, double * saturation,
double * value, double * value,
@ -66,18 +91,28 @@ public:
ColorTransformValues * whitelevel); ColorTransformValues * whitelevel);
private: private:
/// @brief Send a json command message and receive its reply ///
/// Send a json command message and receive its reply
///
/// @param message The message to send /// @param message The message to send
///
/// @return The returned reply /// @return The returned reply
///
Json::Value sendMessage(const Json::Value & message); Json::Value sendMessage(const Json::Value & message);
/// @brief Parse a reply message ///
/// Parse a reply message
///
/// @param reply The received reply /// @param reply The received reply
///
/// @return true if the reply indicates success /// @return true if the reply indicates success
///
bool parseReply(const Json::Value & reply); bool parseReply(const Json::Value & reply);
private: private:
/// Flag for printing all send and received json-messages to the standard out
bool _printJson; bool _printJson;
/// The TCP-Socket with the connection to the server
QTcpSocket _socket; QTcpSocket _socket;
}; };