2013-11-11 21:07:24 +01:00
|
|
|
|
|
|
|
// STL includes
|
|
|
|
#include <cstring>
|
|
|
|
#include <cstdio>
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
// Linux includes
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
|
|
|
|
// hyperion local includes
|
|
|
|
#include "LedDeviceAdalight.h"
|
|
|
|
|
2014-05-04 11:31:13 +02:00
|
|
|
LedDeviceAdalight::LedDeviceAdalight(const std::string& outputDevice, const unsigned baudrate, int delayAfterConnect_ms) :
|
|
|
|
LedRs232Device(outputDevice, baudrate, delayAfterConnect_ms),
|
2013-11-14 19:04:17 +01:00
|
|
|
_ledBuffer(0),
|
|
|
|
_timer()
|
2013-11-11 21:07:24 +01:00
|
|
|
{
|
2013-11-14 19:04:17 +01:00
|
|
|
// setup the timer
|
|
|
|
_timer.setSingleShot(false);
|
|
|
|
_timer.setInterval(5000);
|
|
|
|
connect(&_timer, SIGNAL(timeout()), this, SLOT(rewriteLeds()));
|
|
|
|
|
|
|
|
// start the timer
|
|
|
|
_timer.start();
|
2013-11-11 21:07:24 +01:00
|
|
|
}
|
|
|
|
|
2013-11-12 07:52:00 +01:00
|
|
|
int LedDeviceAdalight::write(const std::vector<ColorRgb> & ledValues)
|
2013-11-11 21:07:24 +01:00
|
|
|
{
|
|
|
|
if (_ledBuffer.size() == 0)
|
|
|
|
{
|
|
|
|
_ledBuffer.resize(6 + 3*ledValues.size());
|
|
|
|
_ledBuffer[0] = 'A';
|
|
|
|
_ledBuffer[1] = 'd';
|
|
|
|
_ledBuffer[2] = 'a';
|
|
|
|
_ledBuffer[3] = ((ledValues.size() - 1) >> 8) & 0xFF; // LED count high byte
|
|
|
|
_ledBuffer[4] = (ledValues.size() - 1) & 0xFF; // LED count low byte
|
|
|
|
_ledBuffer[5] = _ledBuffer[3] ^ _ledBuffer[4] ^ 0x55; // Checksum
|
|
|
|
}
|
|
|
|
|
2013-11-14 19:04:17 +01:00
|
|
|
// restart the timer
|
|
|
|
_timer.start();
|
|
|
|
|
|
|
|
// write data
|
2013-11-11 21:07:24 +01:00
|
|
|
memcpy(6 + _ledBuffer.data(), ledValues.data(), ledValues.size() * 3);
|
|
|
|
return writeBytes(_ledBuffer.size(), _ledBuffer.data());
|
|
|
|
}
|
|
|
|
|
|
|
|
int LedDeviceAdalight::switchOff()
|
|
|
|
{
|
2013-11-14 19:04:17 +01:00
|
|
|
// restart the timer
|
|
|
|
_timer.start();
|
|
|
|
|
|
|
|
// write data
|
2013-11-11 21:07:24 +01:00
|
|
|
memset(6 + _ledBuffer.data(), 0, _ledBuffer.size()-6);
|
|
|
|
return writeBytes(_ledBuffer.size(), _ledBuffer.data());
|
|
|
|
}
|
2013-11-14 19:04:17 +01:00
|
|
|
|
|
|
|
void LedDeviceAdalight::rewriteLeds()
|
|
|
|
{
|
|
|
|
writeBytes(_ledBuffer.size(), _ledBuffer.data());
|
|
|
|
}
|