Skip to content

Commit

Permalink
configure timeout / warning when webusb connection is stalled (#5918)
Browse files Browse the repository at this point in the history
  • Loading branch information
jwunderl authored and abchatra committed Sep 6, 2024
1 parent 345c576 commit 09a90c4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
21 changes: 15 additions & 6 deletions editor/flash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const dataAddr = 0x20002000;
const stackAddr = 0x20001000;
const FULL_FLASH_TIMEOUT = 100000; // 100s
const PARTIAL_FLASH_TIMEOUT = 60000; // 60s
const CONNECTION_CHECK_TIMEOUT = 2000; // 2s
const RETRY_DAP_CMD_TIMEOUT = 50; // .05s

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

private async clearCommandsAsync() {
// before calling into dapjs, push through a few commands to make sure the responses
// to commands from previous sessions (if any) are flushed. Count of 5 is arbitrary.
for (let i = 0; i < 5; i++) {
try {
await this.getDaplinkVersionAsync();
} catch (e) { }
try {
await pxt.Util.promiseTimeout(CONNECTION_CHECK_TIMEOUT, (async () => {
// before calling into dapjs, push through a few commands to make sure the responses
// to commands from previous sessions (if any) are flushed. Count of 5 is arbitrary.
for (let i = 0; i < 5; i++) {
try {
await this.getDaplinkVersionAsync();
} catch (e) { }
}
})());
} catch (e) {
const errOut = new Error(e);
(errOut as any).type = "inittimeout";
throw errOut;
}
}

Expand Down
1 change: 1 addition & 0 deletions pxtarget.json
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,7 @@

"dragFileImage": "/static/download/transfer.png",
"connectDeviceImage": "/static/download/connect-microbit.gif",
"disconnectDeviceImage": "/static/download/device-forgotten.gif",
"selectDeviceImage": "/static/download/selecting-microbit.gif",
"connectionSuccessImage": "/static/download/successfully-paired.png",
"incompatibleHardwareImage": "/static/download/incompatible.png",
Expand Down

0 comments on commit 09a90c4

Please sign in to comment.