* Callback function executed when the WASM module is loaded * Sets up the module loading infrastructure * @param {Function} fastLedLoader - The FastLED loader function
(fastLedLoader)
| 836 | * @param {Function} fastLedLoader - The FastLED loader function |
| 837 | */ |
| 838 | function onModuleLoaded(fastLedLoader) { |
| 839 | // Unpack the module functions and send them to the fastledLoadSetupLoop function |
| 840 | |
| 841 | /** |
| 842 | * Internal function to start FastLED with loaded module (Asyncify-enabled) |
| 843 | * @async |
| 844 | * @param {Object} moduleInstance - The loaded WASM module instance |
| 845 | * @param {number} frameRate - Target frame rate for animations |
| 846 | * @param {Array<Object>} filesJson - Files to load into virtual filesystem |
| 847 | */ |
| 848 | async function __fastledLoadSetupLoop(moduleInstance, frameRate, filesJson) { |
| 849 | const exports_exist = moduleInstance && moduleInstance._extern_setup |
| 850 | && moduleInstance._extern_loop; |
| 851 | if (!exports_exist) { |
| 852 | console.error('FastLED setup or loop functions are not available.'); |
| 853 | return; |
| 854 | } |
| 855 | |
| 856 | await fastledLoadSetupLoop( |
| 857 | frameRate, |
| 858 | moduleInstance, |
| 859 | filesJson, |
| 860 | ); |
| 861 | } |
| 862 | // Start fetch now in parallel |
| 863 | |
| 864 | /** |
| 865 | * Fetches and parses JSON from a given file path |
| 866 | * @async |
| 867 | * @param {string} fetchFilePath - Path to the JSON file to fetch |
| 868 | * @returns {Promise<Object>} Parsed JSON data |
| 869 | */ |
| 870 | const fetchJson = async (fetchFilePath) => { |
| 871 | const response = await fetch(fetchFilePath); |
| 872 | const data = await response.json(); |
| 873 | return data; |
| 874 | }; |
| 875 | const filesJsonPromise = fetchJson('files.json'); |
| 876 | try { |
| 877 | if (typeof fastLedLoader === 'function') { |
| 878 | // Load the module |
| 879 | fastLedLoader().then(async (instance) => { |
| 880 | console.log('Module loaded, running FastLED...'); |
| 881 | |
| 882 | // Expose the updateUiComponents method to the C++ module |
| 883 | // This should be called BY C++ TO UPDATE the frontend, not the other way around |
| 884 | instance._jsUiManager_updateUiComponents = function (jsonString) { |
| 885 | console.log('*** C++ CALLING JS: updateUiComponents with:', jsonString); |
| 886 | if (window.uiManagerInstance && window.uiManagerInstance.updateUiComponents) { |
| 887 | window.uiManagerInstance.updateUiComponents(jsonString); |
| 888 | } else { |
| 889 | console.error('*** UI BINDING ERROR: uiManagerInstance not available ***'); |
| 890 | } |
| 891 | }; |
| 892 | |
| 893 | // Wait for the files.json to load. |
| 894 | let filesJson = null; |
| 895 | try { |
no test coverage detected