Cleaned up html

This commit is contained in:
regymm 2024-01-27 16:56:40 +09:00
parent 1298023463
commit 853e20cc57

View file

@ -4,18 +4,18 @@
<title>wasmFPGAloader -- FPGAOL-CE</title> <title>wasmFPGAloader -- FPGAOL-CE</title>
</head> </head>
<body> <body>
<button id="connectBtn">Connect</button> <button id="connectBtn">Connect USB Device</button>
<button id="testBtn">openFPGAloader --detect</button> <button id="testBtn">openFPGAloader --detect</button>
<p id="status0"></p> <p id="status0"></p>
<input type="file" id="upload" onchange="uploadFile()"> <input type="file" id="upload" onchange="uploadFile()"><br>
<button id="testBtn2">Blast</button> <button id="testBtn2">Blast</button>
<script> <script>
const connectBtn = document.getElementById('connectBtn'); const connectBtn = document.getElementById('connectBtn');
connectBtn.addEventListener('click', connect_a_device); connectBtn.addEventListener('click', connect_a_device);
async function connect_a_device() { async function connect_a_device() {
console.log('connect_a_device') console.log('connect_a_device')
await navigator.usb.requestDevice({ filters: [] }); await navigator.usb.requestDevice({ filters: [] });
} }
const testBtn = document.getElementById('testBtn'); const testBtn = document.getElementById('testBtn');
testBtn.addEventListener('click', ofl_detect); testBtn.addEventListener('click', ofl_detect);
async function ofl_detect() { async function ofl_detect() {
@ -32,7 +32,6 @@
async function test_usb_2() { async function test_usb_2() {
console.log('test_usb_2') console.log('test_usb_2')
await Module.callMain(["-b", "tangnano9k", "" + document.getElementById('upload').files[0].name]); await Module.callMain(["-b", "tangnano9k", "" + document.getElementById('upload').files[0].name]);
//await Module.ccall('myMain', null, null, null);
} }
var Module = { var Module = {
onRuntimeInitialized: function() { onRuntimeInitialized: function() {
@ -46,26 +45,27 @@
} }
}; };
function uploadFile() { function uploadFile() {
var fileInput = document.getElementById('upload');
var file = fileInput.files[0];
var reader = new FileReader();
reader.onload = function() { var fileInput = document.getElementById('upload');
// Create a Uint8Array from file content var file = fileInput.files[0];
var data = new Uint8Array(reader.result); var reader = new FileReader();
// Use Emscripten's FS API to write the file to the virtual filesystem reader.onload = function() {
FS.writeFile('' + file.name, data); // Create a Uint8Array from file content
var data = new Uint8Array(reader.result);
console.log('File writen to WASM file system: ' + file.name); // Use Emscripten's FS API to write the file to the virtual filesystem
FS.writeFile('' + file.name, data);
// Optionally, call a function defined in your WebAssembly module that needs access to the file console.log('File writen to WASM file system: ' + file.name);
// For example, if your module has a function that takes the file path as argument
// Module.ccall('yourFunctionName', 'returnType', ['param1Type'], ['/working/' + file.name]);
};
reader.readAsArrayBuffer(file); // Optionally, call a function defined in your WebAssembly module that needs access to the file
// For example, if your module has a function that takes the file path as argument
// Module.ccall('yourFunctionName', 'returnType', ['param1Type'], ['/working/' + file.name]);
};
reader.readAsArrayBuffer(file);
} }
</script> </script>
<script src="./wasmFPGALoader.js"></script> <script src="./wasmFPGALoader.js"></script>