Skip to content

Commit

Permalink
Merge pull request hyperion-project#402 from AEtHeLsYn/master
Browse files Browse the repository at this point in the history
APA102 end frame fixed (this time for real)

Former-commit-id: 92969b3b0c7b4cd8cc13c86e509274ec63c0b23b
  • Loading branch information
tvdzwan committed Nov 8, 2015
2 parents 1672f41 + 1c41919 commit 42a6f72
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
13 changes: 9 additions & 4 deletions libsrc/leddevice/LedDeviceAPA102.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <cstring>
#include <cstdio>
#include <iostream>
#include <algorithm>

// Linux includes
#include <fcntl.h>
Expand All @@ -21,14 +22,18 @@ 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);
_ledBuffer.resize(mLedCount, 0xFF);
_ledBuffer[0] = 0x00;
_ledBuffer[1] = 0x00;
_ledBuffer[2] = 0x00;
_ledBuffer[3] = 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;
Expand Down
7 changes: 4 additions & 3 deletions libsrc/leddevice/LedDeviceAdalightApa102.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <cstring>
#include <cstdio>
#include <iostream>
#include <algorithm>

// Linux includes
#include <fcntl.h>
Expand All @@ -23,10 +24,10 @@ LedDeviceAdalightApa102::LedDeviceAdalightApa102(const std::string& outputDevice
int LedDeviceAdalightApa102::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);
_ledBuffer.resize(mLedCount, 0xFF);
_ledBuffer[0] = 'A';
_ledBuffer[1] = 'd';
_ledBuffer[2] = 'a';
Expand All @@ -36,7 +37,7 @@ int LedDeviceAdalightApa102::write(const std::vector<ColorRgb> & ledValues)
}

for (unsigned iLed=1; iLed<=ledValues.size(); iLed++) {
const ColorRgb& rgb = ledValues[iLed];
const ColorRgb& rgb = ledValues[iLed-1];
_ledBuffer[iLed*4+6] = 0xFF;
_ledBuffer[iLed*4+1+6] = rgb.red;
_ledBuffer[iLed*4+2+6] = rgb.green;
Expand Down

0 comments on commit 42a6f72

Please sign in to comment.