2013-11-05 17:18:04 +01:00
|
|
|
|
|
|
|
// STL includes
|
|
|
|
#include <cstring>
|
|
|
|
#include <cstdio>
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
// Linux includes
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
|
|
|
|
// hyperion local includes
|
|
|
|
#include "LedDeviceSedu.h"
|
|
|
|
|
|
|
|
struct FrameSpec
|
|
|
|
{
|
|
|
|
uint8_t id;
|
|
|
|
size_t size;
|
|
|
|
};
|
|
|
|
|
2016-08-23 20:07:12 +02:00
|
|
|
LedDeviceSedu::LedDeviceSedu(const Json::Value &deviceConfig)
|
|
|
|
: LedRs232Device(deviceConfig)
|
2013-11-05 17:18:04 +01:00
|
|
|
{
|
|
|
|
// empty
|
|
|
|
}
|
|
|
|
|
2016-08-23 20:07:12 +02:00
|
|
|
LedDevice* LedDeviceSedu::construct(const Json::Value &deviceConfig)
|
|
|
|
{
|
|
|
|
return new LedDeviceSedu(deviceConfig);
|
|
|
|
}
|
|
|
|
|
2013-11-11 10:00:37 +01:00
|
|
|
int LedDeviceSedu::write(const std::vector<ColorRgb> &ledValues)
|
2013-11-05 17:18:04 +01:00
|
|
|
{
|
|
|
|
if (_ledBuffer.size() == 0)
|
|
|
|
{
|
2014-02-04 20:47:02 +01:00
|
|
|
std::vector<FrameSpec> frameSpecs{{0xA1, 256}, {0xA2, 512}, {0xB0, 768}, {0xB1, 1536}, {0xB2, 3072} };
|
2013-11-05 17:18:04 +01:00
|
|
|
|
2013-11-11 10:00:37 +01:00
|
|
|
const unsigned reqColorChannels = ledValues.size() * sizeof(ColorRgb);
|
2013-11-05 17:18:04 +01:00
|
|
|
|
|
|
|
for (const FrameSpec& frameSpec : frameSpecs)
|
|
|
|
{
|
|
|
|
if (reqColorChannels <= frameSpec.size)
|
|
|
|
{
|
|
|
|
_ledBuffer.clear();
|
|
|
|
_ledBuffer.resize(frameSpec.size + 3, 0);
|
|
|
|
_ledBuffer[0] = 0x5A;
|
|
|
|
_ledBuffer[1] = frameSpec.id;
|
|
|
|
_ledBuffer.back() = 0xA5;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_ledBuffer.size() == 0)
|
|
|
|
{
|
2016-06-25 22:08:17 +02:00
|
|
|
Warning(_log, "More rgb-channels required then available");
|
2013-11-05 17:18:04 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-11 10:00:37 +01:00
|
|
|
memcpy(_ledBuffer.data()+2, ledValues.data(), ledValues.size() * sizeof(ColorRgb));
|
2013-11-05 17:18:04 +01:00
|
|
|
return writeBytes(_ledBuffer.size(), _ledBuffer.data());
|
|
|
|
}
|
|
|
|
|
|
|
|
int LedDeviceSedu::switchOff()
|
|
|
|
{
|
|
|
|
memset(_ledBuffer.data()+2, 0, _ledBuffer.size()-3);
|
|
|
|
return writeBytes(_ledBuffer.size(), _ledBuffer.data());
|
|
|
|
}
|