Browse Source

Skip erasing step if not needed and improve progress percentage

pull/110/head
Malte Grimm 3 years ago
parent
commit
81b42542b7
  1. 2
      src/components/Dashboard.tsx
  2. 14
      src/core/flashing/Flasher.ts

2
src/components/Dashboard.tsx

@ -160,7 +160,7 @@ const DeviceList = ({devices, rootConfig, totalConfigCount}: {devices: Device[],
className="gap-2 w-full" className="gap-2 w-full"
disabled={totalConfigCount == 0 || overallFlashingState.state == "busy"} disabled={totalConfigCount == 0 || overallFlashingState.state == "busy"}
onClick={async () => { onClick={async () => {
rootConfig.children[0].getFinalConfig(); // FIXME // rootConfig.children[0].getFinalConfig(); // FIXME
if(overallFlashingState.state == "idle") if(overallFlashingState.state == "idle")
setOverallFlashingState({ state: "busy" }); setOverallFlashingState({ state: "busy" });
let actualFirmware = firmware; let actualFirmware = firmware;

14
src/core/flashing/Flasher.ts

@ -221,14 +221,20 @@ export class FlashOperation {
this.setState("connecting"); this.setState("connecting");
await loader.connect(); await loader.connect();
await loader.loadStub(); await loader.loadStub();
if(sections.length > 1) {
this.setState("erasing"); this.setState("erasing");
await new Promise(resolve => setTimeout(resolve, 2000));
await loader.eraseFlash(); await loader.eraseFlash();
const lul = this; }
for (let i = 0; i < 3; i++) { const thisOp = this;
const totalLength = sections.reduce<number>((p, c) => p + c.data.byteLength, 0);
let bytesFlashed = 0;
for (let i = 0; i < sections.length; i++) {
await loader.flashData(sections[i].data, sections[i].offset, function (idx, cnt) { await loader.flashData(sections[i].data, sections[i].offset, function (idx, cnt) {
lul.setState("flashing", (1/3) * (i + idx/cnt)); const segSize = sections[i].data.length / cnt;
thisOp.setState("flashing", (bytesFlashed + idx * segSize) / totalLength);
console.log(`Flashing progress: ${bytesFlashed} + ${(idx * segSize).toFixed(2)}/${sections[i].data.length} = ${(bytesFlashed + idx * segSize).toFixed(2)} / ${totalLength}`);
}); });
bytesFlashed += sections[i].data.byteLength;
} }
} }
catch (e) { catch (e) {

Loading…
Cancel
Save