mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
Merge pull request #402 from AEtHeLsYn/master
APA102 end frame fixed (this time for real) Former-commit-id: 92969b3b0c7b4cd8cc13c86e509274ec63c0b23b
This commit is contained in:
commit
42a6f72f06
@ -3,6 +3,7 @@
|
|||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
// Linux includes
|
// Linux includes
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
@ -21,14 +22,18 @@ 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 = 4;
|
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;
|
const unsigned int mLedCount = (ledValues.size() * 4) + startFrameSize + endFrameSize;
|
||||||
if(_ledBuffer.size() != mLedCount){
|
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) {
|
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] = 0xFF;
|
||||||
_ledBuffer[iLed*4+1] = rgb.red;
|
_ledBuffer[iLed*4+1] = rgb.red;
|
||||||
_ledBuffer[iLed*4+2] = rgb.green;
|
_ledBuffer[iLed*4+2] = rgb.green;
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
// Linux includes
|
// Linux includes
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
@ -23,10 +24,10 @@ LedDeviceAdalightApa102::LedDeviceAdalightApa102(const std::string& outputDevice
|
|||||||
int LedDeviceAdalightApa102::write(const std::vector<ColorRgb> & ledValues)
|
int LedDeviceAdalightApa102::write(const std::vector<ColorRgb> & ledValues)
|
||||||
{
|
{
|
||||||
const unsigned int startFrameSize = 4;
|
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;
|
const unsigned int mLedCount = (ledValues.size() * 4) + startFrameSize + endFrameSize;
|
||||||
if(_ledBuffer.size() != mLedCount){
|
if(_ledBuffer.size() != mLedCount){
|
||||||
_ledBuffer.resize(mLedCount, 0x00);
|
_ledBuffer.resize(mLedCount, 0xFF);
|
||||||
_ledBuffer[0] = 'A';
|
_ledBuffer[0] = 'A';
|
||||||
_ledBuffer[1] = 'd';
|
_ledBuffer[1] = 'd';
|
||||||
_ledBuffer[2] = 'a';
|
_ledBuffer[2] = 'a';
|
||||||
@ -36,7 +37,7 @@ int LedDeviceAdalightApa102::write(const std::vector<ColorRgb> & ledValues)
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (unsigned iLed=1; iLed<=ledValues.size(); iLed++) {
|
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+6] = 0xFF;
|
||||||
_ledBuffer[iLed*4+1+6] = rgb.red;
|
_ledBuffer[iLed*4+1+6] = rgb.red;
|
||||||
_ledBuffer[iLed*4+2+6] = rgb.green;
|
_ledBuffer[iLed*4+2+6] = rgb.green;
|
||||||
|
Loading…
Reference in New Issue
Block a user