mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
a724fd1535
* update lightberry sketches update compilehowwto (windows disclaimer) some refactoring in main cmakelists + preparation for windows compile tune ada driver, set delayAfterConnect default to 1.5s because some arduino (e.g. mega r3) needs this set priority min/max for grabber/network services - prevent colliding prios between webui/background stuff and grabbers/net services * add check if config is writable. TODO do something usefull in webui * fix indention error * fix typo * fix webui can't write led config * typo * fix cmakelists * change methode of detecting linux
77 lines
2.1 KiB
C++
77 lines
2.1 KiB
C++
#include "LedDeviceAdalight.h"
|
|
|
|
LedDeviceAdalight::LedDeviceAdalight(const QJsonObject &deviceConfig)
|
|
: ProviderRs232()
|
|
, _headerSize(6)
|
|
, _ligthBerryAPA102Mode(false)
|
|
{
|
|
_deviceReady = init(deviceConfig);
|
|
}
|
|
|
|
LedDevice* LedDeviceAdalight::construct(const QJsonObject &deviceConfig)
|
|
{
|
|
return new LedDeviceAdalight(deviceConfig);
|
|
}
|
|
|
|
bool LedDeviceAdalight::init(const QJsonObject &deviceConfig)
|
|
{
|
|
ProviderRs232::init(deviceConfig);
|
|
_ligthBerryAPA102Mode = deviceConfig["lightberry_apa102_mode"].toBool(false);
|
|
|
|
// create ledBuffer
|
|
unsigned int totalLedCount = _ledCount;
|
|
|
|
if (_ligthBerryAPA102Mode)
|
|
{
|
|
const unsigned int startFrameSize = 4;
|
|
const unsigned int bytesPerRGBLed = 4;
|
|
const unsigned int endFrameSize = std::max<unsigned int>(((_ledCount + 15) / 16), bytesPerRGBLed);
|
|
_ledBuffer.resize(_headerSize + (_ledCount * bytesPerRGBLed) + startFrameSize + endFrameSize, 0x00);
|
|
|
|
// init constant data values
|
|
for (signed iLed=1; iLed<=_ledCount; iLed++)
|
|
{
|
|
_ledBuffer[iLed*4+_headerSize] = 0xFF;
|
|
}
|
|
Debug( _log, "Adalight driver with activated LightBerry APA102 mode");
|
|
}
|
|
else
|
|
{
|
|
totalLedCount -= 1;
|
|
_ledBuffer.resize(_headerSize + _ledRGBCount, 0x00);
|
|
}
|
|
|
|
_ledBuffer[0] = 'A';
|
|
_ledBuffer[1] = 'd';
|
|
_ledBuffer[2] = 'a';
|
|
_ledBuffer[3] = (totalLedCount >> 8) & 0xFF; // LED count high byte
|
|
_ledBuffer[4] = totalLedCount & 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;
|
|
}
|
|
|
|
int LedDeviceAdalight::write(const std::vector<ColorRgb> & ledValues)
|
|
{
|
|
if(_ligthBerryAPA102Mode)
|
|
{
|
|
for (signed iLed=1; iLed<=_ledCount; iLed++)
|
|
{
|
|
const ColorRgb& rgb = ledValues[iLed-1];
|
|
_ledBuffer[iLed*4+7] = rgb.red;
|
|
_ledBuffer[iLed*4+8] = rgb.green;
|
|
_ledBuffer[iLed*4+9] = rgb.blue;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
memcpy(_headerSize + _ledBuffer.data(), ledValues.data(), ledValues.size() * 3);
|
|
}
|
|
|
|
return writeBytes(_ledBuffer.size(), _ledBuffer.data());
|
|
}
|
|
|