@microbit/microbit-connection 0.9.0-apps.alpha.9 → 1.0.0-beta.0
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/README.md +106 -27
- package/build/cjs/async-util.d.ts +3 -1
- package/build/cjs/async-util.js +5 -1
- package/build/cjs/async-util.js.map +1 -1
- package/build/cjs/availability.js.map +1 -1
- package/build/cjs/bluetooth/ble-error.d.ts +10 -0
- package/build/cjs/bluetooth/ble-error.js +47 -0
- package/build/cjs/bluetooth/ble-error.js.map +1 -0
- package/build/cjs/bluetooth/connection.d.ts +378 -0
- package/build/cjs/bluetooth/connection.js +623 -0
- package/build/cjs/bluetooth/connection.js.map +1 -0
- package/build/cjs/bluetooth/device-bond-state.d.ts +14 -0
- package/build/cjs/bluetooth/device-bond-state.js +26 -0
- package/build/cjs/bluetooth/device-bond-state.js.map +1 -0
- package/build/cjs/{bluetooth-device-wrapper.d.ts → bluetooth/device-wrapper.d.ts} +36 -21
- package/build/cjs/{bluetooth-device-wrapper.js → bluetooth/device-wrapper.js} +174 -147
- package/build/cjs/bluetooth/device-wrapper.js.map +1 -0
- package/build/{esm → cjs/bluetooth}/flashing/flashing-full.d.ts +2 -2
- package/build/cjs/{flashing → bluetooth/flashing}/flashing-full.js +6 -5
- package/build/cjs/bluetooth/flashing/flashing-full.js.map +1 -0
- package/build/cjs/bluetooth/flashing/flashing-makecode.d.ts +10 -0
- package/build/cjs/{flashing → bluetooth/flashing}/flashing-makecode.js +5 -2
- package/build/cjs/bluetooth/flashing/flashing-makecode.js.map +1 -0
- package/build/cjs/bluetooth/flashing/flashing-partial.d.ts +10 -0
- package/build/cjs/bluetooth/flashing/flashing-partial.js +145 -0
- package/build/cjs/bluetooth/flashing/flashing-partial.js.map +1 -0
- package/build/cjs/bluetooth/flashing/flashing-v1.js.map +1 -0
- package/build/cjs/{flashing → bluetooth/flashing}/nordic-dfu.d.ts +2 -2
- package/build/cjs/{flashing → bluetooth/flashing}/nordic-dfu.js +40 -14
- package/build/cjs/bluetooth/flashing/nordic-dfu.js.map +1 -0
- package/build/cjs/bluetooth/flashing/zip.js.map +1 -0
- package/build/cjs/bluetooth/index.d.ts +5 -0
- package/build/cjs/bluetooth/index.js +9 -0
- package/build/cjs/bluetooth/index.js.map +1 -0
- package/build/cjs/{bluetooth-profile.d.ts → bluetooth/profile.d.ts} +8 -0
- package/build/cjs/{bluetooth-profile.js → bluetooth/profile.js} +7 -1
- package/build/cjs/bluetooth/profile.js.map +1 -0
- package/build/cjs/{accelerometer-service.d.ts → bluetooth/services/accelerometer-service.d.ts} +2 -3
- package/build/cjs/{accelerometer-service.js → bluetooth/services/accelerometer-service.js} +17 -12
- package/build/cjs/bluetooth/services/accelerometer-service.js.map +1 -0
- package/build/{esm → cjs/bluetooth/services}/button-service.d.ts +2 -3
- package/build/cjs/{button-service.js → bluetooth/services/button-service.js} +24 -14
- package/build/cjs/bluetooth/services/button-service.js.map +1 -0
- package/build/{esm → cjs/bluetooth/services}/device-information-service.d.ts +1 -1
- package/build/cjs/bluetooth/services/device-information-service.js +29 -0
- package/build/cjs/bluetooth/services/device-information-service.js.map +1 -0
- package/build/cjs/{dfu-service.js → bluetooth/services/dfu-service.js} +2 -2
- package/build/cjs/bluetooth/services/dfu-service.js.map +1 -0
- package/build/cjs/bluetooth/services/event-service.d.ts +48 -0
- package/build/cjs/bluetooth/services/event-service.js +273 -0
- package/build/cjs/bluetooth/services/event-service.js.map +1 -0
- package/build/cjs/bluetooth/services/io-pin-service.d.ts +65 -0
- package/build/cjs/bluetooth/services/io-pin-service.js +173 -0
- package/build/cjs/bluetooth/services/io-pin-service.js.map +1 -0
- package/build/{esm → cjs/bluetooth/services}/led-service.d.ts +2 -3
- package/build/cjs/{led-service.js → bluetooth/services/led-service.js} +10 -7
- package/build/cjs/bluetooth/services/led-service.js.map +1 -0
- package/build/cjs/{magnetometer-service.d.ts → bluetooth/services/magnetometer-service.d.ts} +2 -3
- package/build/cjs/{magnetometer-service.js → bluetooth/services/magnetometer-service.js} +19 -14
- package/build/cjs/bluetooth/services/magnetometer-service.js.map +1 -0
- package/build/{esm → cjs/bluetooth/services}/partial-flashing-service.d.ts +1 -1
- package/build/cjs/{partial-flashing-service.js → bluetooth/services/partial-flashing-service.js} +8 -8
- package/build/cjs/bluetooth/services/partial-flashing-service.js.map +1 -0
- package/build/cjs/bluetooth/services/temperature-service.d.ts +14 -0
- package/build/cjs/bluetooth/services/temperature-service.js +80 -0
- package/build/cjs/bluetooth/services/temperature-service.js.map +1 -0
- package/build/cjs/{uart-service.d.ts → bluetooth/services/uart-service.d.ts} +2 -2
- package/build/cjs/{uart-service.js → bluetooth/services/uart-service.js} +21 -9
- package/build/cjs/bluetooth/services/uart-service.js.map +1 -0
- package/build/cjs/board-id.d.ts +1 -1
- package/build/cjs/board-id.js.map +1 -1
- package/build/cjs/device.d.ts +191 -101
- package/build/cjs/device.js +47 -110
- package/build/cjs/device.js.map +1 -1
- package/build/cjs/events.d.ts +8 -108
- package/build/cjs/events.js +27 -88
- package/build/cjs/events.js.map +1 -1
- package/build/cjs/hex-util.d.ts +1 -0
- package/build/cjs/hex-util.js +15 -0
- package/build/cjs/hex-util.js.map +1 -0
- package/build/cjs/index.d.ts +8 -16
- package/build/cjs/index.js +9 -28
- package/build/cjs/index.js.map +1 -1
- package/build/cjs/logging.js.map +1 -1
- package/build/cjs/microbit-events.d.ts +67 -0
- package/build/cjs/microbit-events.js +55 -0
- package/build/cjs/microbit-events.js.map +1 -0
- package/build/cjs/radio-bridge/connection.d.ts +52 -0
- package/build/cjs/{usb-radio-bridge.js → radio-bridge/connection.js} +84 -96
- package/build/cjs/radio-bridge/connection.js.map +1 -0
- package/build/cjs/radio-bridge/index.d.ts +4 -0
- package/build/cjs/radio-bridge/index.js +9 -0
- package/build/cjs/radio-bridge/index.js.map +1 -0
- package/build/cjs/{usb-serial-protocol.js → radio-bridge/serial-protocol.js} +1 -1
- package/build/cjs/radio-bridge/serial-protocol.js.map +1 -0
- package/build/cjs/service-events.d.ts +92 -15
- package/build/cjs/service-events.js +6 -36
- package/build/cjs/service-events.js.map +1 -1
- package/build/{esm/hex-flash-data-source.d.ts → cjs/universal-hex/flash-data-source.d.ts} +1 -1
- package/build/cjs/{hex-flash-data-source.js → universal-hex/flash-data-source.js} +6 -3
- package/build/cjs/universal-hex/flash-data-source.js.map +1 -0
- package/build/cjs/universal-hex/index.d.ts +4 -0
- package/build/cjs/universal-hex/index.js +9 -0
- package/build/cjs/universal-hex/index.js.map +1 -0
- package/build/cjs/usb/arm-debug.d.ts +137 -0
- package/build/cjs/usb/arm-debug.js +414 -0
- package/build/cjs/usb/arm-debug.js.map +1 -0
- package/build/{esm → cjs/usb}/board-serial-info.d.ts +2 -1
- package/build/cjs/{board-serial-info.js → usb/board-serial-info.js} +10 -7
- package/build/cjs/usb/board-serial-info.js.map +1 -0
- package/build/cjs/usb/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/connection.d.ts +96 -0
- package/build/cjs/{usb.js → usb/connection.js} +257 -173
- package/build/cjs/usb/connection.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/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/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} +37 -11
- package/build/cjs/{usb-partial-flashing.js → usb/partial-flashing.js} +170 -134
- package/build/cjs/usb/partial-flashing.js.map +1 -0
- package/build/cjs/usb/promise-queue.js.map +1 -0
- package/build/cjs/usb/serial-events.d.ts +16 -0
- package/build/cjs/{led.js → usb/serial-events.js} +1 -1
- package/build/cjs/usb/serial-events.js.map +1 -0
- package/build/cjs/usb/transport.d.ts +42 -0
- package/build/cjs/usb/transport.js +155 -0
- package/build/cjs/usb/transport.js.map +1 -0
- package/build/esm/async-util.d.ts +3 -1
- package/build/esm/async-util.js +5 -1
- package/build/esm/async-util.js.map +1 -1
- package/build/esm/availability.js.map +1 -1
- package/build/esm/bluetooth/ble-error.d.ts +10 -0
- package/build/esm/bluetooth/ble-error.js +42 -0
- package/build/esm/bluetooth/ble-error.js.map +1 -0
- package/build/esm/bluetooth/connection.d.ts +378 -0
- package/build/esm/bluetooth/connection.js +593 -0
- package/build/esm/bluetooth/connection.js.map +1 -0
- package/build/esm/bluetooth/device-bond-state.d.ts +14 -0
- package/build/esm/bluetooth/device-bond-state.js +22 -0
- package/build/esm/bluetooth/device-bond-state.js.map +1 -0
- package/build/esm/{bluetooth-device-wrapper.d.ts → bluetooth/device-wrapper.d.ts} +36 -21
- package/build/esm/{bluetooth-device-wrapper.js → bluetooth/device-wrapper.js} +172 -146
- package/build/esm/bluetooth/device-wrapper.js.map +1 -0
- package/build/{cjs → esm/bluetooth}/flashing/flashing-full.d.ts +2 -2
- package/build/esm/{flashing → bluetooth/flashing}/flashing-full.js +6 -5
- package/build/esm/bluetooth/flashing/flashing-full.js.map +1 -0
- package/build/esm/bluetooth/flashing/flashing-makecode.d.ts +10 -0
- package/build/esm/{flashing → bluetooth/flashing}/flashing-makecode.js +5 -2
- package/build/esm/bluetooth/flashing/flashing-makecode.js.map +1 -0
- package/build/esm/bluetooth/flashing/flashing-partial.d.ts +10 -0
- package/build/esm/bluetooth/flashing/flashing-partial.js +142 -0
- package/build/esm/bluetooth/flashing/flashing-partial.js.map +1 -0
- package/build/esm/bluetooth/flashing/flashing-v1.js.map +1 -0
- package/build/esm/{flashing → bluetooth/flashing}/nordic-dfu.d.ts +2 -2
- package/build/esm/{flashing → bluetooth/flashing}/nordic-dfu.js +40 -14
- package/build/esm/bluetooth/flashing/nordic-dfu.js.map +1 -0
- package/build/esm/bluetooth/flashing/zip.js.map +1 -0
- package/build/esm/bluetooth/index.d.ts +5 -0
- package/build/esm/bluetooth/index.js +5 -0
- package/build/esm/bluetooth/index.js.map +1 -0
- package/build/esm/{bluetooth-profile.d.ts → bluetooth/profile.d.ts} +8 -0
- package/build/esm/{bluetooth-profile.js → bluetooth/profile.js} +7 -1
- package/build/{cjs/bluetooth-profile.js.map → esm/bluetooth/profile.js.map} +1 -1
- package/build/esm/{accelerometer-service.d.ts → bluetooth/services/accelerometer-service.d.ts} +2 -3
- package/build/esm/{accelerometer-service.js → bluetooth/services/accelerometer-service.js} +11 -6
- package/build/esm/bluetooth/services/accelerometer-service.js.map +1 -0
- package/build/{cjs → esm/bluetooth/services}/button-service.d.ts +2 -3
- package/build/esm/{button-service.js → bluetooth/services/button-service.js} +20 -10
- package/build/esm/bluetooth/services/button-service.js.map +1 -0
- package/build/{cjs → esm/bluetooth/services}/device-information-service.d.ts +1 -1
- package/build/esm/bluetooth/services/device-information-service.js +25 -0
- package/build/esm/bluetooth/services/device-information-service.js.map +1 -0
- package/build/esm/{dfu-service.js → bluetooth/services/dfu-service.js} +1 -1
- package/build/esm/bluetooth/services/dfu-service.js.map +1 -0
- package/build/esm/bluetooth/services/event-service.d.ts +48 -0
- package/build/esm/bluetooth/services/event-service.js +269 -0
- package/build/esm/bluetooth/services/event-service.js.map +1 -0
- package/build/esm/bluetooth/services/io-pin-service.d.ts +65 -0
- package/build/esm/bluetooth/services/io-pin-service.js +169 -0
- package/build/esm/bluetooth/services/io-pin-service.js.map +1 -0
- package/build/{cjs → esm/bluetooth/services}/led-service.d.ts +2 -3
- package/build/esm/{led-service.js → bluetooth/services/led-service.js} +4 -1
- package/build/esm/bluetooth/services/led-service.js.map +1 -0
- package/build/esm/{magnetometer-service.d.ts → bluetooth/services/magnetometer-service.d.ts} +2 -3
- package/build/esm/{magnetometer-service.js → bluetooth/services/magnetometer-service.js} +11 -6
- package/build/esm/bluetooth/services/magnetometer-service.js.map +1 -0
- package/build/{cjs → esm/bluetooth/services}/partial-flashing-service.d.ts +1 -1
- package/build/esm/{partial-flashing-service.js → bluetooth/services/partial-flashing-service.js} +4 -4
- package/build/esm/bluetooth/services/partial-flashing-service.js.map +1 -0
- package/build/esm/bluetooth/services/temperature-service.d.ts +14 -0
- package/build/esm/bluetooth/services/temperature-service.js +76 -0
- package/build/esm/bluetooth/services/temperature-service.js.map +1 -0
- package/build/esm/{uart-service.d.ts → bluetooth/services/uart-service.d.ts} +2 -2
- package/build/esm/{uart-service.js → bluetooth/services/uart-service.js} +18 -6
- package/build/esm/bluetooth/services/uart-service.js.map +1 -0
- package/build/esm/board-id.d.ts +1 -1
- package/build/esm/board-id.js.map +1 -1
- package/build/esm/device.d.ts +191 -101
- package/build/esm/device.js +45 -104
- package/build/esm/device.js.map +1 -1
- package/build/esm/events.d.ts +8 -108
- package/build/esm/events.js +26 -86
- package/build/esm/events.js.map +1 -1
- package/build/esm/hex-util.d.ts +1 -0
- package/build/esm/hex-util.js +11 -0
- package/build/esm/hex-util.js.map +1 -0
- package/build/esm/index.d.ts +8 -16
- package/build/esm/index.js +7 -11
- package/build/esm/index.js.map +1 -1
- package/build/esm/logging.js.map +1 -1
- package/build/esm/microbit-events.d.ts +67 -0
- package/build/esm/microbit-events.js +52 -0
- package/build/esm/microbit-events.js.map +1 -0
- package/build/esm/radio-bridge/connection.d.ts +52 -0
- package/build/esm/{usb-radio-bridge.js → radio-bridge/connection.js} +84 -96
- package/build/esm/radio-bridge/connection.js.map +1 -0
- package/build/esm/radio-bridge/index.d.ts +4 -0
- package/build/esm/radio-bridge/index.js +5 -0
- package/build/esm/radio-bridge/index.js.map +1 -0
- package/build/esm/{usb-serial-protocol.js → radio-bridge/serial-protocol.js} +1 -1
- package/build/esm/radio-bridge/serial-protocol.js.map +1 -0
- package/build/esm/service-events.d.ts +92 -15
- package/build/esm/service-events.js +5 -34
- package/build/esm/service-events.js.map +1 -1
- package/build/{cjs/hex-flash-data-source.d.ts → esm/universal-hex/flash-data-source.d.ts} +1 -1
- package/build/esm/{hex-flash-data-source.js → universal-hex/flash-data-source.js} +6 -3
- package/build/esm/universal-hex/flash-data-source.js.map +1 -0
- package/build/esm/universal-hex/index.d.ts +4 -0
- package/build/esm/universal-hex/index.js +5 -0
- package/build/esm/universal-hex/index.js.map +1 -0
- package/build/esm/usb/arm-debug.d.ts +137 -0
- package/build/esm/usb/arm-debug.js +409 -0
- package/build/esm/usb/arm-debug.js.map +1 -0
- package/build/{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/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/connection.d.ts +96 -0
- package/build/esm/{usb.js → usb/connection.js} +253 -168
- package/build/esm/usb/connection.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/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/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} +37 -11
- package/build/esm/{usb-partial-flashing.js → usb/partial-flashing.js} +169 -110
- package/build/esm/usb/partial-flashing.js.map +1 -0
- package/build/esm/usb/promise-queue.js.map +1 -0
- package/build/esm/usb/serial-events.d.ts +16 -0
- package/build/esm/usb/serial-events.js +2 -0
- package/build/esm/usb/serial-events.js.map +1 -0
- package/build/esm/usb/transport.d.ts +42 -0
- package/build/esm/usb/transport.js +151 -0
- package/build/esm/usb/transport.js.map +1 -0
- package/package.json +61 -14
- package/build/cjs/accelerometer-service.js.map +0 -1
- package/build/cjs/accelerometer.d.ts +0 -9
- package/build/cjs/accelerometer.js +0 -16
- package/build/cjs/accelerometer.js.map +0 -1
- package/build/cjs/bluetooth-device-wrapper.js.map +0 -1
- package/build/cjs/bluetooth.d.ts +0 -112
- package/build/cjs/bluetooth.js +0 -457
- package/build/cjs/bluetooth.js.map +0 -1
- package/build/cjs/board-serial-info.js.map +0 -1
- package/build/cjs/button-service.js.map +0 -1
- package/build/cjs/buttons.d.ts +0 -10
- package/build/cjs/buttons.js +0 -22
- package/build/cjs/buttons.js.map +0 -1
- package/build/cjs/constants.d.ts +0 -48
- package/build/cjs/constants.js +0 -73
- package/build/cjs/constants.js.map +0 -1
- package/build/cjs/device-information-service.js +0 -34
- package/build/cjs/device-information-service.js.map +0 -1
- package/build/cjs/dfu-service.js.map +0 -1
- package/build/cjs/flashing/flashing-full.js.map +0 -1
- package/build/cjs/flashing/flashing-makecode.d.ts +0 -6
- package/build/cjs/flashing/flashing-makecode.js.map +0 -1
- package/build/cjs/flashing/flashing-partial.d.ts +0 -9
- package/build/cjs/flashing/flashing-partial.js +0 -98
- package/build/cjs/flashing/flashing-partial.js.map +0 -1
- package/build/cjs/flashing/flashing-v1.js.map +0 -1
- package/build/cjs/flashing/nordic-dfu.js.map +0 -1
- package/build/cjs/flashing/zip.js.map +0 -1
- package/build/cjs/hex-flash-data-source.js.map +0 -1
- package/build/cjs/led-service.js.map +0 -1
- package/build/cjs/led.d.ts +0 -6
- package/build/cjs/led.js.map +0 -1
- package/build/cjs/magnetometer-service.js.map +0 -1
- package/build/cjs/magnetometer.d.ts +0 -9
- package/build/cjs/magnetometer.js +0 -16
- package/build/cjs/magnetometer.js.map +0 -1
- package/build/cjs/partial-flashing-service.js.map +0 -1
- package/build/cjs/promise-queue.js.map +0 -1
- package/build/cjs/serial-events.d.ts +0 -20
- package/build/cjs/serial-events.js +0 -69
- package/build/cjs/serial-events.js.map +0 -1
- package/build/cjs/setupTests.d.ts +0 -6
- package/build/cjs/setupTests.js.map +0 -1
- package/build/cjs/uart-service.js.map +0 -1
- package/build/cjs/uart.d.ts +0 -4
- package/build/cjs/uart.js +0 -16
- package/build/cjs/uart.js.map +0 -1
- package/build/cjs/usb-device-wrapper.d.ts +0 -47
- package/build/cjs/usb-device-wrapper.js +0 -437
- package/build/cjs/usb-device-wrapper.js.map +0 -1
- package/build/cjs/usb-partial-flashing-utils.js.map +0 -1
- package/build/cjs/usb-partial-flashing.js.map +0 -1
- package/build/cjs/usb-radio-bridge.d.ts +0 -24
- package/build/cjs/usb-radio-bridge.js.map +0 -1
- package/build/cjs/usb-serial-protocol.js.map +0 -1
- package/build/cjs/usb.d.ts +0 -66
- package/build/cjs/usb.js.map +0 -1
- package/build/esm/accelerometer-service.js.map +0 -1
- package/build/esm/accelerometer.d.ts +0 -9
- package/build/esm/accelerometer.js +0 -12
- package/build/esm/accelerometer.js.map +0 -1
- package/build/esm/bluetooth-device-wrapper.js.map +0 -1
- package/build/esm/bluetooth-profile.js.map +0 -1
- package/build/esm/bluetooth.d.ts +0 -112
- package/build/esm/bluetooth.js +0 -427
- package/build/esm/bluetooth.js.map +0 -1
- package/build/esm/board-serial-info.js.map +0 -1
- package/build/esm/button-service.js.map +0 -1
- package/build/esm/buttons.d.ts +0 -10
- package/build/esm/buttons.js +0 -18
- package/build/esm/buttons.js.map +0 -1
- package/build/esm/constants.d.ts +0 -48
- package/build/esm/constants.js +0 -70
- package/build/esm/constants.js.map +0 -1
- package/build/esm/device-information-service.js +0 -30
- package/build/esm/device-information-service.js.map +0 -1
- package/build/esm/dfu-service.js.map +0 -1
- package/build/esm/flashing/flashing-full.js.map +0 -1
- package/build/esm/flashing/flashing-makecode.d.ts +0 -6
- package/build/esm/flashing/flashing-makecode.js.map +0 -1
- package/build/esm/flashing/flashing-partial.d.ts +0 -9
- package/build/esm/flashing/flashing-partial.js +0 -95
- package/build/esm/flashing/flashing-partial.js.map +0 -1
- package/build/esm/flashing/flashing-v1.js.map +0 -1
- package/build/esm/flashing/nordic-dfu.js.map +0 -1
- package/build/esm/flashing/zip.js.map +0 -1
- package/build/esm/hex-flash-data-source.js.map +0 -1
- package/build/esm/led-service.js.map +0 -1
- package/build/esm/led.d.ts +0 -6
- package/build/esm/led.js +0 -2
- package/build/esm/led.js.map +0 -1
- package/build/esm/magnetometer-service.js.map +0 -1
- package/build/esm/magnetometer.d.ts +0 -9
- package/build/esm/magnetometer.js +0 -12
- package/build/esm/magnetometer.js.map +0 -1
- package/build/esm/partial-flashing-service.js.map +0 -1
- package/build/esm/promise-queue.js.map +0 -1
- package/build/esm/serial-events.d.ts +0 -20
- package/build/esm/serial-events.js +0 -61
- package/build/esm/serial-events.js.map +0 -1
- package/build/esm/setupTests.d.ts +0 -6
- package/build/esm/setupTests.js.map +0 -1
- package/build/esm/uart-service.js.map +0 -1
- package/build/esm/uart.d.ts +0 -4
- package/build/esm/uart.js +0 -12
- package/build/esm/uart.js.map +0 -1
- package/build/esm/usb-device-wrapper.d.ts +0 -47
- package/build/esm/usb-device-wrapper.js +0 -410
- package/build/esm/usb-device-wrapper.js.map +0 -1
- package/build/esm/usb-partial-flashing-utils.js.map +0 -1
- package/build/esm/usb-partial-flashing.js.map +0 -1
- package/build/esm/usb-radio-bridge.d.ts +0 -24
- package/build/esm/usb-radio-bridge.js.map +0 -1
- package/build/esm/usb-serial-protocol.js.map +0 -1
- package/build/esm/usb.d.ts +0 -66
- package/build/esm/usb.js.map +0 -1
- package/typedoc.json +0 -14
- /package/build/cjs/{flashing → bluetooth/flashing}/flashing-v1.d.ts +0 -0
- /package/build/cjs/{flashing → bluetooth/flashing}/flashing-v1.js +0 -0
- /package/build/cjs/{flashing → bluetooth/flashing}/zip.d.ts +0 -0
- /package/build/cjs/{flashing → bluetooth/flashing}/zip.js +0 -0
- /package/build/cjs/{dfu-service.d.ts → bluetooth/services/dfu-service.d.ts} +0 -0
- /package/build/cjs/{usb-serial-protocol.d.ts → radio-bridge/serial-protocol.d.ts} +0 -0
- /package/build/cjs/{promise-queue.d.ts → usb/promise-queue.d.ts} +0 -0
- /package/build/cjs/{promise-queue.js → usb/promise-queue.js} +0 -0
- /package/build/esm/{flashing → bluetooth/flashing}/flashing-v1.d.ts +0 -0
- /package/build/esm/{flashing → bluetooth/flashing}/flashing-v1.js +0 -0
- /package/build/esm/{flashing → bluetooth/flashing}/zip.d.ts +0 -0
- /package/build/esm/{flashing → bluetooth/flashing}/zip.js +0 -0
- /package/build/esm/{dfu-service.d.ts → bluetooth/services/dfu-service.d.ts} +0 -0
- /package/build/esm/{usb-serial-protocol.d.ts → radio-bridge/serial-protocol.d.ts} +0 -0
- /package/build/esm/{promise-queue.d.ts → usb/promise-queue.d.ts} +0 -0
- /package/build/esm/{promise-queue.js → usb/promise-queue.js} +0 -0
package/README.md
CHANGED
|
@@ -2,39 +2,59 @@
|
|
|
2
2
|
|
|
3
3
|
<a href="https://microbit-foundation.github.io/microbit-connection/" class="typedoc-ignore">This documentation is best viewed on the documentation site rather than GitHub or NPM package site.</a>
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
A TypeScript library for connecting to micro:bit devices via USB and Bluetooth. Works in browsers (via WebUSB and Web Bluetooth) and in native iOS/Android apps (Bluetooth only, via [Capacitor](https://capacitorjs.com/)).
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
[Available on NPM](https://www.npmjs.com/package/@microbit/microbit-connection). Migrating from an earlier version? See the [migration guide](https://github.com/microbit-foundation/microbit-connection/blob/main/MIGRATION.md).
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
### Demo apps
|
|
10
10
|
|
|
11
|
-
[
|
|
11
|
+
- [Demo app](https://microbit-connection.pages.dev/) ([source](https://github.com/microbit-foundation/microbit-connection/tree/main/apps/demo)) — WebUSB, Web Bluetooth, and Capacitor for native mobile
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
### Projects using this library
|
|
14
14
|
|
|
15
|
-
[
|
|
15
|
+
- [micro:bit CreateAI](https://github.com/microbit-foundation/ml-trainer/)
|
|
16
|
+
- [micro:bit Python Editor](https://github.com/microbit-foundation/python-editor-v3/)
|
|
17
|
+
|
|
18
|
+
### Platform support
|
|
19
|
+
|
|
20
|
+
| Feature | Web (browser) | Native (Capacitor) |
|
|
21
|
+
| -------------------- | ------------- | ------------------ |
|
|
22
|
+
| USB connection | WebUSB | Not supported |
|
|
23
|
+
| Bluetooth connection | Web Bluetooth | iOS and Android |
|
|
24
|
+
| Flash via USB | Yes | Not supported |
|
|
25
|
+
| Flash via Bluetooth | Not supported | iOS and Android |
|
|
26
|
+
|
|
27
|
+
## Entrypoints
|
|
28
|
+
|
|
29
|
+
The library is split into separate entrypoints for tree-shaking. Import shared types from the root and connection-specific code from subpaths:
|
|
30
|
+
|
|
31
|
+
| Import path | Contents |
|
|
32
|
+
| --------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------- |
|
|
33
|
+
| `@microbit/microbit-connection` | Shared types and events (`ConnectionStatus`, `DeviceConnection`, `FlashOptions`, etc.) |
|
|
34
|
+
| `@microbit/microbit-connection/bluetooth` | `createBluetoothConnection` and Bluetooth connection types |
|
|
35
|
+
| `@microbit/microbit-connection/usb` | `createUSBConnection` and USB connection types |
|
|
36
|
+
| `@microbit/microbit-connection/universal-hex` | `createUniversalHexFlashDataSource` (depends on `@microbit/microbit-universal-hex`) |
|
|
37
|
+
| `@microbit/microbit-connection/radio-bridge` | **Experimental.** `createRadioBridgeConnection` for radio bridge via USB. Limited service support — see JSDoc for details. |
|
|
16
38
|
|
|
17
39
|
## Usage
|
|
18
40
|
|
|
19
41
|
### Flash a micro:bit
|
|
20
42
|
|
|
21
|
-
Instantiate a WebUSB connection using {@link
|
|
43
|
+
Instantiate a WebUSB connection using {@link @microbit/microbit-connection/usb!createUSBConnection | createUSBConnection} and use it to connect to a micro:bit.
|
|
22
44
|
|
|
23
45
|
```ts
|
|
24
|
-
import {
|
|
46
|
+
import { createUSBConnection } from "@microbit/microbit-connection/usb";
|
|
25
47
|
|
|
26
|
-
const usb =
|
|
27
|
-
|
|
48
|
+
const usb = createUSBConnection();
|
|
49
|
+
await usb.connect();
|
|
28
50
|
|
|
29
|
-
console.log("Connection status: ",
|
|
51
|
+
console.log("Connection status: ", usb.status); // "Connected"
|
|
30
52
|
```
|
|
31
53
|
|
|
32
|
-
{@link ConnectionStatus | Connection status} is `"CONNECTED"` if connection succeeds.
|
|
33
|
-
|
|
34
54
|
Flash a universal hex that supports both V1 and V2:
|
|
35
55
|
|
|
36
56
|
```ts
|
|
37
|
-
import { createUniversalHexFlashDataSource } from "@microbit/microbit-connection";
|
|
57
|
+
import { createUniversalHexFlashDataSource } from "@microbit/microbit-connection/universal-hex";
|
|
38
58
|
|
|
39
59
|
await usb.flash(createUniversalHexFlashDataSource(universalHexString), {
|
|
40
60
|
partial: true,
|
|
@@ -46,13 +66,12 @@ await usb.flash(createUniversalHexFlashDataSource(universalHexString), {
|
|
|
46
66
|
|
|
47
67
|
This code will also work for non-universal hex files so is a good default for unknown hex files.
|
|
48
68
|
|
|
49
|
-
Alternatively, you can create and flash a hex for a specific micro:bit version by providing a function that takes a {@link BoardVersion} and returns a hex.
|
|
69
|
+
Alternatively, you can create and flash a hex for a specific micro:bit version by providing a function that takes a {@link @microbit/microbit-connection!BoardVersion} and returns a hex.
|
|
50
70
|
This can reduce download size or help integrate with APIs that produce a hex for a particular device version.
|
|
51
71
|
This example uses the [@microbit/microbit-fs library](https://microbit-foundation.github.io/microbit-fs/) which can return a hex based on board id.
|
|
52
72
|
|
|
53
73
|
```ts
|
|
54
74
|
import { MicropythonFsHex, microbitBoardId } from "@microbit/microbit-fs";
|
|
55
|
-
import { BoardId } from "@microbit/microbit-connection";
|
|
56
75
|
|
|
57
76
|
const micropythonFs = new MicropythonFsHex([
|
|
58
77
|
{ hex: microPythonV1HexFile, boardId: microbitBoardId.V1 },
|
|
@@ -62,8 +81,7 @@ const micropythonFs = new MicropythonFsHex([
|
|
|
62
81
|
// Flash the device
|
|
63
82
|
await usb.flash(
|
|
64
83
|
async (boardVersion) => {
|
|
65
|
-
|
|
66
|
-
return micropythonFs.getIntelHex(boardId);
|
|
84
|
+
return micropythonFs.getIntelHex(microbitBoardId[boardVersion]);
|
|
67
85
|
},
|
|
68
86
|
{
|
|
69
87
|
partial: true,
|
|
@@ -74,32 +92,93 @@ await usb.flash(
|
|
|
74
92
|
);
|
|
75
93
|
```
|
|
76
94
|
|
|
77
|
-
|
|
95
|
+
#### Post-flash connection state
|
|
96
|
+
|
|
97
|
+
The connection state after flashing differs between USB and Bluetooth because they connect to different parts of the micro:bit hardware:
|
|
98
|
+
|
|
99
|
+
- **USB** connects to the **interface chip** (running DAPLink firmware), which is separate from the application processor that runs user code. Flashing does not affect the interface chip, so the USB connection remains in `"Connected"` state and serial communication is automatically reinitialised.
|
|
100
|
+
|
|
101
|
+
- **Bluetooth** connects directly to the **application processor** (the Nordic nRF51/nRF52 running the user's program and BLE stack). This processor reboots after flashing, so the Bluetooth connection is necessarily lost. The connection is always left in `"Disconnected"` state and callers must call `connect()` again after flashing.
|
|
102
|
+
|
|
103
|
+
#### Tab visibility and the Paused state
|
|
104
|
+
|
|
105
|
+
By default, a USB connection is automatically paused when the browser tab becomes hidden and reconnected when the tab becomes visible again. This frees the USB interface for other tabs or processes while the user isn't looking at the page. During this time the connection status is `"Paused"`.
|
|
106
|
+
|
|
107
|
+
If reconnection fails when the tab becomes visible again (for example, because another process has claimed the USB interface), the connection transitions to `"Disconnected"`.
|
|
108
|
+
|
|
109
|
+
To disable this behaviour, pass `pauseOnHidden: false`:
|
|
110
|
+
|
|
111
|
+
```ts
|
|
112
|
+
const usb = createUSBConnection({ pauseOnHidden: false });
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
For more examples see the [demo app source](https://github.com/microbit-foundation/microbit-connection/tree/main/apps/demo/src).
|
|
78
116
|
|
|
79
117
|
### Connect via Bluetooth
|
|
80
118
|
|
|
81
119
|
By default, the micro:bit's Bluetooth service is not enabled. Visit our [Bluetooth tech site page](https://tech.microbit.org/bluetooth/) to download a hex file that would enable the bluetooth service.
|
|
82
120
|
|
|
83
|
-
Instantiate a Bluetooth connection using {@link
|
|
121
|
+
Instantiate a Bluetooth connection using {@link @microbit/microbit-connection/bluetooth!createBluetoothConnection | createBluetoothConnection} class and use it to connect to a micro:bit.
|
|
84
122
|
|
|
85
123
|
```ts
|
|
86
|
-
import {
|
|
124
|
+
import { createBluetoothConnection } from "@microbit/microbit-connection/bluetooth";
|
|
87
125
|
|
|
88
|
-
const bluetooth =
|
|
89
|
-
|
|
126
|
+
const bluetooth = createBluetoothConnection();
|
|
127
|
+
await bluetooth.connect();
|
|
90
128
|
|
|
91
|
-
console.log("Connection status: ",
|
|
129
|
+
console.log("Connection status: ", bluetooth.status); // "Connected"
|
|
92
130
|
```
|
|
93
131
|
|
|
94
|
-
|
|
132
|
+
For more examples see the [demo app source](https://github.com/microbit-foundation/microbit-connection/tree/main/apps/demo/src).
|
|
133
|
+
|
|
134
|
+
### Error handling
|
|
135
|
+
|
|
136
|
+
Methods that interact with device features (reading sensors, writing to LEDs, serial communication, etc.) throw a {@link @microbit/microbit-connection!DeviceError | DeviceError} with code `"not-connected"` if called without an active connection:
|
|
137
|
+
|
|
138
|
+
```ts
|
|
139
|
+
import { DeviceError } from "@microbit/microbit-connection";
|
|
140
|
+
|
|
141
|
+
try {
|
|
142
|
+
const data = await bluetooth.getAccelerometerData();
|
|
143
|
+
} catch (e) {
|
|
144
|
+
if (e instanceof DeviceError && e.code === "not-connected") {
|
|
145
|
+
console.log("Connect to a micro:bit first");
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
## Known limitations
|
|
151
|
+
|
|
152
|
+
### Bluetooth
|
|
153
|
+
|
|
154
|
+
### Open link security mode hex file already on micro:bit
|
|
155
|
+
|
|
156
|
+
Open link hex files are not common. The most common source is the micro:bit CreateAI. Known issues:
|
|
157
|
+
|
|
158
|
+
- **iOS DFU classroom collision risk with open-link firmware**: When performing DFU on iOS with open-link security firmware (no bonding), the Nordic DFU library scans for the bootloader by DFU service UUID and connects to the first matching device. If multiple micro:bits are in bootloader mode simultaneously, the wrong device could be targeted. This does not affect bonded firmware (where the bootloader uses whitelist-filtered advertising) or Android (which reconnects by MAC address).
|
|
159
|
+
|
|
160
|
+
- **V1 Android PIN dialog with open-link firmware**: On Android with micro:bit V1, calling `createBond` triggers a passkey entry dialog because the V1 DAL declares `IO_CAPS_DISPLAY_ONLY` even in open-link mode. The micro:bit displays a PIN that the user must enter. This is a bug in the V1 DAL (V2 correctly uses `IO_CAPS_NONE`). There is no BLE-visible indicator of the security mode, so the library cannot detect this situation to avoid it. On V2 you get a harmless (but somewhat pointless) "just works" pairing dialog.
|
|
161
|
+
|
|
162
|
+
### No suitable services on the micro:bit to flash
|
|
163
|
+
|
|
164
|
+
- **Hex with no partial flashing or DFU control service (V1)**: Some older CreateAI data-collection hex files for micro:bit V1 fall into this category. There's nothing that can be done via Bluetooth. Workaround: flash via WebUSB or drag and drop from a computer. The equivalent V2 hex does have the Secure DFU service (but not partial flashing) which we support.
|
|
165
|
+
|
|
166
|
+
## Hardware testing
|
|
167
|
+
|
|
168
|
+
The [hardware test app](https://github.com/microbit-foundation/microbit-connection/tree/main/apps/hardware-test) is a human-in-the-loop test runner for USB flashing. It covers partial and full flash, flash fallback paths, serial data integrity after flash, and reconnection after unplug. Run it with:
|
|
169
|
+
|
|
170
|
+
```bash
|
|
171
|
+
cd apps/hardware-test
|
|
172
|
+
npm run dev
|
|
173
|
+
```
|
|
95
174
|
|
|
96
|
-
|
|
175
|
+
The tests prompt you for physical actions (plugging/unplugging) and verify the results automatically.
|
|
97
176
|
|
|
98
177
|
## License
|
|
99
178
|
|
|
100
179
|
This software is under the MIT open source license.
|
|
101
180
|
|
|
102
|
-
[SPDX-License-Identifier: MIT](LICENSE)
|
|
181
|
+
[SPDX-License-Identifier: MIT](https://github.com/microbit-foundation/microbit-connection/blob/main/LICENSE.md)
|
|
103
182
|
|
|
104
183
|
We use dependencies via the NPM registry as specified by the package.json file under common Open Source licenses.
|
|
105
184
|
|
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
*
|
|
4
4
|
* SPDX-License-Identifier: MIT
|
|
5
5
|
*/
|
|
6
|
-
|
|
6
|
+
import { DeviceError } from "./device.js";
|
|
7
|
+
export declare class TimeoutError extends DeviceError {
|
|
8
|
+
constructor(message?: string);
|
|
7
9
|
}
|
|
8
10
|
export declare class DisconnectError extends Error {
|
|
9
11
|
constructor(message?: string);
|
package/build/cjs/async-util.js
CHANGED
|
@@ -10,7 +10,11 @@ exports.disconnectErrorCallback = disconnectErrorCallback;
|
|
|
10
10
|
*
|
|
11
11
|
* SPDX-License-Identifier: MIT
|
|
12
12
|
*/
|
|
13
|
-
|
|
13
|
+
const device_js_1 = require("./device.js");
|
|
14
|
+
class TimeoutError extends device_js_1.DeviceError {
|
|
15
|
+
constructor(message = "Timeout") {
|
|
16
|
+
super({ code: "timeout", message });
|
|
17
|
+
}
|
|
14
18
|
}
|
|
15
19
|
exports.TimeoutError = TimeoutError;
|
|
16
20
|
class DisconnectError extends Error {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"async-util.js","sourceRoot":"","sources":["../../
|
|
1
|
+
{"version":3,"file":"async-util.js","sourceRoot":"","sources":["../../src/async-util.ts"],"names":[],"mappings":";;;AAwBA,kCAQC;AAED,sBAEC;AAED,8CAMC;AAED,0DAMC;AApDD;;;;GAIG;AACH,2CAA0C;AAE1C,MAAa,YAAa,SAAQ,uBAAW;IAC3C,YAAY,UAAkB,SAAS;QACrC,KAAK,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,CAAC;IACtC,CAAC;CACF;AAJD,oCAIC;AAED,MAAa,eAAgB,SAAQ,KAAK;IACxC,YAAY,UAAkB,YAAY;QACxC,KAAK,CAAC,OAAO,CAAC,CAAC;IACjB,CAAC;CACF;AAJD,0CAIC;AAED;;;;GAIG;AACI,KAAK,UAAU,WAAW,CAC/B,aAAyB,EACzB,OAAe;IAEf,OAAO,OAAO,CAAC,IAAI,CAAC;QAClB,aAAa;QACb,iBAAiB,CAAC,OAAO,CAAC;KAC3B,CAAe,CAAC;AACnB,CAAC;AAEM,KAAK,UAAU,KAAK,CAAC,MAAc;IACxC,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC;AAC/D,CAAC;AAEM,KAAK,UAAU,iBAAiB,CACrC,MAAc,EACd,UAAkB,SAAS;IAE3B,MAAM,KAAK,CAAC,MAAM,CAAC,CAAC;IACpB,MAAM,IAAI,YAAY,CAAC,OAAO,CAAC,CAAC;AAClC,CAAC;AAED,SAAgB,uBAAuB,CAAI,UAAkB,YAAY;IACvE,IAAI,QAAgC,CAAC;IACrC,MAAM,OAAO,GAAG,IAAI,OAAO,CAAI,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE;QAC3C,QAAQ,GAAG,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,eAAe,CAAC,OAAO,CAAC,CAAC,CAAC;IACxD,CAAC,CAAC,CAAC;IACH,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAS,EAAE,CAAC;AAC1C,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"availability.js","sourceRoot":"","sources":["../../
|
|
1
|
+
{"version":3,"file":"availability.js","sourceRoot":"","sources":["../../src/availability.ts"],"names":[],"mappings":";;;AAAA;;;;GAIG;AACH,2CAAwE;AAExE;;;;;;GAMG;AACI,MAAM,kBAAkB,GAAG,CAChC,MAAoC,EAC9B,EAAE;IACR,QAAQ,MAAM,EAAE,CAAC;QACf,KAAK,WAAW;YACd,OAAO;QACT,KAAK,aAAa;YAChB,MAAM,IAAI,uBAAW,CAAC;gBACpB,IAAI,EAAE,aAAa;gBACnB,OAAO,EAAE,+BAA+B;aACzC,CAAC,CAAC;QACL,KAAK,UAAU;YACb,MAAM,IAAI,uBAAW,CAAC;gBACpB,IAAI,EAAE,UAAU;gBAChB,OAAO,EAAE,wBAAwB;aAClC,CAAC,CAAC;QACL,KAAK,mBAAmB;YACtB,MAAM,IAAI,uBAAW,CAAC;gBACpB,IAAI,EAAE,mBAAmB;gBACzB,OAAO,EAAE,mBAAmB;aAC7B,CAAC,CAAC;QACL,KAAK,mBAAmB;YACtB,MAAM,IAAI,uBAAW,CAAC;gBACpB,IAAI,EAAE,mBAAmB;gBACzB,OAAO,EAAE,4BAA4B;aACtC,CAAC,CAAC;IACP,CAAC;AACH,CAAC,CAAC;AA3BW,QAAA,kBAAkB,sBA2B7B"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { DeviceError } from "../device.js";
|
|
2
|
+
/**
|
|
3
|
+
* Maps BLE errors from @capacitor-community/bluetooth-le (and Web Bluetooth)
|
|
4
|
+
* to DeviceError with an appropriate code.
|
|
5
|
+
*/
|
|
6
|
+
export declare const mapBleError: (e: unknown) => DeviceError;
|
|
7
|
+
/**
|
|
8
|
+
* Wraps an async operation so that any BLE error is mapped to a DeviceError.
|
|
9
|
+
*/
|
|
10
|
+
export declare function withBleErrorMapping<T>(fn: () => Promise<T>): Promise<T>;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.mapBleError = void 0;
|
|
4
|
+
exports.withBleErrorMapping = withBleErrorMapping;
|
|
5
|
+
const device_js_1 = require("../device.js");
|
|
6
|
+
/**
|
|
7
|
+
* Maps BLE errors from @capacitor-community/bluetooth-le (and Web Bluetooth)
|
|
8
|
+
* to DeviceError with an appropriate code.
|
|
9
|
+
*/
|
|
10
|
+
const mapBleError = (e) => {
|
|
11
|
+
if (e instanceof device_js_1.DeviceError) {
|
|
12
|
+
return e;
|
|
13
|
+
}
|
|
14
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
15
|
+
let code = "connection-error";
|
|
16
|
+
if (e instanceof Error) {
|
|
17
|
+
// @capacitor-community/bluetooth-le error messages:
|
|
18
|
+
// https://github.com/capacitor-community/bluetooth-le/blob/main/ios/Plugin/DeviceManager.swift
|
|
19
|
+
// https://github.com/capacitor-community/bluetooth-le/blob/main/ios/Plugin/Device.swift
|
|
20
|
+
if (/timeout/i.test(message)) {
|
|
21
|
+
// BleClient throws plain Errors for its own timeouts:
|
|
22
|
+
// "Connection timeout", "Read timeout.", "Write timeout.",
|
|
23
|
+
// "Service discovery timeout.", "Disconnection timeout." etc.
|
|
24
|
+
code = "timeout";
|
|
25
|
+
}
|
|
26
|
+
else if (/disconnect/i.test(message)) {
|
|
27
|
+
code = "device-disconnected";
|
|
28
|
+
}
|
|
29
|
+
else if (/permission/i.test(message)) {
|
|
30
|
+
code = "permission-denied";
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return new device_js_1.DeviceError({ code, message, cause: e });
|
|
34
|
+
};
|
|
35
|
+
exports.mapBleError = mapBleError;
|
|
36
|
+
/**
|
|
37
|
+
* Wraps an async operation so that any BLE error is mapped to a DeviceError.
|
|
38
|
+
*/
|
|
39
|
+
async function withBleErrorMapping(fn) {
|
|
40
|
+
try {
|
|
41
|
+
return await fn();
|
|
42
|
+
}
|
|
43
|
+
catch (e) {
|
|
44
|
+
throw (0, exports.mapBleError)(e);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=ble-error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ble-error.js","sourceRoot":"","sources":["../../../src/bluetooth/ble-error.ts"],"names":[],"mappings":";;;AAoCA,kDAMC;AA1CD,4CAA4D;AAE5D;;;GAGG;AACI,MAAM,WAAW,GAAG,CAAC,CAAU,EAAe,EAAE;IACrD,IAAI,CAAC,YAAY,uBAAW,EAAE,CAAC;QAC7B,OAAO,CAAC,CAAC;IACX,CAAC;IAED,MAAM,OAAO,GAAG,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IAC3D,IAAI,IAAI,GAAoB,kBAAkB,CAAC;IAE/C,IAAI,CAAC,YAAY,KAAK,EAAE,CAAC;QACvB,oDAAoD;QACpD,+FAA+F;QAC/F,wFAAwF;QACxF,IAAI,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;YAC7B,sDAAsD;YACtD,2DAA2D;YAC3D,8DAA8D;YAC9D,IAAI,GAAG,SAAS,CAAC;QACnB,CAAC;aAAM,IAAI,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;YACvC,IAAI,GAAG,qBAAqB,CAAC;QAC/B,CAAC;aAAM,IAAI,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;YACvC,IAAI,GAAG,mBAAmB,CAAC;QAC7B,CAAC;IACH,CAAC;IAED,OAAO,IAAI,uBAAW,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC;AACtD,CAAC,CAAC;AAzBW,QAAA,WAAW,eAyBtB;AAEF;;GAEG;AACI,KAAK,UAAU,mBAAmB,CAAI,EAAoB;IAC/D,IAAI,CAAC;QACH,OAAO,MAAM,EAAE,EAAE,CAAC;IACpB,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,MAAM,IAAA,mBAAW,EAAC,CAAC,CAAC,CAAC;IACvB,CAAC;AACH,CAAC"}
|