2013-11-05 17:18:04 +01:00
|
|
|
#include "LedDeviceSedu.h"
|
|
|
|
|
|
|
|
struct FrameSpec
|
|
|
|
{
|
|
|
|
uint8_t id;
|
|
|
|
size_t size;
|
|
|
|
};
|
|
|
|
|
2016-10-13 21:59:58 +02:00
|
|
|
LedDeviceSedu::LedDeviceSedu(const QJsonObject &deviceConfig)
|
2020-08-08 00:21:19 +02:00
|
|
|
: ProviderRs232(deviceConfig)
|
2013-11-05 17:18:04 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-10-13 21:59:58 +02:00
|
|
|
LedDevice* LedDeviceSedu::construct(const QJsonObject &deviceConfig)
|
2016-08-23 20:07:12 +02:00
|
|
|
{
|
|
|
|
return new LedDeviceSedu(deviceConfig);
|
|
|
|
}
|
|
|
|
|
2016-10-13 21:59:58 +02:00
|
|
|
bool LedDeviceSedu::init(const QJsonObject &deviceConfig)
|
2013-11-05 17:18:04 +01:00
|
|
|
{
|
2020-07-12 20:27:56 +02:00
|
|
|
bool isInitOK = false;
|
2013-11-05 17:18:04 +01:00
|
|
|
|
2020-07-12 20:27:56 +02:00
|
|
|
// Initialise sub-class
|
|
|
|
if ( ProviderRs232::init(deviceConfig) )
|
2016-10-08 08:14:36 +02:00
|
|
|
{
|
2020-07-12 20:27:56 +02:00
|
|
|
std::vector<FrameSpec> frameSpecs{{0xA1, 256}, {0xA2, 512}, {0xB0, 768}, {0xB1, 1536}, {0xB2, 3072} };
|
|
|
|
|
|
|
|
for (const FrameSpec& frameSpec : frameSpecs)
|
2013-11-05 17:18:04 +01:00
|
|
|
{
|
2020-07-12 20:27:56 +02:00
|
|
|
if ((unsigned)_ledRGBCount <= frameSpec.size)
|
|
|
|
{
|
|
|
|
_ledBuffer.clear();
|
|
|
|
_ledBuffer.resize(frameSpec.size + 3, 0);
|
|
|
|
_ledBuffer[0] = 0x5A;
|
|
|
|
_ledBuffer[1] = frameSpec.id;
|
|
|
|
_ledBuffer.back() = 0xA5;
|
|
|
|
break;
|
|
|
|
}
|
2013-11-05 17:18:04 +01:00
|
|
|
}
|
|
|
|
|
2020-07-12 20:27:56 +02:00
|
|
|
if (_ledBuffer.empty())
|
|
|
|
{
|
|
|
|
//Warning(_log, "More rgb-channels required then available");
|
|
|
|
QString errortext = "More rgb-channels required then available";
|
|
|
|
this->setInError(errortext);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
isInitOK = true;
|
|
|
|
}
|
2013-11-05 17:18:04 +01:00
|
|
|
}
|
2020-02-10 15:21:58 +01:00
|
|
|
return isInitOK;
|
2016-10-08 08:14:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int LedDeviceSedu::write(const std::vector<ColorRgb> &ledValues)
|
|
|
|
{
|
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());
|
|
|
|
}
|