2015-02-04 21:49:33 +01:00
|
|
|
// hyperion local includes
|
|
|
|
#include "LedDeviceAtmo.h"
|
|
|
|
|
2016-10-13 21:59:58 +02:00
|
|
|
LedDeviceAtmo::LedDeviceAtmo(const QJsonObject &deviceConfig)
|
2016-10-08 08:14:36 +02:00
|
|
|
: ProviderRs232()
|
2015-02-04 21:49:33 +01:00
|
|
|
{
|
2020-02-10 15:21:58 +01:00
|
|
|
_devConfig = deviceConfig;
|
2020-07-12 20:27:56 +02:00
|
|
|
_isDeviceReady = false;
|
|
|
|
|
|
|
|
_activeDeviceType = deviceConfig["type"].toString("UNSPECIFIED").toLower();
|
2015-02-04 21:49:33 +01:00
|
|
|
}
|
|
|
|
|
2020-07-12 20:27:56 +02:00
|
|
|
|
2016-10-13 21:59:58 +02:00
|
|
|
LedDevice* LedDeviceAtmo::construct(const QJsonObject &deviceConfig)
|
2016-08-23 20:07:12 +02:00
|
|
|
{
|
|
|
|
return new LedDeviceAtmo(deviceConfig);
|
|
|
|
}
|
|
|
|
|
2016-10-13 21:59:58 +02:00
|
|
|
bool LedDeviceAtmo::init(const QJsonObject &deviceConfig)
|
2015-02-04 21:49:33 +01:00
|
|
|
{
|
2020-07-12 20:27:56 +02:00
|
|
|
bool isInitOK = false;
|
2016-10-08 08:14:36 +02:00
|
|
|
|
2020-07-12 20:27:56 +02:00
|
|
|
// Initialise sub-class
|
|
|
|
if ( ProviderRs232::init(deviceConfig) )
|
2015-02-23 15:53:05 +01:00
|
|
|
{
|
2020-02-10 15:21:58 +01:00
|
|
|
if (_ledCount != 5)
|
|
|
|
{
|
|
|
|
QString errortext = QString ("%1 channels configured. This should always be 5!").arg(_ledCount);
|
|
|
|
this->setInError(errortext);
|
|
|
|
isInitOK = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_ledBuffer.resize(4 + 5*3); // 4-byte header, 5 RGB values
|
|
|
|
_ledBuffer[0] = 0xFF; // Startbyte
|
|
|
|
_ledBuffer[1] = 0x00; // StartChannel(Low)
|
|
|
|
_ledBuffer[2] = 0x00; // StartChannel(High)
|
|
|
|
_ledBuffer[3] = 0x0F; // Number of Databytes send (always! 15)
|
2020-07-12 20:27:56 +02:00
|
|
|
|
|
|
|
isInitOK = true;
|
2020-02-10 15:21:58 +01:00
|
|
|
}
|
2015-02-23 15:53:05 +01:00
|
|
|
}
|
2020-02-10 15:21:58 +01:00
|
|
|
return isInitOK;
|
2016-10-08 08:14:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int LedDeviceAtmo::write(const std::vector<ColorRgb> &ledValues)
|
|
|
|
{
|
2016-09-23 08:49:22 +02:00
|
|
|
memcpy(4 + _ledBuffer.data(), ledValues.data(), _ledCount * sizeof(ColorRgb));
|
2015-02-04 21:49:33 +01:00
|
|
|
return writeBytes(_ledBuffer.size(), _ledBuffer.data());
|
|
|
|
}
|