Small optimisations.

2D liveView (non-WS) core
soundSim fix
This commit is contained in:
Blaz Kristan
2023-10-25 20:27:01 +02:00
parent 789e34702b
commit db881ee011
6 changed files with 92 additions and 40 deletions

View File

@@ -164,39 +164,39 @@ bool sendLiveLedsWs(uint32_t wsClient)
const size_t MAX_LIVE_LEDS_WS = 1024U;
#endif
size_t n = ((used -1)/MAX_LIVE_LEDS_WS) +1; //only serve every n'th LED if count over MAX_LIVE_LEDS_WS
size_t pos = (strip.isMatrix ? 4 : 2); // start of data
size_t pos = 2; // start of data
#ifndef WLED_DISABLE_2D
if (strip.isMatrix) {
// ignore anything behid matrix (i.e. extra strip)
used = Segment::maxWidth*Segment::maxHeight; // always the size of matrix (more or less than strip.getLengthTotal())
n = 1;
if (used > MAX_LIVE_LEDS_WS) n = 2;
if (used > MAX_LIVE_LEDS_WS*4) n = 4;
pos = 4;
}
#endif
size_t bufSize = pos + (used/n)*3;
AsyncWebSocketMessageBuffer * wsBuf = ws.makeBuffer(bufSize);
if (!wsBuf) return false; //out of memory
uint8_t* buffer = wsBuf->get();
if (!buffer) return false; //out of memory
wsBuf->lock(); // protect buffer from being cleaned by another WS instance
buffer[0] = 'L';
buffer[1] = 1; //version
#ifndef WLED_DISABLE_2D
size_t skipLines = 0;
if (strip.isMatrix) {
buffer[1] = 2; //version
buffer[2] = Segment::maxWidth;
buffer[3] = Segment::maxHeight;
if (used > MAX_LIVE_LEDS_WS*4) {
buffer[2] = Segment::maxWidth/4;
buffer[3] = Segment::maxHeight/4;
skipLines = 3;
} else if (used > MAX_LIVE_LEDS_WS) {
buffer[2] = Segment::maxWidth/2;
buffer[3] = Segment::maxHeight/2;
skipLines = 1;
}
buffer[2] = Segment::maxWidth/n;
buffer[3] = Segment::maxHeight/n;
}
#endif
for (size_t i = 0; pos < bufSize -2; i += n)
{
#ifndef WLED_DISABLE_2D
if (strip.isMatrix && skipLines) {
if ((i/Segment::maxWidth)%(skipLines+1)) i += Segment::maxWidth * skipLines;
}
if (strip.isMatrix && n>1 && (i/Segment::maxWidth)%n) i += Segment::maxWidth * (n-1);
#endif
uint32_t c = strip.getPixelColor(i);
uint8_t r = R(c);
@@ -209,6 +209,8 @@ bool sendLiveLedsWs(uint32_t wsClient)
}
wsc->binary(wsBuf);
wsBuf->unlock(); // un-protect buffer
ws._cleanBuffers();
return true;
}