mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
added timer to LedDeviceAdalight to send color data at least every 5 seconds
Former-commit-id: 6b77588d3ce83ab32ab3c62e7345c7aa11f9c344
This commit is contained in:
parent
4ea48e2ed3
commit
6d47b4c66b
@ -1 +1 @@
|
||||
391a5783725844074e6c221406f39e24d66f0bf3
|
||||
19c49770372d19eddcd87f647455964ca57d4f57
|
@ -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
|
||||
)
|
||||
|
||||
|
@ -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<ColorRgb> & ledValues)
|
||||
@ -31,12 +38,25 @@ int LedDeviceAdalight::write(const std::vector<ColorRgb> & 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());
|
||||
}
|
||||
|
@ -3,14 +3,19 @@
|
||||
// STL includes
|
||||
#include <string>
|
||||
|
||||
// Qt includes
|
||||
#include <QTimer>
|
||||
|
||||
// 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<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;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user