Skip to content

Commit 5213e12

Browse files
authored
configure timeout / warning when webusb connection is stalled (#5918)
1 parent 3db5fa2 commit 5213e12

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

editor/flash.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const dataAddr = 0x20002000;
66
const stackAddr = 0x20001000;
77
const FULL_FLASH_TIMEOUT = 100000; // 100s
88
const PARTIAL_FLASH_TIMEOUT = 60000; // 60s
9+
const CONNECTION_CHECK_TIMEOUT = 2000; // 2s
910
const RETRY_DAP_CMD_TIMEOUT = 50; // .05s
1011

1112
const flashPageBIN = new Uint32Array([
@@ -351,12 +352,20 @@ class DAPWrapper implements pxt.packetio.PacketIOWrapper {
351352
}
352353

353354
private async clearCommandsAsync() {
354-
// before calling into dapjs, push through a few commands to make sure the responses
355-
// to commands from previous sessions (if any) are flushed. Count of 5 is arbitrary.
356-
for (let i = 0; i < 5; i++) {
357-
try {
358-
await this.getDaplinkVersionAsync();
359-
} catch (e) { }
355+
try {
356+
await pxt.Util.promiseTimeout(CONNECTION_CHECK_TIMEOUT, (async () => {
357+
// before calling into dapjs, push through a few commands to make sure the responses
358+
// to commands from previous sessions (if any) are flushed. Count of 5 is arbitrary.
359+
for (let i = 0; i < 5; i++) {
360+
try {
361+
await this.getDaplinkVersionAsync();
362+
} catch (e) { }
363+
}
364+
})());
365+
} catch (e) {
366+
const errOut = new Error(e);
367+
(errOut as any).type = "inittimeout";
368+
throw errOut;
360369
}
361370
}
362371

pxtarget.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,7 @@
590590

591591
"dragFileImage": "/static/download/transfer.png",
592592
"connectDeviceImage": "/static/download/connect-microbit.gif",
593+
"disconnectDeviceImage": "/static/download/device-forgotten.gif",
593594
"selectDeviceImage": "/static/download/selecting-microbit.gif",
594595
"connectionSuccessImage": "/static/download/successfully-paired.png",
595596
"incompatibleHardwareImage": "/static/download/incompatible.png",

0 commit comments

Comments
 (0)