@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.
Files changed (421) hide show
  1. package/README.md +106 -27
  2. package/build/cjs/async-util.d.ts +3 -1
  3. package/build/cjs/async-util.js +5 -1
  4. package/build/cjs/async-util.js.map +1 -1
  5. package/build/cjs/availability.js.map +1 -1
  6. package/build/cjs/bluetooth/ble-error.d.ts +10 -0
  7. package/build/cjs/bluetooth/ble-error.js +47 -0
  8. package/build/cjs/bluetooth/ble-error.js.map +1 -0
  9. package/build/cjs/bluetooth/connection.d.ts +378 -0
  10. package/build/cjs/bluetooth/connection.js +623 -0
  11. package/build/cjs/bluetooth/connection.js.map +1 -0
  12. package/build/cjs/bluetooth/device-bond-state.d.ts +14 -0
  13. package/build/cjs/bluetooth/device-bond-state.js +26 -0
  14. package/build/cjs/bluetooth/device-bond-state.js.map +1 -0
  15. package/build/cjs/{bluetooth-device-wrapper.d.ts → bluetooth/device-wrapper.d.ts} +36 -21
  16. package/build/cjs/{bluetooth-device-wrapper.js → bluetooth/device-wrapper.js} +174 -147
  17. package/build/cjs/bluetooth/device-wrapper.js.map +1 -0
  18. package/build/{esm → cjs/bluetooth}/flashing/flashing-full.d.ts +2 -2
  19. package/build/cjs/{flashing → bluetooth/flashing}/flashing-full.js +6 -5
  20. package/build/cjs/bluetooth/flashing/flashing-full.js.map +1 -0
  21. package/build/cjs/bluetooth/flashing/flashing-makecode.d.ts +10 -0
  22. package/build/cjs/{flashing → bluetooth/flashing}/flashing-makecode.js +5 -2
  23. package/build/cjs/bluetooth/flashing/flashing-makecode.js.map +1 -0
  24. package/build/cjs/bluetooth/flashing/flashing-partial.d.ts +10 -0
  25. package/build/cjs/bluetooth/flashing/flashing-partial.js +145 -0
  26. package/build/cjs/bluetooth/flashing/flashing-partial.js.map +1 -0
  27. package/build/cjs/bluetooth/flashing/flashing-v1.js.map +1 -0
  28. package/build/cjs/{flashing → bluetooth/flashing}/nordic-dfu.d.ts +2 -2
  29. package/build/cjs/{flashing → bluetooth/flashing}/nordic-dfu.js +41 -15
  30. package/build/cjs/bluetooth/flashing/nordic-dfu.js.map +1 -0
  31. package/build/cjs/bluetooth/flashing/zip.js.map +1 -0
  32. package/build/cjs/bluetooth/index.d.ts +5 -0
  33. package/build/cjs/bluetooth/index.js +9 -0
  34. package/build/cjs/bluetooth/index.js.map +1 -0
  35. package/build/cjs/{bluetooth-profile.d.ts → bluetooth/profile.d.ts} +8 -0
  36. package/build/cjs/{bluetooth-profile.js → bluetooth/profile.js} +7 -1
  37. package/build/cjs/bluetooth/profile.js.map +1 -0
  38. package/build/cjs/{accelerometer-service.d.ts → bluetooth/services/accelerometer-service.d.ts} +2 -3
  39. package/build/cjs/{accelerometer-service.js → bluetooth/services/accelerometer-service.js} +17 -12
  40. package/build/cjs/bluetooth/services/accelerometer-service.js.map +1 -0
  41. package/build/{esm → cjs/bluetooth/services}/button-service.d.ts +2 -3
  42. package/build/cjs/{button-service.js → bluetooth/services/button-service.js} +24 -14
  43. package/build/cjs/bluetooth/services/button-service.js.map +1 -0
  44. package/build/{esm → cjs/bluetooth/services}/device-information-service.d.ts +1 -1
  45. package/build/cjs/bluetooth/services/device-information-service.js +29 -0
  46. package/build/cjs/bluetooth/services/device-information-service.js.map +1 -0
  47. package/build/cjs/{dfu-service.js → bluetooth/services/dfu-service.js} +2 -2
  48. package/build/cjs/bluetooth/services/dfu-service.js.map +1 -0
  49. package/build/cjs/bluetooth/services/event-service.d.ts +48 -0
  50. package/build/cjs/bluetooth/services/event-service.js +273 -0
  51. package/build/cjs/bluetooth/services/event-service.js.map +1 -0
  52. package/build/cjs/bluetooth/services/io-pin-service.d.ts +65 -0
  53. package/build/cjs/bluetooth/services/io-pin-service.js +173 -0
  54. package/build/cjs/bluetooth/services/io-pin-service.js.map +1 -0
  55. package/build/{esm → cjs/bluetooth/services}/led-service.d.ts +2 -3
  56. package/build/cjs/{led-service.js → bluetooth/services/led-service.js} +10 -7
  57. package/build/cjs/bluetooth/services/led-service.js.map +1 -0
  58. package/build/cjs/{magnetometer-service.d.ts → bluetooth/services/magnetometer-service.d.ts} +2 -3
  59. package/build/cjs/{magnetometer-service.js → bluetooth/services/magnetometer-service.js} +19 -14
  60. package/build/cjs/bluetooth/services/magnetometer-service.js.map +1 -0
  61. package/build/{esm → cjs/bluetooth/services}/partial-flashing-service.d.ts +1 -1
  62. package/build/cjs/{partial-flashing-service.js → bluetooth/services/partial-flashing-service.js} +8 -8
  63. package/build/cjs/bluetooth/services/partial-flashing-service.js.map +1 -0
  64. package/build/cjs/bluetooth/services/temperature-service.d.ts +14 -0
  65. package/build/cjs/bluetooth/services/temperature-service.js +80 -0
  66. package/build/cjs/bluetooth/services/temperature-service.js.map +1 -0
  67. package/build/cjs/{uart-service.d.ts → bluetooth/services/uart-service.d.ts} +2 -2
  68. package/build/cjs/{uart-service.js → bluetooth/services/uart-service.js} +21 -9
  69. package/build/cjs/bluetooth/services/uart-service.js.map +1 -0
  70. package/build/cjs/board-id.d.ts +1 -1
  71. package/build/cjs/board-id.js.map +1 -1
  72. package/build/cjs/device.d.ts +191 -101
  73. package/build/cjs/device.js +47 -110
  74. package/build/cjs/device.js.map +1 -1
  75. package/build/cjs/events.d.ts +8 -108
  76. package/build/cjs/events.js +27 -88
  77. package/build/cjs/events.js.map +1 -1
  78. package/build/cjs/hex-util.d.ts +1 -0
  79. package/build/cjs/hex-util.js +15 -0
  80. package/build/cjs/hex-util.js.map +1 -0
  81. package/build/cjs/index.d.ts +8 -16
  82. package/build/cjs/index.js +9 -28
  83. package/build/cjs/index.js.map +1 -1
  84. package/build/cjs/logging.js.map +1 -1
  85. package/build/cjs/microbit-events.d.ts +67 -0
  86. package/build/cjs/microbit-events.js +55 -0
  87. package/build/cjs/microbit-events.js.map +1 -0
  88. package/build/cjs/radio-bridge/connection.d.ts +52 -0
  89. package/build/cjs/{usb-radio-bridge.js → radio-bridge/connection.js} +84 -96
  90. package/build/cjs/radio-bridge/connection.js.map +1 -0
  91. package/build/cjs/radio-bridge/index.d.ts +4 -0
  92. package/build/cjs/radio-bridge/index.js +9 -0
  93. package/build/cjs/radio-bridge/index.js.map +1 -0
  94. package/build/cjs/{usb-serial-protocol.js → radio-bridge/serial-protocol.js} +1 -1
  95. package/build/cjs/radio-bridge/serial-protocol.js.map +1 -0
  96. package/build/cjs/service-events.d.ts +92 -15
  97. package/build/cjs/service-events.js +6 -36
  98. package/build/cjs/service-events.js.map +1 -1
  99. package/build/{esm/hex-flash-data-source.d.ts → cjs/universal-hex/flash-data-source.d.ts} +1 -1
  100. package/build/cjs/{hex-flash-data-source.js → universal-hex/flash-data-source.js} +6 -3
  101. package/build/cjs/universal-hex/flash-data-source.js.map +1 -0
  102. package/build/cjs/universal-hex/index.d.ts +4 -0
  103. package/build/cjs/universal-hex/index.js +9 -0
  104. package/build/cjs/universal-hex/index.js.map +1 -0
  105. package/build/cjs/usb/arm-debug.d.ts +137 -0
  106. package/build/cjs/usb/arm-debug.js +414 -0
  107. package/build/cjs/usb/arm-debug.js.map +1 -0
  108. package/build/{esm → cjs/usb}/board-serial-info.d.ts +2 -1
  109. package/build/cjs/{board-serial-info.js → usb/board-serial-info.js} +10 -7
  110. package/build/cjs/usb/board-serial-info.js.map +1 -0
  111. package/build/cjs/usb/cdc-saturation.d.ts +36 -0
  112. package/build/cjs/usb/cdc-saturation.js +151 -0
  113. package/build/cjs/usb/cdc-saturation.js.map +1 -0
  114. package/build/cjs/usb/cmsis-dap.d.ts +113 -0
  115. package/build/cjs/usb/cmsis-dap.js +349 -0
  116. package/build/cjs/usb/cmsis-dap.js.map +1 -0
  117. package/build/cjs/usb/connection.d.ts +96 -0
  118. package/build/cjs/{usb.js → usb/connection.js} +257 -173
  119. package/build/cjs/usb/connection.js.map +1 -0
  120. package/build/cjs/usb/cortex-m.d.ts +72 -0
  121. package/build/cjs/usb/cortex-m.js +165 -0
  122. package/build/cjs/usb/cortex-m.js.map +1 -0
  123. package/build/cjs/usb/daplink.d.ts +69 -0
  124. package/build/cjs/usb/daplink.js +238 -0
  125. package/build/cjs/usb/daplink.js.map +1 -0
  126. package/build/cjs/usb/device-wrapper.d.ts +34 -0
  127. package/build/cjs/usb/device-wrapper.js +102 -0
  128. package/build/cjs/usb/device-wrapper.js.map +1 -0
  129. package/build/cjs/usb/index.d.ts +5 -0
  130. package/build/cjs/usb/index.js +10 -0
  131. package/build/cjs/usb/index.js.map +1 -0
  132. package/build/{esm/usb-partial-flashing-utils.d.ts → cjs/usb/partial-flashing-utils.d.ts} +6 -9
  133. package/build/cjs/{usb-partial-flashing-utils.js → usb/partial-flashing-utils.js} +6 -49
  134. package/build/cjs/usb/partial-flashing-utils.js.map +1 -0
  135. package/build/{esm/usb-partial-flashing.d.ts → cjs/usb/partial-flashing.d.ts} +37 -11
  136. package/build/cjs/{usb-partial-flashing.js → usb/partial-flashing.js} +170 -134
  137. package/build/cjs/usb/partial-flashing.js.map +1 -0
  138. package/build/cjs/usb/promise-queue.js.map +1 -0
  139. package/build/cjs/usb/serial-events.d.ts +16 -0
  140. package/build/cjs/{led.js → usb/serial-events.js} +1 -1
  141. package/build/cjs/usb/serial-events.js.map +1 -0
  142. package/build/cjs/usb/transport.d.ts +42 -0
  143. package/build/cjs/usb/transport.js +155 -0
  144. package/build/cjs/usb/transport.js.map +1 -0
  145. package/build/esm/async-util.d.ts +3 -1
  146. package/build/esm/async-util.js +5 -1
  147. package/build/esm/async-util.js.map +1 -1
  148. package/build/esm/availability.js.map +1 -1
  149. package/build/esm/bluetooth/ble-error.d.ts +10 -0
  150. package/build/esm/bluetooth/ble-error.js +42 -0
  151. package/build/esm/bluetooth/ble-error.js.map +1 -0
  152. package/build/esm/bluetooth/connection.d.ts +378 -0
  153. package/build/esm/bluetooth/connection.js +593 -0
  154. package/build/esm/bluetooth/connection.js.map +1 -0
  155. package/build/esm/bluetooth/device-bond-state.d.ts +14 -0
  156. package/build/esm/bluetooth/device-bond-state.js +22 -0
  157. package/build/esm/bluetooth/device-bond-state.js.map +1 -0
  158. package/build/esm/{bluetooth-device-wrapper.d.ts → bluetooth/device-wrapper.d.ts} +36 -21
  159. package/build/esm/{bluetooth-device-wrapper.js → bluetooth/device-wrapper.js} +172 -146
  160. package/build/esm/bluetooth/device-wrapper.js.map +1 -0
  161. package/build/{cjs → esm/bluetooth}/flashing/flashing-full.d.ts +2 -2
  162. package/build/esm/{flashing → bluetooth/flashing}/flashing-full.js +6 -5
  163. package/build/esm/bluetooth/flashing/flashing-full.js.map +1 -0
  164. package/build/esm/bluetooth/flashing/flashing-makecode.d.ts +10 -0
  165. package/build/esm/{flashing → bluetooth/flashing}/flashing-makecode.js +5 -2
  166. package/build/esm/bluetooth/flashing/flashing-makecode.js.map +1 -0
  167. package/build/esm/bluetooth/flashing/flashing-partial.d.ts +10 -0
  168. package/build/esm/bluetooth/flashing/flashing-partial.js +142 -0
  169. package/build/esm/bluetooth/flashing/flashing-partial.js.map +1 -0
  170. package/build/esm/bluetooth/flashing/flashing-v1.js.map +1 -0
  171. package/build/esm/{flashing → bluetooth/flashing}/nordic-dfu.d.ts +2 -2
  172. package/build/esm/{flashing → bluetooth/flashing}/nordic-dfu.js +41 -15
  173. package/build/esm/bluetooth/flashing/nordic-dfu.js.map +1 -0
  174. package/build/esm/bluetooth/flashing/zip.js.map +1 -0
  175. package/build/esm/bluetooth/index.d.ts +5 -0
  176. package/build/esm/bluetooth/index.js +5 -0
  177. package/build/esm/bluetooth/index.js.map +1 -0
  178. package/build/esm/{bluetooth-profile.d.ts → bluetooth/profile.d.ts} +8 -0
  179. package/build/esm/{bluetooth-profile.js → bluetooth/profile.js} +7 -1
  180. package/build/{cjs/bluetooth-profile.js.map → esm/bluetooth/profile.js.map} +1 -1
  181. package/build/esm/{accelerometer-service.d.ts → bluetooth/services/accelerometer-service.d.ts} +2 -3
  182. package/build/esm/{accelerometer-service.js → bluetooth/services/accelerometer-service.js} +11 -6
  183. package/build/esm/bluetooth/services/accelerometer-service.js.map +1 -0
  184. package/build/{cjs → esm/bluetooth/services}/button-service.d.ts +2 -3
  185. package/build/esm/{button-service.js → bluetooth/services/button-service.js} +20 -10
  186. package/build/esm/bluetooth/services/button-service.js.map +1 -0
  187. package/build/{cjs → esm/bluetooth/services}/device-information-service.d.ts +1 -1
  188. package/build/esm/bluetooth/services/device-information-service.js +25 -0
  189. package/build/esm/bluetooth/services/device-information-service.js.map +1 -0
  190. package/build/esm/{dfu-service.js → bluetooth/services/dfu-service.js} +1 -1
  191. package/build/esm/bluetooth/services/dfu-service.js.map +1 -0
  192. package/build/esm/bluetooth/services/event-service.d.ts +48 -0
  193. package/build/esm/bluetooth/services/event-service.js +269 -0
  194. package/build/esm/bluetooth/services/event-service.js.map +1 -0
  195. package/build/esm/bluetooth/services/io-pin-service.d.ts +65 -0
  196. package/build/esm/bluetooth/services/io-pin-service.js +169 -0
  197. package/build/esm/bluetooth/services/io-pin-service.js.map +1 -0
  198. package/build/{cjs → esm/bluetooth/services}/led-service.d.ts +2 -3
  199. package/build/esm/{led-service.js → bluetooth/services/led-service.js} +4 -1
  200. package/build/esm/bluetooth/services/led-service.js.map +1 -0
  201. package/build/esm/{magnetometer-service.d.ts → bluetooth/services/magnetometer-service.d.ts} +2 -3
  202. package/build/esm/{magnetometer-service.js → bluetooth/services/magnetometer-service.js} +11 -6
  203. package/build/esm/bluetooth/services/magnetometer-service.js.map +1 -0
  204. package/build/{cjs → esm/bluetooth/services}/partial-flashing-service.d.ts +1 -1
  205. package/build/esm/{partial-flashing-service.js → bluetooth/services/partial-flashing-service.js} +4 -4
  206. package/build/esm/bluetooth/services/partial-flashing-service.js.map +1 -0
  207. package/build/esm/bluetooth/services/temperature-service.d.ts +14 -0
  208. package/build/esm/bluetooth/services/temperature-service.js +76 -0
  209. package/build/esm/bluetooth/services/temperature-service.js.map +1 -0
  210. package/build/esm/{uart-service.d.ts → bluetooth/services/uart-service.d.ts} +2 -2
  211. package/build/esm/{uart-service.js → bluetooth/services/uart-service.js} +18 -6
  212. package/build/esm/bluetooth/services/uart-service.js.map +1 -0
  213. package/build/esm/board-id.d.ts +1 -1
  214. package/build/esm/board-id.js.map +1 -1
  215. package/build/esm/device.d.ts +191 -101
  216. package/build/esm/device.js +45 -104
  217. package/build/esm/device.js.map +1 -1
  218. package/build/esm/events.d.ts +8 -108
  219. package/build/esm/events.js +26 -86
  220. package/build/esm/events.js.map +1 -1
  221. package/build/esm/hex-util.d.ts +1 -0
  222. package/build/esm/hex-util.js +11 -0
  223. package/build/esm/hex-util.js.map +1 -0
  224. package/build/esm/index.d.ts +8 -16
  225. package/build/esm/index.js +7 -11
  226. package/build/esm/index.js.map +1 -1
  227. package/build/esm/logging.js.map +1 -1
  228. package/build/esm/microbit-events.d.ts +67 -0
  229. package/build/esm/microbit-events.js +52 -0
  230. package/build/esm/microbit-events.js.map +1 -0
  231. package/build/esm/radio-bridge/connection.d.ts +52 -0
  232. package/build/esm/{usb-radio-bridge.js → radio-bridge/connection.js} +84 -96
  233. package/build/esm/radio-bridge/connection.js.map +1 -0
  234. package/build/esm/radio-bridge/index.d.ts +4 -0
  235. package/build/esm/radio-bridge/index.js +5 -0
  236. package/build/esm/radio-bridge/index.js.map +1 -0
  237. package/build/esm/{usb-serial-protocol.js → radio-bridge/serial-protocol.js} +1 -1
  238. package/build/esm/radio-bridge/serial-protocol.js.map +1 -0
  239. package/build/esm/service-events.d.ts +92 -15
  240. package/build/esm/service-events.js +5 -34
  241. package/build/esm/service-events.js.map +1 -1
  242. package/build/{cjs/hex-flash-data-source.d.ts → esm/universal-hex/flash-data-source.d.ts} +1 -1
  243. package/build/esm/{hex-flash-data-source.js → universal-hex/flash-data-source.js} +6 -3
  244. package/build/esm/universal-hex/flash-data-source.js.map +1 -0
  245. package/build/esm/universal-hex/index.d.ts +4 -0
  246. package/build/esm/universal-hex/index.js +5 -0
  247. package/build/esm/universal-hex/index.js.map +1 -0
  248. package/build/esm/usb/arm-debug.d.ts +137 -0
  249. package/build/esm/usb/arm-debug.js +409 -0
  250. package/build/esm/usb/arm-debug.js.map +1 -0
  251. package/build/{cjs → esm/usb}/board-serial-info.d.ts +2 -1
  252. package/build/esm/{board-serial-info.js → usb/board-serial-info.js} +10 -7
  253. package/build/esm/usb/board-serial-info.js.map +1 -0
  254. package/build/esm/usb/cdc-saturation.d.ts +36 -0
  255. package/build/esm/usb/cdc-saturation.js +148 -0
  256. package/build/esm/usb/cdc-saturation.js.map +1 -0
  257. package/build/esm/usb/cmsis-dap.d.ts +113 -0
  258. package/build/esm/usb/cmsis-dap.js +342 -0
  259. package/build/esm/usb/cmsis-dap.js.map +1 -0
  260. package/build/esm/usb/connection.d.ts +96 -0
  261. package/build/esm/{usb.js → usb/connection.js} +253 -168
  262. package/build/esm/usb/connection.js.map +1 -0
  263. package/build/esm/usb/cortex-m.d.ts +72 -0
  264. package/build/esm/usb/cortex-m.js +161 -0
  265. package/build/esm/usb/cortex-m.js.map +1 -0
  266. package/build/esm/usb/daplink.d.ts +69 -0
  267. package/build/esm/usb/daplink.js +231 -0
  268. package/build/esm/usb/daplink.js.map +1 -0
  269. package/build/esm/usb/device-wrapper.d.ts +34 -0
  270. package/build/esm/usb/device-wrapper.js +98 -0
  271. package/build/esm/usb/device-wrapper.js.map +1 -0
  272. package/build/esm/usb/index.d.ts +5 -0
  273. package/build/esm/usb/index.js +5 -0
  274. package/build/esm/usb/index.js.map +1 -0
  275. package/build/{cjs/usb-partial-flashing-utils.d.ts → esm/usb/partial-flashing-utils.d.ts} +6 -9
  276. package/build/esm/{usb-partial-flashing-utils.js → usb/partial-flashing-utils.js} +4 -44
  277. package/build/esm/usb/partial-flashing-utils.js.map +1 -0
  278. package/build/{cjs/usb-partial-flashing.d.ts → esm/usb/partial-flashing.d.ts} +37 -11
  279. package/build/esm/{usb-partial-flashing.js → usb/partial-flashing.js} +169 -110
  280. package/build/esm/usb/partial-flashing.js.map +1 -0
  281. package/build/esm/usb/promise-queue.js.map +1 -0
  282. package/build/esm/usb/serial-events.d.ts +16 -0
  283. package/build/esm/usb/serial-events.js +2 -0
  284. package/build/esm/usb/serial-events.js.map +1 -0
  285. package/build/esm/usb/transport.d.ts +42 -0
  286. package/build/esm/usb/transport.js +151 -0
  287. package/build/esm/usb/transport.js.map +1 -0
  288. package/package.json +61 -14
  289. package/build/cjs/accelerometer-service.js.map +0 -1
  290. package/build/cjs/accelerometer.d.ts +0 -9
  291. package/build/cjs/accelerometer.js +0 -16
  292. package/build/cjs/accelerometer.js.map +0 -1
  293. package/build/cjs/bluetooth-device-wrapper.js.map +0 -1
  294. package/build/cjs/bluetooth.d.ts +0 -112
  295. package/build/cjs/bluetooth.js +0 -457
  296. package/build/cjs/bluetooth.js.map +0 -1
  297. package/build/cjs/board-serial-info.js.map +0 -1
  298. package/build/cjs/button-service.js.map +0 -1
  299. package/build/cjs/buttons.d.ts +0 -10
  300. package/build/cjs/buttons.js +0 -22
  301. package/build/cjs/buttons.js.map +0 -1
  302. package/build/cjs/constants.d.ts +0 -48
  303. package/build/cjs/constants.js +0 -73
  304. package/build/cjs/constants.js.map +0 -1
  305. package/build/cjs/device-information-service.js +0 -34
  306. package/build/cjs/device-information-service.js.map +0 -1
  307. package/build/cjs/dfu-service.js.map +0 -1
  308. package/build/cjs/flashing/flashing-full.js.map +0 -1
  309. package/build/cjs/flashing/flashing-makecode.d.ts +0 -6
  310. package/build/cjs/flashing/flashing-makecode.js.map +0 -1
  311. package/build/cjs/flashing/flashing-partial.d.ts +0 -9
  312. package/build/cjs/flashing/flashing-partial.js +0 -98
  313. package/build/cjs/flashing/flashing-partial.js.map +0 -1
  314. package/build/cjs/flashing/flashing-v1.js.map +0 -1
  315. package/build/cjs/flashing/nordic-dfu.js.map +0 -1
  316. package/build/cjs/flashing/zip.js.map +0 -1
  317. package/build/cjs/hex-flash-data-source.js.map +0 -1
  318. package/build/cjs/led-service.js.map +0 -1
  319. package/build/cjs/led.d.ts +0 -6
  320. package/build/cjs/led.js.map +0 -1
  321. package/build/cjs/magnetometer-service.js.map +0 -1
  322. package/build/cjs/magnetometer.d.ts +0 -9
  323. package/build/cjs/magnetometer.js +0 -16
  324. package/build/cjs/magnetometer.js.map +0 -1
  325. package/build/cjs/partial-flashing-service.js.map +0 -1
  326. package/build/cjs/promise-queue.js.map +0 -1
  327. package/build/cjs/serial-events.d.ts +0 -20
  328. package/build/cjs/serial-events.js +0 -69
  329. package/build/cjs/serial-events.js.map +0 -1
  330. package/build/cjs/setupTests.d.ts +0 -6
  331. package/build/cjs/setupTests.js.map +0 -1
  332. package/build/cjs/uart-service.js.map +0 -1
  333. package/build/cjs/uart.d.ts +0 -4
  334. package/build/cjs/uart.js +0 -16
  335. package/build/cjs/uart.js.map +0 -1
  336. package/build/cjs/usb-device-wrapper.d.ts +0 -47
  337. package/build/cjs/usb-device-wrapper.js +0 -437
  338. package/build/cjs/usb-device-wrapper.js.map +0 -1
  339. package/build/cjs/usb-partial-flashing-utils.js.map +0 -1
  340. package/build/cjs/usb-partial-flashing.js.map +0 -1
  341. package/build/cjs/usb-radio-bridge.d.ts +0 -24
  342. package/build/cjs/usb-radio-bridge.js.map +0 -1
  343. package/build/cjs/usb-serial-protocol.js.map +0 -1
  344. package/build/cjs/usb.d.ts +0 -66
  345. package/build/cjs/usb.js.map +0 -1
  346. package/build/esm/accelerometer-service.js.map +0 -1
  347. package/build/esm/accelerometer.d.ts +0 -9
  348. package/build/esm/accelerometer.js +0 -12
  349. package/build/esm/accelerometer.js.map +0 -1
  350. package/build/esm/bluetooth-device-wrapper.js.map +0 -1
  351. package/build/esm/bluetooth-profile.js.map +0 -1
  352. package/build/esm/bluetooth.d.ts +0 -112
  353. package/build/esm/bluetooth.js +0 -427
  354. package/build/esm/bluetooth.js.map +0 -1
  355. package/build/esm/board-serial-info.js.map +0 -1
  356. package/build/esm/button-service.js.map +0 -1
  357. package/build/esm/buttons.d.ts +0 -10
  358. package/build/esm/buttons.js +0 -18
  359. package/build/esm/buttons.js.map +0 -1
  360. package/build/esm/constants.d.ts +0 -48
  361. package/build/esm/constants.js +0 -70
  362. package/build/esm/constants.js.map +0 -1
  363. package/build/esm/device-information-service.js +0 -30
  364. package/build/esm/device-information-service.js.map +0 -1
  365. package/build/esm/dfu-service.js.map +0 -1
  366. package/build/esm/flashing/flashing-full.js.map +0 -1
  367. package/build/esm/flashing/flashing-makecode.d.ts +0 -6
  368. package/build/esm/flashing/flashing-makecode.js.map +0 -1
  369. package/build/esm/flashing/flashing-partial.d.ts +0 -9
  370. package/build/esm/flashing/flashing-partial.js +0 -95
  371. package/build/esm/flashing/flashing-partial.js.map +0 -1
  372. package/build/esm/flashing/flashing-v1.js.map +0 -1
  373. package/build/esm/flashing/nordic-dfu.js.map +0 -1
  374. package/build/esm/flashing/zip.js.map +0 -1
  375. package/build/esm/hex-flash-data-source.js.map +0 -1
  376. package/build/esm/led-service.js.map +0 -1
  377. package/build/esm/led.d.ts +0 -6
  378. package/build/esm/led.js +0 -2
  379. package/build/esm/led.js.map +0 -1
  380. package/build/esm/magnetometer-service.js.map +0 -1
  381. package/build/esm/magnetometer.d.ts +0 -9
  382. package/build/esm/magnetometer.js +0 -12
  383. package/build/esm/magnetometer.js.map +0 -1
  384. package/build/esm/partial-flashing-service.js.map +0 -1
  385. package/build/esm/promise-queue.js.map +0 -1
  386. package/build/esm/serial-events.d.ts +0 -20
  387. package/build/esm/serial-events.js +0 -61
  388. package/build/esm/serial-events.js.map +0 -1
  389. package/build/esm/setupTests.d.ts +0 -6
  390. package/build/esm/setupTests.js.map +0 -1
  391. package/build/esm/uart-service.js.map +0 -1
  392. package/build/esm/uart.d.ts +0 -4
  393. package/build/esm/uart.js +0 -12
  394. package/build/esm/uart.js.map +0 -1
  395. package/build/esm/usb-device-wrapper.d.ts +0 -47
  396. package/build/esm/usb-device-wrapper.js +0 -410
  397. package/build/esm/usb-device-wrapper.js.map +0 -1
  398. package/build/esm/usb-partial-flashing-utils.js.map +0 -1
  399. package/build/esm/usb-partial-flashing.js.map +0 -1
  400. package/build/esm/usb-radio-bridge.d.ts +0 -24
  401. package/build/esm/usb-radio-bridge.js.map +0 -1
  402. package/build/esm/usb-serial-protocol.js.map +0 -1
  403. package/build/esm/usb.d.ts +0 -66
  404. package/build/esm/usb.js.map +0 -1
  405. package/typedoc.json +0 -14
  406. /package/build/cjs/{flashing → bluetooth/flashing}/flashing-v1.d.ts +0 -0
  407. /package/build/cjs/{flashing → bluetooth/flashing}/flashing-v1.js +0 -0
  408. /package/build/cjs/{flashing → bluetooth/flashing}/zip.d.ts +0 -0
  409. /package/build/cjs/{flashing → bluetooth/flashing}/zip.js +0 -0
  410. /package/build/cjs/{dfu-service.d.ts → bluetooth/services/dfu-service.d.ts} +0 -0
  411. /package/build/cjs/{usb-serial-protocol.d.ts → radio-bridge/serial-protocol.d.ts} +0 -0
  412. /package/build/cjs/{promise-queue.d.ts → usb/promise-queue.d.ts} +0 -0
  413. /package/build/cjs/{promise-queue.js → usb/promise-queue.js} +0 -0
  414. /package/build/esm/{flashing → bluetooth/flashing}/flashing-v1.d.ts +0 -0
  415. /package/build/esm/{flashing → bluetooth/flashing}/flashing-v1.js +0 -0
  416. /package/build/esm/{flashing → bluetooth/flashing}/zip.d.ts +0 -0
  417. /package/build/esm/{flashing → bluetooth/flashing}/zip.js +0 -0
  418. /package/build/esm/{dfu-service.d.ts → bluetooth/services/dfu-service.d.ts} +0 -0
  419. /package/build/esm/{usb-serial-protocol.d.ts → radio-bridge/serial-protocol.d.ts} +0 -0
  420. /package/build/esm/{promise-queue.d.ts → usb/promise-queue.d.ts} +0 -0
  421. /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
