Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

configure timeout / warning when webusb connection is stalled #5918

Merged
merged 1 commit into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading