From 6d47b4c66bebe3f18e7fb0d7dd8b362a08d4fa7e Mon Sep 17 00:00:00 2001 From: johan Date: Thu, 14 Nov 2013 19:04:17 +0100 Subject: [PATCH] added timer to LedDeviceAdalight to send color data at least every 5 seconds Former-commit-id: 6b77588d3ce83ab32ab3c62e7345c7aa11f9c344 --- deploy/hyperiond.REMOVED.git-id | 2 +- libsrc/hyperion/CMakeLists.txt | 2 +- libsrc/hyperion/device/LedDeviceAdalight.cpp | 24 ++++++++++++++++++-- libsrc/hyperion/device/LedDeviceAdalight.h | 16 ++++++++++++- 4 files changed, 39 insertions(+), 5 deletions(-) diff --git a/deploy/hyperiond.REMOVED.git-id b/deploy/hyperiond.REMOVED.git-id index 87abc0ab..1827fa2e 100644 --- a/deploy/hyperiond.REMOVED.git-id +++ b/deploy/hyperiond.REMOVED.git-id @@ -1 +1 @@ -391a5783725844074e6c221406f39e24d66f0bf3 \ No newline at end of file +19c49770372d19eddcd87f647455964ca57d4f57 \ No newline at end of file diff --git a/libsrc/hyperion/CMakeLists.txt b/libsrc/hyperion/CMakeLists.txt index 89e04a5a..5cd73b84 100644 --- a/libsrc/hyperion/CMakeLists.txt +++ b/libsrc/hyperion/CMakeLists.txt @@ -10,6 +10,7 @@ SET(Hyperion_QT_HEADERS ${CURRENT_HEADER_DIR}/Hyperion.h ${CURRENT_SOURCE_DIR}/LinearColorSmoothing.h + ${CURRENT_SOURCE_DIR}/device/LedDeviceAdalight.h ) SET(Hyperion_HEADERS @@ -30,7 +31,6 @@ SET(Hyperion_HEADERS ${CURRENT_SOURCE_DIR}/device/LedDeviceWs2801.h ${CURRENT_SOURCE_DIR}/device/LedDeviceLpd6803.h ${CURRENT_SOURCE_DIR}/device/LedDeviceLpd8806.h - ${CURRENT_SOURCE_DIR}/device/LedDeviceAdalight.h ${CURRENT_SOURCE_DIR}/device/LedDeviceLightpack.h ) diff --git a/libsrc/hyperion/device/LedDeviceAdalight.cpp b/libsrc/hyperion/device/LedDeviceAdalight.cpp index 782b8c9d..f19bb4be 100644 --- a/libsrc/hyperion/device/LedDeviceAdalight.cpp +++ b/libsrc/hyperion/device/LedDeviceAdalight.cpp @@ -13,9 +13,16 @@ LedDeviceAdalight::LedDeviceAdalight(const std::string& outputDevice, const unsigned baudrate) : LedRs232Device(outputDevice, baudrate), - _ledBuffer(0) + _ledBuffer(0), + _timer() { - // empty + // setup the timer + _timer.setSingleShot(false); + _timer.setInterval(5000); + connect(&_timer, SIGNAL(timeout()), this, SLOT(rewriteLeds())); + + // start the timer + _timer.start(); } int LedDeviceAdalight::write(const std::vector & ledValues) @@ -31,12 +38,25 @@ int LedDeviceAdalight::write(const std::vector & ledValues) _ledBuffer[5] = _ledBuffer[3] ^ _ledBuffer[4] ^ 0x55; // Checksum } + // restart the timer + _timer.start(); + + // write data memcpy(6 + _ledBuffer.data(), ledValues.data(), ledValues.size() * 3); return writeBytes(_ledBuffer.size(), _ledBuffer.data()); } int LedDeviceAdalight::switchOff() { + // restart the timer + _timer.start(); + + // write data memset(6 + _ledBuffer.data(), 0, _ledBuffer.size()-6); return writeBytes(_ledBuffer.size(), _ledBuffer.data()); } + +void LedDeviceAdalight::rewriteLeds() +{ + writeBytes(_ledBuffer.size(), _ledBuffer.data()); +} diff --git a/libsrc/hyperion/device/LedDeviceAdalight.h b/libsrc/hyperion/device/LedDeviceAdalight.h index f1085aee..30e7bfb7 100644 --- a/libsrc/hyperion/device/LedDeviceAdalight.h +++ b/libsrc/hyperion/device/LedDeviceAdalight.h @@ -3,14 +3,19 @@ // STL includes #include +// Qt includes +#include + // hyperion incluse #include "LedRs232Device.h" /// /// Implementation of the LedDevice interface for writing to an Adalight led device. /// -class LedDeviceAdalight : public LedRs232Device +class LedDeviceAdalight : public QObject, public LedRs232Device { + Q_OBJECT + public: /// /// Constructs the LedDevice for attached Adalight device @@ -31,7 +36,16 @@ public: /// Switch the leds off virtual int switchOff(); +private slots: + /// Write the last data to the leds again + void rewriteLeds(); + private: /// The buffer containing the packed RGB values std::vector _ledBuffer; + + /// Timer object which makes sure that led data is written at a minimum rate + /// The Adalight device will switch off when it does not receive data at least + /// every 15 seconds + QTimer _timer; };