Added Progress bar and Fixed OTA update
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
c0228cdf49
commit
8f052ecb37
3 changed files with 29 additions and 6 deletions
|
@ -1,4 +1,5 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module classpath="External" external.linked.project.id="firmware" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="CompDB" type="CPP_MODULE" version="4" />
|
||||||
<module version="4">
|
<module version="4">
|
||||||
<component name="FacetManager">
|
<component name="FacetManager">
|
||||||
<facet type="Python" name="Python facet">
|
<facet type="Python" name="Python facet">
|
||||||
|
|
|
@ -33,7 +33,7 @@ main section:target {
|
||||||
|
|
||||||
.table > .row > * {
|
.table > .row > * {
|
||||||
display: table-cell;
|
display: table-cell;
|
||||||
padding: .3em 2.4em .3em .6em;
|
padding: .3em .6em .3em .6em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.table > header.row > * {
|
.table > header.row > * {
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
<title>fiatlux v0.2</title>
|
<title>fiatlux v0.2</title>
|
||||||
<link rel="stylesheet" href="css/picnic.min.css">
|
<link rel="stylesheet" href="css/picnic.min.css">
|
||||||
<link rel="stylesheet" href="css/style.css">
|
<link rel="stylesheet" href="css/style.css">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<nav>
|
<nav>
|
||||||
|
@ -30,6 +31,12 @@
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<span><input id="firmware_file" type="file" onchange="load_firmware(event)"/></span>
|
<span><input id="firmware_file" type="file" onchange="load_firmware(event)"/></span>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="full" id="progress_ct_ota">
|
||||||
|
<div id="progress_bar_ota"
|
||||||
|
style="background:#0074d9; display: block; width:9%; color: #fff"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<span><input id="transmit_firmware" disabled type="submit" value="Upload"
|
<span><input id="transmit_firmware" disabled type="submit" value="Upload"
|
||||||
onclick="transmit_firmware(event)"></span>
|
onclick="transmit_firmware(event)"></span>
|
||||||
|
@ -237,7 +244,7 @@
|
||||||
|
|
||||||
if (cmd === 'G')
|
if (cmd === 'G')
|
||||||
console.log("LED switched", val);
|
console.log("LED switched", val);
|
||||||
else if (cmd === 'F') {
|
else if ((cmd === 'F') || (cmd === "C")) {
|
||||||
receive_chunk_confirmation(dv);
|
receive_chunk_confirmation(dv);
|
||||||
} else if (cmd === 'V') {
|
} else if (cmd === 'V') {
|
||||||
voltage.innerHTML = (val * 13 / 1024).toFixed(2);
|
voltage.innerHTML = (val * 13 / 1024).toFixed(2);
|
||||||
|
@ -248,7 +255,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function wsOpen() {
|
function wsOpen() {
|
||||||
var uri = "/stream"
|
var uri = "/stream";
|
||||||
if (ws === undefined || ws.readyState !== 0) {
|
if (ws === undefined || ws.readyState !== 0) {
|
||||||
if (retries)
|
if (retries)
|
||||||
setMsg("warning", "WebSocket timeout, retrying..");
|
setMsg("warning", "WebSocket timeout, retrying..");
|
||||||
|
@ -264,6 +271,12 @@
|
||||||
console.error(evt);
|
console.error(evt);
|
||||||
setMsg("error", "WebSocket error!"); /*window.location.reload(true);*/
|
setMsg("error", "WebSocket error!"); /*window.location.reload(true);*/
|
||||||
};
|
};
|
||||||
|
ws.onclose = function (evt) {
|
||||||
|
msgStyle = "warning";
|
||||||
|
if (!evt.wasClean) msgStyle = "error";
|
||||||
|
setMsg(msgStyle, "WebSocket closed!");
|
||||||
|
setTimeout(() => wsOpen(), 0);
|
||||||
|
};
|
||||||
ws.onmessage = function (evt) {
|
ws.onmessage = function (evt) {
|
||||||
onMessage(evt);
|
onMessage(evt);
|
||||||
};
|
};
|
||||||
|
@ -371,10 +384,10 @@
|
||||||
headerview.setInt32(4, buf.byteLength);
|
headerview.setInt32(4, buf.byteLength);
|
||||||
headerview.setInt32(8, hash);
|
headerview.setInt32(8, hash);
|
||||||
receive_chunk_confirmation = (dv) => {
|
receive_chunk_confirmation = (dv) => {
|
||||||
resolve(i);
|
resolve(true);
|
||||||
}
|
}
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
reject(i);
|
reject(false);
|
||||||
}, 500);
|
}, 500);
|
||||||
wsWrite(frame);
|
wsWrite(frame);
|
||||||
});
|
});
|
||||||
|
@ -386,14 +399,23 @@
|
||||||
(async () => {
|
(async () => {
|
||||||
const ash = crc32(firmware_file);
|
const ash = crc32(firmware_file);
|
||||||
for (var i = 0; i * chunk_size < firmware_file.byteLength; i++) {
|
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_chunk(firmware_file, i);
|
||||||
}
|
}
|
||||||
await transmit_firmware_final(firmware_file, crc32(firmware_file));
|
await transmit_firmware_final(firmware_file, crc32(firmware_file));
|
||||||
|
update_progress("ota", 100);
|
||||||
})().then(() => {
|
})().then(() => {
|
||||||
console.log("transmit_firmware done");
|
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>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
Loading…
Reference in a new issue