stuff in index.html #18

Closed
_7m9 wants to merge 3 commits from _7m9:_7m9/dev/http into stable

View file

@ -5,6 +5,7 @@
<title>fiatlux v0.2</title>
<link rel="stylesheet" href="css/picnic.min.css">
<link rel="stylesheet" href="css/style.css">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<nav>
@ -34,6 +35,9 @@
<span><input id="transmit_firmware" disabled type="submit" value="Upload"
onclick="transmit_firmware(event)"></span>
</div>
<div class="row" id="progress_ct_ota">
<div id="progress_bar_ota" style="display: block; width:9%; background-color: #00b; padding: unset"></div>
</div>
</div>
</article>
<article class="card">
@ -237,7 +241,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);
@ -264,6 +268,11 @@
console.error(evt);
setMsg("error", "WebSocket error!"); /*window.location.reload(true);*/
};
ws.onclose = function (evt) {
msgStyle = "warning";
if(!evt.wasClean) msgStyle = "error";
setMsg(msgStyle, "WebSocket closed!")
};
ws.onmessage = function (evt) {
onMessage(evt);
};
@ -371,10 +380,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 +395,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 + "%";
}
</script>
</body>
</html>