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