MCPcopy Create free account
hub / github.com/FastLED/FastLED / _jsSetCanvasSize

Function _jsSetCanvasSize

src/platforms/wasm/js_bindings.cpp.hpp:257–311  ·  view source on GitHub ↗

* Canvas Size Setting Function - Push-based notification to JavaScript * When a screenmap is created or updated, this function pushes the complete * screenmap data to JavaScript, eliminating the need for per-frame polling * * Internal function called by EngineListener when screenmaps are updated. * Not exposed in public API - platform-specific listener handles JS communication. */

Source from the content-addressed store, hash-verified

255 * Not exposed in public API - platform-specific listener handles JS communication.
256 */
257void _jsSetCanvasSize(int cledcontoller_id, const fl::ScreenMap &screenmap) {
258 // Get the complete screenmap data for all strips
259 fl::ActiveStripData& active_strips = fl::ActiveStripData::Instance();
260 const auto& screenMaps = active_strips.getScreenMaps();
261
262 // Create dictionary of screenmaps (stripId → screenmap object)
263 fl::json root = fl::json::object();
264
265 // Build a separate screenmap object for each strip
266 for (const auto &[stripIndex, screenMap] : screenMaps) {
267 // Create this strip's screenmap object
268 fl::json screenMapObj = fl::json::object();
269
270 // Create strips object containing only this strip
271 fl::json stripsObj = fl::json::object();
272 fl::json stripMapObj = fl::json::object();
273
274 fl::json mapObj = fl::json::object();
275 fl::json xArray = fl::json::array();
276 fl::json yArray = fl::json::array();
277
278 for (u32 i = 0; i < screenMap.getLength(); i++) {
279 float x = screenMap[i].x;
280 float y = screenMap[i].y;
281
282 xArray.push_back(fl::json(x));
283 yArray.push_back(fl::json(y));
284 }
285
286 mapObj.set("x", xArray);
287 mapObj.set("y", yArray);
288 stripMapObj.set("map", mapObj);
289
290 // Add diameter
291 stripMapObj.set("diameter", screenMap.getDiameter());
292
293 // Add this strip to the strips object
294 stripsObj.set(fl::to_string(stripIndex), stripMapObj);
295
296 // Set strips object
297 screenMapObj.set("strips", stripsObj);
298
299 // Add this screenmap to the root dictionary
300 root.set(fl::to_string(stripIndex), screenMapObj);
301 }
302
303 // Serialize to JSON
304 fl::string jsonBuffer = root.to_string();
305
306 // Push the complete screenmap data to JavaScript
307 // JavaScript worker will cache this and avoid per-frame polling
308 // NOTE: EM_JS has linking issues with partial linking - use polling approach instead
309 // Worker will call getScreenMapData() during initialization to fetch this data
310 FL_DBG("Screenmap update available (worker will poll via getScreenMapData): " << jsonBuffer.c_str());
311}
312
313EMSCRIPTEN_KEEPALIVE void jsFillInMissingScreenMaps(ActiveStripData &active_strips) {
314 struct Function {

Callers 2

onCanvasUiSetMethod · 0.85

Calls 9

getDiameterMethod · 0.80
arrayClass · 0.50
jsonClass · 0.50
to_stringFunction · 0.50
getLengthMethod · 0.45
push_backMethod · 0.45
setMethod · 0.45
to_stringMethod · 0.45
c_strMethod · 0.45

Tested by

no test coverage detected