- This is a JavaScript library for micro:bit connections in browsers via USB and Bluetooth.
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
- This project is a work in progress. We are extracting WebUSB and Web Bluetooth code from the [micro:bit Python Editor](https://github.com/microbit-foundation/python-editor-v3/) and other projects. The API is not stable and it's not yet recommended that third parties use this project unless they are happy to update usage as the API evolves.
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
- [Demo page](https://microbit-connection.pages.dev/) for this library.
9
+ ### Demo apps
10
10
 
11
- [Alpha releases are now on NPM](https://www.npmjs.com/package/@microbit/microbit-connection).
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
- [micro:bit CreateAI](https://github.com/microbit-foundation/ml-trainer/) is already using this library for WebUSB and Web Bluetooth.
13
+ ### Projects using this library
14
14
 
15
- [This Python Editor PR](https://github.com/microbit-foundation/python-editor-v3/pull/1190) tracks updating the micro:bit Python Editor to use this library.
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 createWebUSBConnection} class and use it to connect to a micro:bit.
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 { createWebUSBConnection } from "@microbit/microbit-connection";
46
+ import { createUSBConnection } from "@microbit/microbit-connection/usb";
25
47
 
26
- const usb = createWebUSBConnection();
27
- const connectionStatus = await usb.connect();
48
+ const usb = createUSBConnection();
49
+ await usb.connect();
28
50
 
29
- console.log("Connection status: ", connectionStatus);
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
- const boardId = BoardId.forVersion(boardVersion).id;
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
- For more examples of using other methods in the {@link MicrobitWebUSBConnection} class, see our [demo code](https://github.com/microbit-foundation/microbit-connection/blob/main/src/demo.ts) for our [demo site](https://microbit-connection.pages.dev/).
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 createWebBluetoothConnection} class and use it to connect to a micro:bit.
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 { createWebBluetoothConnection } from "@microbit/microbit-connection";
124
+ import { createBluetoothConnection } from "@microbit/microbit-connection/bluetooth";
87
125
 
88
- const bluetooth = createWebBluetoothConnection();
89
- const connectionStatus = await bluetooth.connect();
126
+ const bluetooth = createBluetoothConnection();
127
+ await bluetooth.connect();
90
128
 
91
- console.log("Connection status: ", connectionStatus);
129
+ console.log("Connection status: ", bluetooth.status); // "Connected"
92
130
  ```
93
131
 
94
- {@link ConnectionStatus | Connection status} is `"CONNECTED"` if connection succeeds.
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
- For more examples of using other methods in the {@link createWebBluetoothConnection} class, see our [demo code](https://github.com/microbit-foundation/microbit-connection/blob/main/src/demo.ts) for our [demo site](https://microbit-connection.pages.dev/).
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
- export declare class TimeoutError extends Error {
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);
@@ -10,7 +10,11 @@ exports.disconnectErrorCallback = disconnectErrorCallback;
10
10
  *
11
11
  * SPDX-License-Identifier: MIT
12
12
  */
13
- class TimeoutError extends Error {
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":["../../lib/async-util.ts"],"names":[],"mappings":";;;AAkBA,kCAQC;AAED,sBAEC;AAED,8CAMC;AAED,0DAMC;AA9CD;;;;GAIG;AACH,MAAa,YAAa,SAAQ,KAAK;CAAG;AAA1C,oCAA0C;AAE1C,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,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,IAAI,EAAE,mBAAmB;gBACzB,OAAO,EAAE,4BAA4B;aACtC,CAAC,CAAC;IACP,CAAC;AACH,CAAC,CAAC;AA3BW,QAAA,kBAAkB,sBA2B7B"}
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;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