Update LedDeviceAPA102.cpp

Problem with endFrame was not only endFrameSize, but ledValue index too

Former-commit-id: cc14e9d440a1d27f6a51c18f92aeba1f438c9c01
This commit is contained in:
AEtHeLsYn 2015-10-30 20:07:21 +01:00
parent 6230f1dfe7
commit acc1a1b397
1 changed files with 3 additions and 2 deletions

View File

@ -3,6 +3,7 @@
#include <cstring>
#include <cstdio>
#include <iostream>
#include <algorithm>
// Linux includes
#include <fcntl.h>
@ -21,14 +22,14 @@ LedDeviceAPA102::LedDeviceAPA102(const std::string& outputDevice, const unsigned
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 endFrameSize = std::max<unsigned int>(((ledValues.size() + 15) / 16), 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];
const ColorRgb& rgb = ledValues[iLed-1];
_ledBuffer[iLed*4] = 0xFF;
_ledBuffer[iLed*4+1] = rgb.red;
_ledBuffer[iLed*4+2] = rgb.green;