@microbit/microbit-connection 0.9.0-apps.alpha.8 → 1.0.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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} +35 -19
  16. package/build/cjs/{bluetooth-device-wrapper.js → bluetooth/device-wrapper.js} +169 -122
  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 +40 -14
  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} +35 -19
  159. package/build/esm/{bluetooth-device-wrapper.js → bluetooth/device-wrapper.js} +167 -121
  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 +40 -14
  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
@@ -1 +1 @@
1
- {"version":3,"file":"board-id.js","sourceRoot":"","sources":["../../lib/board-id.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAIH;;GAEG;AACH,MAAa,OAAO;IAIlB,YAAmB,EAAU;QAAjB;;;;mBAAO,EAAE;WAAQ;QAC3B,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE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CAAC,CAAC,CAAC;IAC1C,CAAC;IAED,MAAM,CAAC,UAAU,CAAC,YAA0B;QAC1C,QAAQ,YAAY,EAAE,CAAC;YACrB,KAAK,IAAI;gBACP,OAAO,IAAI,CAAC,YAAY,CAAC;YAC3B,KAAK,IAAI;gBACP,OAAO,IAAI,CAAC,YAAY,CAAC;QAC7B,CAAC;IACH,CAAC;;AA5DH,0BA6DC;AA5DgB;;;;WAAe,IAAI,OAAO,CAAC,MAAM,CAAC;EAAtB,CAAuB;AACnC;;;;WAAe,IAAI,OAAO,CAAC,MAAM,CAAC;EAAtB,CAAuB"}
@@ -3,99 +3,128 @@
3
3
  *
4
4
  * SPDX-License-Identifier: MIT
5
5
  */
6
- import { TypedEventTarget, ValueIsEvent } from "./events.js";
7
6
  /**
8
7
  * Connection availability status returned by checkAvailability().
9
8
  * Used for pre-flight UX decisions before attempting to connect.
10
9
  */
11
10
  export type ConnectionAvailabilityStatus = "available" | "unsupported" | "disabled" | "permission-denied" | "location-disabled";
12
11
  /**
13
- * Specific identified error types.
12
+ * Error codes identifying specific failure modes.
14
13
  *
15
- * New members may be added over time.
14
+ * Each code represents a distinct category of failure that apps can
15
+ * match on to decide what message to show or what recovery to attempt.
16
+ * New codes may be added in future minor releases.
17
+ *
18
+ * Codes are annotated with **USB**, **BLE**, or **USB, BLE** to indicate
19
+ * which connection types can produce them. USB-only apps can ignore
20
+ * BLE-only codes.
16
21
  */
17
22
  export type DeviceErrorCode =
18
23
  /**
19
- * Device not selected, e.g. because the user cancelled the dialog.
20
- */
21
- "no-device-selected"
22
- /**
23
- * Device not found, perhaps because it doesn't have new enough firmware (for V1).
24
+ * **BLE.** The operation was cancelled via an `AbortSignal`
25
+ * supplied by the caller. No user-facing error is needed.
24
26
  */
25
- | "update-req"
27
+ "aborted"
26
28
  /**
27
- * Unable to claim the interface, usually because it's in use in another tab/window.
29
+ * **USB, BLE.** The user dismissed the device-picker dialog without
30
+ * selecting a device. Typically no error message is needed — the user
31
+ * chose not to proceed.
28
32
  */
29
- | "clear-connect"
33
+ | "no-device-selected"
30
34
  /**
31
- * The device was found to be disconnected.
35
+ * **USB, BLE.** The connection type is not supported on this platform
36
+ * or browser. Corresponds to {@link ConnectionAvailabilityStatus}
37
+ * `"unsupported"`.
32
38
  */
33
- | "device-disconnected"
39
+ | "unsupported"
34
40
  /**
35
- * A communication timeout occurred.
41
+ * **BLE.** Bluetooth is turned off at the OS level. Prompt the user
42
+ * to enable it in system settings. Corresponds to
43
+ * {@link ConnectionAvailabilityStatus} `"disabled"`.
36
44
  */
37
- | "timeout-error"
45
+ | "disabled"
38
46
  /**
39
- * This is the fallback error case suggesting that the user reconnects their device.
47
+ * **BLE.** The app does not have the required Bluetooth permissions
48
+ * (iOS/Android). Prompt the user to grant permission in system
49
+ * settings. Corresponds to {@link ConnectionAvailabilityStatus}
50
+ * `"permission-denied"`.
40
51
  */
41
- | "reconnect-microbit"
52
+ | "permission-denied"
42
53
  /**
43
- * Error occured during serial or bluetooth communication.
54
+ * **BLE.** Location services are disabled. Required on Android
55
+ * versions before 12 for Bluetooth scanning. Prompt the user to
56
+ * enable location in system settings. Corresponds to
57
+ * {@link ConnectionAvailabilityStatus} `"location-disabled"`.
44
58
  */
45
- | "background-comms-error"
59
+ | "location-disabled"
46
60
  /**
47
- * Bluetooth service is missing on device.
61
+ * **USB, BLE.** A method was called that requires an active
62
+ * connection, but no connection is currently open. Call
63
+ * {@link DeviceConnection.connect} first.
48
64
  */
49
- | "service-missing"
65
+ | "not-connected"
50
66
  /**
51
- * Failed to establish Bluetooth connection.
67
+ * **USB.** The USB interface could not be claimed, usually because
68
+ * another browser tab or application already has an open connection
69
+ * to the device.
52
70
  */
53
- | "bluetooth-connection-failed"
71
+ | "device-in-use"
54
72
  /**
55
- * Partial flash operation failed.
73
+ * **USB, BLE.** The device disconnected during an operation.
74
+ * The physical USB or Bluetooth connection was lost.
56
75
  */
57
- | "flash-partial-failed"
76
+ | "device-disconnected"
58
77
  /**
59
- * Full flash operation failed.
78
+ * **USB, BLE.** A communication timeout — the device did not respond
79
+ * within the expected time. This may indicate the device is busy,
80
+ * hung, or that the connection is degraded.
60
81
  */
61
- | "flash-full-failed"
82
+ | "timeout"
62
83
  /**
63
- * Flash operation was cancelled.
84
+ * **USB, BLE.** A communication failure that does not match any more
85
+ * specific code. Typical handling: prompt the user to physically
86
+ * disconnect and reconnect the device, then retry.
64
87
  */
65
- | "flash-cancelled"
88
+ | "connection-error"
66
89
  /**
67
- * Connection type is not supported on this platform/browser.
68
- * Aligns with ConnectionAvailabilityStatus "unsupported".
90
+ * **USB.** The USB device was found but lacks the expected CMSIS-DAP
91
+ * interface. On micro:bit V1 this indicates the DAPLink firmware is
92
+ * too old and needs updating.
69
93
  */
70
- | "unsupported"
94
+ | "firmware-update-required"
71
95
  /**
72
- * Connection is disabled (e.g., Bluetooth turned off).
73
- * Aligns with ConnectionAvailabilityStatus "disabled".
96
+ * **BLE.** The micro:bit's Bluetooth pairing/bonding information has
97
+ * been lost (e.g. after a firmware reflash). The user needs to
98
+ * re-pair the device. Currently only detected on iOS.
74
99
  */
75
- | "disabled"
100
+ | "pairing-information-lost";
76
101
  /**
77
- * Required permissions were denied.
78
- * Aligns with ConnectionAvailabilityStatus "permission-denied".
102
+ * Stages reported by the progress callback during connection and flashing.
79
103
  */
80
- | "permission-denied"
81
- /**
82
- * Location services are disabled (Android < 12 only).
83
- * Aligns with ConnectionAvailabilityStatus "location-disabled".
84
- */
85
- | "location-disabled";
86
- export declare enum ProgressStage {
87
- Initializing = "Initializing",
88
- FindingDevice = "FindingDevice",
89
- Connecting = "Connecting",
90
- PartialFlashing = "PartialFlashing",
91
- FullFlashing = "FullFlashing"
92
- }
104
+ export declare const ProgressStage: {
105
+ /** Checking permissions and availability before connecting. */
106
+ readonly Initializing: "Initializing";
107
+ /** Finding device. */
108
+ readonly FindingDevice: "FindingDevice";
109
+ /** Checking that a bond is established. Only applicable on Native platforms. */
110
+ readonly CheckingBond: "CheckingBond";
111
+ /** Resetting device in preparation for flashing. Only applicable on Native platforms. */
112
+ readonly ResettingDevice: "ResettingDevice";
113
+ /** Connecting for flashing. */
114
+ readonly Connecting: "Connecting";
115
+ /** Partial flashing. */
116
+ readonly PartialFlashing: "PartialFlashing";
117
+ /** Full flashing. */
118
+ readonly FullFlashing: "FullFlashing";
119
+ };
120
+ export type ProgressStage = (typeof ProgressStage)[keyof typeof ProgressStage];
93
121
  /**
94
122
  * Progress callback for tracking operation stages (connection and flashing).
95
123
  *
96
124
  * @param stage - The current stage of the operation
97
125
  * @param progress - Optional progress value (0-1) for PartialFlashing and FullFlashing stages.
98
- * Initializing, FindingDevice, and Connecting stages are called once
126
+ * Initializing, FindingDevice, CheckingBond (only for native platforms),
127
+ * ResettingDevice (only for native platforms), and Connecting stages are called once
99
128
  * without progress values to indicate stage entry.
100
129
  *
101
130
  * @example
@@ -119,15 +148,21 @@ export type ProgressCallback = (stage: ProgressStage, progress?: number) => void
119
148
  */
120
149
  export declare class DeviceError extends Error {
121
150
  code: DeviceErrorCode;
122
- constructor({ code, message }: {
151
+ constructor({ code, message, cause, }: {
123
152
  code: DeviceErrorCode;
124
153
  message?: string;
154
+ cause?: unknown;
125
155
  });
126
156
  }
157
+ /**
158
+ * Asserts that a connection is active, throwing a {@link DeviceError}
159
+ * with code `"not-connected"` if it is not.
160
+ */
161
+ export declare function assertConnected<T>(connection: T | undefined): asserts connection is T;
127
162
  /**
128
163
  * Tracks connection status.
129
164
  */
130
- export declare enum ConnectionStatus {
165
+ export declare const ConnectionStatus: {
131
166
  /**
132
167
  * No device available.
133
168
  *
@@ -137,36 +172,57 @@ export declare enum ConnectionStatus {
137
172
  * Use checkAvailability() to determine whether the connection type is
138
173
  * supported before attempting to connect.
139
174
  */
140
- NO_AUTHORIZED_DEVICE = "NO_AUTHORIZED_DEVICE",
141
- /**
142
- * Authorized device available but we haven't connected to it.
143
- */
144
- DISCONNECTED = "DISCONNECTED",
145
- /**
146
- * Connected.
147
- */
148
- CONNECTED = "CONNECTED",
149
- /**
150
- * Connecting.
151
- */
152
- CONNECTING = "CONNECTING",
153
- /**
154
- * Reconnecting. When there is unexpected disruption in the connection,
155
- * a reconnection is attempted.
156
- */
157
- RECONNECTING = "RECONNECTING",
175
+ readonly NoAuthorizedDevice: "NoAuthorizedDevice";
176
+ /** Authorized device available but we haven't connected to it. */
177
+ readonly Disconnected: "Disconnected";
178
+ /** Connected. */
179
+ readonly Connected: "Connected";
180
+ /** Connecting. */
181
+ readonly Connecting: "Connecting";
158
182
  /**
159
183
  * Paused due to tab visibility. The connection was temporarily suspended
160
184
  * because the browser tab became hidden. Reconnection will be attempted
161
185
  * automatically when the tab becomes visible again.
162
186
  */
163
- PAUSED = "PAUSED"
164
- }
187
+ readonly Paused: "Paused";
188
+ };
189
+ export type ConnectionStatus = (typeof ConnectionStatus)[keyof typeof ConnectionStatus];
190
+ /**
191
+ * Controls bonding behaviour and post-bond device mode on native platforms.
192
+ *
193
+ * - `"pairing"` — Bond if needed, then reset the device into pairing mode.
194
+ * Use when you intend to flash immediately after connecting.
195
+ * - `"application"` — Bond if needed, then reset the device into application
196
+ * mode. Use when you want to interact with BLE services (sensors, UART, …)
197
+ * on firmware that has BLE enabled in application mode.
198
+ * - `"none"` — Skip bonding entirely and just connect. Use for open-link
199
+ * firmware where no bonding is required.
200
+ *
201
+ * Ignored on web platforms where the browser manages pairing transparently.
202
+ */
203
+ export type BondMode = "pairing" | "application" | "none";
165
204
  export interface ConnectOptions {
166
205
  /**
167
206
  * Optional progress callback for tracking connection stages.
168
207
  */
169
208
  progress?: ProgressCallback;
209
+ /**
210
+ * Optional AbortSignal to abort the connection attempt.
211
+ * When aborted, the connect promise will reject with a DeviceError
212
+ * with code "aborted".
213
+ *
214
+ * Note: Currently only aborts during the FindingDevice stage on native
215
+ * platforms. Web platform device selection (browser picker) cannot be
216
+ * aborted programmatically.
217
+ */
218
+ signal?: AbortSignal;
219
+ /**
220
+ * Controls bonding and post-bond device mode on native platforms.
221
+ * Ignored on web. Default: `"pairing"`.
222
+ *
223
+ * @see {@link BondMode}
224
+ */
225
+ bondMode?: BondMode;
170
226
  }
171
227
  export interface FlashOptions {
172
228
  /**
@@ -186,34 +242,48 @@ export interface FlashOptions {
186
242
  * Smallest possible progress increment to limit callback rate.
187
243
  */
188
244
  minimumProgressIncrement?: number;
245
+ /**
246
+ * Optional AbortSignal to abort the flash operation.
247
+ * When aborted, the flash promise will reject with a DeviceError
248
+ * with code "aborted".
249
+ *
250
+ * Note: Currently only aborts during the FindingDevice stage on native
251
+ * platforms. Once a device is found and flashing begins, the operation
252
+ * cannot be aborted.
253
+ */
254
+ signal?: AbortSignal;
189
255
  }
190
256
  export declare class FlashDataError extends Error {
191
257
  }
192
258
  export type FlashDataSource = (boardVersion: BoardVersion) => Promise<string | Uint8Array>;
193
259
  export type BoardVersion = "V1" | "V2";
194
- export declare class ConnectionStatusEvent extends Event {
195
- readonly status: ConnectionStatus;
196
- readonly previousStatus: ConnectionStatus;
197
- constructor(status: ConnectionStatus, previousStatus: ConnectionStatus);
198
- }
199
- export declare class BeforeRequestDevice extends Event {
200
- constructor();
201
- }
202
- export declare class AfterRequestDevice extends Event {
203
- constructor();
260
+ export interface ConnectionStatusChange {
261
+ status: ConnectionStatus;
262
+ previousStatus: ConnectionStatus;
204
263
  }
205
- export declare class BackgroundErrorEvent extends Event {
206
- readonly errorMessage: string;
207
- readonly error?: unknown | undefined;
208
- constructor(errorMessage: string, error?: unknown | undefined);
264
+ export interface BackgroundErrorData {
265
+ error: DeviceError;
266
+ event?: string;
209
267
  }
210
- export declare class DeviceConnectionEventMap {
211
- "status": ConnectionStatusEvent;
212
- "backgrounderror": BackgroundErrorEvent;
213
- "beforerequestdevice": Event;
214
- "afterrequestdevice": Event;
268
+ export interface DeviceConnectionEventMap {
269
+ status: ConnectionStatusChange;
270
+ backgrounderror: BackgroundErrorData;
271
+ beforerequestdevice: void;
272
+ afterrequestdevice: void;
273
+ flash: void;
215
274
  }
216
- export interface DeviceConnection<M extends ValueIsEvent<M>> extends TypedEventTarget<DeviceConnectionEventMap & M> {
275
+ export interface DeviceConnection {
276
+ addEventListener(type: "status", listener: (data: ConnectionStatusChange) => void): void;
277
+ addEventListener(type: "backgrounderror", listener: (data: BackgroundErrorData) => void): void;
278
+ addEventListener(type: "beforerequestdevice", listener: () => void): void;
279
+ addEventListener(type: "afterrequestdevice", listener: () => void): void;
280
+ addEventListener(type: "flash", listener: () => void): void;
281
+ removeEventListener(type: "status", listener: (data: ConnectionStatusChange) => void): void;
282
+ removeEventListener(type: "backgrounderror", listener: (data: BackgroundErrorData) => void): void;
283
+ removeEventListener(type: "beforerequestdevice", listener: () => void): void;
284
+ removeEventListener(type: "afterrequestdevice", listener: () => void): void;
285
+ removeEventListener(type: "flash", listener: () => void): void;
286
+ readonly type: string;
217
287
  status: ConnectionStatus;
218
288
  /**
219
289
  * Initializes the device.
@@ -235,29 +305,49 @@ export interface DeviceConnection<M extends ValueIsEvent<M>> extends TypedEventT
235
305
  /**
236
306
  * Connects to a currently paired device or requests pairing.
237
307
  *
238
- * @param options Optional connection options including progress callback.
308
+ * @param options Optional connection options including progress callback and abort signal.
239
309
  * @throws {DeviceError} On connection failure. The error.code property indicates the failure type.
240
310
  */
241
311
  connect(options?: ConnectOptions): Promise<void>;
242
312
  /**
243
313
  * Get the board version.
244
314
  *
245
- * @returns the board version or undefined if there is no connection.
315
+ * Cached after the first successful connection until {@link clearDevice}
316
+ * is called, so remains available after disconnection.
317
+ *
318
+ * @returns the board version.
319
+ * @throws {DeviceError} with code `not-connected` if no device has been connected.
246
320
  */
247
- getBoardVersion(): BoardVersion | undefined;
321
+ getBoardVersion(): BoardVersion;
248
322
  /**
249
323
  * Disconnect from the device.
250
324
  */
251
325
  disconnect(): Promise<void>;
252
326
  /**
253
- * Write serial data to the device.
327
+ * Flash the micro:bit.
328
+ *
329
+ * Not all connection types support flashing. For example, radio bridge
330
+ * connections do not support flashing, and Bluetooth connections only
331
+ * support flashing on native platforms (not Web).
332
+ *
333
+ * Post-flash connection state differs by transport:
334
+ *
335
+ * - **USB**: The connection remains in {@link ConnectionStatus.Connected} state.
336
+ * USB connects to the micro:bit's interface chip (running DAPLink firmware),
337
+ * which is not affected by flashing the application processor, so the
338
+ * connection persists and serial communication is automatically reinitialised.
254
339
  *
255
- * Does nothing if there is no connection.
340
+ * - **Bluetooth**: The connection is always left in {@link ConnectionStatus.Disconnected}
341
+ * state. Bluetooth connects to the application processor directly, which
342
+ * reboots after flashing, so the connection is necessarily lost. Callers
343
+ * must call {@link connect} again after flashing.
256
344
  *
257
- * @param data The data to write.
258
- * @returns A promise that resolves when the write is complete.
345
+ * @param dataSource The data to use.
346
+ * @param options Flash options and progress callback.
347
+ * @throws {DeviceError} On flash failure. The error.code property indicates the failure type.
348
+ * @throws {FlashDataError} If data preparation fails.
259
349
  */
260
- serialWrite(data: string): Promise<void>;
350
+ flash?(dataSource: FlashDataSource, options: FlashOptions): Promise<void>;
261
351
  /**
262
352
  * Clear device to enable chooseDevice.
263
353
  */
@@ -1,14 +1,31 @@
1
1
  "use strict";
2
+ /**
3
+ * (c) 2021, Micro:bit Educational Foundation and contributors
4
+ *
5
+ * SPDX-License-Identifier: MIT
6
+ */
2
7
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DeviceConnectionEventMap = exports.BackgroundErrorEvent = exports.AfterRequestDevice = exports.BeforeRequestDevice = exports.ConnectionStatusEvent = exports.FlashDataError = exports.ConnectionStatus = exports.DeviceError = exports.ProgressStage = void 0;
4
- var ProgressStage;
5
- (function (ProgressStage) {
6
- ProgressStage["Initializing"] = "Initializing";
7
- ProgressStage["FindingDevice"] = "FindingDevice";
8
- ProgressStage["Connecting"] = "Connecting";
9
- ProgressStage["PartialFlashing"] = "PartialFlashing";
10
- ProgressStage["FullFlashing"] = "FullFlashing";
11
- })(ProgressStage || (exports.ProgressStage = ProgressStage = {}));
8
+ exports.FlashDataError = exports.ConnectionStatus = exports.DeviceError = exports.ProgressStage = void 0;
9
+ exports.assertConnected = assertConnected;
10
+ /**
11
+ * Stages reported by the progress callback during connection and flashing.
12
+ */
13
+ exports.ProgressStage = {
14
+ /** Checking permissions and availability before connecting. */
15
+ Initializing: "Initializing",
16
+ /** Finding device. */
17
+ FindingDevice: "FindingDevice",
18
+ /** Checking that a bond is established. Only applicable on Native platforms. */
19
+ CheckingBond: "CheckingBond",
20
+ /** Resetting device in preparation for flashing. Only applicable on Native platforms. */
21
+ ResettingDevice: "ResettingDevice",
22
+ /** Connecting for flashing. */
23
+ Connecting: "Connecting",
24
+ /** Partial flashing. */
25
+ PartialFlashing: "PartialFlashing",
26
+ /** Full flashing. */
27
+ FullFlashing: "FullFlashing",
28
+ };
12
29
  /**
13
30
  * Error type used for all interactions with this module.
14
31
  *
@@ -19,8 +36,8 @@ var ProgressStage;
19
36
  * English.
20
37
  */
21
38
  class DeviceError extends Error {
22
- constructor({ code, message }) {
23
- super(message);
39
+ constructor({ code, message, cause, }) {
40
+ super(message, { cause });
24
41
  Object.defineProperty(this, "code", {
25
42
  enumerable: true,
26
43
  configurable: true,
@@ -31,11 +48,19 @@ class DeviceError extends Error {
31
48
  }
32
49
  }
33
50
  exports.DeviceError = DeviceError;
51
+ /**
52
+ * Asserts that a connection is active, throwing a {@link DeviceError}
53
+ * with code `"not-connected"` if it is not.
54
+ */
55
+ function assertConnected(connection) {
56
+ if (!connection) {
57
+ throw new DeviceError({ code: "not-connected", message: "Not connected" });
58
+ }
59
+ }
34
60
  /**
35
61
  * Tracks connection status.
36
62
  */
37
- var ConnectionStatus;
38
- (function (ConnectionStatus) {
63
+ exports.ConnectionStatus = {
39
64
  /**
40
65
  * No device available.
41
66
  *
@@ -45,109 +70,21 @@ var ConnectionStatus;
45
70
  * Use checkAvailability() to determine whether the connection type is
46
71
  * supported before attempting to connect.
47
72
  */
48
- ConnectionStatus["NO_AUTHORIZED_DEVICE"] = "NO_AUTHORIZED_DEVICE";
49
- /**
50
- * Authorized device available but we haven't connected to it.
51
- */
52
- ConnectionStatus["DISCONNECTED"] = "DISCONNECTED";
53
- /**
54
- * Connected.
55
- */
56
- ConnectionStatus["CONNECTED"] = "CONNECTED";
57
- /**
58
- * Connecting.
59
- */
60
- ConnectionStatus["CONNECTING"] = "CONNECTING";
61
- /**
62
- * Reconnecting. When there is unexpected disruption in the connection,
63
- * a reconnection is attempted.
64
- */
65
- ConnectionStatus["RECONNECTING"] = "RECONNECTING";
73
+ NoAuthorizedDevice: "NoAuthorizedDevice",
74
+ /** Authorized device available but we haven't connected to it. */
75
+ Disconnected: "Disconnected",
76
+ /** Connected. */
77
+ Connected: "Connected",
78
+ /** Connecting. */
79
+ Connecting: "Connecting",
66
80
  /**
67
81
  * Paused due to tab visibility. The connection was temporarily suspended
68
82
  * because the browser tab became hidden. Reconnection will be attempted
69
83
  * automatically when the tab becomes visible again.
70
84
  */
71
- ConnectionStatus["PAUSED"] = "PAUSED";
72
- })(ConnectionStatus || (exports.ConnectionStatus = ConnectionStatus = {}));
85
+ Paused: "Paused",
86
+ };
73
87
  class FlashDataError extends Error {
74
88
  }
75
89
  exports.FlashDataError = FlashDataError;
76
- class ConnectionStatusEvent extends Event {
77
- constructor(status, previousStatus) {
78
- super("status");
79
- Object.defineProperty(this, "status", {
80
- enumerable: true,
81
- configurable: true,
82
- writable: true,
83
- value: status
84
- });
85
- Object.defineProperty(this, "previousStatus", {
86
- enumerable: true,
87
- configurable: true,
88
- writable: true,
89
- value: previousStatus
90
- });
91
- }
92
- }
93
- exports.ConnectionStatusEvent = ConnectionStatusEvent;
94
- class BeforeRequestDevice extends Event {
95
- constructor() {
96
- super("beforerequestdevice");
97
- }
98
- }
99
- exports.BeforeRequestDevice = BeforeRequestDevice;
100
- class AfterRequestDevice extends Event {
101
- constructor() {
102
- super("afterrequestdevice");
103
- }
104
- }
105
- exports.AfterRequestDevice = AfterRequestDevice;
106
- class BackgroundErrorEvent extends Event {
107
- constructor(errorMessage, error) {
108
- super("backgrounderror");
109
- Object.defineProperty(this, "errorMessage", {
110
- enumerable: true,
111
- configurable: true,
112
- writable: true,
113
- value: errorMessage
114
- });
115
- Object.defineProperty(this, "error", {
116
- enumerable: true,
117
- configurable: true,
118
- writable: true,
119
- value: error
120
- });
121
- }
122
- }
123
- exports.BackgroundErrorEvent = BackgroundErrorEvent;
124
- class DeviceConnectionEventMap {
125
- constructor() {
126
- Object.defineProperty(this, "status", {
127
- enumerable: true,
128
- configurable: true,
129
- writable: true,
130
- value: void 0
131
- });
132
- Object.defineProperty(this, "backgrounderror", {
133
- enumerable: true,
134
- configurable: true,
135
- writable: true,
136
- value: void 0
137
- });
138
- Object.defineProperty(this, "beforerequestdevice", {
139
- enumerable: true,
140
- configurable: true,
141
- writable: true,
142
- value: void 0
143
- });
144
- Object.defineProperty(this, "afterrequestdevice", {
145
- enumerable: true,
146
- configurable: true,
147
- writable: true,
148
- value: void 0
149
- });
150
- }
151
- }
152
- exports.DeviceConnectionEventMap = DeviceConnectionEventMap;
153
90
  //# sourceMappingURL=device.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"device.js","sourceRoot":"","sources":["../../lib/device.ts"],"names":[],"mappings":";;;AA6FA,IAAY,aAMX;AAND,WAAY,aAAa;IACvB,8CAA6B,CAAA;IAC7B,gDAA+B,CAAA;IAC/B,0CAAyB,CAAA;IACzB,oDAAmC,CAAA;IACnC,8CAA6B,CAAA;AAC/B,CAAC,EANW,aAAa,6BAAb,aAAa,QAMxB;AAwBD;;;;;;;;GAQG;AACH,MAAa,WAAY,SAAQ,KAAK;IAEpC,YAAY,EAAE,IAAI,EAAE,OAAO,EAA+C;QACxE,KAAK,CAAC,OAAO,CAAC,CAAC;QAFjB;;;;;WAAsB;QAGpB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF;AAND,kCAMC;AAED;;GAEG;AACH,IAAY,gBAkCX;AAlCD,WAAY,gBAAgB;IAC1B;;;;;;;;OAQG;IACH,iEAA6C,CAAA;IAC7C;;OAEG;IACH,iDAA6B,CAAA;IAC7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