mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
Leddevices source tree refactoring (#461)
* rework structure of leddevice source tree * fix data type vor v4l sig detection value in webui * automate leddevicefactory.cpp
This commit is contained in:
47
libsrc/leddevice/dev_spi/LedDeviceP9813.cpp
Normal file
47
libsrc/leddevice/dev_spi/LedDeviceP9813.cpp
Normal file
@@ -0,0 +1,47 @@
|
||||
#include "LedDeviceP9813.h"
|
||||
|
||||
LedDeviceP9813::LedDeviceP9813(const QJsonObject &deviceConfig)
|
||||
: ProviderSpi()
|
||||
{
|
||||
_deviceReady = init(deviceConfig);
|
||||
}
|
||||
|
||||
LedDevice* LedDeviceP9813::construct(const QJsonObject &deviceConfig)
|
||||
{
|
||||
return new LedDeviceP9813(deviceConfig);
|
||||
}
|
||||
|
||||
bool LedDeviceP9813::init(const QJsonObject &deviceConfig)
|
||||
{
|
||||
ProviderSpi::init(deviceConfig);
|
||||
|
||||
_ledBuffer.resize(_ledCount * 4 + 8, 0x00);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int LedDeviceP9813::write(const std::vector<ColorRgb> &ledValues)
|
||||
{
|
||||
uint8_t * dataPtr = _ledBuffer.data();
|
||||
for (const ColorRgb & color : ledValues)
|
||||
{
|
||||
*dataPtr++ = calculateChecksum(color);
|
||||
*dataPtr++ = color.blue;
|
||||
*dataPtr++ = color.green;
|
||||
*dataPtr++ = color.red;
|
||||
}
|
||||
|
||||
return writeBytes(_ledBuffer.size(), _ledBuffer.data());
|
||||
}
|
||||
|
||||
uint8_t LedDeviceP9813::calculateChecksum(const ColorRgb & color) const
|
||||
{
|
||||
uint8_t res = 0;
|
||||
|
||||
res |= (uint8_t)0x03 << 6;
|
||||
res |= (uint8_t)(~(color.blue >> 6) & 0x03) << 4;
|
||||
res |= (uint8_t)(~(color.green >> 6) & 0x03) << 2;
|
||||
res |= (uint8_t)(~(color.red >> 6) & 0x03);
|
||||
|
||||
return res;
|
||||
}
|
Reference in New Issue
Block a user