2016-09-21 23:03:01 +02:00
|
|
|
#include "LedDeviceUdpH801.h"
|
|
|
|
|
2016-10-13 21:59:58 +02:00
|
|
|
LedDeviceUdpH801::LedDeviceUdpH801(const QJsonObject &deviceConfig)
|
2016-09-22 00:18:46 +02:00
|
|
|
: ProviderUdp()
|
2016-09-21 23:03:01 +02:00
|
|
|
{
|
2016-10-08 08:14:36 +02:00
|
|
|
_deviceReady = init(deviceConfig);
|
2016-09-21 23:03:01 +02:00
|
|
|
}
|
|
|
|
|
2016-10-13 21:59:58 +02:00
|
|
|
bool LedDeviceUdpH801::init(const QJsonObject &deviceConfig)
|
2016-09-21 23:03:01 +02:00
|
|
|
{
|
|
|
|
/* The H801 port is fixed */
|
2016-10-08 08:14:36 +02:00
|
|
|
_LatchTime_ns = 10000000;
|
|
|
|
_port = 30977;
|
|
|
|
ProviderUdp::init(deviceConfig, "255.255.255.255");
|
2016-09-21 23:03:01 +02:00
|
|
|
|
|
|
|
_ids.clear();
|
2016-10-13 21:59:58 +02:00
|
|
|
QJsonArray lArray = deviceConfig["lightIds"].toArray();
|
|
|
|
for (int i = 0; i < lArray.size(); i++)
|
2016-09-23 08:49:22 +02:00
|
|
|
{
|
2016-10-13 21:59:58 +02:00
|
|
|
QString id = lArray[i].toString();
|
2016-09-21 23:03:01 +02:00
|
|
|
_ids.push_back(id.toInt(nullptr, 16));
|
|
|
|
}
|
|
|
|
|
|
|
|
_message = QByteArray(_prefix_size + _colors + _id_size * _ids.size() + _suffix_size, 0x00);
|
|
|
|
_message[0] = 0xFB;
|
|
|
|
_message[1] = 0xEB;
|
|
|
|
|
2016-09-21 23:32:17 +02:00
|
|
|
for (int i = 0; i < _ids.length(); i++) {
|
2016-09-21 23:03:01 +02:00
|
|
|
_message[_prefix_size + _colors + i * _id_size + 0] = (_ids[i] >> 0x00) & 0xFF;
|
|
|
|
_message[_prefix_size + _colors + i * _id_size + 1] = (_ids[i] >> 0x08) & 0xFF;
|
|
|
|
_message[_prefix_size + _colors + i * _id_size + 2] = (_ids[i] >> 0x10) & 0xFF;
|
|
|
|
}
|
|
|
|
|
2016-09-21 23:32:17 +02:00
|
|
|
Debug(_log, "H801 using %s:%d", _address.toString().toStdString().c_str(), _port);
|
2016-09-21 23:03:01 +02:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-10-13 21:59:58 +02:00
|
|
|
LedDevice* LedDeviceUdpH801::construct(const QJsonObject &deviceConfig)
|
2016-09-21 23:03:01 +02:00
|
|
|
{
|
|
|
|
return new LedDeviceUdpH801(deviceConfig);
|
|
|
|
}
|
|
|
|
|
|
|
|
int LedDeviceUdpH801::write(const std::vector<ColorRgb> &ledValues)
|
|
|
|
{
|
|
|
|
ColorRgb color = ledValues[0];
|
|
|
|
_message[_prefix_size + 0] = color.red;
|
|
|
|
_message[_prefix_size + 1] = color.green;
|
|
|
|
_message[_prefix_size + 2] = color.blue;
|
|
|
|
|
2016-09-22 00:18:46 +02:00
|
|
|
return writeBytes(_message.size(), reinterpret_cast<const uint8_t*>(_message.data()));
|
2016-09-21 23:03:01 +02:00
|
|
|
}
|