2013-11-11 21:07:24 +01:00
|
|
|
#include "LedDeviceAdalight.h"
|
|
|
|
|
2016-08-23 20:07:12 +02:00
|
|
|
LedDeviceAdalight::LedDeviceAdalight(const Json::Value &deviceConfig)
|
2016-10-08 08:14:36 +02:00
|
|
|
: ProviderRs232()
|
2013-11-14 19:04:17 +01:00
|
|
|
|
2016-10-08 08:14:36 +02:00
|
|
|
{
|
|
|
|
_deviceReady = init(deviceConfig);
|
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);
|
|
|
|
}
|
|
|
|
|
2016-10-08 08:14:36 +02:00
|
|
|
bool LedDeviceAdalight::init(const Json::Value &deviceConfig)
|
|
|
|
{
|
|
|
|
ProviderRs232::init(deviceConfig);
|
|
|
|
|
|
|
|
_ledBuffer.resize(6 + _ledRGBCount);
|
|
|
|
_ledBuffer[0] = 'A';
|
|
|
|
_ledBuffer[1] = 'd';
|
|
|
|
_ledBuffer[2] = 'a';
|
|
|
|
_ledBuffer[3] = (((unsigned int)_ledCount - 1) >> 8) & 0xFF; // LED count high byte
|
|
|
|
_ledBuffer[4] = ((unsigned int)_ledCount - 1) & 0xFF; // LED count low byte
|
|
|
|
_ledBuffer[5] = _ledBuffer[3] ^ _ledBuffer[4] ^ 0x55; // Checksum
|
|
|
|
Debug( _log, "Adalight header for %d leds: %c%c%c 0x%02x 0x%02x 0x%02x", _ledCount,
|
|
|
|
_ledBuffer[0], _ledBuffer[1], _ledBuffer[2], _ledBuffer[3], _ledBuffer[4], _ledBuffer[5]
|
|
|
|
);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-11-12 07:52:00 +01:00
|
|
|
int LedDeviceAdalight::write(const std::vector<ColorRgb> & ledValues)
|
2013-11-11 21:07:24 +01:00
|
|
|
{
|
|
|
|
memcpy(6 + _ledBuffer.data(), ledValues.data(), ledValues.size() * 3);
|
|
|
|
return writeBytes(_ledBuffer.size(), _ledBuffer.data());
|
|
|
|
}
|
|
|
|
|