show flashing progress bar

This commit is contained in:
liamcottle
2024-07-14 19:54:34 +12:00
parent b7d1146960
commit a56842685d
2 changed files with 16 additions and 21 deletions

View File

@@ -41,10 +41,10 @@
</div> </div>
<div v-else> <div v-else>
<span v-if="progress > 0">Flashing: {{progress}}%</span> <span v-if="flashingProgress > 0">Flashing: {{flashingProgress}}%</span>
<span v-else>Flashing: please wait...</span> <span v-else>Flashing: please wait...</span>
<div class="mt-1 w-[200px] overflow-hidden rounded-full bg-gray-200"> <div class="mt-1 w-[200px] overflow-hidden rounded-full bg-gray-200">
<div class="h-2 rounded-full bg-blue-600" :style="{ 'width': `${progress}%`}"></div> <div class="h-2 rounded-full bg-blue-600" :style="{ 'width': `${flashingProgress}%`}"></div>
</div> </div>
</div> </div>
@@ -64,7 +64,7 @@
data() { data() {
return { return {
isFlashing: false, isFlashing: false,
progress: 0, flashingProgress: 0,
}; };
}, },
mounted() { mounted() {
@@ -114,22 +114,24 @@
// update progress // update progress
this.isFlashing = true; this.isFlashing = true;
this.progress = 0; this.flashingProgress = 0;
// flash file
try { try {
// flash file
const flasher = new Nrf52DfuFlasher(serialPort); const flasher = new Nrf52DfuFlasher(serialPort);
await flasher.flash(file, (percentage) => { await flasher.flash(file, (percentage, message) => {
this.progress = percentage; this.flashingProgress = percentage;
if(this.progress === 100){
this.isFlashing = false;
alert("Firmware has been flashed!");
}
}); });
// flashing successful
alert("Firmware has been flashed!");
} catch(e) { } catch(e) {
this.isFlashing = false;
alert("Firmware flashing failed: " + e); alert("Firmware flashing failed: " + e);
console.log(e); console.log(e);
} finally {
this.isFlashing = false;
} }
}, },

View File

@@ -175,18 +175,16 @@ class Nrf52DfuFlasher {
console.log("Sending DFU init packet"); console.log("Sending DFU init packet");
await this.sendInitPacket(init_packet); await this.sendInitPacket(init_packet);
console.log("Sending firmware file") console.log("Sending firmware");
await this.sendFirmware(firmware, progressCallback); await this.sendFirmware(firmware, progressCallback);
// close port // close port
console.log("Closing Port"); console.log("Closing serial port");
await this.serialPort.close(); await this.serialPort.close();
// todo // todo
// sleep(self.dfu_transport.get_activate_wait_time()) // sleep(self.dfu_transport.get_activate_wait_time())
console.log("Done");
} }
/** /**
@@ -399,11 +397,6 @@ class Nrf52DfuFlasher {
...this.int32ToBytes(this.DFU_STOP_DATA_PACKET), ...this.int32ToBytes(this.DFU_STOP_DATA_PACKET),
])); ]));
// send final progress
if(progressCallback){
progressCallback(100);
}
} }
/** /**