mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
Slight style changes to the pull of the P9813 device
Former-commit-id: 77892a5cfbcc4793061d518a761931be26ef842b
This commit is contained in:
@@ -13,44 +13,44 @@
|
||||
|
||||
LedDeviceP9813::LedDeviceP9813(const std::string& outputDevice, const unsigned baudrate) :
|
||||
LedSpiDevice(outputDevice, baudrate, 0),
|
||||
mLedCount(0)
|
||||
_ledCount(0)
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
int LedDeviceP9813::write(const std::vector<ColorRgb> &ledValues)
|
||||
{
|
||||
mLedCount = ledValues.size();
|
||||
if (_ledCount != ledValues.size())
|
||||
{
|
||||
_ledBuf.resize(ledValues.size() * 4 + 8, 0x00);
|
||||
_ledCount = ledValues.size();
|
||||
}
|
||||
|
||||
const unsigned dataLen = ledValues.size() * 4 + 8;
|
||||
uint8_t data[dataLen];
|
||||
uint8_t * dataPtr = _ledBuf.data();
|
||||
for (const ColorRgb & color : ledValues)
|
||||
{
|
||||
*dataPtr++ = calculateChecksum(color);
|
||||
*dataPtr++ = color.blue;
|
||||
*dataPtr++ = color.green;
|
||||
*dataPtr++ = color.red;
|
||||
}
|
||||
|
||||
memset(data, 0x00, dataLen);
|
||||
|
||||
int j = 4;
|
||||
for (unsigned i = 0; i < mLedCount; i++){
|
||||
data[j++] = calculateChecksum(ledValues[i]);
|
||||
data[j++] = ledValues[i].blue;
|
||||
data[j++] = ledValues[i].green;
|
||||
data[j++] = ledValues[i].red;
|
||||
}
|
||||
|
||||
return writeBytes(dataLen, data);
|
||||
return writeBytes(_ledBuf.size(), _ledBuf.data());
|
||||
}
|
||||
|
||||
int LedDeviceP9813::switchOff()
|
||||
{
|
||||
return write(std::vector<ColorRgb>(mLedCount, ColorRgb{0,0,0}));
|
||||
return write(std::vector<ColorRgb>(_ledCount, ColorRgb{0,0,0}));
|
||||
}
|
||||
|
||||
const uint8_t LedDeviceP9813::calculateChecksum(const ColorRgb color)
|
||||
uint8_t LedDeviceP9813::calculateChecksum(const ColorRgb & color) const
|
||||
{
|
||||
uint8_t res = 0;
|
||||
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);
|
||||
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;
|
||||
return res;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user