feat: wait ready

This commit is contained in:
2026-01-30 17:38:46 +01:00
parent afa0d9ffd7
commit f618ffbada
2 changed files with 13 additions and 10 deletions

View File

@@ -538,6 +538,7 @@ export class CharaDevice {
async updateFirmware(
file: ArrayBuffer,
progress: (transferred: number, total: number) => void,
throttle = false,
): Promise<void> {
while (this.lock) {
await this.lock;
@@ -584,16 +585,14 @@ export class CharaDevice {
});
const chunkSize = 1024;
const promises = [];
for (let i = 0; i < file.byteLength; i += chunkSize) {
const chunk = file.slice(i, i + chunkSize);
promises.push(
writer
.write(new Uint8Array(chunk))
.then(() => progress(i + chunk.byteLength, file.byteLength)),
);
if (throttle) {
await writer.ready;
}
await writer.write(new Uint8Array(chunk));
progress(i + chunk.byteLength, file.byteLength);
}
await Promise.all(promises);
serialLog.update((it) => {
it.push({

View File

@@ -56,9 +56,13 @@
retries = 2;
while (retries-- > 0 && !success) {
try {
await port.updateFirmware(file, (transferred, total) => {
progress = transferred / total;
});
await port.updateFirmware(
file,
(transferred, total) => {
progress = transferred / total;
},
retries === 0,
);
success = true;
} catch (e) {