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

Function FastLED_SetupAndLoop

src/platforms/wasm/compiler/index.ts:538–707  ·  view source on GitHub ↗

* Main setup and loop execution function for FastLED programs (Pure JavaScript Architecture) * @async * @param {Object} moduleInstance - The WASM module instance * @param {number} frame_rate - Target frame rate for the animation loop * @returns {Promise } Promise that resolves when setup is

(moduleInstance, frame_rate)

Source from the content-addressed store, hash-verified

536 * @returns {Promise<void>} Promise that resolves when setup is complete and loop is started
537 */
538async function FastLED_SetupAndLoop(moduleInstance, frame_rate) {
539 FASTLED_DEBUG_TRACE('INDEX_JS', 'FastLED_SetupAndLoop', 'ENTER', { frame_rate });
540
541 try {
542 FASTLED_DEBUG_LOG('INDEX_JS', 'Initializing FastLED with Pure JavaScript Architecture...');
543 console.log('Initializing FastLED with Pure JavaScript Architecture...');
544
545 // Check if moduleInstance is valid
546 FASTLED_DEBUG_LOG('INDEX_JS', 'Checking moduleInstance', {
547 hasModule: !!moduleInstance,
548 hasExternSetup: !!(moduleInstance && moduleInstance._extern_setup),
549 hasExternLoop: !!(moduleInstance && moduleInstance._extern_loop),
550 hasCwrap: !!(moduleInstance && moduleInstance.cwrap),
551 });
552
553 if (!moduleInstance) {
554 throw new Error('moduleInstance is null or undefined');
555 }
556
557 // Create the pure JavaScript async controller
558 FASTLED_DEBUG_LOG('INDEX_JS', 'Creating FastLEDAsyncController...');
559 fastLEDController = new FastLEDAsyncController(moduleInstance, frame_rate);
560 FASTLED_DEBUG_LOG('INDEX_JS', 'FastLEDAsyncController created successfully');
561
562 // Expose controller globally for debugging and external control
563 window.fastLEDController = fastLEDController;
564
565 // Expose event system globally
566 window.fastLEDEvents = fastLEDEvents;
567 window.fastLEDPerformanceMonitor = fastLEDPerformanceMonitor;
568
569 FASTLED_DEBUG_LOG('INDEX_JS', 'Globals exposed, calling controller.setup()...');
570
571 // Setup FastLED with proper error handling
572 console.log('🔧 About to call fastLEDController.setup()');
573 try {
574 fastLEDController.setup();
575 console.log('🔧 fastLEDController.setup() completed successfully');
576 } catch (error) {
577 console.error('🔧 setup() threw error:', error);
578 console.error('🔧 Error stack:', error.stack);
579 throw error; // Re-throw to prevent silent failure
580 }
581
582 FASTLED_DEBUG_LOG('INDEX_JS', 'Controller setup completed, initializing worker mode...');
583
584 // Initialize Web Worker mode for background thread rendering (always enabled)
585 const canvas = /** @type {HTMLCanvasElement | null} */ (document.getElementById('myCanvas'));
586 if (!canvas) {
587 throw new Error('Canvas element not found');
588 }
589
590 FASTLED_DEBUG_LOG('INDEX_JS', 'Initializing Web Worker mode with OffscreenCanvas...');
591 await fastLEDController.initializeWorkerMode(canvas, {
592 maxRetries: 3
593 });
594 FASTLED_DEBUG_LOG('INDEX_JS', 'Web Worker mode initialized successfully');
595

Callers 1

fastledLoadSetupLoopFunction · 0.85

Calls 15

FASTLED_DEBUG_TRACEFunction · 0.90
FASTLED_DEBUG_LOGFunction · 0.90
FASTLED_DEBUG_ERRORFunction · 0.90
toggleFastLEDFunction · 0.85
initializeWorkerModeMethod · 0.80
stopWithWorkerSupportMethod · 0.80
getFPSMethod · 0.80
getAverageFrameTimeMethod · 0.80
recordFrameTimeMethod · 0.80
recordMemoryUsageMethod · 0.80
emitErrorMethod · 0.80

Tested by

no test coverage detected