@microbit/microbit-connection 0.9.0-apps.alpha.2 → 0.9.0-apps.alpha.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/cjs/async-util.d.ts +3 -1
- package/build/cjs/async-util.js +5 -1
- package/build/cjs/async-util.js.map +1 -1
- package/build/cjs/async-util.test.d.ts +1 -0
- package/build/cjs/async-util.test.js +20 -0
- package/build/cjs/async-util.test.js.map +1 -0
- package/build/cjs/availability.d.ts +14 -0
- package/build/cjs/availability.js +44 -0
- package/build/cjs/availability.js.map +1 -0
- package/build/cjs/bluetooth/ble-error.d.ts +10 -0
- package/build/cjs/bluetooth/ble-error.js +47 -0
- package/build/cjs/bluetooth/ble-error.js.map +1 -0
- package/build/cjs/bluetooth/connection.d.ts +378 -0
- package/build/cjs/bluetooth/connection.js +623 -0
- package/build/cjs/bluetooth/connection.js.map +1 -0
- package/build/cjs/bluetooth/connection.test.d.ts +1 -0
- package/build/cjs/bluetooth/connection.test.js +88 -0
- package/build/cjs/bluetooth/connection.test.js.map +1 -0
- package/build/cjs/bluetooth/device-bond-state.d.ts +14 -0
- package/build/cjs/bluetooth/device-bond-state.js +26 -0
- package/build/cjs/bluetooth/device-bond-state.js.map +1 -0
- package/build/cjs/{bluetooth-device-wrapper.d.ts → bluetooth/device-wrapper.d.ts} +35 -19
- package/build/cjs/{bluetooth-device-wrapper.js → bluetooth/device-wrapper.js} +169 -101
- package/build/cjs/bluetooth/device-wrapper.js.map +1 -0
- package/build/{esm → cjs/bluetooth}/flashing/flashing-full.d.ts +2 -2
- package/build/cjs/{flashing → bluetooth/flashing}/flashing-full.js +6 -5
- package/build/cjs/bluetooth/flashing/flashing-full.js.map +1 -0
- package/build/cjs/bluetooth/flashing/flashing-makecode.d.ts +10 -0
- package/build/cjs/{flashing → bluetooth/flashing}/flashing-makecode.js +5 -2
- package/build/cjs/bluetooth/flashing/flashing-makecode.js.map +1 -0
- package/build/cjs/bluetooth/flashing/flashing-makecode.test.d.ts +1 -0
- package/build/cjs/bluetooth/flashing/flashing-makecode.test.js +253 -0
- package/build/cjs/bluetooth/flashing/flashing-makecode.test.js.map +1 -0
- package/build/cjs/bluetooth/flashing/flashing-partial.d.ts +10 -0
- package/build/cjs/bluetooth/flashing/flashing-partial.js +145 -0
- package/build/cjs/bluetooth/flashing/flashing-partial.js.map +1 -0
- package/build/cjs/bluetooth/flashing/flashing-v1.js.map +1 -0
- package/build/cjs/{flashing → bluetooth/flashing}/nordic-dfu.d.ts +2 -2
- package/build/cjs/{flashing → bluetooth/flashing}/nordic-dfu.js +40 -14
- package/build/cjs/bluetooth/flashing/nordic-dfu.js.map +1 -0
- package/build/cjs/bluetooth/flashing/zip.js.map +1 -0
- package/build/cjs/bluetooth/flashing/zip.test.d.ts +1 -0
- package/build/cjs/bluetooth/flashing/zip.test.js +96 -0
- package/build/cjs/bluetooth/flashing/zip.test.js.map +1 -0
- package/build/cjs/bluetooth/index.d.ts +5 -0
- package/build/cjs/bluetooth/index.js +9 -0
- package/build/cjs/bluetooth/index.js.map +1 -0
- package/build/cjs/{bluetooth-profile.d.ts → bluetooth/profile.d.ts} +8 -0
- package/build/cjs/{bluetooth-profile.js → bluetooth/profile.js} +7 -1
- package/build/cjs/bluetooth/profile.js.map +1 -0
- package/build/{esm → cjs/bluetooth/services}/accelerometer-service.d.ts +2 -3
- package/build/cjs/{accelerometer-service.js → bluetooth/services/accelerometer-service.js} +17 -12
- package/build/cjs/bluetooth/services/accelerometer-service.js.map +1 -0
- package/build/{esm → cjs/bluetooth/services}/button-service.d.ts +2 -3
- package/build/cjs/{button-service.js → bluetooth/services/button-service.js} +24 -14
- package/build/cjs/bluetooth/services/button-service.js.map +1 -0
- package/build/{esm → cjs/bluetooth/services}/device-information-service.d.ts +1 -1
- package/build/cjs/bluetooth/services/device-information-service.js +29 -0
- package/build/cjs/bluetooth/services/device-information-service.js.map +1 -0
- package/build/cjs/{dfu-service.js → bluetooth/services/dfu-service.js} +2 -2
- package/build/cjs/bluetooth/services/dfu-service.js.map +1 -0
- package/build/cjs/bluetooth/services/event-service.d.ts +48 -0
- package/build/cjs/bluetooth/services/event-service.js +273 -0
- package/build/cjs/bluetooth/services/event-service.js.map +1 -0
- package/build/cjs/bluetooth/services/event-service.test.d.ts +1 -0
- package/build/cjs/bluetooth/services/event-service.test.js +252 -0
- package/build/cjs/bluetooth/services/event-service.test.js.map +1 -0
- package/build/cjs/bluetooth/services/io-pin-service.d.ts +65 -0
- package/build/cjs/bluetooth/services/io-pin-service.js +173 -0
- package/build/cjs/bluetooth/services/io-pin-service.js.map +1 -0
- package/build/cjs/{led-service.d.ts → bluetooth/services/led-service.d.ts} +2 -3
- package/build/cjs/{led-service.js → bluetooth/services/led-service.js} +10 -7
- package/build/cjs/bluetooth/services/led-service.js.map +1 -0
- package/build/cjs/{magnetometer-service.d.ts → bluetooth/services/magnetometer-service.d.ts} +2 -3
- package/build/cjs/{magnetometer-service.js → bluetooth/services/magnetometer-service.js} +19 -14
- package/build/cjs/bluetooth/services/magnetometer-service.js.map +1 -0
- package/build/{esm → cjs/bluetooth/services}/partial-flashing-service.d.ts +1 -1
- package/build/cjs/{partial-flashing-service.js → bluetooth/services/partial-flashing-service.js} +8 -8
- package/build/cjs/bluetooth/services/partial-flashing-service.js.map +1 -0
- package/build/cjs/bluetooth/services/temperature-service.d.ts +14 -0
- package/build/cjs/bluetooth/services/temperature-service.js +80 -0
- package/build/cjs/bluetooth/services/temperature-service.js.map +1 -0
- package/build/cjs/{uart-service.d.ts → bluetooth/services/uart-service.d.ts} +2 -2
- package/build/cjs/{uart-service.js → bluetooth/services/uart-service.js} +21 -9
- package/build/cjs/bluetooth/services/uart-service.js.map +1 -0
- package/build/cjs/board-id.d.ts +1 -1
- package/build/cjs/board-id.js.map +1 -1
- package/build/cjs/device.d.ts +214 -97
- package/build/cjs/device.js +57 -114
- package/build/cjs/device.js.map +1 -1
- package/build/cjs/events.d.ts +8 -108
- package/build/cjs/events.js +27 -88
- package/build/cjs/events.js.map +1 -1
- package/build/cjs/events.test.d.ts +1 -0
- package/build/cjs/events.test.js +115 -0
- package/build/cjs/events.test.js.map +1 -0
- package/build/cjs/hex-util.d.ts +1 -0
- package/build/cjs/hex-util.js +15 -0
- package/build/cjs/hex-util.js.map +1 -0
- package/build/cjs/index.d.ts +8 -16
- package/build/cjs/index.js +9 -28
- package/build/cjs/index.js.map +1 -1
- package/build/cjs/logging.js.map +1 -1
- package/build/cjs/microbit-events.d.ts +67 -0
- package/build/cjs/microbit-events.js +55 -0
- package/build/cjs/microbit-events.js.map +1 -0
- package/build/cjs/radio-bridge/connection.d.ts +52 -0
- package/build/cjs/{usb-radio-bridge.js → radio-bridge/connection.js} +108 -97
- package/build/cjs/radio-bridge/connection.js.map +1 -0
- package/build/cjs/radio-bridge/index.d.ts +4 -0
- package/build/cjs/radio-bridge/index.js +9 -0
- package/build/cjs/radio-bridge/index.js.map +1 -0
- package/build/cjs/{usb-serial-protocol.js → radio-bridge/serial-protocol.js} +1 -1
- package/build/cjs/radio-bridge/serial-protocol.js.map +1 -0
- package/build/cjs/service-events.d.ts +92 -15
- package/build/cjs/service-events.js +6 -36
- package/build/cjs/service-events.js.map +1 -1
- package/build/cjs/setupTests.js +8 -0
- package/build/cjs/setupTests.js.map +1 -1
- package/build/{esm/hex-flash-data-source.d.ts → cjs/universal-hex/flash-data-source.d.ts} +1 -1
- package/build/cjs/{hex-flash-data-source.js → universal-hex/flash-data-source.js} +6 -3
- package/build/cjs/universal-hex/flash-data-source.js.map +1 -0
- package/build/cjs/universal-hex/index.d.ts +4 -0
- package/build/cjs/universal-hex/index.js +9 -0
- package/build/cjs/universal-hex/index.js.map +1 -0
- package/build/cjs/usb/arm-debug.d.ts +137 -0
- package/build/cjs/usb/arm-debug.js +414 -0
- package/build/cjs/usb/arm-debug.js.map +1 -0
- package/build/cjs/usb/arm-debug.test.d.ts +1 -0
- package/build/cjs/usb/arm-debug.test.js +333 -0
- package/build/cjs/usb/arm-debug.test.js.map +1 -0
- package/build/{esm → cjs/usb}/board-serial-info.d.ts +2 -1
- package/build/cjs/{board-serial-info.js → usb/board-serial-info.js} +10 -7
- package/build/cjs/usb/board-serial-info.js.map +1 -0
- package/build/cjs/usb/board-serial-info.test.d.ts +1 -0
- package/build/cjs/usb/board-serial-info.test.js +46 -0
- package/build/cjs/usb/board-serial-info.test.js.map +1 -0
- package/build/cjs/usb/cdc-saturation.d.ts +36 -0
- package/build/cjs/usb/cdc-saturation.js +151 -0
- package/build/cjs/usb/cdc-saturation.js.map +1 -0
- package/build/cjs/usb/cmsis-dap.d.ts +113 -0
- package/build/cjs/usb/cmsis-dap.js +349 -0
- package/build/cjs/usb/cmsis-dap.js.map +1 -0
- package/build/cjs/usb/cmsis-dap.test.d.ts +1 -0
- package/build/cjs/usb/cmsis-dap.test.js +350 -0
- package/build/cjs/usb/cmsis-dap.test.js.map +1 -0
- package/build/cjs/usb/connection.d.ts +96 -0
- package/build/cjs/{usb.js → usb/connection.js} +274 -193
- package/build/cjs/usb/connection.js.map +1 -0
- package/build/cjs/usb/connection.test.d.ts +1 -0
- package/build/cjs/usb/connection.test.js +266 -0
- package/build/cjs/usb/connection.test.js.map +1 -0
- package/build/cjs/usb/cortex-m.d.ts +72 -0
- package/build/cjs/usb/cortex-m.js +165 -0
- package/build/cjs/usb/cortex-m.js.map +1 -0
- package/build/cjs/usb/cortex-m.test.d.ts +1 -0
- package/build/cjs/usb/cortex-m.test.js +217 -0
- package/build/cjs/usb/cortex-m.test.js.map +1 -0
- package/build/cjs/usb/daplink.d.ts +69 -0
- package/build/cjs/usb/daplink.js +238 -0
- package/build/cjs/usb/daplink.js.map +1 -0
- package/build/cjs/usb/daplink.test.d.ts +1 -0
- package/build/cjs/usb/daplink.test.js +290 -0
- package/build/cjs/usb/daplink.test.js.map +1 -0
- package/build/cjs/usb/device-wrapper.d.ts +34 -0
- package/build/cjs/usb/device-wrapper.js +102 -0
- package/build/cjs/usb/device-wrapper.js.map +1 -0
- package/build/cjs/usb/index.d.ts +5 -0
- package/build/cjs/usb/index.js +10 -0
- package/build/cjs/usb/index.js.map +1 -0
- package/build/cjs/{usb-partial-flashing-utils.d.ts → usb/partial-flashing-utils.d.ts} +6 -9
- package/build/cjs/{usb-partial-flashing-utils.js → usb/partial-flashing-utils.js} +6 -49
- package/build/cjs/usb/partial-flashing-utils.js.map +1 -0
- package/build/cjs/{usb-partial-flashing.d.ts → usb/partial-flashing.d.ts} +37 -11
- package/build/cjs/{usb-partial-flashing.js → usb/partial-flashing.js} +170 -134
- package/build/cjs/usb/partial-flashing.js.map +1 -0
- package/build/cjs/usb/promise-queue.js.map +1 -0
- package/build/cjs/usb/promise-queue.test.d.ts +1 -0
- package/build/cjs/usb/promise-queue.test.js +68 -0
- package/build/cjs/usb/promise-queue.test.js.map +1 -0
- package/build/cjs/usb/serial-events.d.ts +16 -0
- package/build/cjs/{led.js → usb/serial-events.js} +1 -1
- package/build/cjs/usb/serial-events.js.map +1 -0
- package/build/cjs/usb/transport.d.ts +42 -0
- package/build/cjs/usb/transport.js +155 -0
- package/build/cjs/usb/transport.js.map +1 -0
- package/build/esm/async-util.d.ts +3 -1
- package/build/esm/async-util.js +5 -1
- package/build/esm/async-util.js.map +1 -1
- package/build/esm/async-util.test.d.ts +1 -0
- package/build/esm/async-util.test.js +18 -0
- package/build/esm/async-util.test.js.map +1 -0
- package/build/esm/availability.d.ts +14 -0
- package/build/esm/availability.js +40 -0
- package/build/esm/availability.js.map +1 -0
- package/build/esm/bluetooth/ble-error.d.ts +10 -0
- package/build/esm/bluetooth/ble-error.js +42 -0
- package/build/esm/bluetooth/ble-error.js.map +1 -0
- package/build/esm/bluetooth/connection.d.ts +378 -0
- package/build/esm/bluetooth/connection.js +593 -0
- package/build/esm/bluetooth/connection.js.map +1 -0
- package/build/esm/bluetooth/connection.test.d.ts +1 -0
- package/build/esm/bluetooth/connection.test.js +86 -0
- package/build/esm/bluetooth/connection.test.js.map +1 -0
- package/build/esm/bluetooth/device-bond-state.d.ts +14 -0
- package/build/esm/bluetooth/device-bond-state.js +22 -0
- package/build/esm/bluetooth/device-bond-state.js.map +1 -0
- package/build/esm/{bluetooth-device-wrapper.d.ts → bluetooth/device-wrapper.d.ts} +35 -19
- package/build/esm/{bluetooth-device-wrapper.js → bluetooth/device-wrapper.js} +167 -100
- package/build/esm/bluetooth/device-wrapper.js.map +1 -0
- package/build/{cjs → esm/bluetooth}/flashing/flashing-full.d.ts +2 -2
- package/build/esm/{flashing → bluetooth/flashing}/flashing-full.js +6 -5
- package/build/esm/bluetooth/flashing/flashing-full.js.map +1 -0
- package/build/esm/bluetooth/flashing/flashing-makecode.d.ts +10 -0
- package/build/esm/{flashing → bluetooth/flashing}/flashing-makecode.js +5 -2
- package/build/esm/bluetooth/flashing/flashing-makecode.js.map +1 -0
- package/build/esm/bluetooth/flashing/flashing-makecode.test.d.ts +1 -0
- package/build/esm/bluetooth/flashing/flashing-makecode.test.js +248 -0
- package/build/esm/bluetooth/flashing/flashing-makecode.test.js.map +1 -0
- package/build/esm/bluetooth/flashing/flashing-partial.d.ts +10 -0
- package/build/esm/bluetooth/flashing/flashing-partial.js +142 -0
- package/build/esm/bluetooth/flashing/flashing-partial.js.map +1 -0
- package/build/esm/bluetooth/flashing/flashing-v1.js.map +1 -0
- package/build/esm/{flashing → bluetooth/flashing}/nordic-dfu.d.ts +2 -2
- package/build/esm/{flashing → bluetooth/flashing}/nordic-dfu.js +40 -14
- package/build/esm/bluetooth/flashing/nordic-dfu.js.map +1 -0
- package/build/esm/bluetooth/flashing/zip.js.map +1 -0
- package/build/esm/bluetooth/flashing/zip.test.d.ts +1 -0
- package/build/esm/bluetooth/flashing/zip.test.js +94 -0
- package/build/esm/bluetooth/flashing/zip.test.js.map +1 -0
- package/build/esm/bluetooth/index.d.ts +5 -0
- package/build/esm/bluetooth/index.js +5 -0
- package/build/esm/bluetooth/index.js.map +1 -0
- package/build/esm/{bluetooth-profile.d.ts → bluetooth/profile.d.ts} +8 -0
- package/build/esm/{bluetooth-profile.js → bluetooth/profile.js} +7 -1
- package/build/{cjs/bluetooth-profile.js.map → esm/bluetooth/profile.js.map} +1 -1
- package/build/{cjs → esm/bluetooth/services}/accelerometer-service.d.ts +2 -3
- package/build/esm/{accelerometer-service.js → bluetooth/services/accelerometer-service.js} +11 -6
- package/build/esm/bluetooth/services/accelerometer-service.js.map +1 -0
- package/build/{cjs → esm/bluetooth/services}/button-service.d.ts +2 -3
- package/build/esm/{button-service.js → bluetooth/services/button-service.js} +20 -10
- package/build/esm/bluetooth/services/button-service.js.map +1 -0
- package/build/{cjs → esm/bluetooth/services}/device-information-service.d.ts +1 -1
- package/build/esm/bluetooth/services/device-information-service.js +25 -0
- package/build/esm/bluetooth/services/device-information-service.js.map +1 -0
- package/build/esm/{dfu-service.js → bluetooth/services/dfu-service.js} +1 -1
- package/build/esm/bluetooth/services/dfu-service.js.map +1 -0
- package/build/esm/bluetooth/services/event-service.d.ts +48 -0
- package/build/esm/bluetooth/services/event-service.js +269 -0
- package/build/esm/bluetooth/services/event-service.js.map +1 -0
- package/build/esm/bluetooth/services/event-service.test.d.ts +1 -0
- package/build/esm/bluetooth/services/event-service.test.js +250 -0
- package/build/esm/bluetooth/services/event-service.test.js.map +1 -0
- package/build/esm/bluetooth/services/io-pin-service.d.ts +65 -0
- package/build/esm/bluetooth/services/io-pin-service.js +169 -0
- package/build/esm/bluetooth/services/io-pin-service.js.map +1 -0
- package/build/esm/{led-service.d.ts → bluetooth/services/led-service.d.ts} +2 -3
- package/build/esm/{led-service.js → bluetooth/services/led-service.js} +4 -1
- package/build/esm/bluetooth/services/led-service.js.map +1 -0
- package/build/esm/{magnetometer-service.d.ts → bluetooth/services/magnetometer-service.d.ts} +2 -3
- package/build/esm/{magnetometer-service.js → bluetooth/services/magnetometer-service.js} +11 -6
- package/build/esm/bluetooth/services/magnetometer-service.js.map +1 -0
- package/build/{cjs → esm/bluetooth/services}/partial-flashing-service.d.ts +1 -1
- package/build/esm/{partial-flashing-service.js → bluetooth/services/partial-flashing-service.js} +4 -4
- package/build/esm/bluetooth/services/partial-flashing-service.js.map +1 -0
- package/build/esm/bluetooth/services/temperature-service.d.ts +14 -0
- package/build/esm/bluetooth/services/temperature-service.js +76 -0
- package/build/esm/bluetooth/services/temperature-service.js.map +1 -0
- package/build/esm/{uart-service.d.ts → bluetooth/services/uart-service.d.ts} +2 -2
- package/build/esm/{uart-service.js → bluetooth/services/uart-service.js} +18 -6
- package/build/esm/bluetooth/services/uart-service.js.map +1 -0
- package/build/esm/board-id.d.ts +1 -1
- package/build/esm/board-id.js.map +1 -1
- package/build/esm/device.d.ts +214 -97
- package/build/esm/device.js +55 -108
- package/build/esm/device.js.map +1 -1
- package/build/esm/events.d.ts +8 -108
- package/build/esm/events.js +26 -86
- package/build/esm/events.js.map +1 -1
- package/build/esm/events.test.d.ts +1 -0
- package/build/esm/events.test.js +113 -0
- package/build/esm/events.test.js.map +1 -0
- package/build/esm/hex-util.d.ts +1 -0
- package/build/esm/hex-util.js +11 -0
- package/build/esm/hex-util.js.map +1 -0
- package/build/esm/index.d.ts +8 -16
- package/build/esm/index.js +7 -11
- package/build/esm/index.js.map +1 -1
- package/build/esm/logging.js.map +1 -1
- package/build/esm/microbit-events.d.ts +67 -0
- package/build/esm/microbit-events.js +52 -0
- package/build/esm/microbit-events.js.map +1 -0
- package/build/esm/radio-bridge/connection.d.ts +52 -0
- package/build/esm/{usb-radio-bridge.js → radio-bridge/connection.js} +108 -97
- package/build/esm/radio-bridge/connection.js.map +1 -0
- package/build/esm/radio-bridge/index.d.ts +4 -0
- package/build/esm/radio-bridge/index.js +5 -0
- package/build/esm/radio-bridge/index.js.map +1 -0
- package/build/esm/{usb-serial-protocol.js → radio-bridge/serial-protocol.js} +1 -1
- package/build/esm/radio-bridge/serial-protocol.js.map +1 -0
- package/build/esm/service-events.d.ts +92 -15
- package/build/esm/service-events.js +5 -34
- package/build/esm/service-events.js.map +1 -1
- package/build/esm/setupTests.js +7 -0
- package/build/esm/setupTests.js.map +1 -1
- package/build/{cjs/hex-flash-data-source.d.ts → esm/universal-hex/flash-data-source.d.ts} +1 -1
- package/build/esm/{hex-flash-data-source.js → universal-hex/flash-data-source.js} +6 -3
- package/build/esm/universal-hex/flash-data-source.js.map +1 -0
- package/build/esm/universal-hex/index.d.ts +4 -0
- package/build/esm/universal-hex/index.js +5 -0
- package/build/esm/universal-hex/index.js.map +1 -0
- package/build/esm/usb/arm-debug.d.ts +137 -0
- package/build/esm/usb/arm-debug.js +409 -0
- package/build/esm/usb/arm-debug.js.map +1 -0
- package/build/esm/usb/arm-debug.test.d.ts +1 -0
- package/build/esm/usb/arm-debug.test.js +331 -0
- package/build/esm/usb/arm-debug.test.js.map +1 -0
- package/build/{cjs → esm/usb}/board-serial-info.d.ts +2 -1
- package/build/esm/{board-serial-info.js → usb/board-serial-info.js} +10 -7
- package/build/esm/usb/board-serial-info.js.map +1 -0
- package/build/esm/usb/board-serial-info.test.d.ts +1 -0
- package/build/esm/usb/board-serial-info.test.js +44 -0
- package/build/esm/usb/board-serial-info.test.js.map +1 -0
- package/build/esm/usb/cdc-saturation.d.ts +36 -0
- package/build/esm/usb/cdc-saturation.js +148 -0
- package/build/esm/usb/cdc-saturation.js.map +1 -0
- package/build/esm/usb/cmsis-dap.d.ts +113 -0
- package/build/esm/usb/cmsis-dap.js +342 -0
- package/build/esm/usb/cmsis-dap.js.map +1 -0
- package/build/esm/usb/cmsis-dap.test.d.ts +1 -0
- package/build/esm/usb/cmsis-dap.test.js +348 -0
- package/build/esm/usb/cmsis-dap.test.js.map +1 -0
- package/build/esm/usb/connection.d.ts +96 -0
- package/build/esm/{usb.js → usb/connection.js} +270 -188
- package/build/esm/usb/connection.js.map +1 -0
- package/build/esm/usb/connection.test.d.ts +1 -0
- package/build/esm/usb/connection.test.js +264 -0
- package/build/esm/usb/connection.test.js.map +1 -0
- package/build/esm/usb/cortex-m.d.ts +72 -0
- package/build/esm/usb/cortex-m.js +161 -0
- package/build/esm/usb/cortex-m.js.map +1 -0
- package/build/esm/usb/cortex-m.test.d.ts +1 -0
- package/build/esm/usb/cortex-m.test.js +215 -0
- package/build/esm/usb/cortex-m.test.js.map +1 -0
- package/build/esm/usb/daplink.d.ts +69 -0
- package/build/esm/usb/daplink.js +231 -0
- package/build/esm/usb/daplink.js.map +1 -0
- package/build/esm/usb/daplink.test.d.ts +1 -0
- package/build/esm/usb/daplink.test.js +288 -0
- package/build/esm/usb/daplink.test.js.map +1 -0
- package/build/esm/usb/device-wrapper.d.ts +34 -0
- package/build/esm/usb/device-wrapper.js +98 -0
- package/build/esm/usb/device-wrapper.js.map +1 -0
- package/build/esm/usb/index.d.ts +5 -0
- package/build/esm/usb/index.js +5 -0
- package/build/esm/usb/index.js.map +1 -0
- package/build/esm/{usb-partial-flashing-utils.d.ts → usb/partial-flashing-utils.d.ts} +6 -9
- package/build/esm/{usb-partial-flashing-utils.js → usb/partial-flashing-utils.js} +4 -44
- package/build/esm/usb/partial-flashing-utils.js.map +1 -0
- package/build/esm/{usb-partial-flashing.d.ts → usb/partial-flashing.d.ts} +37 -11
- package/build/esm/{usb-partial-flashing.js → usb/partial-flashing.js} +169 -110
- package/build/esm/usb/partial-flashing.js.map +1 -0
- package/build/esm/usb/promise-queue.js.map +1 -0
- package/build/esm/usb/promise-queue.test.d.ts +1 -0
- package/build/esm/usb/promise-queue.test.js +66 -0
- package/build/esm/usb/promise-queue.test.js.map +1 -0
- package/build/esm/usb/serial-events.d.ts +16 -0
- package/build/esm/usb/serial-events.js +2 -0
- package/build/esm/usb/serial-events.js.map +1 -0
- package/build/esm/usb/transport.d.ts +42 -0
- package/build/esm/usb/transport.js +151 -0
- package/build/esm/usb/transport.js.map +1 -0
- package/package.json +55 -15
- package/LICENSE.md +0 -21
- package/README.md +0 -125
- package/build/cjs/accelerometer-service.js.map +0 -1
- package/build/cjs/accelerometer.d.ts +0 -9
- package/build/cjs/accelerometer.js +0 -16
- package/build/cjs/accelerometer.js.map +0 -1
- package/build/cjs/bluetooth-device-wrapper.js.map +0 -1
- package/build/cjs/bluetooth.d.ts +0 -112
- package/build/cjs/bluetooth.js +0 -458
- package/build/cjs/bluetooth.js.map +0 -1
- package/build/cjs/board-serial-info.js.map +0 -1
- package/build/cjs/button-service.js.map +0 -1
- package/build/cjs/buttons.d.ts +0 -10
- package/build/cjs/buttons.js +0 -22
- package/build/cjs/buttons.js.map +0 -1
- package/build/cjs/constants.d.ts +0 -48
- package/build/cjs/constants.js +0 -73
- package/build/cjs/constants.js.map +0 -1
- package/build/cjs/device-information-service.js +0 -34
- package/build/cjs/device-information-service.js.map +0 -1
- package/build/cjs/dfu-service.js.map +0 -1
- package/build/cjs/flashing/flashing-full.js.map +0 -1
- package/build/cjs/flashing/flashing-makecode.d.ts +0 -6
- package/build/cjs/flashing/flashing-makecode.js.map +0 -1
- package/build/cjs/flashing/flashing-partial.d.ts +0 -9
- package/build/cjs/flashing/flashing-partial.js +0 -98
- package/build/cjs/flashing/flashing-partial.js.map +0 -1
- package/build/cjs/flashing/flashing-v1.js.map +0 -1
- package/build/cjs/flashing/nordic-dfu.js.map +0 -1
- package/build/cjs/flashing/zip.js.map +0 -1
- package/build/cjs/hex-flash-data-source.js.map +0 -1
- package/build/cjs/led-service.js.map +0 -1
- package/build/cjs/led.d.ts +0 -6
- package/build/cjs/led.js.map +0 -1
- package/build/cjs/magnetometer-service.js.map +0 -1
- package/build/cjs/magnetometer.d.ts +0 -9
- package/build/cjs/magnetometer.js +0 -16
- package/build/cjs/magnetometer.js.map +0 -1
- package/build/cjs/partial-flashing-service.js.map +0 -1
- package/build/cjs/promise-queue.js.map +0 -1
- package/build/cjs/serial-events.d.ts +0 -20
- package/build/cjs/serial-events.js +0 -69
- package/build/cjs/serial-events.js.map +0 -1
- package/build/cjs/uart-service.js.map +0 -1
- package/build/cjs/uart.d.ts +0 -4
- package/build/cjs/uart.js +0 -16
- package/build/cjs/uart.js.map +0 -1
- package/build/cjs/usb-device-wrapper.d.ts +0 -47
- package/build/cjs/usb-device-wrapper.js +0 -437
- package/build/cjs/usb-device-wrapper.js.map +0 -1
- package/build/cjs/usb-partial-flashing-utils.js.map +0 -1
- package/build/cjs/usb-partial-flashing.js.map +0 -1
- package/build/cjs/usb-radio-bridge.d.ts +0 -24
- package/build/cjs/usb-radio-bridge.js.map +0 -1
- package/build/cjs/usb-serial-protocol.js.map +0 -1
- package/build/cjs/usb.d.ts +0 -66
- package/build/cjs/usb.js.map +0 -1
- package/build/esm/accelerometer-service.js.map +0 -1
- package/build/esm/accelerometer.d.ts +0 -9
- package/build/esm/accelerometer.js +0 -12
- package/build/esm/accelerometer.js.map +0 -1
- package/build/esm/bluetooth-device-wrapper.js.map +0 -1
- package/build/esm/bluetooth-profile.js.map +0 -1
- package/build/esm/bluetooth.d.ts +0 -112
- package/build/esm/bluetooth.js +0 -428
- package/build/esm/bluetooth.js.map +0 -1
- package/build/esm/board-serial-info.js.map +0 -1
- package/build/esm/button-service.js.map +0 -1
- package/build/esm/buttons.d.ts +0 -10
- package/build/esm/buttons.js +0 -18
- package/build/esm/buttons.js.map +0 -1
- package/build/esm/constants.d.ts +0 -48
- package/build/esm/constants.js +0 -70
- package/build/esm/constants.js.map +0 -1
- package/build/esm/device-information-service.js +0 -30
- package/build/esm/device-information-service.js.map +0 -1
- package/build/esm/dfu-service.js.map +0 -1
- package/build/esm/flashing/flashing-full.js.map +0 -1
- package/build/esm/flashing/flashing-makecode.d.ts +0 -6
- package/build/esm/flashing/flashing-makecode.js.map +0 -1
- package/build/esm/flashing/flashing-partial.d.ts +0 -9
- package/build/esm/flashing/flashing-partial.js +0 -95
- package/build/esm/flashing/flashing-partial.js.map +0 -1
- package/build/esm/flashing/flashing-v1.js.map +0 -1
- package/build/esm/flashing/nordic-dfu.js.map +0 -1
- package/build/esm/flashing/zip.js.map +0 -1
- package/build/esm/hex-flash-data-source.js.map +0 -1
- package/build/esm/led-service.js.map +0 -1
- package/build/esm/led.d.ts +0 -6
- package/build/esm/led.js +0 -2
- package/build/esm/led.js.map +0 -1
- package/build/esm/magnetometer-service.js.map +0 -1
- package/build/esm/magnetometer.d.ts +0 -9
- package/build/esm/magnetometer.js +0 -12
- package/build/esm/magnetometer.js.map +0 -1
- package/build/esm/partial-flashing-service.js.map +0 -1
- package/build/esm/promise-queue.js.map +0 -1
- package/build/esm/serial-events.d.ts +0 -20
- package/build/esm/serial-events.js +0 -61
- package/build/esm/serial-events.js.map +0 -1
- package/build/esm/uart-service.js.map +0 -1
- package/build/esm/uart.d.ts +0 -4
- package/build/esm/uart.js +0 -12
- package/build/esm/uart.js.map +0 -1
- package/build/esm/usb-device-wrapper.d.ts +0 -47
- package/build/esm/usb-device-wrapper.js +0 -410
- package/build/esm/usb-device-wrapper.js.map +0 -1
- package/build/esm/usb-partial-flashing-utils.js.map +0 -1
- package/build/esm/usb-partial-flashing.js.map +0 -1
- package/build/esm/usb-radio-bridge.d.ts +0 -24
- package/build/esm/usb-radio-bridge.js.map +0 -1
- package/build/esm/usb-serial-protocol.js.map +0 -1
- package/build/esm/usb.d.ts +0 -66
- package/build/esm/usb.js.map +0 -1
- package/typedoc.json +0 -14
- /package/build/cjs/{flashing → bluetooth/flashing}/flashing-v1.d.ts +0 -0
- /package/build/cjs/{flashing → bluetooth/flashing}/flashing-v1.js +0 -0
- /package/build/cjs/{flashing → bluetooth/flashing}/zip.d.ts +0 -0
- /package/build/cjs/{flashing → bluetooth/flashing}/zip.js +0 -0
- /package/build/cjs/{dfu-service.d.ts → bluetooth/services/dfu-service.d.ts} +0 -0
- /package/build/cjs/{usb-serial-protocol.d.ts → radio-bridge/serial-protocol.d.ts} +0 -0
- /package/build/cjs/{promise-queue.d.ts → usb/promise-queue.d.ts} +0 -0
- /package/build/cjs/{promise-queue.js → usb/promise-queue.js} +0 -0
- /package/build/esm/{flashing → bluetooth/flashing}/flashing-v1.d.ts +0 -0
- /package/build/esm/{flashing → bluetooth/flashing}/flashing-v1.js +0 -0
- /package/build/esm/{flashing → bluetooth/flashing}/zip.d.ts +0 -0
- /package/build/esm/{flashing → bluetooth/flashing}/zip.js +0 -0
- /package/build/esm/{dfu-service.d.ts → bluetooth/services/dfu-service.d.ts} +0 -0
- /package/build/esm/{usb-serial-protocol.d.ts → radio-bridge/serial-protocol.d.ts} +0 -0
- /package/build/esm/{promise-queue.d.ts → usb/promise-queue.d.ts} +0 -0
- /package/build/esm/{promise-queue.js → usb/promise-queue.js} +0 -0
|
@@ -1,58 +1,55 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.applyDeviceFilters = exports.
|
|
3
|
+
exports.applyDeviceFilters = exports.createUSBConnection = exports.DeviceSelectionMode = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* (c) 2021, Micro:bit Educational Foundation and contributors
|
|
6
6
|
*
|
|
7
7
|
* SPDX-License-Identifier: MIT
|
|
8
8
|
*/
|
|
9
|
-
const async_util_js_1 = require("
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
9
|
+
const async_util_js_1 = require("../async-util.js");
|
|
10
|
+
const availability_js_1 = require("../availability.js");
|
|
11
|
+
const device_js_1 = require("../device.js");
|
|
12
|
+
const events_js_1 = require("../events.js");
|
|
13
|
+
const logging_js_1 = require("../logging.js");
|
|
13
14
|
const promise_queue_js_1 = require("./promise-queue.js");
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
// Temporary workaround for ChromeOS 105 bug.
|
|
18
|
-
// See https://bugs.chromium.org/p/chromium/issues/detail?id=1363712&q=usb&can=2
|
|
19
|
-
const isChromeOS105 = () => {
|
|
20
|
-
const userAgent = navigator.userAgent;
|
|
21
|
-
return /CrOS/.test(userAgent) && /Chrome\/105\b/.test(userAgent);
|
|
22
|
-
};
|
|
23
|
-
exports.isChromeOS105 = isChromeOS105;
|
|
15
|
+
const device_wrapper_js_1 = require("./device-wrapper.js");
|
|
16
|
+
const partial_flashing_js_1 = require("./partial-flashing.js");
|
|
17
|
+
const cdc_saturation_js_1 = require("./cdc-saturation.js");
|
|
24
18
|
const defaultFilters = [{ vendorId: 0x0d28, productId: 0x0204 }];
|
|
25
|
-
|
|
26
|
-
(function (DeviceSelectionMode) {
|
|
19
|
+
exports.DeviceSelectionMode = {
|
|
27
20
|
/**
|
|
28
21
|
* Attempts to connect to known device, otherwise asks which device to
|
|
29
22
|
* connect to.
|
|
30
23
|
*/
|
|
31
|
-
|
|
24
|
+
AlwaysAsk: "AlwaysAsk",
|
|
32
25
|
/**
|
|
33
26
|
* Attempts to connect to known device, otherwise attempts to connect to any
|
|
34
27
|
* allowed devices. If that fails, asks which device to connect to.
|
|
35
28
|
*/
|
|
36
|
-
|
|
37
|
-
}
|
|
29
|
+
UseAnyAllowed: "UseAnyAllowed",
|
|
30
|
+
};
|
|
38
31
|
/**
|
|
39
32
|
* A WebUSB connection factory.
|
|
40
33
|
*/
|
|
41
|
-
const
|
|
42
|
-
exports.
|
|
34
|
+
const createUSBConnection = (options) => new MicrobitUSBConnectionImpl(options);
|
|
35
|
+
exports.createUSBConnection = createUSBConnection;
|
|
43
36
|
/**
|
|
44
37
|
* A WebUSB connection to a micro:bit device.
|
|
45
38
|
*/
|
|
46
|
-
class
|
|
39
|
+
class MicrobitUSBConnectionImpl extends events_js_1.TypedEventTarget {
|
|
47
40
|
constructor(options = {}) {
|
|
48
41
|
super();
|
|
42
|
+
Object.defineProperty(this, "type", {
|
|
43
|
+
enumerable: true,
|
|
44
|
+
configurable: true,
|
|
45
|
+
writable: true,
|
|
46
|
+
value: "usb"
|
|
47
|
+
});
|
|
49
48
|
Object.defineProperty(this, "status", {
|
|
50
49
|
enumerable: true,
|
|
51
50
|
configurable: true,
|
|
52
51
|
writable: true,
|
|
53
|
-
value:
|
|
54
|
-
? device_js_1.ConnectionStatus.NO_AUTHORIZED_DEVICE
|
|
55
|
-
: device_js_1.ConnectionStatus.NOT_SUPPORTED
|
|
52
|
+
value: device_js_1.ConnectionStatus.NoAuthorizedDevice
|
|
56
53
|
});
|
|
57
54
|
Object.defineProperty(this, "exclusionFilters", {
|
|
58
55
|
enumerable: true,
|
|
@@ -61,9 +58,18 @@ class MicrobitWebUSBConnectionImpl extends events_js_1.TypedEventTarget {
|
|
|
61
58
|
value: void 0
|
|
62
59
|
});
|
|
63
60
|
/**
|
|
64
|
-
* The USB device we last connected to.
|
|
61
|
+
* The raw USB device we last connected to.
|
|
65
62
|
* Cleared if it is disconnected.
|
|
66
63
|
*/
|
|
64
|
+
Object.defineProperty(this, "usbDevice", {
|
|
65
|
+
enumerable: true,
|
|
66
|
+
configurable: true,
|
|
67
|
+
writable: true,
|
|
68
|
+
value: void 0
|
|
69
|
+
});
|
|
70
|
+
/**
|
|
71
|
+
* Device-specific state. Created on connect, cleared on disconnect.
|
|
72
|
+
*/
|
|
67
73
|
Object.defineProperty(this, "device", {
|
|
68
74
|
enumerable: true,
|
|
69
75
|
configurable: true,
|
|
@@ -71,14 +77,37 @@ class MicrobitWebUSBConnectionImpl extends events_js_1.TypedEventTarget {
|
|
|
71
77
|
value: void 0
|
|
72
78
|
});
|
|
73
79
|
/**
|
|
74
|
-
*
|
|
80
|
+
* Cached device properties that persist across reconnections until clearDevice.
|
|
75
81
|
*/
|
|
76
|
-
Object.defineProperty(this, "
|
|
82
|
+
Object.defineProperty(this, "cachedConnectionInfo", {
|
|
77
83
|
enumerable: true,
|
|
78
84
|
configurable: true,
|
|
79
85
|
writable: true,
|
|
80
86
|
value: void 0
|
|
81
87
|
});
|
|
88
|
+
Object.defineProperty(this, "loggedBoardSerialInfo", {
|
|
89
|
+
enumerable: true,
|
|
90
|
+
configurable: true,
|
|
91
|
+
writable: true,
|
|
92
|
+
value: void 0
|
|
93
|
+
});
|
|
94
|
+
/**
|
|
95
|
+
* Whether CDC pipeline saturation has been performed for this physical
|
|
96
|
+
* USB connection. Once saturated, the buffers stay full until the device
|
|
97
|
+
* is physically disconnected.
|
|
98
|
+
*/
|
|
99
|
+
Object.defineProperty(this, "cdcSaturated", {
|
|
100
|
+
enumerable: true,
|
|
101
|
+
configurable: true,
|
|
102
|
+
writable: true,
|
|
103
|
+
value: false
|
|
104
|
+
});
|
|
105
|
+
/**
|
|
106
|
+
* Whether the serial read loop is running.
|
|
107
|
+
*
|
|
108
|
+
* This is false even if we have serial listeners when we're disconnected or flashing.
|
|
109
|
+
* The serial reads interfere with the flash process.
|
|
110
|
+
*/
|
|
82
111
|
Object.defineProperty(this, "serialState", {
|
|
83
112
|
enumerable: true,
|
|
84
113
|
configurable: true,
|
|
@@ -96,7 +125,7 @@ class MicrobitWebUSBConnectionImpl extends events_js_1.TypedEventTarget {
|
|
|
96
125
|
configurable: true,
|
|
97
126
|
writable: true,
|
|
98
127
|
value: (data) => {
|
|
99
|
-
this.
|
|
128
|
+
this.dispatchEvent("serialdata", { data });
|
|
100
129
|
}
|
|
101
130
|
});
|
|
102
131
|
Object.defineProperty(this, "flashing", {
|
|
@@ -105,13 +134,7 @@ class MicrobitWebUSBConnectionImpl extends events_js_1.TypedEventTarget {
|
|
|
105
134
|
writable: true,
|
|
106
135
|
value: false
|
|
107
136
|
});
|
|
108
|
-
Object.defineProperty(this, "
|
|
109
|
-
enumerable: true,
|
|
110
|
-
configurable: true,
|
|
111
|
-
writable: true,
|
|
112
|
-
value: false
|
|
113
|
-
});
|
|
114
|
-
Object.defineProperty(this, "visibilityReconnect", {
|
|
137
|
+
Object.defineProperty(this, "pauseAfterFlash", {
|
|
115
138
|
enumerable: true,
|
|
116
139
|
configurable: true,
|
|
117
140
|
writable: true,
|
|
@@ -123,27 +146,26 @@ class MicrobitWebUSBConnectionImpl extends events_js_1.TypedEventTarget {
|
|
|
123
146
|
writable: true,
|
|
124
147
|
value: () => {
|
|
125
148
|
if (document.visibilityState === "visible") {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
this.visibilityReconnect = false;
|
|
149
|
+
// We may not have actually paused when we became hidden due to an in-progress flash.
|
|
150
|
+
this.pauseAfterFlash = false;
|
|
151
|
+
if (this.status === device_js_1.ConnectionStatus.Paused) {
|
|
130
152
|
if (!this.flashing) {
|
|
131
153
|
this.log("Reconnecting visible tab");
|
|
132
|
-
|
|
154
|
+
// withEnrichedErrors already disconnects and logs on failure.
|
|
155
|
+
this.connect().catch(() => { });
|
|
133
156
|
}
|
|
134
157
|
}
|
|
135
158
|
}
|
|
136
159
|
else {
|
|
137
|
-
if (!this.unloading && this.status === device_js_1.ConnectionStatus.
|
|
160
|
+
if (!this.unloading && this.status === device_js_1.ConnectionStatus.Connected) {
|
|
138
161
|
if (!this.flashing) {
|
|
139
|
-
this.log("
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
});
|
|
162
|
+
this.log("Pausing connection for hidden tab");
|
|
163
|
+
// Transition to PAUSED not DISCONNECTED
|
|
164
|
+
this.disconnect(false, device_js_1.ConnectionStatus.Paused);
|
|
143
165
|
}
|
|
144
166
|
else {
|
|
145
167
|
this.log("Scheduling disconnect of hidden tab for after flash");
|
|
146
|
-
this.
|
|
168
|
+
this.pauseAfterFlash = true;
|
|
147
169
|
}
|
|
148
170
|
}
|
|
149
171
|
}
|
|
@@ -170,9 +192,9 @@ class MicrobitWebUSBConnectionImpl extends events_js_1.TypedEventTarget {
|
|
|
170
192
|
window.addEventListener("focus", () => {
|
|
171
193
|
const assumePageIsStayingOpenDelay = 1000;
|
|
172
194
|
setTimeout(() => {
|
|
173
|
-
if (this.status === device_js_1.ConnectionStatus.
|
|
195
|
+
if (this.status === device_js_1.ConnectionStatus.Connected) {
|
|
174
196
|
this.unloading = false;
|
|
175
|
-
if (this.
|
|
197
|
+
if (this.hasSerialEventListeners()) {
|
|
176
198
|
this.startSerialInternal();
|
|
177
199
|
}
|
|
178
200
|
}
|
|
@@ -192,29 +214,29 @@ class MicrobitWebUSBConnectionImpl extends events_js_1.TypedEventTarget {
|
|
|
192
214
|
writable: true,
|
|
193
215
|
value: void 0
|
|
194
216
|
});
|
|
195
|
-
Object.defineProperty(this, "
|
|
217
|
+
Object.defineProperty(this, "pauseOnHidden", {
|
|
196
218
|
enumerable: true,
|
|
197
219
|
configurable: true,
|
|
198
220
|
writable: true,
|
|
199
|
-
value:
|
|
200
|
-
serialdata: 0,
|
|
201
|
-
}
|
|
221
|
+
value: void 0
|
|
202
222
|
});
|
|
203
223
|
Object.defineProperty(this, "handleDisconnect", {
|
|
204
224
|
enumerable: true,
|
|
205
225
|
configurable: true,
|
|
206
226
|
writable: true,
|
|
207
227
|
value: (event) => {
|
|
208
|
-
if (event.device === this.
|
|
209
|
-
this.
|
|
228
|
+
if (event.device === this.usbDevice) {
|
|
229
|
+
this.cdcSaturated = false;
|
|
210
230
|
this.device = undefined;
|
|
211
|
-
this.
|
|
231
|
+
this.usbDevice = undefined;
|
|
232
|
+
this.setStatus(device_js_1.ConnectionStatus.NoAuthorizedDevice);
|
|
212
233
|
}
|
|
213
234
|
}
|
|
214
235
|
});
|
|
215
236
|
this.logging = options.logging || new logging_js_1.ConsoleLogging();
|
|
216
237
|
this.deviceSelectionMode =
|
|
217
|
-
options.deviceSelectionMode || DeviceSelectionMode.AlwaysAsk;
|
|
238
|
+
options.deviceSelectionMode || exports.DeviceSelectionMode.AlwaysAsk;
|
|
239
|
+
this.pauseOnHidden = options.pauseOnHidden ?? true;
|
|
218
240
|
}
|
|
219
241
|
log(v) {
|
|
220
242
|
this.logging.log(v);
|
|
@@ -225,18 +247,24 @@ class MicrobitWebUSBConnectionImpl extends events_js_1.TypedEventTarget {
|
|
|
225
247
|
}
|
|
226
248
|
if (typeof window !== "undefined") {
|
|
227
249
|
window.addEventListener("beforeunload", this.beforeUnloadListener);
|
|
228
|
-
if (window.document) {
|
|
250
|
+
if (this.pauseOnHidden && window.document) {
|
|
229
251
|
window.document.addEventListener("visibilitychange", this.visibilityChangeListener);
|
|
230
252
|
}
|
|
231
253
|
}
|
|
232
254
|
}
|
|
255
|
+
async checkAvailability() {
|
|
256
|
+
if (!navigator.usb) {
|
|
257
|
+
return "unsupported";
|
|
258
|
+
}
|
|
259
|
+
return "available";
|
|
260
|
+
}
|
|
233
261
|
dispose() {
|
|
234
262
|
if (navigator.usb) {
|
|
235
263
|
navigator.usb.removeEventListener("disconnect", this.handleDisconnect);
|
|
236
264
|
}
|
|
237
265
|
if (typeof window !== "undefined") {
|
|
238
266
|
window.removeEventListener("beforeunload", this.beforeUnloadListener);
|
|
239
|
-
if (window.document) {
|
|
267
|
+
if (this.pauseOnHidden && window.document) {
|
|
240
268
|
window.document.removeEventListener("visibilitychange", this.visibilityChangeListener);
|
|
241
269
|
}
|
|
242
270
|
}
|
|
@@ -251,20 +279,22 @@ class MicrobitWebUSBConnectionImpl extends events_js_1.TypedEventTarget {
|
|
|
251
279
|
});
|
|
252
280
|
}
|
|
253
281
|
getDeviceId() {
|
|
254
|
-
|
|
282
|
+
(0, device_js_1.assertConnected)(this.cachedConnectionInfo);
|
|
283
|
+
return this.cachedConnectionInfo.deviceId;
|
|
255
284
|
}
|
|
256
285
|
getDevice() {
|
|
257
|
-
return this.
|
|
286
|
+
return this.usbDevice;
|
|
258
287
|
}
|
|
259
288
|
getBoardVersion() {
|
|
260
|
-
|
|
289
|
+
(0, device_js_1.assertConnected)(this.cachedConnectionInfo);
|
|
290
|
+
return this.cachedConnectionInfo.boardSerialInfo.id.toBoardVersion();
|
|
261
291
|
}
|
|
262
292
|
async flash(dataSource, options) {
|
|
263
293
|
this.flashing = true;
|
|
264
294
|
try {
|
|
265
295
|
const startTime = new Date().getTime();
|
|
266
296
|
await this.withEnrichedErrors(() => this.flashInternal(dataSource, options));
|
|
267
|
-
this.
|
|
297
|
+
this.dispatchEvent("flash");
|
|
268
298
|
const flashTime = new Date().getTime() - startTime;
|
|
269
299
|
this.logging.event({
|
|
270
300
|
type: "WebUSB-time",
|
|
@@ -285,17 +315,41 @@ class MicrobitWebUSBConnectionImpl extends events_js_1.TypedEventTarget {
|
|
|
285
315
|
await this.stopSerialInternal();
|
|
286
316
|
this.log("Reconnecting before flash");
|
|
287
317
|
await this.connectInternal(progress);
|
|
288
|
-
if (!this.
|
|
318
|
+
if (!this.device) {
|
|
289
319
|
throw new device_js_1.DeviceError({
|
|
290
|
-
code: "
|
|
320
|
+
code: "connection-error",
|
|
291
321
|
message: "Must be connected now",
|
|
292
322
|
});
|
|
293
323
|
}
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
324
|
+
// Saturate DAPLink's CDC buffers on the first flash after physical
|
|
325
|
+
// connection, but only if someone is listening for serial data.
|
|
326
|
+
// Once saturated, the buffers stay full until physical disconnect.
|
|
327
|
+
if (!this.cdcSaturated && this.hasSerialEventListeners()) {
|
|
328
|
+
// Ensure DAPLink's UART is at 115200 before saturation.
|
|
329
|
+
// V1 DAPLink defaults to 9600 on fresh connection.
|
|
330
|
+
// setBaudrate may reset the target, so reinit SWD afterwards.
|
|
331
|
+
const currentBaud = await this.device.serial.getBaudrate();
|
|
332
|
+
if (currentBaud !== 115200) {
|
|
333
|
+
this.log(`Setting DAPLink baud from ${currentBaud} to 115200`);
|
|
334
|
+
await this.device.serial.setBaudrate(115200);
|
|
335
|
+
await this.device.adi.reinit();
|
|
336
|
+
}
|
|
337
|
+
this.log("Halting target");
|
|
338
|
+
await this.device.cortexM.halt();
|
|
339
|
+
const boardVersion = this.cachedConnectionInfo.boardSerialInfo.id.toBoardVersion();
|
|
340
|
+
await (0, cdc_saturation_js_1.saturateCdcPipeline)(this.device, boardVersion, this.logging);
|
|
341
|
+
this.cdcSaturated = true;
|
|
342
|
+
await this.device.serial.drain();
|
|
343
|
+
}
|
|
344
|
+
// Halt unconditionally — flash needs the target stopped.
|
|
345
|
+
if (!(await this.device.cortexM.isHalted())) {
|
|
346
|
+
this.log("Halting target");
|
|
347
|
+
await this.device.cortexM.halt();
|
|
348
|
+
}
|
|
349
|
+
const { boardSerialInfo, pageSize, numPages } = this.cachedConnectionInfo;
|
|
350
|
+
const boardVersion = boardSerialInfo.id.toBoardVersion();
|
|
297
351
|
const data = await dataSource(boardVersion);
|
|
298
|
-
const flashing = new
|
|
352
|
+
const flashing = new partial_flashing_js_1.PartialFlashing(this.device, this.logging, boardVersion, pageSize, numPages);
|
|
299
353
|
let wasPartial = false;
|
|
300
354
|
try {
|
|
301
355
|
if (partial) {
|
|
@@ -307,18 +361,30 @@ class MicrobitWebUSBConnectionImpl extends events_js_1.TypedEventTarget {
|
|
|
307
361
|
}
|
|
308
362
|
finally {
|
|
309
363
|
progress(wasPartial ? device_js_1.ProgressStage.PartialFlashing : device_js_1.ProgressStage.FullFlashing, undefined);
|
|
310
|
-
if (this.
|
|
364
|
+
if (this.pauseAfterFlash) {
|
|
311
365
|
this.log("Disconnecting after flash due to tab visibility");
|
|
312
|
-
this.
|
|
313
|
-
await this.disconnect();
|
|
314
|
-
this.visibilityReconnect = true;
|
|
366
|
+
this.pauseAfterFlash = false;
|
|
367
|
+
await this.disconnect(false, device_js_1.ConnectionStatus.Paused);
|
|
315
368
|
}
|
|
316
369
|
else {
|
|
317
|
-
|
|
370
|
+
await this.device.adi.reinit();
|
|
371
|
+
// Start serial before resetting so we capture startup output.
|
|
372
|
+
// For full flash FLASH_CLOSE already reset the target, so its
|
|
373
|
+
// early output accumulates in DAPLink's 512-byte serial ring
|
|
374
|
+
// buffer until the first read here.
|
|
375
|
+
if (this.hasSerialEventListeners()) {
|
|
318
376
|
this.log("Reinstating serial after flash");
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
377
|
+
await this.startSerialInternal();
|
|
378
|
+
}
|
|
379
|
+
if (wasPartial) {
|
|
380
|
+
// Partial flash writes pages via SWD without resetting.
|
|
381
|
+
// Full flash already resets via FLASH_CLOSE.
|
|
382
|
+
this.log("Resetting micro:bit to run new program");
|
|
383
|
+
try {
|
|
384
|
+
await this.device.cortexM.reset();
|
|
385
|
+
}
|
|
386
|
+
catch (e) {
|
|
387
|
+
// Allow errors on resetting, user can always manually reset if necessary.
|
|
322
388
|
}
|
|
323
389
|
}
|
|
324
390
|
}
|
|
@@ -326,38 +392,51 @@ class MicrobitWebUSBConnectionImpl extends events_js_1.TypedEventTarget {
|
|
|
326
392
|
}
|
|
327
393
|
async startSerialInternal() {
|
|
328
394
|
return this.serialStateChangeQueue.add(async () => {
|
|
329
|
-
if (!this.
|
|
395
|
+
if (!this.device || this.serialState) {
|
|
330
396
|
return;
|
|
331
397
|
}
|
|
332
398
|
this.log("Starting serial");
|
|
333
399
|
this.serialState = true;
|
|
334
|
-
this.
|
|
335
|
-
|
|
400
|
+
const serial = this.device.serial;
|
|
401
|
+
const currentBaud = await serial.getBaudrate();
|
|
402
|
+
if (currentBaud !== 115200) {
|
|
403
|
+
// Changing the baud rate causes a micro:bit reset, so only do it if necessary
|
|
404
|
+
await serial.setBaudrate(115200);
|
|
405
|
+
}
|
|
406
|
+
serial
|
|
407
|
+
.startPolling(this.serialListener, 1)
|
|
336
408
|
.then(() => {
|
|
337
409
|
this.log("Finished listening for serial data");
|
|
338
410
|
})
|
|
339
411
|
.catch((e) => {
|
|
340
|
-
this.
|
|
412
|
+
this.dispatchEvent("backgrounderror", {
|
|
413
|
+
error: enrichedError(e),
|
|
414
|
+
event: "serialdata",
|
|
415
|
+
});
|
|
341
416
|
})
|
|
342
417
|
.finally(() => {
|
|
343
418
|
this.serialState = false;
|
|
419
|
+
// Don't reset when paused — the same program is still running and
|
|
420
|
+
// serial will resume when the tab becomes visible again.
|
|
421
|
+
if (this.status !== device_js_1.ConnectionStatus.Paused) {
|
|
422
|
+
this.dispatchEvent("serialreset");
|
|
423
|
+
}
|
|
344
424
|
});
|
|
345
425
|
});
|
|
346
426
|
}
|
|
347
427
|
async stopSerialInternal() {
|
|
348
428
|
return this.serialStateChangeQueue.add(async () => {
|
|
349
|
-
if (!this.
|
|
429
|
+
if (!this.device || !this.serialState) {
|
|
350
430
|
return;
|
|
351
431
|
}
|
|
352
|
-
this.
|
|
353
|
-
this.dispatchTypedEvent("serialreset", new serial_events_js_1.SerialResetEvent());
|
|
432
|
+
this.device.serial.stopPolling();
|
|
354
433
|
});
|
|
355
434
|
}
|
|
356
|
-
async disconnect(quiet) {
|
|
435
|
+
async disconnect(quiet, finalStatus = device_js_1.ConnectionStatus.Disconnected) {
|
|
357
436
|
try {
|
|
358
|
-
if (this.
|
|
437
|
+
if (this.device) {
|
|
359
438
|
await this.stopSerialInternal();
|
|
360
|
-
await this.
|
|
439
|
+
await this.device.disconnect();
|
|
361
440
|
}
|
|
362
441
|
}
|
|
363
442
|
catch (e) {
|
|
@@ -370,8 +449,8 @@ class MicrobitWebUSBConnectionImpl extends events_js_1.TypedEventTarget {
|
|
|
370
449
|
}
|
|
371
450
|
}
|
|
372
451
|
finally {
|
|
373
|
-
this.
|
|
374
|
-
this.setStatus(
|
|
452
|
+
this.device = undefined;
|
|
453
|
+
this.setStatus(finalStatus);
|
|
375
454
|
if (!quiet) {
|
|
376
455
|
this.logging.log("Disconnection complete");
|
|
377
456
|
this.logging.event({
|
|
@@ -382,10 +461,30 @@ class MicrobitWebUSBConnectionImpl extends events_js_1.TypedEventTarget {
|
|
|
382
461
|
}
|
|
383
462
|
}
|
|
384
463
|
setStatus(newStatus) {
|
|
464
|
+
const previousStatus = this.status;
|
|
385
465
|
this.status = newStatus;
|
|
386
|
-
this.visibilityReconnect = false;
|
|
387
466
|
this.log("USB connection status " + newStatus);
|
|
388
|
-
this.
|
|
467
|
+
this.dispatchEvent("status", {
|
|
468
|
+
status: newStatus,
|
|
469
|
+
previousStatus,
|
|
470
|
+
});
|
|
471
|
+
}
|
|
472
|
+
logBoardInfo(info) {
|
|
473
|
+
this.logging.event({
|
|
474
|
+
type: "WebUSB-info",
|
|
475
|
+
message: "connected",
|
|
476
|
+
});
|
|
477
|
+
if (!this.loggedBoardSerialInfo || !this.loggedBoardSerialInfo.eq(info)) {
|
|
478
|
+
this.loggedBoardSerialInfo = info;
|
|
479
|
+
this.logging.event({
|
|
480
|
+
type: "WebUSB-info",
|
|
481
|
+
message: "board-id/" + info.id,
|
|
482
|
+
});
|
|
483
|
+
this.logging.event({
|
|
484
|
+
type: "WebUSB-info",
|
|
485
|
+
message: "board-family-hic/" + info.familyId + info.hic,
|
|
486
|
+
});
|
|
487
|
+
}
|
|
389
488
|
}
|
|
390
489
|
async withEnrichedErrors(f) {
|
|
391
490
|
try {
|
|
@@ -419,68 +518,75 @@ class MicrobitWebUSBConnectionImpl extends events_js_1.TypedEventTarget {
|
|
|
419
518
|
}
|
|
420
519
|
}
|
|
421
520
|
serialWrite(data) {
|
|
521
|
+
(0, device_js_1.assertConnected)(this.device);
|
|
522
|
+
const device = this.device;
|
|
422
523
|
return this.withEnrichedErrors(async () => {
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
start = end;
|
|
433
|
-
}
|
|
524
|
+
// WebUSB packets are 64 bytes with a two byte header.
|
|
525
|
+
// https://github.com/microbit-foundation/python-editor-v3/issues/215
|
|
526
|
+
const maxSerialWrite = 62;
|
|
527
|
+
let start = 0;
|
|
528
|
+
while (start < data.length) {
|
|
529
|
+
const end = Math.min(start + maxSerialWrite, data.length);
|
|
530
|
+
const chunkData = data.slice(start, end);
|
|
531
|
+
await device.serial.write(chunkData);
|
|
532
|
+
start = end;
|
|
434
533
|
}
|
|
435
534
|
});
|
|
436
535
|
}
|
|
437
536
|
async softwareReset() {
|
|
438
|
-
|
|
537
|
+
(0, device_js_1.assertConnected)(this.device);
|
|
538
|
+
const device = this.device;
|
|
539
|
+
return this.serialStateChangeQueue.add(async () => await device.cortexM.softwareReset());
|
|
439
540
|
}
|
|
440
541
|
async clearDevice() {
|
|
441
542
|
await this.disconnect();
|
|
442
|
-
this.
|
|
443
|
-
this.
|
|
543
|
+
this.usbDevice = undefined;
|
|
544
|
+
this.cachedConnectionInfo = undefined;
|
|
545
|
+
this.cdcSaturated = false;
|
|
546
|
+
this.setStatus(device_js_1.ConnectionStatus.NoAuthorizedDevice);
|
|
444
547
|
}
|
|
445
548
|
async connectInternal(progress) {
|
|
446
549
|
const reportProgress = progress ?? (() => { });
|
|
447
|
-
|
|
550
|
+
reportProgress(device_js_1.ProgressStage.Initializing);
|
|
551
|
+
(0, availability_js_1.throwIfUnavailable)(await this.checkAvailability());
|
|
552
|
+
if (!this.device && this.usbDevice) {
|
|
448
553
|
reportProgress(device_js_1.ProgressStage.Connecting);
|
|
449
|
-
this.
|
|
450
|
-
await (0, async_util_js_1.withTimeout)(this.
|
|
554
|
+
this.device = new device_wrapper_js_1.USBDeviceWrapper(this.usbDevice, this.logging);
|
|
555
|
+
this.cachedConnectionInfo = await (0, async_util_js_1.withTimeout)(this.device.reconnect(), 10_000);
|
|
451
556
|
}
|
|
452
|
-
else if (!this.
|
|
557
|
+
else if (!this.device) {
|
|
453
558
|
await this.connectWithOtherDevice(reportProgress);
|
|
454
559
|
}
|
|
455
560
|
else {
|
|
456
561
|
reportProgress(device_js_1.ProgressStage.Connecting);
|
|
457
|
-
await (0, async_util_js_1.withTimeout)(this.
|
|
562
|
+
this.cachedConnectionInfo = await (0, async_util_js_1.withTimeout)(this.device.reconnect(), 10_000);
|
|
458
563
|
}
|
|
459
|
-
|
|
564
|
+
this.logBoardInfo(this.cachedConnectionInfo.boardSerialInfo);
|
|
565
|
+
if (this.hasSerialEventListeners() && !this.flashing) {
|
|
460
566
|
this.startSerialInternal();
|
|
461
567
|
}
|
|
462
|
-
this.setStatus(device_js_1.ConnectionStatus.
|
|
568
|
+
this.setStatus(device_js_1.ConnectionStatus.Connected);
|
|
463
569
|
}
|
|
464
570
|
async connectWithOtherDevice(progress) {
|
|
465
|
-
if (this.deviceSelectionMode === DeviceSelectionMode.UseAnyAllowed) {
|
|
571
|
+
if (this.deviceSelectionMode === exports.DeviceSelectionMode.UseAnyAllowed) {
|
|
466
572
|
await this.attemptConnectAllowedDevices();
|
|
467
573
|
}
|
|
468
|
-
if (!this.
|
|
574
|
+
if (!this.device) {
|
|
469
575
|
progress(device_js_1.ProgressStage.FindingDevice);
|
|
470
|
-
this.
|
|
576
|
+
this.usbDevice = await this.chooseDevice();
|
|
471
577
|
progress(device_js_1.ProgressStage.Connecting);
|
|
472
|
-
this.
|
|
473
|
-
await (0, async_util_js_1.withTimeout)(this.
|
|
578
|
+
this.device = new device_wrapper_js_1.USBDeviceWrapper(this.usbDevice, this.logging);
|
|
579
|
+
this.cachedConnectionInfo = await (0, async_util_js_1.withTimeout)(this.device.reconnect(), 10_000);
|
|
474
580
|
}
|
|
475
581
|
}
|
|
476
582
|
// Based on: https://github.com/microsoft/pxt/blob/ab97a2422879824c730f009b15d4bf446b0e8547/pxtlib/webusb.ts#L361
|
|
477
583
|
async attemptConnectAllowedDevices() {
|
|
478
584
|
const pairedDevices = await this.getFilteredAllowedDevices();
|
|
479
|
-
for (const
|
|
480
|
-
const
|
|
481
|
-
if (
|
|
585
|
+
for (const usbDevice of pairedDevices) {
|
|
586
|
+
const device = await this.attemptDeviceConnection(usbDevice);
|
|
587
|
+
if (device) {
|
|
588
|
+
this.usbDevice = usbDevice;
|
|
482
589
|
this.device = device;
|
|
483
|
-
this.connection = connection;
|
|
484
590
|
return;
|
|
485
591
|
}
|
|
486
592
|
}
|
|
@@ -495,34 +601,33 @@ class MicrobitWebUSBConnectionImpl extends events_js_1.TypedEventTarget {
|
|
|
495
601
|
const filteredDevices = devices.filter((device) => (0, exports.applyDeviceFilters)(device, defaultFilters, this.exclusionFilters ?? []));
|
|
496
602
|
return filteredDevices;
|
|
497
603
|
}
|
|
498
|
-
async attemptDeviceConnection(
|
|
499
|
-
this.log(`Attempting connection to: ${
|
|
500
|
-
this.log(`Serial number: ${
|
|
501
|
-
const
|
|
502
|
-
await (0, async_util_js_1.withTimeout)(
|
|
503
|
-
return
|
|
604
|
+
async attemptDeviceConnection(usbDevice) {
|
|
605
|
+
this.log(`Attempting connection to: ${usbDevice.manufacturerName} ${usbDevice.productName}`);
|
|
606
|
+
this.log(`Serial number: ${usbDevice.serialNumber}`);
|
|
607
|
+
const device = new device_wrapper_js_1.USBDeviceWrapper(usbDevice, this.logging);
|
|
608
|
+
this.cachedConnectionInfo = await (0, async_util_js_1.withTimeout)(device.reconnect(), 10_000);
|
|
609
|
+
return device;
|
|
504
610
|
}
|
|
505
611
|
async chooseDevice() {
|
|
506
|
-
this.
|
|
612
|
+
this.dispatchEvent("beforerequestdevice");
|
|
507
613
|
try {
|
|
508
|
-
this.
|
|
614
|
+
this.usbDevice = await navigator.usb.requestDevice({
|
|
509
615
|
exclusionFilters: this.exclusionFilters,
|
|
510
616
|
filters: defaultFilters,
|
|
511
617
|
});
|
|
512
618
|
}
|
|
513
619
|
finally {
|
|
514
|
-
this.
|
|
620
|
+
this.dispatchEvent("afterrequestdevice");
|
|
515
621
|
}
|
|
516
|
-
return this.
|
|
622
|
+
return this.usbDevice;
|
|
517
623
|
}
|
|
518
624
|
eventActivated(type) {
|
|
519
625
|
switch (type) {
|
|
520
626
|
case "serialdata": {
|
|
521
|
-
// Prevent starting serial
|
|
522
|
-
if (!this.
|
|
627
|
+
// Prevent starting serial when flashing. We'll reinstate later.
|
|
628
|
+
if (!this.flashing) {
|
|
523
629
|
this.startSerialInternal();
|
|
524
630
|
}
|
|
525
|
-
this.addedListeners.serialdata++;
|
|
526
631
|
break;
|
|
527
632
|
}
|
|
528
633
|
}
|
|
@@ -530,14 +635,14 @@ class MicrobitWebUSBConnectionImpl extends events_js_1.TypedEventTarget {
|
|
|
530
635
|
async eventDeactivated(type) {
|
|
531
636
|
switch (type) {
|
|
532
637
|
case "serialdata": {
|
|
533
|
-
this.
|
|
534
|
-
if (!this.addedListeners.serialdata) {
|
|
535
|
-
this.stopSerialInternal();
|
|
536
|
-
}
|
|
638
|
+
this.stopSerialInternal();
|
|
537
639
|
break;
|
|
538
640
|
}
|
|
539
641
|
}
|
|
540
642
|
}
|
|
643
|
+
hasSerialEventListeners() {
|
|
644
|
+
return this.getActiveEvents().includes("serialdata");
|
|
645
|
+
}
|
|
541
646
|
}
|
|
542
647
|
/**
|
|
543
648
|
* Applying WebUSB device filter. Exported for testing.
|
|
@@ -583,66 +688,42 @@ const hasMatchingInterface = (device, filter) => {
|
|
|
583
688
|
});
|
|
584
689
|
});
|
|
585
690
|
};
|
|
586
|
-
const genericErrorSuggestingReconnect = (e) => new device_js_1.DeviceError({
|
|
587
|
-
code: "reconnect-microbit",
|
|
588
|
-
message: e.message,
|
|
589
|
-
});
|
|
590
|
-
// tslint:disable-next-line: no-any
|
|
591
691
|
const enrichedError = (err) => {
|
|
592
692
|
if (err instanceof device_js_1.DeviceError) {
|
|
593
693
|
return err;
|
|
594
694
|
}
|
|
595
|
-
if (err instanceof
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
err = err.reason;
|
|
606
|
-
}
|
|
607
|
-
// This is somewhat fragile but worth it for scenario specific errors.
|
|
608
|
-
// These messages changed to be prefixed in 2023 so we've relaxed the checks.
|
|
609
|
-
if (/No valid interfaces found/.test(err.message)) {
|
|
610
|
-
// This comes from DAPjs's WebUSB open.
|
|
611
|
-
return new device_js_1.DeviceError({
|
|
612
|
-
code: "update-req",
|
|
613
|
-
message: err.message,
|
|
614
|
-
});
|
|
615
|
-
}
|
|
616
|
-
else if (/No device selected/.test(err.message)) {
|
|
617
|
-
return new device_js_1.DeviceError({
|
|
618
|
-
code: "no-device-selected",
|
|
619
|
-
message: err.message,
|
|
620
|
-
});
|
|
621
|
-
}
|
|
622
|
-
else if (/Unable to claim interface/.test(err.message)) {
|
|
623
|
-
return new device_js_1.DeviceError({
|
|
624
|
-
code: "clear-connect",
|
|
625
|
-
message: err.message,
|
|
626
|
-
});
|
|
627
|
-
}
|
|
628
|
-
else if (err.name === "device-disconnected") {
|
|
629
|
-
return new device_js_1.DeviceError({
|
|
630
|
-
code: "device-disconnected",
|
|
631
|
-
message: err.message,
|
|
632
|
-
});
|
|
633
|
-
}
|
|
634
|
-
else {
|
|
635
|
-
// Unhandled error. User will need to reconnect their micro:bit
|
|
636
|
-
return genericErrorSuggestingReconnect(err);
|
|
637
|
-
}
|
|
638
|
-
case "string": {
|
|
639
|
-
// Caught a string. Example case: "Flash error" from DAPjs
|
|
640
|
-
return genericErrorSuggestingReconnect(err);
|
|
695
|
+
if (err instanceof Error) {
|
|
696
|
+
// Match Chromium WebUSB DOMException messages for user-friendly error codes.
|
|
697
|
+
// These are hardcoded English strings in Chromium (not localized).
|
|
698
|
+
// https://chromium.googlesource.com/chromium/src/+/main/third_party/blink/renderer/modules/webusb/usb.cc
|
|
699
|
+
if (/No device selected/.test(err.message)) {
|
|
700
|
+
return new device_js_1.DeviceError({
|
|
701
|
+
code: "no-device-selected",
|
|
702
|
+
message: err.message,
|
|
703
|
+
cause: err,
|
|
704
|
+
});
|
|
641
705
|
}
|
|
642
|
-
|
|
643
|
-
|
|
706
|
+
// https://chromium.googlesource.com/chromium/src/+/main/third_party/blink/renderer/modules/webusb/usb_device.cc
|
|
707
|
+
if (/Unable to claim interface/.test(err.message)) {
|
|
708
|
+
return new device_js_1.DeviceError({
|
|
709
|
+
code: "device-in-use",
|
|
710
|
+
message: err.message,
|
|
711
|
+
cause: err,
|
|
712
|
+
});
|
|
713
|
+
}
|
|
714
|
+
if (/The device was disconnected/.test(err.message)) {
|
|
715
|
+
return new device_js_1.DeviceError({
|
|
716
|
+
code: "device-disconnected",
|
|
717
|
+
message: err.message,
|
|
718
|
+
cause: err,
|
|
719
|
+
});
|
|
644
720
|
}
|
|
645
721
|
}
|
|
722
|
+
return new device_js_1.DeviceError({
|
|
723
|
+
code: "connection-error",
|
|
724
|
+
message: err.message,
|
|
725
|
+
cause: err,
|
|
726
|
+
});
|
|
646
727
|
};
|
|
647
728
|
const rateLimitProgress = (minimumProgressIncrement, callback) => {
|
|
648
729
|
let lastCallValue = -1;
|
|
@@ -659,4 +740,4 @@ const rateLimitProgress = (minimumProgressIncrement, callback) => {
|
|
|
659
740
|
}
|
|
660
741
|
};
|
|
661
742
|
};
|
|
662
|
-
//# sourceMappingURL=
|
|
743
|
+
//# sourceMappingURL=connection.js.map
|