mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
c9636aaa6b
End frame fixed Former-commit-id: 44107997d92d729f84adee368d12e35f1b5be6f1
45 lines
1.1 KiB
C++
45 lines
1.1 KiB
C++
|
|
// STL includes
|
|
#include <cstring>
|
|
#include <cstdio>
|
|
#include <iostream>
|
|
|
|
// Linux includes
|
|
#include <fcntl.h>
|
|
#include <sys/ioctl.h>
|
|
|
|
// hyperion local includes
|
|
#include "LedDeviceAPA102.h"
|
|
|
|
LedDeviceAPA102::LedDeviceAPA102(const std::string& outputDevice, const unsigned baudrate) :
|
|
LedSpiDevice(outputDevice, baudrate, 500000),
|
|
_ledBuffer(0)
|
|
{
|
|
// empty
|
|
}
|
|
|
|
int LedDeviceAPA102::write(const std::vector<ColorRgb> &ledValues)
|
|
{
|
|
const unsigned int startFrameSize = 4;
|
|
const unsigned int endFrameSize = (ledValues.size() + 63) / 64 * 4;
|
|
const unsigned int mLedCount = (ledValues.size() * 4) + startFrameSize + endFrameSize;
|
|
if(_ledBuffer.size() != mLedCount){
|
|
_ledBuffer.resize(mLedCount, 0x00);
|
|
}
|
|
|
|
for (unsigned iLed=1; iLed<=ledValues.size(); ++iLed) {
|
|
const ColorRgb& rgb = ledValues[iLed];
|
|
_ledBuffer[iLed*4] = 0xFF;
|
|
_ledBuffer[iLed*4+1] = rgb.red;
|
|
_ledBuffer[iLed*4+2] = rgb.green;
|
|
_ledBuffer[iLed*4+3] = rgb.blue;
|
|
}
|
|
|
|
return writeBytes(_ledBuffer.size(), _ledBuffer.data());
|
|
}
|
|
|
|
int LedDeviceAPA102::switchOff()
|
|
{
|
|
return write(std::vector<ColorRgb>(_ledBuffer.size(), ColorRgb{0,0,0}));
|
|
}
|