From d6b5dc7ae65a4ce59aa1bed4fc54c1086502530f Mon Sep 17 00:00:00 2001 From: wisc17 Date: Tue, 9 Feb 2016 20:21:49 +0100 Subject: [PATCH] Revert "Update LedDeviceAPA102.cpp by pcaffardi" Former-commit-id: 493b32c03f922cc26d9fb4fce4778636f6a96e84 --- libsrc/leddevice/LedDeviceAPA102.cpp | 53 ++++++++++------------------ 1 file changed, 18 insertions(+), 35 deletions(-) diff --git a/libsrc/leddevice/LedDeviceAPA102.cpp b/libsrc/leddevice/LedDeviceAPA102.cpp index 17bec4fc..26a21f72 100644 --- a/libsrc/leddevice/LedDeviceAPA102.cpp +++ b/libsrc/leddevice/LedDeviceAPA102.cpp @@ -1,7 +1,9 @@ + // STL includes #include #include #include +#include // Linux includes #include @@ -17,46 +19,27 @@ 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 = 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); + const unsigned int startFrameSize = 4; + const unsigned int endFrameSize = std::max(((ledValues.size() + 15) / 16), 4); + const unsigned int mLedCount = (ledValues.size() * 4) + startFrameSize + endFrameSize; + if(_ledBuffer.size() != mLedCount){ + _ledBuffer.resize(mLedCount, 0xFF); + _ledBuffer[0] = 0x00; + _ledBuffer[1] = 0x00; + _ledBuffer[2] = 0x00; + _ledBuffer[3] = 0x00; } - - unsigned idx = 0, i; - for (i=0; i