Binary Websockets for Peek (#2516)

* Binary Websockets for Peek

* No IRAM_ATTR here

* Use builtin LittleFS for all ESP32 builds

* Attempt LittleFS compilation fix

* Use tasmota zip for all ESP32 builds

* Revert to Arduino Core 1 for the time being
This commit is contained in:
Christian Schwinne
2022-02-01 12:02:04 +01:00
committed by GitHub
parent 0a5a0bef48
commit 565d8d8f04
11 changed files with 897 additions and 857 deletions

View File

@@ -123,6 +123,34 @@ void sendDataWs(AsyncWebSocketClient * client)
}
}
#define MAX_LIVE_LEDS_WS 256
bool sendLiveLedsWs(uint32_t wsClient)
{
AsyncWebSocketClient * wsc = ws.client(wsClient);
if (!wsc || wsc->queueLength() > 0) return false; //only send if queue free
uint16_t used = strip.getLengthTotal();
uint16_t n = (used -1) /MAX_LIVE_LEDS_WS +1; //only serve every n'th LED if count over MAX_LIVE_LEDS
AsyncWebSocketMessageBuffer * wsBuf = ws.makeBuffer(2 + MIN(used, MAX_LIVE_LEDS_WS)*3);
if (!wsBuf) return false; //out of memory
uint8_t* buffer = wsBuf->get();
buffer[0] = 'L';
buffer[1] = 1; //version
uint16_t pos = 2;
for (uint16_t i= 0; i < used; i += n)
{
uint32_t c = strip.getPixelColor(i);
buffer[pos++] = qadd8(W(c), R(c)); //R, add white channel to RGB channels as a simple RGBW -> RGB map
buffer[pos++] = qadd8(W(c), G(c)); //G
buffer[pos++] = qadd8(W(c), B(c)); //B
}
wsc->binary(wsBuf);
return true;
}
void handleWs()
{
if (millis() - wsLastLiveTime > WS_LIVE_INTERVAL)
@@ -130,7 +158,7 @@ void handleWs()
ws.cleanupClients();
bool success = true;
if (wsLiveClientId)
success = serveLiveLeds(nullptr, wsLiveClientId);
success = sendLiveLedsWs(wsLiveClientId);
wsLastLiveTime = millis();
if (!success) wsLastLiveTime -= 20; //try again in 20ms if failed due to non-empty WS queue
}