#include "recorder.h" #include "my_fastled.h" #include "functions.h" #include "effects.h" #include #ifdef RECORDER_ENABLE Recorder::Recorder() { _buffer_len = LED_WIDTH * LED_HEIGHT * 3 + 3; _buffer = (char*)malloc(_buffer_len); _server = new AsyncServer(RECORDER_PORT); _server->onClient([&](void* a, AsyncClient* c) { LOGln("Recorder * New client: %s. Waiting for port number...", c->remoteIP().toString().c_str()); if (_client) { LOGln("Recorder * Killing old client."); _client->close(); _client_port = 0; delete _client; } _client = c; _msgid = 0; char dim[3] = {LED_WIDTH, LED_HEIGHT, 255}; _client->write(dim, 3); _client->onDisconnect([&](void* a, AsyncClient* client) { LOGln("Recorder * Client disconnected"); _client_port = 0; }, NULL); _client->onData([&](void* a, AsyncClient* client, void* data, size_t len) { if (*(char*)data == 'P') { LOGln("Found."); if (len >= 3) { uint8_t* d = (uint8_t*)data; _client_port = d[1]<<8 | d[2]; LOGln("Recorder * Sending data to port %d", _client_port); } } else if (*(char*)data == 'E') { String effect = String(((char*)(data+1))); LOGln("Recorder * Setting effect %s", effect.c_str()); change_current_effect(effect); } }, NULL); }, _server); _server->begin(); LOGln("Recorder * Listening on port %d", RECORDER_PORT); } void Recorder::loop() { if (_client && _client_port) { _buffer[0] = _msgid >> 8; _buffer[1] = _msgid & 0xFF; for (uint8_t y=0; ywrite(_buffer, _buffer_len); } } #endif