hyperion.ng/libsrc/leddevice/LedDeviceFadeCandy.h
redpanther b6060d392e make opc channel available in via config.
Former-commit-id: 6a065cd049e29d7184a3aa1454de0fe1855e9941
2016-01-27 10:44:51 +01:00

72 lines
1.6 KiB
C++
Executable File

#pragma once
// STL/Qt includes
#include <fstream>
#include <QObject>
#include <QTcpSocket>
// Leddevice includes
#include <leddevice/LedDevice.h>
///
/// Implementation of the LedDevice interface for sending to
/// fadecandy/opc-server via network by using the 'open pixel control' protocol.
///
class LedDeviceFadeCandy : public QObject, public LedDevice
{
Q_OBJECT
public:
///
/// Constructs the LedDevice for fadecandy/opc server
///
/// @param host The ip address/host name of fadecandy/opc server
/// @param port The port to use (fadecandy default is 7890)
///
LedDeviceFadeCandy(const std::string& host, const uint16_t port, const unsigned channel);
///
/// Destructor of the LedDevice; closes the tcp client
///
virtual ~LedDeviceFadeCandy();
///
/// 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<ColorRgb> & ledValues);
/// Switch the leds off
virtual int switchOff();
private:
QTcpSocket _client;
const std::string _host;
const uint16_t _port;
const unsigned _channel;
QByteArray _opc_data;
/// 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();
};