Skip to content

Commit

Permalink
Add easy segment mirroring (closes Aircoookie#1010)
Browse files Browse the repository at this point in the history
  • Loading branch information
Aircoookie committed Aug 19, 2020
1 parent b1c9dbd commit 39a80f8
Show file tree
Hide file tree
Showing 6 changed files with 1,871 additions and 1,865 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

### Development versions after 0.10.0 release

#### Build 2008200

- Added segment mirroring to web UI
- Fixed segment mirroring when in reverse mode

#### Build 2008140

- Removed verbose live mode info from `<ds>` in HTTP API response
Expand Down
4 changes: 2 additions & 2 deletions wled00/FX.h
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ class WS2812FX {
uint16_t groupLen = groupLength();
uint16_t vLength = (length() + groupLen - 1) / groupLen;
if (options & MIRROR)
vLength = (vLength + 1) /2; // divide by 2 if mirror, leave at least a signle LED
vLength = (vLength + 1) /2; // divide by 2 if mirror, leave at least a single LED
return vLength;
}
} segment;
Expand Down Expand Up @@ -450,7 +450,7 @@ class WS2812FX {
setRgbwPwm(void);

bool
reverseMode = false,
reverseMode = false, //is the entire LED strip reversed?
gammaCorrectBri = false,
gammaCorrectCol = true,
applyToAllSelected = true,
Expand Down
28 changes: 19 additions & 9 deletions wled00/FX_fcn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,20 +106,25 @@ void WS2812FX::setPixelColor(uint16_t n, uint32_t c) {
setPixelColor(n, r, g, b, w);
}

#define REV(i) (_length - 1 - (i))

//used to map from segment index to physical pixel, taking into account grouping, offsets, reverse and mirroring
uint16_t WS2812FX::realPixelIndex(uint16_t i) {
int16_t iGroup = i * SEGMENT.groupLength();

/* reverse just an individual segment */
int16_t realIndex = iGroup;
if (IS_REVERSE)
if (IS_MIRROR)
realIndex = SEGMENT.length() / 2 - iGroup - 1; //only need to index half the pixels
else
if (IS_REVERSE) {
if (IS_MIRROR) {
realIndex = (SEGMENT.length() -1) / 2 - iGroup; //only need to index half the pixels
} else {
realIndex = SEGMENT.length() - iGroup - 1;
}
}

realIndex += SEGMENT.start;
/* Reverse the whole string */
if (reverseMode) realIndex = _length - 1 - realIndex;
if (reverseMode) realIndex = REV(realIndex);

return realIndex;
}
Expand Down Expand Up @@ -176,18 +181,23 @@ void WS2812FX::setPixelColor(uint16_t i, byte r, byte g, byte b, byte w)
for (uint16_t j = 0; j < SEGMENT.grouping; j++) {
int16_t indexSet = realIndex + (reversed ? -j : j);
int16_t indexSetRev = indexSet;
if (reverseMode) indexSetRev = _length - 1 - indexSet;
if (reverseMode) indexSetRev = REV(indexSet);
#ifdef WLED_CUSTOM_LED_MAPPING
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);
if (IS_MIRROR) { //set the corresponding mirrored pixel
if (reverseMode) {
bus->SetPixelColor(REV(SEGMENT.start) - indexSet + skip + REV(SEGMENT.stop) + 1, col);
} else {
bus->SetPixelColor(SEGMENT.stop - indexSet + skip + SEGMENT.start - 1, col);
}
}
}
}
} else { //live data, etc.
if (reverseMode) i = _length - 1 - i;
if (reverseMode) i = REV(i);
#ifdef WLED_CUSTOM_LED_MAPPING
if (i < customMappingSize) i = customMappingTable[i];
#endif
Expand Down
31 changes: 11 additions & 20 deletions wled00/data/index.htm
Original file line number Diff line number Diff line change
Expand Up @@ -478,26 +478,6 @@
background: var(--c-f);
transform: translateY(7px);
}
input[type=range]::-ms-track {
width: 100%;
height: 30px;
background: transparent;
border-color: transparent;
color: transparent;
}
input[type=range]::-ms-fill-lower {
background: transparent;
}
input[type=range]::-ms-fill-upper {
background: transparent;
}
input[type=range]::-ms-thumb {
height: 16px;
width: 16px;
border-radius: 16px;
background: var(--c-f);
margin-top: -12px;
}

#wwrap {
display: none;
Expand Down Expand Up @@ -1422,6 +1402,11 @@
<input type="checkbox" id="seg${i}rev" onchange="setRev(${i})" ${inst.rev ? "checked":""}>
<span class="checkmark schk"></span>
</label>
<label class="check revchkl">
Mirror effect
<input type="checkbox" id="seg${i}mi" onchange="setMi(${i})" ${inst.mi ? "checked":""}>
<span class="checkmark schk"></span>
</label>
</div>
</div><br>`;
}
Expand Down Expand Up @@ -1783,6 +1768,12 @@
requestJson(obj, false);
}

function setMi(s){
var mi = d.getElementById(`seg${s}mi`).checked;
var obj = {"seg": {"id": s, "mi": mi}};
requestJson(obj, false);
}

function setSegPwr(s){
var obj = {"seg": {"id": s, "on": !powered[s]}};
requestJson(obj);
Expand Down
Loading

0 comments on commit 39a80f8

Please sign in to comment.