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"
|
2016-08-23 20:07:12 +02:00
|
|
|
#include <leddevice/LedDevice.h>
|
2013-11-11 21:07:24 +01:00
|
|
|
|
2016-08-23 20:07:12 +02:00
|
|
|
LedDeviceAdalight::LedDeviceAdalight(const Json::Value &deviceConfig)
|
2016-08-28 07:12:48 +02:00
|
|
|
: ProviderRs232(deviceConfig)
|
2016-08-14 10:46:44 +02:00
|
|
|
, _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
|
|
|
}
|
|
|
|
|
2016-08-23 20:07:12 +02:00
|
|
|
LedDevice* LedDeviceAdalight::construct(const Json::Value &deviceConfig)
|
|
|
|
{
|
|
|
|
return new LedDeviceAdalight(deviceConfig);
|
|
|
|
}
|
|
|
|
|
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
|
2016-09-13 14:25:42 +02:00
|
|
|
Debug( _log, "Adalight header for %d leds: %c%c%c 0x%02x 0x%02x 0x%02x",
|
|
|
|
ledValues.size(),
|
|
|
|
_ledBuffer[0],
|
|
|
|
_ledBuffer[1],
|
|
|
|
_ledBuffer[2],
|
|
|
|
_ledBuffer[3],
|
|
|
|
_ledBuffer[4],
|
|
|
|
_ledBuffer[5]
|
|
|
|
);
|
2013-11-11 21:07:24 +01:00
|
|
|
}
|
|
|
|
|
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());
|
|
|
|
}
|