diff --git a/libsrc/leddevice/LedDevice.cpp b/libsrc/leddevice/LedDevice.cpp index 8da0ba5a..ea144b99 100644 --- a/libsrc/leddevice/LedDevice.cpp +++ b/libsrc/leddevice/LedDevice.cpp @@ -40,8 +40,19 @@ LedDevice::~LedDevice() int LedDevice::open() { - setEnable (true); - return 0; + int retval = -1; + QString errortext; + _deviceReady = false; + + // General initialisation and configuration of LedDevice + if ( init(_devConfig) ) + { + // Everything is OK -> enable device + _deviceReady = true; + setEnable(true); + retval = 0; + } + return retval; } void LedDevice::setInError(const QString& errorMsg) @@ -71,6 +82,11 @@ void LedDevice::setEnable(bool enable) Error(_log, "Device '%s' cannot be enabled, as it is not ready!", QSTRING_CSTR(_activeDeviceType)); return; } + else + { + // Open worked + _deviceInError = false; + } } // emit signal when state changed @@ -101,6 +117,8 @@ void LedDevice::setActiveDeviceType(const QString& deviceType) bool LedDevice::init(const QJsonObject &deviceConfig) { + //Debug(_log, "deviceConfig: [%s]", QString(QJsonDocument(_devConfig).toJson(QJsonDocument::Compact)).toUtf8().constData() ); + _colorOrder = deviceConfig["colorOrder"].toString("RGB"); _activeDeviceType = deviceConfig["type"].toString("file").toLower(); setLedCount(static_cast( deviceConfig["currentLedCount"].toInt(1) )); // property injected to reflect real led count @@ -146,7 +164,7 @@ void LedDevice::stopRefreshTimer() int LedDevice::updateLeds(const std::vector& ledValues) { int retval = 0; - if ( !_deviceReady ) + if ( !_deviceReady || _deviceInError) { std::cout << "LedDevice::updateLeds(), LedDevice NOT ready!" << std::endl; return -1; diff --git a/libsrc/leddevice/dev_rpi_pwm/LedDeviceWS281x.cpp b/libsrc/leddevice/dev_rpi_pwm/LedDeviceWS281x.cpp index ca93aa76..add73c98 100644 --- a/libsrc/leddevice/dev_rpi_pwm/LedDeviceWS281x.cpp +++ b/libsrc/leddevice/dev_rpi_pwm/LedDeviceWS281x.cpp @@ -11,6 +11,11 @@ LedDeviceWS281x::~LedDeviceWS281x() { } +LedDevice* LedDeviceWS281x::construct(const QJsonObject &deviceConfig) +{ + return new LedDeviceWS281x(deviceConfig); +} + bool LedDeviceWS281x::init(const QJsonObject &deviceConfig) { QString errortext; @@ -84,11 +89,6 @@ void LedDeviceWS281x::close() } } -LedDevice* LedDeviceWS281x::construct(const QJsonObject &deviceConfig) -{ - return new LedDeviceWS281x(deviceConfig); -} - // Send new values down the LED chain int LedDeviceWS281x::write(const std::vector &ledValues) { diff --git a/libsrc/leddevice/dev_rpi_pwm/LedDeviceWS281x.h b/libsrc/leddevice/dev_rpi_pwm/LedDeviceWS281x.h index 2af413f4..a6dc6c4e 100644 --- a/libsrc/leddevice/dev_rpi_pwm/LedDeviceWS281x.h +++ b/libsrc/leddevice/dev_rpi_pwm/LedDeviceWS281x.h @@ -15,12 +15,12 @@ public: /// /// @param deviceConfig json device config /// - LedDeviceWS281x(const QJsonObject &deviceConfig); + explicit LedDeviceWS281x(const QJsonObject &deviceConfig); /// /// Destructor of the LedDevice, waits for DMA to complete and then cleans up /// - ~LedDeviceWS281x() override; + virtual ~LedDeviceWS281x() override; /// constructs leddevice static LedDevice* construct(const QJsonObject &deviceConfig); @@ -30,7 +30,7 @@ public: /// /// @param deviceConfig the json device config /// @return true if success - bool init(const QJsonObject &deviceConfig) override; + virtual bool init(const QJsonObject &deviceConfig) override; public slots: /// @@ -39,7 +39,7 @@ public slots: /// virtual void close() override; -private: +protected: /// /// Writes the led color values to the led-device /// @@ -48,6 +48,8 @@ private: /// virtual int write(const std::vector &ledValues) override; +private: + ws2811_t _led_string; int _channel; RGBW::WhiteAlgorithm _whiteAlgorithm; diff --git a/libsrc/leddevice/dev_serial/LedDeviceKarate.cpp b/libsrc/leddevice/dev_serial/LedDeviceKarate.cpp index 44b20af5..647ac221 100644 --- a/libsrc/leddevice/dev_serial/LedDeviceKarate.cpp +++ b/libsrc/leddevice/dev_serial/LedDeviceKarate.cpp @@ -46,7 +46,7 @@ bool LedDeviceKarate::init(const QJsonObject &deviceConfig) int LedDeviceKarate::write(const std::vector &ledValues) { - for (signed iLed=0; iLed<_ledCount; iLed++) + for (signed iLed=0; iLed< static_cast(_ledCount); iLed++) { const ColorRgb& rgb = ledValues[iLed];