diff --git a/rust/src/webserver/config.html b/rust/src/webserver/config.html index 1df2846..7521a13 100644 --- a/rust/src/webserver/config.html +++ b/rust/src/webserver/config.html @@ -20,9 +20,10 @@

Battery Firmeware (bq34z100 may be R2)


- +
-

+

+

diff --git a/rust/src_webpack/src/battery.ts b/rust/src_webpack/src/battery.ts index 9c3847f..1aa51f7 100644 --- a/rust/src_webpack/src/battery.ts +++ b/rust/src_webpack/src/battery.ts @@ -2,58 +2,37 @@ let battery_flash_button = document.getElementById("battery_flash_button") as HT let battery_flash_file = document.getElementById("battery_flash_file") as HTMLInputElement; let battery_flash_message = document.getElementById("battery_flash_message") as HTMLElement; let battery_flash_progressBar = document.getElementById("battery_flash_progressBar") as HTMLProgressElement; +let battery_flash_loaded_n_total = document.getElementById("battery_flash_loaded_n_total") as HTMLElement; +let battery_flash_status = document.getElementById("battery_flash_status") as HTMLElement; + var ajax = new XMLHttpRequest(); ajax.upload.addEventListener("progress", event => { - loaded_n_total.innerHTML = "Uploaded " + event.loaded + " bytes of " + event.total; + battery_flash_loaded_n_total.innerHTML = "Uploaded " + event.loaded + " bytes of " + event.total; var percent = (event.loaded / event.total) * 100; - progressBar.value = Math.round(percent); - status.innerHTML = Math.round(percent) + "%"; - answer.innerHTML = "in progress"; + battery_flash_progressBar.value = Math.round(percent); + battery_flash_status.innerHTML = Math.round(percent) + "%"; + battery_flash_message.innerHTML = "in progress"; }, false); ajax.addEventListener("load", () => { - status.innerHTML = ajax.responseText; - answer.innerHTML = "finished"; - progressBar.value = 0; + battery_flash_status.innerHTML = ajax.responseText; + battery_flash_message.innerHTML = "finished"; + battery_flash_progressBar.value = 0; }, false); ajax.addEventListener("error", () => { - status.innerHTML = ajax.responseText; - answer.innerHTML = "failed"; + battery_flash_status.innerHTML = ajax.responseText; + battery_flash_message.innerHTML = "failed"; }, false); ajax.addEventListener("abort", () => { - status.innerHTML = ajax.responseText; - answer.innerHTML = "aborted"; + battery_flash_status.innerHTML = ajax.responseText; + battery_flash_message.innerHTML = "aborted"; }, false); -ajax.open("POST", "/ota"); -ajax.send(file); -} -export async function streamToText(stream: ReadableStream): Promise { - let result = ''; - const reader = stream.pipeThrough(new TextDecoderStream()).getReader(); - while (true) { - const { done, value } = await reader.read(); - if (done) { - break; - } - result += value; - battery_flash_message.innerHTML = result; - battery_flash_message.scrollTop = battery_flash_message.scrollHeight; - } - return result; -} + battery_flash_button.onclick = async function (){ - fetch("/flashbattery", { - method :"POST", - body: battery_flash_file.files[0], - headers: { - "Content-Type": "" - }, - }).then((response) => response.body) - .then((body) => { - streamToText(body) - }); + ajax.open("POST", "/flashbattery"); + ajax.send(battery_flash_file.files[0]); }; diff --git a/rust/src_webpack/src/form.ts b/rust/src_webpack/src/form.ts index 5aa72dd..9f4c278 100644 --- a/rust/src_webpack/src/form.ts +++ b/rust/src_webpack/src/form.ts @@ -327,7 +327,8 @@ let fromWrapper = (() => { updateJson() fetch("/set_config", { method :"POST", - body: json.value + body: json.value, + }) .then(response => response.text()) .then(text => submit_status.innerText = text)