working begin routine
This commit is contained in:
parent
05236797c2
commit
fdf32d8503
8 changed files with 510 additions and 415 deletions
|
@ -4,7 +4,7 @@
|
|||
<h3>LCD Display Management</h3>
|
||||
<hr>
|
||||
<h3>Upload TFT Firmware</h3>
|
||||
<input type="file" name="update" id="file" onchange="sub(this)" style="display: none" />
|
||||
<input type="file" name="update" id="file" onchange="sub(this)" style="display: none" , accept=".tft" />
|
||||
<label id="file-input" for="file">Choose file...</label>
|
||||
<input type="button" class="btn" value="Upload" onclick="uploadFirmware()" /><br /><br />
|
||||
<div id="prg"></div>
|
||||
|
@ -26,30 +26,47 @@
|
|||
var file = document.getElementById('file').files[0];
|
||||
var reader = new FileReader();
|
||||
var path = window.location.pathname;
|
||||
// Path have index.html at the end and / at the beginning, remove it
|
||||
path = path.substring(0, path.length - 10);
|
||||
reader.onload = function (e) {
|
||||
var data = new Uint8Array(e.target.result);
|
||||
var size = data.length;
|
||||
var chunkSize = 4096;
|
||||
var index = 0;
|
||||
|
||||
// Begin the update
|
||||
$.post(path + '/ota/begin', JSON.stringify({ size: size }), function () {
|
||||
// Send the data in chunks
|
||||
function sendNextChunk() {
|
||||
if (index < size) {
|
||||
var chunk = data.subarray(index, index + chunkSize);
|
||||
var chunkArray = Array.from(chunk);
|
||||
$.post(path + '/ota/write', JSON.stringify({ size: chunk.length, data: chunkArray }), function () {
|
||||
index += chunkSize;
|
||||
sendNextChunk();
|
||||
});
|
||||
} else {
|
||||
// End the update
|
||||
$.post(path + '/ota/end');
|
||||
$.ajax({
|
||||
url: path + 'ota/begin',
|
||||
type: 'POST',
|
||||
data: JSON.stringify({ size: size }),
|
||||
contentType: 'application/json',
|
||||
success: function () {
|
||||
// Send the data in chunks
|
||||
function sendNextChunk() {
|
||||
if (index < size) {
|
||||
var chunk = data.subarray(index, index + chunkSize);
|
||||
var chunkArray = Array.from(chunk);
|
||||
$.ajax({
|
||||
url: path + 'ota/write',
|
||||
type: 'POST',
|
||||
data: JSON.stringify({ size: chunk.length, data: chunkArray }),
|
||||
contentType: 'application/json',
|
||||
success: function () {
|
||||
index += chunkSize;
|
||||
sendNextChunk();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// End the update
|
||||
$.ajax({
|
||||
url: path + 'ota/end',
|
||||
type: 'POST',
|
||||
contentType: 'application/json'
|
||||
});
|
||||
}
|
||||
}
|
||||
sendNextChunk();
|
||||
}
|
||||
sendNextChunk();
|
||||
});
|
||||
})
|
||||
};
|
||||
reader.readAsArrayBuffer(file);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue