Update LedDeviceAPA102.cpp by pcaffardi

Former-commit-id: e7efe8917fc10ceb860e44bbb37442cffa3512db
This commit is contained in:
wisc 2016-02-07 17:40:24 +01:00
parent 543042b870
commit 79dda5e840

View File

@ -2,7 +2,6 @@
#include <cstring> #include <cstring>
#include <cstdio> #include <cstdio>
#include <iostream> #include <iostream>
#include <algorithm>
// Linux includes // Linux includes
#include <fcntl.h> #include <fcntl.h>
@ -32,11 +31,11 @@ LedDeviceAPA102::LedDeviceAPA102(const std::string& outputDevice, const unsigned
int LedDeviceAPA102::write(const std::vector<ColorRgb> &ledValues) int LedDeviceAPA102::write(const std::vector<ColorRgb> &ledValues)
{ {
const unsigned int startFrameSize = APA102_START_FRAME_BYTES; const unsigned int startFrameSize = APA102_START_FRAME_BYTES;
const unsigned int ledsCount = ledValues.size() ; const unsigned int ledsCount = ledValues.size() ;
const unsigned int ledsSize = ledsCount * APA102_LED_BYTES ; const unsigned int ledsSize = ledsCount * APA102_LED_BYTES ;
const unsigned int endFrameBits = APA102_END_FRAME_BITS(ledsCount) ; const unsigned int endFrameBits = APA102_END_FRAME_BITS(ledsCount) ;
const unsigned int endFrameSize = APA102_END_FRAME_BYTES(ledsCount) ; const unsigned int endFrameSize = APA102_END_FRAME_BYTES(ledsCount) ;
const unsigned int transferSize = startFrameSize + ledsSize + endFrameSize ; const unsigned int transferSize = startFrameSize + ledsSize + endFrameSize ;
if(_ledBuffer.size() != transferSize){ if(_ledBuffer.size() != transferSize){
_ledBuffer.resize(transferSize, 0x00); _ledBuffer.resize(transferSize, 0x00);
@ -56,7 +55,7 @@ int LedDeviceAPA102::write(const std::vector<ColorRgb> &ledValues)
_ledBuffer[idx++] = rgb.blue; _ledBuffer[idx++] = rgb.blue;
} }
for(i=0; i<endFrameSize; i++) for(i=0; i<endFrameSize; i++)
_ledBuffer[idx++] = 0x00 ; _ledBuffer[idx++] = 0x00 ;
return writeBytes(_ledBuffer.size(), _ledBuffer.data()); return writeBytes(_ledBuffer.size(), _ledBuffer.data());
} }