diff --git a/editor/flash.ts b/editor/flash.ts index b923dd925b1..75a8c7e69d3 100644 --- a/editor/flash.ts +++ b/editor/flash.ts @@ -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([ @@ -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; } } diff --git a/pxtarget.json b/pxtarget.json index ce1f989411c..5ec1e02f6aa 100644 --- a/pxtarget.json +++ b/pxtarget.json @@ -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",