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