diff --git a/libsrc/leddevice/LedDeviceFactory.cpp b/libsrc/leddevice/LedDeviceFactory.cpp index b0fd064f..f692b03c 100755 --- a/libsrc/leddevice/LedDeviceFactory.cpp +++ b/libsrc/leddevice/LedDeviceFactory.cpp @@ -246,9 +246,10 @@ LedDevice * LedDeviceFactory::construct(const Json::Value & deviceConfig) } else if (type == "fadecandy") { - const std::string host = deviceConfig.get("output", "127.0.0.1").asString(); - const uint16_t port = deviceConfig.get("port", 7890).asInt(); - device = new LedDeviceFadeCandy(host,port); + const std::string host = deviceConfig.get("output", "127.0.0.1").asString(); + const uint16_t port = deviceConfig.get("port", 7890).asInt(); + const uint16_t channel = deviceConfig.get("channel", 0).asInt(); + device = new LedDeviceFadeCandy(host, port, channel); } else if (type == "tpm2") { diff --git a/libsrc/leddevice/LedDeviceFadeCandy.cpp b/libsrc/leddevice/LedDeviceFadeCandy.cpp index a9548842..685795a9 100755 --- a/libsrc/leddevice/LedDeviceFadeCandy.cpp +++ b/libsrc/leddevice/LedDeviceFadeCandy.cpp @@ -1,16 +1,15 @@ #include "LedDeviceFadeCandy.h" -static const unsigned MAX_NUM_LEDS = 10000; -static const unsigned OPC_BROADCAST = 0; // OPC broadcast channel -static const unsigned OPC_SET_PIXELS = 0; // OPC command codes -static const unsigned OPC_HEADER_SIZE = 4; // OPC header size +static const unsigned MAX_NUM_LEDS = 10000; // OPC can handle 21845 leds - in theory, fadecandy device should handle 10000 leds +static const unsigned OPC_SET_PIXELS = 0; // OPC command codes +static const unsigned OPC_HEADER_SIZE = 4; // OPC header size -LedDeviceFadeCandy::LedDeviceFadeCandy(const std::string& host, const uint16_t port) : - _host(host), _port(port) +LedDeviceFadeCandy::LedDeviceFadeCandy(const std::string& host, const uint16_t port, const unsigned channel) : + _host(host), _port(port), _channel(channel) { _opc_data.resize( OPC_HEADER_SIZE ); - _opc_data[0] = OPC_BROADCAST; + _opc_data[0] = channel; _opc_data[1] = OPC_SET_PIXELS; _opc_data[2] = 0; _opc_data[3] = 0; @@ -33,7 +32,8 @@ bool LedDeviceFadeCandy::tryConnect() { if ( _client.state() == QAbstractSocket::UnconnectedState ) { _client.connectToHost( _host.c_str(), _port); - _client.waitForConnected(1000); + if ( _client.waitForConnected(1000) ) + qDebug("fadecandy/opc: connected to %s:%i on channel %i", _host.c_str(), _port, _channel); } return isConnected(); @@ -48,7 +48,7 @@ int LedDeviceFadeCandy::write( const std::vector & ledValues ) if (nrLedValues > MAX_NUM_LEDS) { - std::cerr << "Invalid attempt to write led values. Not more than " << MAX_NUM_LEDS << " leds are allowed." << std::endl; + std::cerr << "fadecandy/opc: Invalid attempt to write led values. Not more than " << MAX_NUM_LEDS << " leds are allowed." << std::endl; return -1; } diff --git a/libsrc/leddevice/LedDeviceFadeCandy.h b/libsrc/leddevice/LedDeviceFadeCandy.h index 0b894e88..ebcd85d9 100755 --- a/libsrc/leddevice/LedDeviceFadeCandy.h +++ b/libsrc/leddevice/LedDeviceFadeCandy.h @@ -23,7 +23,7 @@ public: /// @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); + LedDeviceFadeCandy(const std::string& host, const uint16_t port, const unsigned channel); /// /// Destructor of the LedDevice; closes the tcp client @@ -46,6 +46,7 @@ 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