* Main function to initialize and start the FastLED setup/loop cycle (Asyncify-enabled) * @async * @param {number} frame_rate - Target frame rate for animations * @param {Object} moduleInstance - The loaded WASM module instance * @param {Array } filesJson - Array of files to load into the
( frame_rate, moduleInstance, filesJson, )
| 731 | * @param {Array<Object>} filesJson - Array of files to load into the virtual filesystem |
| 732 | */ |
| 733 | async function fastledLoadSetupLoop( |
| 734 | frame_rate, |
| 735 | moduleInstance, |
| 736 | filesJson, |
| 737 | ) { |
| 738 | console.log('Calling setup function...'); |
| 739 | |
| 740 | const fileManifest = getFileManifestJson(filesJson, frame_rate); |
| 741 | moduleInstance.cwrap('fastled_declare_files', null, ['string'])(JSON.stringify(fileManifest)); |
| 742 | console.log('Files JSON:', filesJson); |
| 743 | |
| 744 | /** |
| 745 | * Processes a single file by streaming it to the WASM module |
| 746 | * @async |
| 747 | * @param {Object} file - File object with path and data |
| 748 | * @param {string} file.path - File path in the virtual filesystem |
| 749 | * @param {number} file.size - File size in bytes |
| 750 | */ |
| 751 | const processFile = async (file) => { |
| 752 | try { |
| 753 | const response = await fetch(file.path); |
| 754 | const reader = response.body.getReader(); |
| 755 | |
| 756 | console.log(`File fetched: ${file.path}, size: ${file.size}`); |
| 757 | |
| 758 | while (true) { |
| 759 | // deno-lint-ignore no-await-in-loop |
| 760 | const { value, done } = await reader.read(); |
| 761 | if (done) break; |
| 762 | // Allocate and copy chunk data |
| 763 | jsAppendFileUint8(moduleInstance, file.path, value); |
| 764 | } |
| 765 | } catch (error) { |
| 766 | console.error(`Error processing file ${file.path}:`, error); |
| 767 | } |
| 768 | }; |
| 769 | |
| 770 | /** |
| 771 | * Fetches all files in parallel and calls completion callback |
| 772 | * @async |
| 773 | * @param {Array<Object>} filesJson - Array of file objects to fetch |
| 774 | * @param {Function} [onComplete] - Optional callback when all files are loaded |
| 775 | */ |
| 776 | const fetchAllFiles = async (filesJson, onComplete) => { |
| 777 | const promises = filesJson.map(async (file) => { |
| 778 | await processFile(file); |
| 779 | }); |
| 780 | await Promise.all(promises); |
| 781 | if (onComplete) { |
| 782 | onComplete(); |
| 783 | } |
| 784 | }; |
| 785 | |
| 786 | // NOTE: Callback functions are now automatically registered by importing fastled_callbacks.js |
| 787 | // No need to manually bind them here - they're pure JavaScript functions |
| 788 | |
| 789 | // Verify that the pure JavaScript callbacks are properly loaded |
| 790 | console.log('FastLED Pure JavaScript callbacks verified:', { |
no test coverage detected