Transpose fix for XY()

Slight internal API change.
Renamed c1x,c2x,c3x to custom1, custom2, custom3 to be in line with SR.
This commit is contained in:
Blaz Kristan 2022-05-21 13:19:11 +02:00
parent 62abc63f7a
commit e003ec39fb
6 changed files with 547 additions and 536 deletions

View File

@ -277,6 +277,9 @@ class WS2812FX {
static WS2812FX* instance; static WS2812FX* instance;
// mode (effect) name and its slider control data array
static const char *_modeData[MODE_COUNT];
public: public:
// segment parameters // segment parameters
@ -294,7 +297,7 @@ class WS2812FX {
uint32_t colors[NUM_COLORS]; uint32_t colors[NUM_COLORS];
uint8_t cct; //0==1900K, 255==10091K uint8_t cct; //0==1900K, 255==10091K
uint8_t _capabilities; uint8_t _capabilities;
uint8_t c1x, c2x, c3x; // custom FX parameters uint8_t custom1, custom2, custom3; // custom FX parameters
uint16_t startY; // start Y coodrinate 2D (top) uint16_t startY; // start Y coodrinate 2D (top)
uint16_t stopY; // stop Y coordinate 2D (bottom) uint16_t stopY; // stop Y coordinate 2D (bottom)
char *name; char *name;
@ -344,6 +347,7 @@ class WS2812FX {
ColorTransition::startTransition(0, colors[0], instance->_transitionDur, segn, 0); ColorTransition::startTransition(0, colors[0], instance->_transitionDur, segn, 0);
} }
} }
// 2D matrix
uint16_t virtualWidth() { uint16_t virtualWidth() {
uint16_t groupLen = groupLength(); uint16_t groupLen = groupLength();
uint16_t vWidth = (width() + groupLen - 1) / groupLen; uint16_t vWidth = (width() + groupLen - 1) / groupLen;
@ -356,6 +360,7 @@ class WS2812FX {
if (getOption(SEG_OPTION_MIRROR_Y)) vHeight = (vHeight + 1) /2; // divide by 2 if mirror, leave at least a single LED if (getOption(SEG_OPTION_MIRROR_Y)) vHeight = (vHeight + 1) /2; // divide by 2 if mirror, leave at least a single LED
return vHeight; return vHeight;
} }
// 1D strip
uint16_t virtualLength() { uint16_t virtualLength() {
uint16_t groupLen = groupLength(); uint16_t groupLen = groupLength();
uint16_t vLength = (length() + groupLen - 1) / groupLen; uint16_t vLength = (length() + groupLen - 1) / groupLen;
@ -934,7 +939,7 @@ class WS2812FX {
uint16_t uint16_t
XY(uint16_t, uint16_t), XY(uint16_t, uint16_t),
getPixelIndex(uint16_t x, uint16_t y, uint8_t seg=255); get2DPixelIndex(uint16_t x, uint16_t y, uint8_t seg=255);
uint32_t uint32_t
getPixelColorXY(uint16_t, uint16_t); getPixelColorXY(uint16_t, uint16_t);

View File

@ -106,20 +106,27 @@ void WS2812FX::setUpMatrix() {
} }
} }
// XY(x,y) - gets pixel index within current segment // XY(x,y) - gets pixel index within current segment (takes into account transposed segment)
uint16_t IRAM_ATTR WS2812FX::XY(uint16_t x, uint16_t y) { uint16_t IRAM_ATTR WS2812FX::XY(uint16_t x, uint16_t y) {
uint16_t width = SEGMENT.virtualWidth(); // segment width in logical pixels uint16_t width = SEGMENT.virtualWidth(); // segment width in logical pixels (is already transposed)
if (SEGMENT.getOption(SEG_OPTION_TRANSPOSED)) { uint16_t t = x; x = y; y = t; } // swap X & Y if segment transposed uint16_t height = SEGMENT.virtualHeight(); // segment height in logical pixels (is already transposed)
return (x%width) + (y%SEGMENT.virtualHeight()) * width; if (SEGMENT.getOption(SEG_OPTION_TRANSPOSED)) {
uint16_t t;
// swap X & Y if segment transposed
t = x; x = y; y = t;
// swap width & height if segment transposed
t = width; width = height; height = t;
}
return (x%width) + (y%height) * width;
} }
// getPixelIndex(x,y,seg) - returns an index of segment pixel in a matrix layout // get2DPixelIndex(x,y,seg) - returns an index of segment pixel in a matrix layout
// index still needs to undergo ledmap processing to represent actual physical pixel // index still needs to undergo ledmap processing to represent actual physical pixel
// matrix is always organized by matrixHeight number of matrixWidth pixels from top to bottom, left to right // matrix is always organized by matrixHeight number of matrixWidth pixels from top to bottom, left to right
// so: pixel at getPixelIndex(5,6) in a 2D segment with [start=10, stop=19, startY=20, stopY=29 : 10x10 pixels] // so: pixel at get2DPixelIndex(5,6) in a 2D segment with [start=10, stop=19, startY=20, stopY=29 : 10x10 pixels]
// corresponds to pixel with logical index of 847 (0 based) if a 2D segment belongs to a 32x32 matrix. // corresponds to pixel with logical index of 847 (0 based) if a 2D segment belongs to a 32x32 matrix.
// math: (matrixWidth * (startY + y)) + start + x => (32 * (20+6)) + 10 + 5 = 847 // math: (matrixWidth * (startY + y)) + start + x => (32 * (20+6)) + 10 + 5 = 847
uint16_t IRAM_ATTR WS2812FX::getPixelIndex(uint16_t x, uint16_t y, uint8_t seg) { uint16_t IRAM_ATTR WS2812FX::get2DPixelIndex(uint16_t x, uint16_t y, uint8_t seg) {
if (seg == 255) seg = _segment_index; if (seg == 255) seg = _segment_index;
x %= _segments[seg].width(); // just in case constrain x (wrap around) x %= _segments[seg].width(); // just in case constrain x (wrap around)
y %= _segments[seg].height(); // just in case constrain y (wrap around) y %= _segments[seg].height(); // just in case constrain y (wrap around)
@ -152,17 +159,17 @@ void IRAM_ATTR WS2812FX::setPixelColorXY(uint16_t x, uint16_t y, byte r, byte g,
if (SEGMENT.getOption(SEG_OPTION_REVERSED) ) xX = SEGMENT.width() - xX - 1; if (SEGMENT.getOption(SEG_OPTION_REVERSED) ) xX = SEGMENT.width() - xX - 1;
if (SEGMENT.getOption(SEG_OPTION_REVERSED_Y)) yY = SEGMENT.height() - yY - 1; if (SEGMENT.getOption(SEG_OPTION_REVERSED_Y)) yY = SEGMENT.height() - yY - 1;
index = getPixelIndex(xX, yY); index = get2DPixelIndex(xX, yY);
if (index < customMappingSize) index = customMappingTable[index]; if (index < customMappingSize) index = customMappingTable[index];
busses.setPixelColor(index, col); busses.setPixelColor(index, col);
if (SEGMENT.getOption(SEG_OPTION_MIRROR)) { //set the corresponding horizontally mirrored pixel if (SEGMENT.getOption(SEG_OPTION_MIRROR)) { //set the corresponding horizontally mirrored pixel
index = getPixelIndex(SEGMENT.width() - xX - 1, yY); index = get2DPixelIndex(SEGMENT.width() - xX - 1, yY);
if (index < customMappingSize) index = customMappingTable[index]; if (index < customMappingSize) index = customMappingTable[index];
busses.setPixelColor(index, col); busses.setPixelColor(index, col);
} }
if (SEGMENT.getOption(SEG_OPTION_MIRROR_Y)) { //set the corresponding vertically mirrored pixel if (SEGMENT.getOption(SEG_OPTION_MIRROR_Y)) { //set the corresponding vertically mirrored pixel
index = getPixelIndex(xX, SEGMENT.height() - yY - 1); index = get2DPixelIndex(xX, SEGMENT.height() - yY - 1);
if (index < customMappingSize) index = customMappingTable[index]; if (index < customMappingSize) index = customMappingTable[index];
busses.setPixelColor(index, col); busses.setPixelColor(index, col);
} }
@ -181,7 +188,7 @@ uint32_t WS2812FX::getPixelColorXY(uint16_t x, uint16_t y) {
if (SEGMENT.getOption(SEG_OPTION_REVERSED) ) x = SEGMENT.width() - x - 1; if (SEGMENT.getOption(SEG_OPTION_REVERSED) ) x = SEGMENT.width() - x - 1;
if (SEGMENT.getOption(SEG_OPTION_REVERSED_Y)) y = SEGMENT.height() - y - 1; if (SEGMENT.getOption(SEG_OPTION_REVERSED_Y)) y = SEGMENT.height() - y - 1;
uint16_t index = getPixelIndex(x, y); uint16_t index = get2DPixelIndex(x, y);
if (index < customMappingSize) index = customMappingTable[index]; if (index < customMappingSize) index = customMappingTable[index];
return busses.getPixelColor(index); return busses.getPixelColor(index);

View File

@ -566,9 +566,9 @@ uint8_t WS2812FX::Segment::differs(Segment& b) {
if (speed != b.speed) d |= SEG_DIFFERS_FX; if (speed != b.speed) d |= SEG_DIFFERS_FX;
if (intensity != b.intensity) d |= SEG_DIFFERS_FX; if (intensity != b.intensity) d |= SEG_DIFFERS_FX;
if (palette != b.palette) d |= SEG_DIFFERS_FX; if (palette != b.palette) d |= SEG_DIFFERS_FX;
if (c1x != b.c1x) d |= SEG_DIFFERS_FX; if (custom1 != b.custom1) d |= SEG_DIFFERS_FX;
if (c2x != b.c2x) d |= SEG_DIFFERS_FX; if (custom2 != b.custom2) d |= SEG_DIFFERS_FX;
if (c3x != b.c3x) d |= SEG_DIFFERS_FX; if (custom3 != b.custom3) d |= SEG_DIFFERS_FX;
if (startY != b.startY) d |= SEG_DIFFERS_BOUNDS; if (startY != b.startY) d |= SEG_DIFFERS_BOUNDS;
if (stopY != b.stopY) d |= SEG_DIFFERS_BOUNDS; if (stopY != b.stopY) d |= SEG_DIFFERS_BOUNDS;
@ -710,9 +710,9 @@ void WS2812FX::resetSegments() {
_segments[0].setOption(SEG_OPTION_ON, 1); _segments[0].setOption(SEG_OPTION_ON, 1);
_segments[0].opacity = 255; _segments[0].opacity = 255;
_segments[0].cct = 127; _segments[0].cct = 127;
_segments[0].c1x = DEFAULT_C1; _segments[0].custom1 = DEFAULT_C1;
_segments[0].c2x = DEFAULT_C2; _segments[0].custom2 = DEFAULT_C2;
_segments[0].c3x = DEFAULT_C3; _segments[0].custom3 = DEFAULT_C3;
for (uint16_t i = 1; i < MAX_NUM_SEGMENTS; i++) for (uint16_t i = 1; i < MAX_NUM_SEGMENTS; i++)
{ {
@ -723,9 +723,9 @@ void WS2812FX::resetSegments() {
_segments[i].cct = 127; _segments[i].cct = 127;
_segments[i].speed = DEFAULT_SPEED; _segments[i].speed = DEFAULT_SPEED;
_segments[i].intensity = DEFAULT_INTENSITY; _segments[i].intensity = DEFAULT_INTENSITY;
_segments[i].c1x = DEFAULT_C1; _segments[i].custom1 = DEFAULT_C1;
_segments[i].c2x = DEFAULT_C2; _segments[i].custom2 = DEFAULT_C2;
_segments[i].c3x = DEFAULT_C3; _segments[i].custom3 = DEFAULT_C3;
_segment_runtimes[i].markForReset(); _segment_runtimes[i].markForReset();
} }
_segment_runtimes[0].markForReset(); _segment_runtimes[0].markForReset();

View File

@ -1221,9 +1221,9 @@ function readState(s,command=false)
gId('sliderSpeed').value = i.sx; gId('sliderSpeed').value = i.sx;
gId('sliderIntensity').value = i.ix; gId('sliderIntensity').value = i.ix;
gId('sliderC1').value = i.c1x ? i.c1x : 0; gId('sliderC1').value = i.c1 ? i.c1 : 0;
gId('sliderC2').value = i.c2x ? i.c2x : 0; gId('sliderC2').value = i.c2 ? i.c2 : 0;
gId('sliderC3').value = i.c3x ? i.c3x : 0; gId('sliderC3').value = i.c3 ? i.c3 : 0;
if (s.error && s.error != 0) { if (s.error && s.error != 0) {
var errstr = ""; var errstr = "";
@ -2011,9 +2011,9 @@ function setCustom(i=1)
if (i<1 || i>3) return; if (i<1 || i>3) return;
var obj = {"seg": {}}; var obj = {"seg": {}};
var val = parseInt(gId(`sliderC${i}`).value); var val = parseInt(gId(`sliderC${i}`).value);
if (i===3) obj.seg.c3x = val; if (i===3) obj.seg.c3 = val;
else if (i===2) obj.seg.c2x = val; else if (i===2) obj.seg.c2 = val;
else obj.seg.c1x = val; else obj.seg.c1 = val;
requestJson(obj); requestJson(obj);
} }

File diff suppressed because it is too large Load Diff

View File

@ -165,9 +165,9 @@ void deserializeSegment(JsonObject elem, byte it, byte presetId)
getVal(elem[F("sx")], &seg.speed, 0, 255); getVal(elem[F("sx")], &seg.speed, 0, 255);
getVal(elem[F("ix")], &seg.intensity, 0, 255); getVal(elem[F("ix")], &seg.intensity, 0, 255);
getVal(elem["pal"], &seg.palette, 1, strip.getPaletteCount()); getVal(elem["pal"], &seg.palette, 1, strip.getPaletteCount());
getVal(elem[F("c1x")], &seg.c1x, 0, 255); getVal(elem[F("c1")], &seg.custom1, 0, 255);
getVal(elem[F("c2x")], &seg.c2x, 0, 255); getVal(elem[F("c2")], &seg.custom2, 0, 255);
getVal(elem[F("c3x")], &seg.c3x, 0, 255); getVal(elem[F("c3")], &seg.custom3, 0, 255);
JsonArray iarr = elem[F("i")]; //set individual LEDs JsonArray iarr = elem[F("i")]; //set individual LEDs
if (!iarr.isNull()) { if (!iarr.isNull()) {
@ -433,9 +433,9 @@ void serializeSegment(JsonObject& root, WS2812FX::Segment& seg, byte id, bool fo
root[F("sx")] = seg.speed; root[F("sx")] = seg.speed;
root[F("ix")] = seg.intensity; root[F("ix")] = seg.intensity;
root["pal"] = seg.palette; root["pal"] = seg.palette;
root[F("c1x")] = seg.c1x; root[F("c1")] = seg.custom1;
root[F("c2x")] = seg.c2x; root[F("c2")] = seg.custom2;
root[F("c3x")] = seg.c3x; root[F("c3")] = seg.custom3;
root[F("sel")] = seg.isSelected(); root[F("sel")] = seg.isSelected();
root["rev"] = seg.getOption(SEG_OPTION_REVERSED); root["rev"] = seg.getOption(SEG_OPTION_REVERSED);
root[F("mi")] = seg.getOption(SEG_OPTION_MIRROR); root[F("mi")] = seg.getOption(SEG_OPTION_MIRROR);