From adebeaf6ccaafd0edfc9e666b3b00a3be4ad5b3c Mon Sep 17 00:00:00 2001 From: Marcus Date: Wed, 8 Sep 2021 01:23:03 +0200 Subject: [PATCH] Added Progress bar and Fixed OTA update --- firmware/fsdata/fs/index.html | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/firmware/fsdata/fs/index.html b/firmware/fsdata/fs/index.html index 8ceefa7..09777c7 100644 --- a/firmware/fsdata/fs/index.html +++ b/firmware/fsdata/fs/index.html @@ -34,6 +34,9 @@ +
+
+
@@ -237,7 +240,7 @@ if (cmd === 'G') console.log("LED switched", val); - else if (cmd === 'F') { + else if ((cmd === 'F') || (cmd === "C")) { receive_chunk_confirmation(dv); } else if (cmd === 'V') { voltage.innerHTML = (val * 13 / 1024).toFixed(2); @@ -371,10 +374,10 @@ headerview.setInt32(4, buf.byteLength); headerview.setInt32(8, hash); receive_chunk_confirmation = (dv) => { - resolve(i); + resolve(true); } setTimeout(() => { - reject(i); + reject(false); }, 500); wsWrite(frame); }); @@ -386,14 +389,23 @@ (async () => { const ash = crc32(firmware_file); for (var i = 0; i * chunk_size < firmware_file.byteLength; i++) { + update_progress("ota", i*chunk_size/firmware_file.byteLength*100); await transmit_firmware_chunk(firmware_file, i); } await transmit_firmware_final(firmware_file, crc32(firmware_file)); + update_progress("ota", 100); })().then(() => { console.log("transmit_firmware done"); }) } } + + function update_progress(progressBar, progress) { + var iP = Math.floor(progress); + var dBar = document.getElementById("progress_bar_" + progressBar); + dBar.innerText = iP + "%"; + dBar.style.width = progress + "%"; + }