From b50e798d55d42b86596cc8e4637849ba968f0510 Mon Sep 17 00:00:00 2001 From: twlare <38672507+twlare@users.noreply.github.com> Date: Tue, 4 Aug 2020 09:50:16 -0700 Subject: [PATCH] Add segment mirror option * Add segment mirror option (#1010) * Update new pull with playlist and palette changes * Revert "Update new pull with playlist and palette changes" This reverts commit 9802a7c4e22d408337fc574e031dc49d4265fef3. --- wled00/FX.h | 11 +++++++++-- wled00/FX_fcn.cpp | 8 +++++++- wled00/const.h | 2 +- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/wled00/FX.h b/wled00/FX.h index 7afca48a4..da8a6942d 100644 --- a/wled00/FX.h +++ b/wled00/FX.h @@ -84,16 +84,19 @@ // options // bit 7: segment is in transition mode -// bits 3-6: TBD +// bits 4-6: TBD +// bit 3: mirror effect within segment // bit 2: segment is on // bit 1: reverse segment // bit 0: segment is selected #define NO_OPTIONS (uint8_t)0x00 #define TRANSITIONAL (uint8_t)0x80 +#define MIRROR (uint8_t)0x08 #define SEGMENT_ON (uint8_t)0x04 #define REVERSE (uint8_t)0x02 #define SELECTED (uint8_t)0x01 #define IS_TRANSITIONAL ((SEGMENT.options & TRANSITIONAL) == TRANSITIONAL) +#define IS_MIRROR ((SEGMENT.options & MIRROR ) == MIRROR ) #define IS_SEGMENT_ON ((SEGMENT.options & SEGMENT_ON ) == SEGMENT_ON ) #define IS_REVERSE ((SEGMENT.options & REVERSE ) == REVERSE ) #define IS_SELECTED ((SEGMENT.options & SELECTED ) == SELECTED ) @@ -264,7 +267,11 @@ class WS2812FX { uint16_t virtualLength() { uint16_t groupLen = groupLength(); - return (length() + groupLen -1) / groupLen; + uint16_t vLength; + vLength = (length() + groupLen - 1) / groupLen; + if (options & MIRROR) + vLength /= 2; // divide by 2 if mirror; leaves a blank LED in the middle if length is odd + return vLength; } } segment; diff --git a/wled00/FX_fcn.cpp b/wled00/FX_fcn.cpp index a1b4096cb..464e9d2aa 100644 --- a/wled00/FX_fcn.cpp +++ b/wled00/FX_fcn.cpp @@ -111,7 +111,11 @@ uint16_t WS2812FX::realPixelIndex(uint16_t i) { /* reverse just an individual segment */ int16_t realIndex = iGroup; - if (IS_REVERSE) realIndex = SEGMENT.length() -iGroup -1; + if (IS_REVERSE) + if (IS_MIRROR) + realIndex = SEGMENT.length() / 2 - iGroup - 1; //only need to index half the pixels + else + realIndex = SEGMENT.length() - iGroup - 1; realIndex += SEGMENT.start; /* Reverse the whole string */ @@ -177,6 +181,8 @@ void WS2812FX::setPixelColor(uint16_t i, byte r, byte g, byte b, byte w) if (indexSet < customMappingSize) indexSet = customMappingTable[indexSet]; #endif if (indexSetRev >= SEGMENT.start && indexSetRev < SEGMENT.stop) bus->SetPixelColor(indexSet + skip, col); + if (IS_MIRROR) //set the corresponding mirrored pixel + bus->SetPixelColor(SEGMENT.stop - (indexSet + skip) + SEGMENT.start - 1, col); } } else { //live data, etc. if (reverseMode) i = _length - 1 - i; diff --git a/wled00/const.h b/wled00/const.h index 1ec4caf58..ac3549b5f 100644 --- a/wled00/const.h +++ b/wled00/const.h @@ -99,7 +99,7 @@ #define SEG_OPTION_SELECTED 0 #define SEG_OPTION_REVERSED 1 #define SEG_OPTION_ON 2 -#define SEG_OPTION_PAUSED 3 //unused +#define SEG_OPTION_MIRROR 3 //Indicates that the effect will be mirrored within the segment #define SEG_OPTION_NONUNITY 4 //Indicates that the effect does not use FRAMETIME or needs getPixelColor #define SEG_OPTION_TRANSITIONAL 7