From 2eea311dcef21d6dedc3f1712238b7d1b69c89be Mon Sep 17 00:00:00 2001 From: pcaffardi Date: Sun, 9 Aug 2015 16:15:25 +0200 Subject: [PATCH 1/2] Update LedDeviceAPA102.cpp This fix the previous limit of 64 APA102 leds, because of too short end frame. Now the end frame is computed accordling to this documentation: https://cpldcpu.wordpress.com/2014/11/30/understanding-the-apa102-superled/. Tested on my 98 leds, it works fine. I suggest to modify hyperion to allow LED drivers to apply the brightness parameter because APA102 has a parameter for that, without the need to elaborate RGB color to simulate it (result is wrong colors!). Is it possible to introduce such parameter in LED drivers and let the driver apply that? Former-commit-id: 2d714e6eb075ec57e0973839fe96d2d7a051c57f --- libsrc/leddevice/LedDeviceAPA102.cpp | 48 ++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 13 deletions(-) diff --git a/libsrc/leddevice/LedDeviceAPA102.cpp b/libsrc/leddevice/LedDeviceAPA102.cpp index 2af01acf..00eba4bd 100644 --- a/libsrc/leddevice/LedDeviceAPA102.cpp +++ b/libsrc/leddevice/LedDeviceAPA102.cpp @@ -1,4 +1,3 @@ - // STL includes #include #include @@ -18,22 +17,45 @@ LedDeviceAPA102::LedDeviceAPA102(const std::string& outputDevice, const unsigned // empty } +#define MIN(a,b) ((a)<(b)?(a):(b)) +#define MAX(a,b) ((a)>(b)?(a):(b)) + +#define APA102_START_FRAME_BYTES 4 +#define APA102_LED_BYTES 4 +#define APA102_END_FRAME_BITS_MIN 32 +#define APA102_END_FRAME_BITS(leds) MAX((((leds-1)/2)+1),APA102_END_FRAME_BITS_MIN) +#define APA102_END_FRAME_BYTES(leds) (((APA102_END_FRAME_BITS(leds)-1)/8)+1) +#define APA102_LED_HEADER 0xe0 +#define APA102_LED_MAX_INTENSITY 0x1f + int LedDeviceAPA102::write(const std::vector &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); + const unsigned int startFrameSize = APA102_START_FRAME_BYTES; + const unsigned int ledsCount = ledValues.size() ; + const unsigned int ledsSize = ledsCount * APA102_LED_BYTES ; + const unsigned int endFrameBits = APA102_END_FRAME_BITS(ledsCount) ; + const unsigned int endFrameSize = APA102_END_FRAME_BYTES(ledsCount) ; + const unsigned int transferSize = startFrameSize + ledsSize + endFrameSize ; + + if(_ledBuffer.size() != transferSize){ + _ledBuffer.resize(transferSize, 0x00); + } + + unsigned idx = 0, i; + for (i=0; i &ledValues) int LedDeviceAPA102::switchOff() { return write(std::vector(_ledBuffer.size(), ColorRgb{0,0,0})); -} +} From 79dda5e8402219c9e78c9711bb59e1a29b428944 Mon Sep 17 00:00:00 2001 From: wisc Date: Sun, 7 Feb 2016 17:40:24 +0100 Subject: [PATCH 2/2] Update LedDeviceAPA102.cpp by pcaffardi Former-commit-id: e7efe8917fc10ceb860e44bbb37442cffa3512db --- libsrc/leddevice/LedDeviceAPA102.cpp | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/libsrc/leddevice/LedDeviceAPA102.cpp b/libsrc/leddevice/LedDeviceAPA102.cpp index fb016229..17bec4fc 100644 --- a/libsrc/leddevice/LedDeviceAPA102.cpp +++ b/libsrc/leddevice/LedDeviceAPA102.cpp @@ -2,7 +2,6 @@ #include #include #include -#include // Linux includes #include @@ -32,15 +31,15 @@ LedDeviceAPA102::LedDeviceAPA102(const std::string& outputDevice, const unsigned int LedDeviceAPA102::write(const std::vector &ledValues) { const unsigned int startFrameSize = APA102_START_FRAME_BYTES; - const unsigned int ledsCount = ledValues.size() ; - const unsigned int ledsSize = ledsCount * APA102_LED_BYTES ; - const unsigned int endFrameBits = APA102_END_FRAME_BITS(ledsCount) ; - const unsigned int endFrameSize = APA102_END_FRAME_BYTES(ledsCount) ; - const unsigned int transferSize = startFrameSize + ledsSize + endFrameSize ; + const unsigned int ledsCount = ledValues.size() ; + const unsigned int ledsSize = ledsCount * APA102_LED_BYTES ; + const unsigned int endFrameBits = APA102_END_FRAME_BITS(ledsCount) ; + const unsigned int endFrameSize = APA102_END_FRAME_BYTES(ledsCount) ; + const unsigned int transferSize = startFrameSize + ledsSize + endFrameSize ; if(_ledBuffer.size() != transferSize){ _ledBuffer.resize(transferSize, 0x00); - } + } unsigned idx = 0, i; for (i=0; i &ledValues) _ledBuffer[idx++] = rgb.blue; } for(i=0; i &ledValues) int LedDeviceAPA102::switchOff() { return write(std::vector(_ledBuffer.size(), ColorRgb{0,0,0})); -} +}