diff --git a/wled00/FX.h b/wled00/FX.h index 7afca48a..da8a6942 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 a1b4096c..464e9d2a 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 1ec4caf5..ac3549b5 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