2016-01-04 12:06:56 +01:00
|
|
|
#pragma once
|
|
|
|
|
2016-01-04 14:29:47 +01:00
|
|
|
// STL/Qt includes
|
2016-01-04 12:06:56 +01:00
|
|
|
#include <QTcpSocket>
|
|
|
|
|
|
|
|
// Leddevice includes
|
|
|
|
#include <leddevice/LedDevice.h>
|
|
|
|
|
|
|
|
///
|
2016-01-04 14:29:47 +01:00
|
|
|
/// Implementation of the LedDevice interface for sending to
|
|
|
|
/// fadecandy/opc-server via network by using the 'open pixel control' protocol.
|
2016-01-04 12:06:56 +01:00
|
|
|
///
|
2016-08-14 10:46:44 +02:00
|
|
|
class LedDeviceFadeCandy : public LedDevice
|
2016-01-04 12:06:56 +01:00
|
|
|
{
|
2016-01-04 14:29:47 +01:00
|
|
|
Q_OBJECT
|
|
|
|
|
2016-01-04 12:06:56 +01:00
|
|
|
public:
|
|
|
|
///
|
2016-01-04 14:29:47 +01:00
|
|
|
/// Constructs the LedDevice for fadecandy/opc server
|
|
|
|
///
|
2016-07-12 22:37:45 +02:00
|
|
|
/// following code shows all config options
|
|
|
|
/// @code
|
|
|
|
/// "device" :
|
|
|
|
/// {
|
|
|
|
/// "name" : "MyPi",
|
|
|
|
/// "type" : "fadecandy",
|
|
|
|
/// "output" : "localhost",
|
|
|
|
/// "colorOrder" : "rgb",
|
2016-07-13 11:18:12 +02:00
|
|
|
/// "setFcConfig" : false,
|
2016-07-12 22:37:45 +02:00
|
|
|
/// "gamma" : 1.0,
|
|
|
|
/// "whitepoint" : [1.0, 1.0, 1.0],
|
|
|
|
/// "dither" : false,
|
|
|
|
/// "interpolation" : false,
|
|
|
|
/// "manualLed" : false,
|
|
|
|
/// "ledOn" : false
|
|
|
|
/// },
|
|
|
|
///@endcode
|
2016-01-04 12:06:56 +01:00
|
|
|
///
|
2016-07-12 22:37:45 +02:00
|
|
|
/// @param deviceConfig json config for fadecandy
|
|
|
|
///
|
2016-10-13 21:59:58 +02:00
|
|
|
LedDeviceFadeCandy(const QJsonObject &deviceConfig);
|
2016-01-04 12:06:56 +01:00
|
|
|
|
|
|
|
///
|
2016-01-04 14:29:47 +01:00
|
|
|
/// Destructor of the LedDevice; closes the tcp client
|
2016-01-04 12:06:56 +01:00
|
|
|
///
|
|
|
|
virtual ~LedDeviceFadeCandy();
|
|
|
|
|
2016-08-23 20:07:12 +02:00
|
|
|
/// constructs leddevice
|
2016-10-13 21:59:58 +02:00
|
|
|
static LedDevice* construct(const QJsonObject &deviceConfig);
|
2016-08-23 20:07:12 +02:00
|
|
|
|
2016-07-12 22:37:45 +02:00
|
|
|
///
|
|
|
|
/// Sets configuration
|
|
|
|
///
|
|
|
|
/// @param deviceConfig the json device config
|
|
|
|
/// @return true if success
|
2016-10-13 21:59:58 +02:00
|
|
|
bool init(const QJsonObject &deviceConfig);
|
2016-07-12 22:37:45 +02:00
|
|
|
|
2016-01-04 12:06:56 +01:00
|
|
|
///
|
2016-01-04 14:29:47 +01:00
|
|
|
/// Writes the led color values to the led-device
|
2016-01-04 12:06:56 +01:00
|
|
|
///
|
|
|
|
/// @param ledValues The color-value per led
|
2016-01-04 14:29:47 +01:00
|
|
|
/// @return Zero on succes else negative
|
2016-01-04 12:06:56 +01:00
|
|
|
///
|
|
|
|
virtual int write(const std::vector<ColorRgb> & ledValues);
|
|
|
|
|
|
|
|
private:
|
2016-07-12 22:37:45 +02:00
|
|
|
QTcpSocket _client;
|
|
|
|
std::string _host;
|
|
|
|
uint16_t _port;
|
|
|
|
unsigned _channel;
|
|
|
|
QByteArray _opc_data;
|
|
|
|
|
|
|
|
// fadecandy sysEx
|
2016-07-13 11:18:12 +02:00
|
|
|
bool _setFcConfig;
|
2016-07-12 22:37:45 +02:00
|
|
|
double _gamma;
|
|
|
|
double _whitePoint_r;
|
|
|
|
double _whitePoint_g;
|
|
|
|
double _whitePoint_b;
|
|
|
|
bool _noDither;
|
|
|
|
bool _noInterp;
|
|
|
|
bool _manualLED;
|
|
|
|
bool _ledOnOff;
|
2016-01-04 14:29:47 +01:00
|
|
|
|
|
|
|
/// try to establish connection to opc server, if not connected yet
|
|
|
|
///
|
|
|
|
/// @return true if connection is established
|
|
|
|
///
|
|
|
|
bool tryConnect();
|
|
|
|
|
|
|
|
/// return the conenction state
|
|
|
|
///
|
|
|
|
/// @return True if connection established
|
|
|
|
///
|
|
|
|
bool isConnected();
|
|
|
|
|
|
|
|
/// transfer current opc_data buffer to opc server
|
|
|
|
///
|
|
|
|
/// @return amount of transfered bytes. -1 error while transfering, -2 error while connecting
|
|
|
|
///
|
|
|
|
int transferData();
|
|
|
|
|
2016-07-12 22:37:45 +02:00
|
|
|
/// send system exclusive commands
|
|
|
|
///
|
|
|
|
/// @param systemId fadecandy device identifier (for standard fadecandy always: 1)
|
|
|
|
/// @param commandId id of command
|
|
|
|
/// @param msg the sysEx message
|
|
|
|
/// @return amount bytes written, -1 if fail
|
|
|
|
int sendSysEx(uint8_t systemId, uint8_t commandId, QByteArray msg);
|
|
|
|
|
|
|
|
/// sends the configuration to fcserver
|
|
|
|
void sendFadeCandyConfiguration();
|
|
|
|
|
2016-01-04 12:06:56 +01:00
|
|
|
};
|