@microbit/microbit-connection 0.9.0-apps.alpha.9 → 1.0.0-beta.1
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 +41 -15
- 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 +41 -15
- 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
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* (c) 2026, Micro:bit Educational Foundation and contributors
|
|
4
|
+
*
|
|
5
|
+
* SPDX-License-Identifier: MIT
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.DefaultDeviceBondState = void 0;
|
|
9
|
+
class DefaultDeviceBondState {
|
|
10
|
+
constructor() {
|
|
11
|
+
Object.defineProperty(this, "bondStates", {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
configurable: true,
|
|
14
|
+
writable: true,
|
|
15
|
+
value: {}
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
setBonded(id, isBonded) {
|
|
19
|
+
this.bondStates[id] = isBonded;
|
|
20
|
+
}
|
|
21
|
+
isBonded(id) {
|
|
22
|
+
return this.bondStates[id] ?? false;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.DefaultDeviceBondState = DefaultDeviceBondState;
|
|
26
|
+
//# sourceMappingURL=device-bond-state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"device-bond-state.js","sourceRoot":"","sources":["../../../src/bluetooth/device-bond-state.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAOH,MAAa,sBAAsB;IAAnC;QACU;;;;mBAAsC,EAAE;WAAC;IAOnD,CAAC;IANC,SAAS,CAAC,EAAU,EAAE,QAAiB;QACrC,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC,GAAG,QAAQ,CAAC;IACjC,CAAC;IACD,QAAQ,CAAC,EAAU;QACjB,OAAO,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC,IAAI,KAAK,CAAC;IACtC,CAAC;CACF;AARD,wDAQC"}
|
|
@@ -4,17 +4,26 @@
|
|
|
4
4
|
* SPDX-License-Identifier: MIT
|
|
5
5
|
*/
|
|
6
6
|
import { BleDevice, TimeoutOptions } from "@capacitor-community/bluetooth-le";
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
7
|
+
import { BoardVersion, ConnectOptions } from "../device.js";
|
|
8
|
+
import { Logging, LoggingEvent } from "../logging.js";
|
|
9
|
+
import { ServiceConnectionEventMap, TypedServiceEvent, TypedServiceEventDispatcher } from "../service-events.js";
|
|
10
|
+
import { DeviceBondState } from "./device-bond-state.js";
|
|
11
|
+
import { AccelerometerService } from "./services/accelerometer-service.js";
|
|
12
|
+
import { ButtonService } from "./services/button-service.js";
|
|
13
|
+
import { DeviceInformationService } from "./services/device-information-service.js";
|
|
14
|
+
import { EventService } from "./services/event-service.js";
|
|
15
|
+
import { IoPinService } from "./services/io-pin-service.js";
|
|
16
|
+
import { LedService } from "./services/led-service.js";
|
|
17
|
+
import { MagnetometerService } from "./services/magnetometer-service.js";
|
|
18
|
+
import { TemperatureService } from "./services/temperature-service.js";
|
|
19
|
+
import { UARTService } from "./services/uart-service.js";
|
|
20
|
+
/**
|
|
21
|
+
* The @capacitor-community/bluetooth-le plugin throws this message when
|
|
22
|
+
* a characteristic UUID is not found in the device's GATT table.
|
|
23
|
+
*/
|
|
24
|
+
export declare const isCharacteristicNotFoundError: (e: unknown) => boolean;
|
|
16
25
|
export declare const bondingTimeoutInMs = 40000;
|
|
17
|
-
export declare const connectTimeoutInMs =
|
|
26
|
+
export declare const connectTimeoutInMs = 10000;
|
|
18
27
|
export declare const scanningTimeoutInMs = 10000;
|
|
19
28
|
export declare const isAndroid: () => boolean;
|
|
20
29
|
export interface Service {
|
|
@@ -25,24 +34,25 @@ export interface Service {
|
|
|
25
34
|
}
|
|
26
35
|
interface ConnectCallbacks {
|
|
27
36
|
onConnecting: () => void;
|
|
28
|
-
|
|
29
|
-
onFail: () => void;
|
|
37
|
+
onDisconnect: () => void;
|
|
30
38
|
onSuccess: () => void;
|
|
31
39
|
}
|
|
32
40
|
export declare class BluetoothDeviceWrapper implements Logging {
|
|
33
|
-
readonly
|
|
41
|
+
readonly bleDevice: BleDevice;
|
|
34
42
|
private logging;
|
|
43
|
+
private deviceBondState;
|
|
35
44
|
private currentEvents;
|
|
36
45
|
private callbacks;
|
|
37
|
-
|
|
38
|
-
private connected;
|
|
39
|
-
private isReconnect;
|
|
46
|
+
connected: boolean;
|
|
40
47
|
private serviceIds;
|
|
41
48
|
accelerometer: AccelerometerService;
|
|
42
49
|
buttons: ButtonService;
|
|
43
50
|
deviceInformation: DeviceInformationService;
|
|
51
|
+
events: EventService;
|
|
52
|
+
ioPin: IoPinService;
|
|
44
53
|
led: LedService;
|
|
45
54
|
magnetometer: MagnetometerService;
|
|
55
|
+
temperature: TemperatureService;
|
|
46
56
|
uart: UARTService;
|
|
47
57
|
/**
|
|
48
58
|
* Only defined after connection.
|
|
@@ -51,13 +61,13 @@ export declare class BluetoothDeviceWrapper implements Logging {
|
|
|
51
61
|
private services;
|
|
52
62
|
private waitingForDisconnectEventCallbacks;
|
|
53
63
|
private internalNotificationListeners;
|
|
54
|
-
constructor(
|
|
55
|
-
|
|
64
|
+
constructor(bleDevice: BleDevice, logging: Logging | undefined, deviceBondState: DeviceBondState | undefined, dispatchTypedEvent: TypedServiceEventDispatcher, currentEvents: () => Array<keyof ServiceConnectionEventMap>, callbacks: ConnectCallbacks);
|
|
65
|
+
setBonded(isBonded: boolean): void;
|
|
66
|
+
connect(options?: ConnectOptions): Promise<void>;
|
|
56
67
|
private connectInternal;
|
|
57
68
|
disconnect(): Promise<void>;
|
|
58
69
|
private disconnectInternal;
|
|
59
|
-
|
|
60
|
-
handleDisconnectEvent: () => Promise<void>;
|
|
70
|
+
handleDisconnectEvent: () => void;
|
|
61
71
|
getBoardVersion(): Promise<BoardVersion>;
|
|
62
72
|
startNotifications(type: TypedServiceEvent): Promise<void>;
|
|
63
73
|
stopNotifications(type: TypedServiceEvent): Promise<void>;
|
|
@@ -81,7 +91,6 @@ export declare class BluetoothDeviceWrapper implements Logging {
|
|
|
81
91
|
raceDisconnectAndTimeout<T>(promise: Promise<T>, options?: {
|
|
82
92
|
actionName?: string;
|
|
83
93
|
timeout?: number;
|
|
84
|
-
initiallyDisconnected?: boolean;
|
|
85
94
|
}): Promise<T>;
|
|
86
95
|
private disconnectErrorPromise;
|
|
87
96
|
event(event: LoggingEvent): void;
|
|
@@ -94,5 +103,11 @@ export declare class BluetoothDeviceWrapper implements Logging {
|
|
|
94
103
|
*/
|
|
95
104
|
private connectHandlingBond;
|
|
96
105
|
private bondConnectDeviceInternal;
|
|
106
|
+
/**
|
|
107
|
+
* On iOS, accessing an encrypted characteristic triggers the pairing dialog.
|
|
108
|
+
* Try each candidate characteristic in turn until one succeeds. The error is
|
|
109
|
+
* fast (local GATT cache lookup) so there's no meaningful delay from retries.
|
|
110
|
+
*/
|
|
111
|
+
private triggerIosPairing;
|
|
97
112
|
}
|
|
98
113
|
export {};
|
|
@@ -5,53 +5,42 @@
|
|
|
5
5
|
* SPDX-License-Identifier: MIT
|
|
6
6
|
*/
|
|
7
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
exports.BluetoothDeviceWrapper = exports.isAndroid = exports.scanningTimeoutInMs = exports.connectTimeoutInMs = exports.bondingTimeoutInMs = void 0;
|
|
8
|
+
exports.BluetoothDeviceWrapper = exports.isAndroid = exports.scanningTimeoutInMs = exports.connectTimeoutInMs = exports.bondingTimeoutInMs = exports.isCharacteristicNotFoundError = void 0;
|
|
9
9
|
const bluetooth_le_1 = require("@capacitor-community/bluetooth-le");
|
|
10
10
|
const core_1 = require("@capacitor/core");
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
const
|
|
11
|
+
const async_util_js_1 = require("../async-util.js");
|
|
12
|
+
const device_js_1 = require("../device.js");
|
|
13
|
+
const logging_js_1 = require("../logging.js");
|
|
14
|
+
const device_bond_state_js_1 = require("./device-bond-state.js");
|
|
15
|
+
const profile_js_1 = require("./profile.js");
|
|
16
|
+
const accelerometer_service_js_1 = require("./services/accelerometer-service.js");
|
|
17
|
+
const button_service_js_1 = require("./services/button-service.js");
|
|
18
|
+
const device_information_service_js_1 = require("./services/device-information-service.js");
|
|
19
|
+
const event_service_js_1 = require("./services/event-service.js");
|
|
20
|
+
const io_pin_service_js_1 = require("./services/io-pin-service.js");
|
|
21
|
+
const led_service_js_1 = require("./services/led-service.js");
|
|
22
|
+
const magnetometer_service_js_1 = require("./services/magnetometer-service.js");
|
|
23
|
+
const partial_flashing_service_js_1 = require("./services/partial-flashing-service.js");
|
|
24
|
+
const temperature_service_js_1 = require("./services/temperature-service.js");
|
|
25
|
+
const uart_service_js_1 = require("./services/uart-service.js");
|
|
26
|
+
/**
|
|
27
|
+
* The @capacitor-community/bluetooth-le plugin throws this message when
|
|
28
|
+
* a characteristic UUID is not found in the device's GATT table.
|
|
29
|
+
*/
|
|
30
|
+
const isCharacteristicNotFoundError = (e) => e instanceof Error && e.message === "Characteristic not found.";
|
|
31
|
+
exports.isCharacteristicNotFoundError = isCharacteristicNotFoundError;
|
|
21
32
|
exports.bondingTimeoutInMs = 40_000;
|
|
22
|
-
exports.connectTimeoutInMs =
|
|
33
|
+
exports.connectTimeoutInMs = 10_000;
|
|
23
34
|
exports.scanningTimeoutInMs = 10_000;
|
|
24
|
-
const connectionMaxAttempts = 4;
|
|
25
35
|
const isAndroid = () => core_1.Capacitor.getPlatform() === "android";
|
|
26
36
|
exports.isAndroid = isAndroid;
|
|
27
|
-
// TODO: We've removed the support for these behaviours as we need to
|
|
28
|
-
// re-evaluate how best to support then via capacitor-ble (or reinstate
|
|
29
|
-
// the direct Web Bluetooth connection code.
|
|
30
|
-
//
|
|
31
|
-
// On ChromeOS and Mac there's no timeout and no clear way to abort
|
|
32
|
-
// device.gatt.connect(), so we accept that sometimes we'll still
|
|
33
|
-
// be trying to connect when we'd rather not be. If it succeeds when
|
|
34
|
-
// we no longer intend to be connected then we disconnect at that
|
|
35
|
-
// point. If we try to connect when a previous connection attempt is
|
|
36
|
-
// still around then we wait for it for our timeout period.
|
|
37
|
-
//
|
|
38
|
-
// On Windows it times out after 7s.
|
|
39
|
-
// https://bugs.chromium.org/p/chromium/issues/detail?id=684073
|
|
40
|
-
//
|
|
41
|
-
// Additionally we've remove the delay before trying to connect again
|
|
42
|
-
// on Windows.
|
|
43
|
-
//
|
|
44
|
-
// We also used to have a timeout around requestDevice that reloaded the page.
|
|
45
|
-
//
|
|
46
|
-
// > In some situations the Chrome device prompt simply doesn't appear so we time
|
|
47
|
-
// > this out after 30 seconds and reload the page
|
|
48
37
|
class BluetoothDeviceWrapper {
|
|
49
|
-
constructor(
|
|
50
|
-
Object.defineProperty(this, "
|
|
38
|
+
constructor(bleDevice, logging = new logging_js_1.ConsoleLogging(), deviceBondState = new device_bond_state_js_1.DefaultDeviceBondState(), dispatchTypedEvent, currentEvents, callbacks) {
|
|
39
|
+
Object.defineProperty(this, "bleDevice", {
|
|
51
40
|
enumerable: true,
|
|
52
41
|
configurable: true,
|
|
53
42
|
writable: true,
|
|
54
|
-
value:
|
|
43
|
+
value: bleDevice
|
|
55
44
|
});
|
|
56
45
|
Object.defineProperty(this, "logging", {
|
|
57
46
|
enumerable: true,
|
|
@@ -59,25 +48,23 @@ class BluetoothDeviceWrapper {
|
|
|
59
48
|
writable: true,
|
|
60
49
|
value: logging
|
|
61
50
|
});
|
|
62
|
-
Object.defineProperty(this, "
|
|
51
|
+
Object.defineProperty(this, "deviceBondState", {
|
|
63
52
|
enumerable: true,
|
|
64
53
|
configurable: true,
|
|
65
54
|
writable: true,
|
|
66
|
-
value:
|
|
55
|
+
value: deviceBondState
|
|
67
56
|
});
|
|
68
|
-
Object.defineProperty(this, "
|
|
57
|
+
Object.defineProperty(this, "currentEvents", {
|
|
69
58
|
enumerable: true,
|
|
70
59
|
configurable: true,
|
|
71
60
|
writable: true,
|
|
72
|
-
value:
|
|
61
|
+
value: currentEvents
|
|
73
62
|
});
|
|
74
|
-
|
|
75
|
-
// or reconnection itself.
|
|
76
|
-
Object.defineProperty(this, "duringExplicitConnectDisconnect", {
|
|
63
|
+
Object.defineProperty(this, "callbacks", {
|
|
77
64
|
enumerable: true,
|
|
78
65
|
configurable: true,
|
|
79
66
|
writable: true,
|
|
80
|
-
value:
|
|
67
|
+
value: callbacks
|
|
81
68
|
});
|
|
82
69
|
Object.defineProperty(this, "connected", {
|
|
83
70
|
enumerable: true,
|
|
@@ -85,12 +72,6 @@ class BluetoothDeviceWrapper {
|
|
|
85
72
|
writable: true,
|
|
86
73
|
value: false
|
|
87
74
|
});
|
|
88
|
-
Object.defineProperty(this, "isReconnect", {
|
|
89
|
-
enumerable: true,
|
|
90
|
-
configurable: true,
|
|
91
|
-
writable: true,
|
|
92
|
-
value: false
|
|
93
|
-
});
|
|
94
75
|
// Only updated after the full connection flow completes not during bond handling.
|
|
95
76
|
Object.defineProperty(this, "serviceIds", {
|
|
96
77
|
enumerable: true,
|
|
@@ -116,6 +97,18 @@ class BluetoothDeviceWrapper {
|
|
|
116
97
|
writable: true,
|
|
117
98
|
value: void 0
|
|
118
99
|
});
|
|
100
|
+
Object.defineProperty(this, "events", {
|
|
101
|
+
enumerable: true,
|
|
102
|
+
configurable: true,
|
|
103
|
+
writable: true,
|
|
104
|
+
value: void 0
|
|
105
|
+
});
|
|
106
|
+
Object.defineProperty(this, "ioPin", {
|
|
107
|
+
enumerable: true,
|
|
108
|
+
configurable: true,
|
|
109
|
+
writable: true,
|
|
110
|
+
value: void 0
|
|
111
|
+
});
|
|
119
112
|
Object.defineProperty(this, "led", {
|
|
120
113
|
enumerable: true,
|
|
121
114
|
configurable: true,
|
|
@@ -128,6 +121,12 @@ class BluetoothDeviceWrapper {
|
|
|
128
121
|
writable: true,
|
|
129
122
|
value: void 0
|
|
130
123
|
});
|
|
124
|
+
Object.defineProperty(this, "temperature", {
|
|
125
|
+
enumerable: true,
|
|
126
|
+
configurable: true,
|
|
127
|
+
writable: true,
|
|
128
|
+
value: void 0
|
|
129
|
+
});
|
|
131
130
|
Object.defineProperty(this, "uart", {
|
|
132
131
|
enumerable: true,
|
|
133
132
|
configurable: true,
|
|
@@ -165,66 +164,64 @@ class BluetoothDeviceWrapper {
|
|
|
165
164
|
enumerable: true,
|
|
166
165
|
configurable: true,
|
|
167
166
|
writable: true,
|
|
168
|
-
value:
|
|
167
|
+
value: () => {
|
|
169
168
|
this.waitingForDisconnectEventCallbacks.forEach((cb) => cb());
|
|
170
169
|
this.waitingForDisconnectEventCallbacks.length = 0;
|
|
171
170
|
this.connected = false;
|
|
172
|
-
|
|
173
|
-
if (!this.duringExplicitConnectDisconnect) {
|
|
174
|
-
this.logging.log("Bluetooth disconnected... automatically trying reconnect");
|
|
175
|
-
await this.reconnect();
|
|
176
|
-
}
|
|
177
|
-
else {
|
|
178
|
-
this.logging.log("Bluetooth disconnect ignored during explicit disconnect");
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
catch (e) {
|
|
182
|
-
this.logging.error("Bluetooth connect triggered by disconnect listener failed", e);
|
|
183
|
-
}
|
|
171
|
+
this.callbacks.onDisconnect();
|
|
184
172
|
}
|
|
185
173
|
});
|
|
186
|
-
this.accelerometer = new accelerometer_service_js_1.AccelerometerService(
|
|
187
|
-
this.buttons = new button_service_js_1.ButtonService(
|
|
188
|
-
this.deviceInformation = new device_information_service_js_1.DeviceInformationService(
|
|
189
|
-
this.
|
|
190
|
-
this.
|
|
191
|
-
this.
|
|
174
|
+
this.accelerometer = new accelerometer_service_js_1.AccelerometerService(bleDevice.deviceId, dispatchTypedEvent);
|
|
175
|
+
this.buttons = new button_service_js_1.ButtonService(bleDevice.deviceId, dispatchTypedEvent);
|
|
176
|
+
this.deviceInformation = new device_information_service_js_1.DeviceInformationService(bleDevice.deviceId);
|
|
177
|
+
this.events = new event_service_js_1.EventService(bleDevice.deviceId, dispatchTypedEvent, () => this.boardVersion);
|
|
178
|
+
this.ioPin = new io_pin_service_js_1.IoPinService(bleDevice.deviceId, dispatchTypedEvent);
|
|
179
|
+
this.led = new led_service_js_1.LedService(bleDevice.deviceId);
|
|
180
|
+
this.magnetometer = new magnetometer_service_js_1.MagnetometerService(bleDevice.deviceId, dispatchTypedEvent);
|
|
181
|
+
this.temperature = new temperature_service_js_1.TemperatureService(bleDevice.deviceId, dispatchTypedEvent);
|
|
182
|
+
this.uart = new uart_service_js_1.UARTService(bleDevice.deviceId, dispatchTypedEvent);
|
|
192
183
|
this.services = [
|
|
193
184
|
this.accelerometer,
|
|
194
185
|
this.buttons,
|
|
186
|
+
this.events,
|
|
187
|
+
this.ioPin,
|
|
195
188
|
this.led,
|
|
196
189
|
this.magnetometer,
|
|
190
|
+
this.temperature,
|
|
197
191
|
this.uart,
|
|
198
192
|
];
|
|
199
193
|
}
|
|
200
|
-
|
|
194
|
+
setBonded(isBonded) {
|
|
195
|
+
this.deviceBondState.setBonded(this.bleDevice.deviceId, isBonded);
|
|
196
|
+
}
|
|
197
|
+
async connect(options) {
|
|
198
|
+
const progress = options?.progress ?? (() => { });
|
|
201
199
|
this.logging.event({
|
|
202
|
-
type:
|
|
200
|
+
type: "Connect",
|
|
203
201
|
message: "Bluetooth connect start",
|
|
204
202
|
});
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
}
|
|
208
|
-
else {
|
|
209
|
-
this.callbacks.onConnecting();
|
|
210
|
-
}
|
|
211
|
-
this.duringExplicitConnectDisconnect++;
|
|
203
|
+
this.callbacks.onConnecting();
|
|
204
|
+
const bondMode = options?.bondMode ?? "pairing";
|
|
212
205
|
try {
|
|
213
|
-
if (core_1.Capacitor.isNativePlatform()) {
|
|
214
|
-
|
|
206
|
+
if (core_1.Capacitor.isNativePlatform() && bondMode !== "none") {
|
|
207
|
+
const isBonded = this.deviceBondState.isBonded(this.bleDevice.deviceId);
|
|
208
|
+
await this.connectHandlingBond(progress, isBonded ?? false, bondMode);
|
|
209
|
+
this.setBonded(true);
|
|
210
|
+
// We need this on Android for reconnecting after DFU.
|
|
211
|
+
await bluetooth_le_1.BleClient.discoverServices(this.bleDevice.deviceId);
|
|
215
212
|
}
|
|
216
213
|
else {
|
|
214
|
+
progress(device_js_1.ProgressStage.Connecting);
|
|
217
215
|
await this.connectInternal();
|
|
218
216
|
}
|
|
219
217
|
await this.getBoardVersion();
|
|
220
218
|
const events = this.currentEvents();
|
|
221
|
-
await bluetooth_le_1.BleClient.
|
|
222
|
-
const services = await bluetooth_le_1.BleClient.getServices(this.device.deviceId);
|
|
219
|
+
const services = await bluetooth_le_1.BleClient.getServices(this.bleDevice.deviceId);
|
|
223
220
|
this.serviceIds = new Set(services.map((s) => s.uuid));
|
|
224
221
|
this.logging.log(`Starting notifications for current events ${events}`);
|
|
225
222
|
events.forEach((e) => this.startNotifications(e));
|
|
226
223
|
this.logging.event({
|
|
227
|
-
type:
|
|
224
|
+
type: "Connect",
|
|
228
225
|
message: "Bluetooth connect success",
|
|
229
226
|
});
|
|
230
227
|
this.callbacks.onSuccess();
|
|
@@ -232,79 +229,53 @@ class BluetoothDeviceWrapper {
|
|
|
232
229
|
catch (e) {
|
|
233
230
|
this.logging.error("Bluetooth connect error", e);
|
|
234
231
|
this.logging.event({
|
|
235
|
-
type:
|
|
232
|
+
type: "Connect",
|
|
236
233
|
message: "Bluetooth connect failed",
|
|
237
234
|
});
|
|
238
235
|
await this.disconnectInternal(false);
|
|
239
|
-
this.callbacks.
|
|
236
|
+
this.callbacks.onDisconnect();
|
|
240
237
|
if (e instanceof device_js_1.DeviceError) {
|
|
241
238
|
throw e;
|
|
242
239
|
}
|
|
243
|
-
|
|
240
|
+
this.setBonded(false);
|
|
241
|
+
if (
|
|
242
|
+
// Error thrown in iOS only.
|
|
243
|
+
e instanceof Error &&
|
|
244
|
+
e.message === "Peer removed pairing information") {
|
|
244
245
|
throw new device_js_1.DeviceError({
|
|
245
|
-
code: "
|
|
246
|
-
message: e
|
|
246
|
+
code: "pairing-information-lost",
|
|
247
|
+
message: e.message,
|
|
248
|
+
cause: e,
|
|
247
249
|
});
|
|
248
250
|
}
|
|
249
251
|
throw new device_js_1.DeviceError({
|
|
250
|
-
code: "
|
|
252
|
+
code: "connection-error",
|
|
251
253
|
message: e instanceof Error ? e.message : String(e),
|
|
254
|
+
cause: e,
|
|
252
255
|
});
|
|
253
256
|
}
|
|
254
|
-
finally {
|
|
255
|
-
this.duringExplicitConnectDisconnect--;
|
|
256
|
-
// Reset isReconnect for next time
|
|
257
|
-
this.isReconnect = false;
|
|
258
|
-
}
|
|
259
257
|
}
|
|
260
258
|
async connectInternal() {
|
|
261
259
|
this.waitingForDisconnectEventCallbacks.length = 0;
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
await this.raceDisconnectAndTimeout(bluetooth_le_1.BleClient.connect(this.device.deviceId, this.handleDisconnectEvent), {
|
|
267
|
-
actionName: "connect internal",
|
|
268
|
-
timeout: exports.connectTimeoutInMs,
|
|
269
|
-
initiallyDisconnected: true,
|
|
270
|
-
});
|
|
271
|
-
this.connected = true;
|
|
272
|
-
return;
|
|
273
|
-
}
|
|
274
|
-
catch (error) {
|
|
275
|
-
const attempts = i + 1;
|
|
276
|
-
if (attempts === connectionMaxAttempts) {
|
|
277
|
-
throw error;
|
|
278
|
-
}
|
|
279
|
-
const delayDuration = Math.pow(2, i) * 1000; // 1s, 2s, 4s
|
|
280
|
-
this.logging.log(`Attempt ${attempts} failed, retrying in ${delayDuration}ms...`);
|
|
281
|
-
await (0, async_util_js_1.delay)(delayDuration);
|
|
282
|
-
}
|
|
283
|
-
}
|
|
260
|
+
await bluetooth_le_1.BleClient.connect(this.bleDevice.deviceId, this.handleDisconnectEvent, {
|
|
261
|
+
timeout: exports.connectTimeoutInMs,
|
|
262
|
+
});
|
|
263
|
+
this.connected = true;
|
|
284
264
|
}
|
|
285
265
|
async disconnect() {
|
|
286
266
|
return this.disconnectInternal(true);
|
|
287
267
|
}
|
|
288
268
|
async disconnectInternal(userTriggered) {
|
|
289
269
|
this.logging.log(`Bluetooth disconnect ${userTriggered ? "(user triggered)" : "(programmatic)"}`);
|
|
290
|
-
this.duringExplicitConnectDisconnect++;
|
|
291
270
|
try {
|
|
292
271
|
if (this.connected) {
|
|
293
|
-
await bluetooth_le_1.BleClient.disconnect(this.
|
|
272
|
+
await bluetooth_le_1.BleClient.disconnect(this.bleDevice.deviceId);
|
|
294
273
|
}
|
|
295
274
|
}
|
|
296
275
|
catch (e) {
|
|
297
276
|
this.logging.error("Bluetooth GATT disconnect error (ignored)", e);
|
|
298
277
|
// We might have already lost the connection.
|
|
299
278
|
}
|
|
300
|
-
finally {
|
|
301
|
-
this.duringExplicitConnectDisconnect--;
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
async reconnect() {
|
|
305
|
-
this.logging.log("Bluetooth reconnect");
|
|
306
|
-
this.isReconnect = true;
|
|
307
|
-
await this.connect();
|
|
308
279
|
}
|
|
309
280
|
async getBoardVersion() {
|
|
310
281
|
// We read this when we connect and it won't change.
|
|
@@ -325,7 +296,7 @@ class BluetoothDeviceWrapper {
|
|
|
325
296
|
}
|
|
326
297
|
async startInternalNotifications(serviceId, characteristicId, options) {
|
|
327
298
|
const key = this.getNotificationKey(serviceId, characteristicId);
|
|
328
|
-
await this.raceDisconnectAndTimeout(bluetooth_le_1.BleClient.startNotifications(this.
|
|
299
|
+
await this.raceDisconnectAndTimeout(bluetooth_le_1.BleClient.startNotifications(this.bleDevice.deviceId, serviceId, characteristicId, (value) => {
|
|
329
300
|
const bytes = new Uint8Array(value.buffer);
|
|
330
301
|
// Notify all registered callbacks.
|
|
331
302
|
this.internalNotificationListeners
|
|
@@ -345,7 +316,7 @@ class BluetoothDeviceWrapper {
|
|
|
345
316
|
this.internalNotificationListeners.get(key)?.delete(callback);
|
|
346
317
|
}
|
|
347
318
|
async stopInternalNotifications(serviceId, characteristicId) {
|
|
348
|
-
await bluetooth_le_1.BleClient.stopNotifications(this.
|
|
319
|
+
await bluetooth_le_1.BleClient.stopNotifications(this.bleDevice.deviceId, serviceId, characteristicId);
|
|
349
320
|
const key = this.getNotificationKey(serviceId, characteristicId);
|
|
350
321
|
this.internalNotificationListeners.delete(key);
|
|
351
322
|
}
|
|
@@ -366,7 +337,7 @@ class BluetoothDeviceWrapper {
|
|
|
366
337
|
this.subscribe(serviceId, characteristicId, notificationListener);
|
|
367
338
|
});
|
|
368
339
|
try {
|
|
369
|
-
await bluetooth_le_1.BleClient.writeWithoutResponse(this.
|
|
340
|
+
await bluetooth_le_1.BleClient.writeWithoutResponse(this.bleDevice.deviceId, serviceId, characteristicId, value);
|
|
370
341
|
return await this.raceDisconnectAndTimeout(notificationPromise, {
|
|
371
342
|
timeout: 3_000,
|
|
372
343
|
actionName: "flash notification wait",
|
|
@@ -404,7 +375,7 @@ class BluetoothDeviceWrapper {
|
|
|
404
375
|
* and general disconnection
|
|
405
376
|
*/
|
|
406
377
|
async raceDisconnectAndTimeout(promise, options = {}) {
|
|
407
|
-
if (!this.connected
|
|
378
|
+
if (!this.connected) {
|
|
408
379
|
throw new async_util_js_1.DisconnectError();
|
|
409
380
|
}
|
|
410
381
|
const actionName = options.actionName ?? "action";
|
|
@@ -436,9 +407,10 @@ class BluetoothDeviceWrapper {
|
|
|
436
407
|
* Bonds with device and handles the post-bond device state only returning
|
|
437
408
|
* when we can reattempt a connection with the device.
|
|
438
409
|
*/
|
|
439
|
-
async connectHandlingBond() {
|
|
410
|
+
async connectHandlingBond(progress, isAlreadyIosBonded, bondMode) {
|
|
411
|
+
progress(device_js_1.ProgressStage.CheckingBond);
|
|
440
412
|
const startTime = Date.now();
|
|
441
|
-
const maybeJustBonded = await this.bondConnectDeviceInternal();
|
|
413
|
+
const maybeJustBonded = await this.bondConnectDeviceInternal(isAlreadyIosBonded);
|
|
442
414
|
if (maybeJustBonded) {
|
|
443
415
|
// If we did just bond then the device disconnects after 2_000 and then
|
|
444
416
|
// resets after a further 13_000 In future we'd like a firmware change
|
|
@@ -465,18 +437,31 @@ class BluetoothDeviceWrapper {
|
|
|
465
437
|
}
|
|
466
438
|
}
|
|
467
439
|
await this.connectInternal();
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
440
|
+
try {
|
|
441
|
+
const targetMode = bondMode === "pairing"
|
|
442
|
+
? partial_flashing_service_js_1.MicroBitMode.Pairing
|
|
443
|
+
: partial_flashing_service_js_1.MicroBitMode.Application;
|
|
444
|
+
progress(device_js_1.ProgressStage.ResettingDevice);
|
|
445
|
+
this.log(`Resetting to ${bondMode} mode`);
|
|
446
|
+
const pf = new partial_flashing_service_js_1.PartialFlashingService(this);
|
|
447
|
+
await pf.resetToMode(targetMode);
|
|
448
|
+
await this.waitForDisconnect(10_000);
|
|
449
|
+
progress(device_js_1.ProgressStage.Connecting);
|
|
450
|
+
await this.connectInternal();
|
|
451
|
+
}
|
|
452
|
+
catch (e) {
|
|
453
|
+
if ((0, exports.isCharacteristicNotFoundError)(e)) {
|
|
454
|
+
this.log("Partial flashing characteristic not found, skipping reset.");
|
|
455
|
+
}
|
|
456
|
+
else {
|
|
457
|
+
throw e;
|
|
458
|
+
}
|
|
459
|
+
}
|
|
476
460
|
}
|
|
461
|
+
this.log(`Connection ready; took ${Date.now() - startTime}`);
|
|
477
462
|
}
|
|
478
|
-
async bondConnectDeviceInternal() {
|
|
479
|
-
const { deviceId } = this.
|
|
463
|
+
async bondConnectDeviceInternal(isAlreadyIosBonded) {
|
|
464
|
+
const { deviceId } = this.bleDevice;
|
|
480
465
|
if ((0, exports.isAndroid)()) {
|
|
481
466
|
let justBonded = false;
|
|
482
467
|
// This gets us a nicer pairing dialog than just going straight for the characteristic.
|
|
@@ -494,13 +479,55 @@ class BluetoothDeviceWrapper {
|
|
|
494
479
|
// need to call startNotifications again. We need to be connected to
|
|
495
480
|
// startNotifications.
|
|
496
481
|
await this.connectInternal();
|
|
482
|
+
if (!isAlreadyIosBonded) {
|
|
483
|
+
await this.triggerIosPairing({ timeout: exports.bondingTimeoutInMs });
|
|
484
|
+
}
|
|
485
|
+
return !isAlreadyIosBonded;
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
/**
|
|
489
|
+
* On iOS, accessing an encrypted characteristic triggers the pairing dialog.
|
|
490
|
+
* Try each candidate characteristic in turn until one succeeds. The error is
|
|
491
|
+
* fast (local GATT cache lookup) so there's no meaningful delay from retries.
|
|
492
|
+
*/
|
|
493
|
+
async triggerIosPairing(options) {
|
|
494
|
+
const { deviceId } = this.bleDevice;
|
|
495
|
+
// 1. Partial flashing notifications (most common case)
|
|
496
|
+
try {
|
|
497
497
|
const pf = new partial_flashing_service_js_1.PartialFlashingService(this);
|
|
498
|
-
await pf.startNotifications(
|
|
499
|
-
// We just did it now to trigger pairing at a well defined point.
|
|
498
|
+
await pf.startNotifications(options);
|
|
500
499
|
await pf.stopNotifications();
|
|
501
|
-
return
|
|
500
|
+
return;
|
|
501
|
+
}
|
|
502
|
+
catch (e) {
|
|
503
|
+
if (!(0, exports.isCharacteristicNotFoundError)(e)) {
|
|
504
|
+
throw e;
|
|
505
|
+
}
|
|
506
|
+
this.log("PF characteristic not found for pairing trigger, trying Secure DFU");
|
|
507
|
+
}
|
|
508
|
+
// 2. Nordic Secure DFU buttonless notifications (V2 without PF)
|
|
509
|
+
try {
|
|
510
|
+
await bluetooth_le_1.BleClient.startNotifications(deviceId, profile_js_1.profile.nordicSecureDfu.id, profile_js_1.profile.nordicSecureDfu.characteristics.buttonless.id, () => { }, options);
|
|
511
|
+
await bluetooth_le_1.BleClient.stopNotifications(deviceId, profile_js_1.profile.nordicSecureDfu.id, profile_js_1.profile.nordicSecureDfu.characteristics.buttonless.id);
|
|
512
|
+
return;
|
|
513
|
+
}
|
|
514
|
+
catch (e) {
|
|
515
|
+
if (!(0, exports.isCharacteristicNotFoundError)(e)) {
|
|
516
|
+
throw e;
|
|
517
|
+
}
|
|
518
|
+
this.log("Secure DFU characteristic not found for pairing trigger, trying DFU control");
|
|
519
|
+
}
|
|
520
|
+
// 3. micro:bit DFU control read (V1 without PF)
|
|
521
|
+
try {
|
|
522
|
+
await bluetooth_le_1.BleClient.read(deviceId, profile_js_1.profile.dfuControl.id, profile_js_1.profile.dfuControl.characteristics.control.id, options);
|
|
523
|
+
}
|
|
524
|
+
catch (e) {
|
|
525
|
+
if (!(0, exports.isCharacteristicNotFoundError)(e)) {
|
|
526
|
+
throw e;
|
|
527
|
+
}
|
|
528
|
+
this.log("No suitable characteristic found to trigger pairing");
|
|
502
529
|
}
|
|
503
530
|
}
|
|
504
531
|
}
|
|
505
532
|
exports.BluetoothDeviceWrapper = BluetoothDeviceWrapper;
|
|
506
|
-
//# sourceMappingURL=
|
|
533
|
+
//# sourceMappingURL=device-wrapper.js.map
|