added timer to LedDeviceAdalight to send color data at least every 5 seconds

Former-commit-id: 6b77588d3ce83ab32ab3c62e7345c7aa11f9c344
This commit is contained in:
johan 2013-11-14 19:04:17 +01:00
parent 4ea48e2ed3
commit 6d47b4c66b
4 changed files with 39 additions and 5 deletions

View File

@ -1 +1 @@
391a5783725844074e6c221406f39e24d66f0bf3 19c49770372d19eddcd87f647455964ca57d4f57

View File

@ -10,6 +10,7 @@ SET(Hyperion_QT_HEADERS
${CURRENT_HEADER_DIR}/Hyperion.h ${CURRENT_HEADER_DIR}/Hyperion.h
${CURRENT_SOURCE_DIR}/LinearColorSmoothing.h ${CURRENT_SOURCE_DIR}/LinearColorSmoothing.h
${CURRENT_SOURCE_DIR}/device/LedDeviceAdalight.h
) )
SET(Hyperion_HEADERS SET(Hyperion_HEADERS
@ -30,7 +31,6 @@ SET(Hyperion_HEADERS
${CURRENT_SOURCE_DIR}/device/LedDeviceWs2801.h ${CURRENT_SOURCE_DIR}/device/LedDeviceWs2801.h
${CURRENT_SOURCE_DIR}/device/LedDeviceLpd6803.h ${CURRENT_SOURCE_DIR}/device/LedDeviceLpd6803.h
${CURRENT_SOURCE_DIR}/device/LedDeviceLpd8806.h ${CURRENT_SOURCE_DIR}/device/LedDeviceLpd8806.h
${CURRENT_SOURCE_DIR}/device/LedDeviceAdalight.h
${CURRENT_SOURCE_DIR}/device/LedDeviceLightpack.h ${CURRENT_SOURCE_DIR}/device/LedDeviceLightpack.h
) )

View File

@ -13,9 +13,16 @@
LedDeviceAdalight::LedDeviceAdalight(const std::string& outputDevice, const unsigned baudrate) : LedDeviceAdalight::LedDeviceAdalight(const std::string& outputDevice, const unsigned baudrate) :
LedRs232Device(outputDevice, 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<ColorRgb> & ledValues) int LedDeviceAdalight::write(const std::vector<ColorRgb> & ledValues)
@ -31,12 +38,25 @@ int LedDeviceAdalight::write(const std::vector<ColorRgb> & ledValues)
_ledBuffer[5] = _ledBuffer[3] ^ _ledBuffer[4] ^ 0x55; // Checksum _ledBuffer[5] = _ledBuffer[3] ^ _ledBuffer[4] ^ 0x55; // Checksum
} }
// restart the timer
_timer.start();
// write data
memcpy(6 + _ledBuffer.data(), ledValues.data(), ledValues.size() * 3); memcpy(6 + _ledBuffer.data(), ledValues.data(), ledValues.size() * 3);
return writeBytes(_ledBuffer.size(), _ledBuffer.data()); return writeBytes(_ledBuffer.size(), _ledBuffer.data());
} }
int LedDeviceAdalight::switchOff() int LedDeviceAdalight::switchOff()
{ {
// restart the timer
_timer.start();
// write data
memset(6 + _ledBuffer.data(), 0, _ledBuffer.size()-6); memset(6 + _ledBuffer.data(), 0, _ledBuffer.size()-6);
return writeBytes(_ledBuffer.size(), _ledBuffer.data()); return writeBytes(_ledBuffer.size(), _ledBuffer.data());
} }
void LedDeviceAdalight::rewriteLeds()
{
writeBytes(_ledBuffer.size(), _ledBuffer.data());
}

View File

@ -3,14 +3,19 @@
// STL includes // STL includes
#include <string> #include <string>
// Qt includes
#include <QTimer>
// hyperion incluse // hyperion incluse
#include "LedRs232Device.h" #include "LedRs232Device.h"
/// ///
/// Implementation of the LedDevice interface for writing to an Adalight led device. /// 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: public:
/// ///
/// Constructs the LedDevice for attached Adalight device /// Constructs the LedDevice for attached Adalight device
@ -31,7 +36,16 @@ public:
/// Switch the leds off /// Switch the leds off
virtual int switchOff(); virtual int switchOff();
private slots:
/// Write the last data to the leds again
void rewriteLeds();
private: private:
/// The buffer containing the packed RGB values /// The buffer containing the packed RGB values
std::vector<uint8_t> _ledBuffer; std::vector<uint8_t> _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;
}; };