* 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)
| 536 | * @returns {Promise<void>} Promise that resolves when setup is complete and loop is started |
| 537 | */ |
| 538 | async 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 |
no test coverage detected