web: move fake upload button mapping to upload.js

This commit is contained in:
Fischer Moseley 2024-04-16 22:50:40 -07:00
parent 5381261f0f
commit d485971a1c
3 changed files with 30 additions and 27 deletions

View File

@ -1,24 +1,42 @@
let data;
let fileUploaded = false;
// Map the fake upload button to the real (hidden) upload button
document.addEventListener("DOMContentLoaded", function() {
const uploadButton = document.getElementById("uploadButton");
const fileInput = document.getElementById("fileInput");
const filePathDisplay = document.getElementById("filePath");
uploadButton.addEventListener("click", function() {
fileInput.click();
});
fileInput.addEventListener("change", function() {
const filePath = fileInput.value; // Get the file path from the file input
filePathDisplay.textContent = "Loaded " + filePath; // Display the file path
});
});
// Update fileUploaded flag when a file gets uploaded
document.getElementById('fileInput').addEventListener('change', function(event) {
const file = event.target.files[0];
const reader = new FileReader();
reader.onload = function(e) {
data = e.target.result;
fileUploaded = true; // Set the flag to indicate file upload completion
fileUploaded = true;
};
reader.readAsText(file);
});
// Continuously poll to see if the file has been uploaded
function runAfterUpload() {
if (!fileUploaded) {
setTimeout(runAfterUpload, 100); // Check again after 100ms
return;
}
// Your additional JavaScript code to run after file upload
WebTerminal(data);
// Additional JavaScript code to run after file upload
// WebTerminal(data);
}
runAfterUpload(); // Start checking for file upload completion
runAfterUpload();

View File

@ -1,4 +1,5 @@
document.getElementById('connectButton').addEventListener('click', selectPort);
document.getElementById('runButton').addEventListener('click', webTerminal);
async function selectPort(){
await navigator.serial.requestPort();
@ -19,11 +20,11 @@ serialWorker.onmessage = (e) => {
};
// Main function for the Web Terminal
async function WebTerminal(data){
async function webTerminal(){
let pyodide = await loadPyodide();
// Load Manta.yaml into pyodide's file system
pyodide.FS.writeFile("/manta.yaml", data, { encoding: "utf8" });
// pyodide.FS.writeFile("/manta.yaml", data, { encoding: "utf8" });
// Load micropip, setuptools, manta
await pyodide.loadPackage("micropip");

View File

@ -1,5 +1,3 @@
## Open Serial Port
<button class="md-button" id="connectButton">Connect</button>
@ -8,29 +6,15 @@
<input type="file" id="fileInput" accept=".yaml,.yml" style="display: none">
<div id="filePath"></div>
## Run Main Thread
<button class="md-button" id="runButton">Run!</button>
<!-- Load Javascript -->
<script src="../javascripts/webTerminal.js"></script>
<script src="../javascripts/serial.js"></script>
<script src="../javascripts/upload.js"></script>
<!-- <script src="../javascripts/upload.js"></script> -->
<script src="https://cdn.jsdelivr.net/pyodide/v0.25.1/full/pyodide.js"></script>
<script>
document.addEventListener("DOMContentLoaded", function() {
const uploadButton = document.getElementById("uploadButton");
const fileInput = document.getElementById("fileInput");
const filePathDisplay = document.getElementById("filePath");
uploadButton.addEventListener("click", function() {
fileInput.click();
});
fileInput.addEventListener("change", function() {
const filePath = fileInput.value; // Get the file path from the file input
filePathDisplay.textContent = "Loaded " + filePath; // Display the file path
});
});
</script>
<!-- <iframe src="https://app.surfer-project.org/?load_url=https://app.surfer-project.org/picorv32.vcd&amp;startup_commands=show_quick_start;module_add%20testbench.top;toggle_menu" ,="" style="width: 100%; height: 100%"></iframe> -->
<!-- <iframe src="https://app.surfer-project.org/?load_url=https://app.surfer-project.org/picorv32.vcd&amp;startup_commands=show_quick_start;module_add%20testbench.top;toggle_menu" ,="" style="width: 100%; height: 500px"></iframe> -->