From 56368a9a798b57193d14a94e1a1e708acdc49534 Mon Sep 17 00:00:00 2001 From: Jake Date: Tue, 30 Sep 2025 00:12:50 +0800 Subject: [PATCH] can play animation files from control panel, animation now via keyframe, not individual frames --- index.html | 2 ++ script.js | 42 +++++++++++++++++++++++++++++++++++++++++- serial.js | 7 +++++++ todo.md | 1 - 4 files changed, 50 insertions(+), 2 deletions(-) diff --git a/index.html b/index.html index c9d463f..3ec7623 100644 --- a/index.html +++ b/index.html @@ -49,11 +49,13 @@ +
Animations
+
diff --git a/script.js b/script.js index a3f374d..9b60669 100644 --- a/script.js +++ b/script.js @@ -7,6 +7,7 @@ window.onload = () => { const disconnectBtn = document.getElementById('disconnect'); const connectBtn = document.getElementById('connect'); const syncCheckbox = document.getElementById("syncCheckbox"); + const clearBtn = document.getElementById("clearAnimation"); // Limits rate of move commands sent while sliding timeslider let lastSyncTime = 0; // global or outer-scope variable @@ -15,7 +16,6 @@ window.onload = () => { let isInterpolating = false; let currentFrame = 0; let dialKeyframes = Array.from({ length: 5 }, () => ({})); - let currentAnimation = null; let selectedDial = null; let draggingKeyframe = null; // { dialIndex, originalFrame } @@ -35,6 +35,7 @@ window.onload = () => { // Animation File List const fileListElement = document.getElementById('fileList'); + const playButton = document.getElementById('playFile'); const loadButton = document.getElementById('loadFile'); const deleteButton = document.getElementById('deleteFile'); @@ -67,6 +68,30 @@ window.onload = () => { fileListElement.appendChild(li); } + playButton.addEventListener('click', () => { + if (!selectedFile) return; + + const filename = selectedFile; + console.log("Sanitized filename for delete:", filename); + + const filenameBytes = new TextEncoder().encode(filename); + const filenameLength = filenameBytes.length; + + // Total size: 2 bytes for length + filename bytes + const buffer = new ArrayBuffer(2 + filenameLength); + const view = new DataView(buffer); + let offset = 0; + + // 🔹 Filename block + view.setUint16(offset, filenameLength, true); offset += 2; + filenameBytes.forEach(byte => view.setUint8(offset++, byte)); + + const payload = new Uint8Array(buffer); + //serial.deleteFile(payload); // CMD_DELETE_FILE + + serial.requestPlayFile(payload); + }); + loadButton.addEventListener('click', () => { if (!selectedFile || loadButton.disabled) return; @@ -259,6 +284,7 @@ window.onload = () => { document.getElementById('log').value += `File deleted\n`; // 🔹 Do something with the file //handleLoadedFile(fileData); + serial.requestFileList(); break; case 0x05: // CMD_SAVE_FILE @@ -267,6 +293,7 @@ window.onload = () => { document.getElementById('log').value += `Saved file Response Recieved\n`; // 🔹 Do something with the file //handleLoadedFile(fileData); + serial.requestFileList(); break; case 0x06: // CMD_MESSAGE @@ -288,6 +315,11 @@ window.onload = () => { // 🔹 Do something with the file //handleLoadedFile(fileData); break; + + case 0x08: // CMD_PLAY_FILE + console.log(`Anim file played`); + console.log(new Uint8Array(payload)); + document.getElementById('log').value += `Anim file played\n`; // Add more cases as needed default: document.getElementById('log').value += `Unknown command ${command}\n`; @@ -386,6 +418,8 @@ window.onload = () => { deleteButton.disabled = false; document.getElementById("filenameInput").value = selectedFile.replace(/\.anim$/i, ""); + + drawTimelineMarkers(); } function sanitizeFilename(input) { @@ -512,6 +546,12 @@ window.onload = () => { }); + clearBtn.addEventListener('click', () => { + currentFrame = 0; + dialKeyframes = Array.from({ length: 5 }, () => ({})); + drawTimelineMarkers(); + }); + document.getElementById('send').onclick = async () => { const text = document.getElementById('input').value + '\n'; diff --git a/serial.js b/serial.js index f9974ca..2a9ac9f 100644 --- a/serial.js +++ b/serial.js @@ -10,6 +10,7 @@ const CMD_LOAD_FILE = 0x03; const CMD_SAVE_FILE = 0x05; const CMD_DELETE_FILE = 0x04; const CMD_SET_POSITION = 0x07; +const CMD_PLAY_FILE = 0x08; export class SerialManager { constructor() { @@ -58,6 +59,12 @@ export class SerialManager { await this.send(CMD_LOAD_FILE, payload); // CMD_LOAD_FILE } + async requestPlayFile(payload){ + console.log("Playing File: " + "filename"); + await this.send(CMD_PLAY_FILE, payload); + + } + async saveFile(payload) { console.log("Saving File: " + "filename"); await this.send(CMD_SAVE_FILE, payload); diff --git a/todo.md b/todo.md index 5cdd049..a2ee085 100644 --- a/todo.md +++ b/todo.md @@ -1,3 +1,2 @@ -Add play animation command play combined animations play combined animations with masks \ No newline at end of file