fadecandy led device:

implement switchOff methode
tidy up code and add doxy comments


Former-commit-id: a162e2aae756f8b74b8e65f08740c00f3c820e50
This commit is contained in:
redpanther
2016-01-04 14:29:47 +01:00
parent 7f5a664864
commit 9182dd5af7
2 changed files with 97 additions and 76 deletions

View File

@@ -1,55 +1,70 @@
#pragma once
// STL includes0
// STL/Qt includes
#include <fstream>
#include <QObject>
#include <QtNetwork>
#include <QObject>
#include <QString>
#include <QTcpSocket>
// Leddevice includes
#include <leddevice/LedDevice.h>
///
/// Implementation of the LedDevice that write the led-colors to an
/// ASCII-textfile('/home/pi/LedDevice.out')
/// 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
class LedDeviceFadeCandy : public QObject, public LedDevice
{
Q_OBJECT
Q_OBJECT
public:
///
/// Constructs the test-device, which opens an output stream to the file
/// 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);
///
/// Destructor of this test-device
/// Destructor of the LedDevice; closes the tcp client
///
virtual ~LedDeviceFadeCandy();
///
/// Writes the given led-color values to the output stream
/// Writes the led color values to the led-device
///
/// @param ledValues The color-value per led
///
/// @return Zero on success else negative
/// @return Zero on succes else negative
///
virtual int write(const std::vector<ColorRgb> & ledValues);
/// Switch the leds off
virtual int switchOff();
bool tryConnect();
bool isConnected();
//public slots:
private:
QTcpSocket _client;
const std::string _host;
const uint16_t _port;
QByteArray _opc_data;
QTcpSocket _client;
const std::string _host;
const uint16_t _port;
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();
};