@microbit/microbit-connection 0.9.0-apps.alpha.15 → 0.9.0-apps.alpha.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (452) hide show
  1. package/build/cjs/async-util.js.map +1 -1
  2. package/build/cjs/async-util.test.d.ts +1 -0
  3. package/build/cjs/async-util.test.js +20 -0
  4. package/build/cjs/async-util.test.js.map +1 -0
  5. package/build/cjs/availability.js.map +1 -1
  6. package/build/{esm/bluetooth.d.ts → cjs/bluetooth/connection.d.ts} +30 -26
  7. package/build/cjs/{bluetooth.js → bluetooth/connection.js} +183 -106
  8. package/build/cjs/bluetooth/connection.js.map +1 -0
  9. package/build/cjs/bluetooth/connection.test.d.ts +1 -0
  10. package/build/cjs/bluetooth/connection.test.js +88 -0
  11. package/build/cjs/bluetooth/connection.test.js.map +1 -0
  12. package/build/cjs/bluetooth/device-bond-state.js.map +1 -0
  13. package/build/cjs/{bluetooth-device-wrapper.d.ts → bluetooth/device-wrapper.d.ts} +22 -11
  14. package/build/cjs/{bluetooth-device-wrapper.js → bluetooth/device-wrapper.js} +99 -42
  15. package/build/cjs/bluetooth/device-wrapper.js.map +1 -0
  16. package/build/cjs/{flashing → bluetooth/flashing}/flashing-full.d.ts +2 -2
  17. package/build/cjs/{flashing → bluetooth/flashing}/flashing-full.js +4 -4
  18. package/build/cjs/bluetooth/flashing/flashing-full.js.map +1 -0
  19. package/build/cjs/bluetooth/flashing/flashing-makecode.d.ts +10 -0
  20. package/build/cjs/{flashing → bluetooth/flashing}/flashing-makecode.js +5 -2
  21. package/build/cjs/bluetooth/flashing/flashing-makecode.js.map +1 -0
  22. package/build/cjs/bluetooth/flashing/flashing-makecode.test.d.ts +1 -0
  23. package/build/cjs/bluetooth/flashing/flashing-makecode.test.js +253 -0
  24. package/build/cjs/bluetooth/flashing/flashing-makecode.test.js.map +1 -0
  25. package/build/cjs/{flashing → bluetooth/flashing}/flashing-partial.d.ts +3 -2
  26. package/build/cjs/{flashing → bluetooth/flashing}/flashing-partial.js +17 -3
  27. package/build/cjs/bluetooth/flashing/flashing-partial.js.map +1 -0
  28. package/build/cjs/bluetooth/flashing/flashing-v1.js.map +1 -0
  29. package/build/cjs/{flashing → bluetooth/flashing}/nordic-dfu.d.ts +2 -2
  30. package/build/cjs/{flashing → bluetooth/flashing}/nordic-dfu.js +25 -11
  31. package/build/cjs/bluetooth/flashing/nordic-dfu.js.map +1 -0
  32. package/build/cjs/bluetooth/flashing/zip.js.map +1 -0
  33. package/build/cjs/bluetooth/flashing/zip.test.d.ts +1 -0
  34. package/build/cjs/bluetooth/flashing/zip.test.js +96 -0
  35. package/build/cjs/bluetooth/flashing/zip.test.js.map +1 -0
  36. package/build/cjs/bluetooth/index.d.ts +5 -0
  37. package/build/cjs/bluetooth/index.js +9 -0
  38. package/build/cjs/bluetooth/index.js.map +1 -0
  39. package/build/cjs/{bluetooth-profile.d.ts → bluetooth/profile.d.ts} +8 -0
  40. package/build/cjs/{bluetooth-profile.js → bluetooth/profile.js} +7 -1
  41. package/build/cjs/bluetooth/profile.js.map +1 -0
  42. package/build/{esm → cjs/bluetooth/services}/accelerometer-service.d.ts +2 -3
  43. package/build/cjs/{accelerometer-service.js → bluetooth/services/accelerometer-service.js} +16 -12
  44. package/build/cjs/bluetooth/services/accelerometer-service.js.map +1 -0
  45. package/build/{esm → cjs/bluetooth/services}/button-service.d.ts +2 -3
  46. package/build/cjs/{button-service.js → bluetooth/services/button-service.js} +15 -14
  47. package/build/cjs/bluetooth/services/button-service.js.map +1 -0
  48. package/build/{esm → cjs/bluetooth/services}/device-information-service.d.ts +1 -1
  49. package/build/cjs/{device-information-service.js → bluetooth/services/device-information-service.js} +2 -2
  50. package/build/cjs/bluetooth/services/device-information-service.js.map +1 -0
  51. package/build/cjs/{dfu-service.js → bluetooth/services/dfu-service.js} +2 -2
  52. package/build/cjs/bluetooth/services/dfu-service.js.map +1 -0
  53. package/build/cjs/{led-service.d.ts → bluetooth/services/led-service.d.ts} +2 -3
  54. package/build/cjs/{led-service.js → bluetooth/services/led-service.js} +7 -7
  55. package/build/cjs/bluetooth/services/led-service.js.map +1 -0
  56. package/build/cjs/{magnetometer-service.d.ts → bluetooth/services/magnetometer-service.d.ts} +2 -3
  57. package/build/cjs/{magnetometer-service.js → bluetooth/services/magnetometer-service.js} +18 -14
  58. package/build/cjs/bluetooth/services/magnetometer-service.js.map +1 -0
  59. package/build/{esm → cjs/bluetooth/services}/partial-flashing-service.d.ts +1 -1
  60. package/build/cjs/{partial-flashing-service.js → bluetooth/services/partial-flashing-service.js} +8 -8
  61. package/build/cjs/bluetooth/services/partial-flashing-service.js.map +1 -0
  62. package/build/cjs/{uart-service.d.ts → bluetooth/services/uart-service.d.ts} +2 -2
  63. package/build/cjs/{uart-service.js → bluetooth/services/uart-service.js} +12 -9
  64. package/build/cjs/bluetooth/services/uart-service.js.map +1 -0
  65. package/build/cjs/board-id.d.ts +1 -1
  66. package/build/cjs/board-id.js.map +1 -1
  67. package/build/cjs/device.d.ts +82 -75
  68. package/build/cjs/device.js +40 -126
  69. package/build/cjs/device.js.map +1 -1
  70. package/build/cjs/events.d.ts +9 -108
  71. package/build/cjs/events.js +27 -88
  72. package/build/cjs/events.js.map +1 -1
  73. package/build/cjs/events.test.d.ts +1 -0
  74. package/build/cjs/events.test.js +115 -0
  75. package/build/cjs/events.test.js.map +1 -0
  76. package/build/cjs/hex-util.d.ts +1 -0
  77. package/build/cjs/hex-util.js +15 -0
  78. package/build/cjs/hex-util.js.map +1 -0
  79. package/build/cjs/index.d.ts +7 -16
  80. package/build/cjs/index.js +6 -26
  81. package/build/cjs/index.js.map +1 -1
  82. package/build/cjs/logging.js.map +1 -1
  83. package/build/cjs/radio-bridge/connection.d.ts +39 -0
  84. package/build/cjs/{usb-radio-bridge.js → radio-bridge/connection.js} +39 -25
  85. package/build/cjs/radio-bridge/connection.js.map +1 -0
  86. package/build/cjs/radio-bridge/index.d.ts +4 -0
  87. package/build/cjs/radio-bridge/index.js +9 -0
  88. package/build/cjs/radio-bridge/index.js.map +1 -0
  89. package/build/cjs/{usb-serial-protocol.js → radio-bridge/serial-protocol.js} +1 -1
  90. package/build/cjs/radio-bridge/serial-protocol.js.map +1 -0
  91. package/build/cjs/service-events.d.ts +42 -14
  92. package/build/cjs/service-events.js +6 -36
  93. package/build/cjs/service-events.js.map +1 -1
  94. package/build/cjs/setupTests.js +8 -0
  95. package/build/cjs/setupTests.js.map +1 -1
  96. package/build/{esm/hex-flash-data-source.d.ts → cjs/universal-hex/flash-data-source.d.ts} +1 -2
  97. package/build/cjs/{hex-flash-data-source.js → universal-hex/flash-data-source.js} +7 -15
  98. package/build/cjs/universal-hex/flash-data-source.js.map +1 -0
  99. package/build/cjs/universal-hex/index.d.ts +4 -0
  100. package/build/cjs/universal-hex/index.js +9 -0
  101. package/build/cjs/universal-hex/index.js.map +1 -0
  102. package/build/cjs/usb/arm-debug.d.ts +137 -0
  103. package/build/cjs/usb/arm-debug.js +414 -0
  104. package/build/cjs/usb/arm-debug.js.map +1 -0
  105. package/build/cjs/usb/arm-debug.test.d.ts +1 -0
  106. package/build/cjs/usb/arm-debug.test.js +333 -0
  107. package/build/cjs/usb/arm-debug.test.js.map +1 -0
  108. package/build/cjs/{board-serial-info.d.ts → 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/board-serial-info.test.d.ts +1 -0
  112. package/build/cjs/usb/board-serial-info.test.js +46 -0
  113. package/build/cjs/usb/board-serial-info.test.js.map +1 -0
  114. package/build/cjs/usb/cdc-saturation.d.ts +36 -0
  115. package/build/cjs/usb/cdc-saturation.js +151 -0
  116. package/build/cjs/usb/cdc-saturation.js.map +1 -0
  117. package/build/cjs/usb/cmsis-dap.d.ts +113 -0
  118. package/build/cjs/usb/cmsis-dap.js +349 -0
  119. package/build/cjs/usb/cmsis-dap.js.map +1 -0
  120. package/build/cjs/usb/cmsis-dap.test.d.ts +1 -0
  121. package/build/cjs/usb/cmsis-dap.test.js +350 -0
  122. package/build/cjs/usb/cmsis-dap.test.js.map +1 -0
  123. package/build/cjs/usb/connection.d.ts +81 -0
  124. package/build/cjs/{usb.js → usb/connection.js} +243 -166
  125. package/build/cjs/usb/connection.js.map +1 -0
  126. package/build/cjs/usb/connection.test.d.ts +1 -0
  127. package/build/cjs/usb/connection.test.js +266 -0
  128. package/build/cjs/usb/connection.test.js.map +1 -0
  129. package/build/cjs/usb/cortex-m.d.ts +72 -0
  130. package/build/cjs/usb/cortex-m.js +165 -0
  131. package/build/cjs/usb/cortex-m.js.map +1 -0
  132. package/build/cjs/usb/cortex-m.test.d.ts +1 -0
  133. package/build/cjs/usb/cortex-m.test.js +217 -0
  134. package/build/cjs/usb/cortex-m.test.js.map +1 -0
  135. package/build/cjs/usb/daplink.d.ts +69 -0
  136. package/build/cjs/usb/daplink.js +238 -0
  137. package/build/cjs/usb/daplink.js.map +1 -0
  138. package/build/cjs/usb/daplink.test.d.ts +1 -0
  139. package/build/cjs/usb/daplink.test.js +290 -0
  140. package/build/cjs/usb/daplink.test.js.map +1 -0
  141. package/build/cjs/usb/device-wrapper.d.ts +34 -0
  142. package/build/cjs/usb/device-wrapper.js +102 -0
  143. package/build/cjs/usb/device-wrapper.js.map +1 -0
  144. package/build/cjs/usb/index.d.ts +5 -0
  145. package/build/cjs/usb/index.js +10 -0
  146. package/build/cjs/usb/index.js.map +1 -0
  147. package/build/{esm/usb-partial-flashing-utils.d.ts → cjs/usb/partial-flashing-utils.d.ts} +6 -9
  148. package/build/cjs/{usb-partial-flashing-utils.js → usb/partial-flashing-utils.js} +6 -49
  149. package/build/cjs/usb/partial-flashing-utils.js.map +1 -0
  150. package/build/cjs/{usb-partial-flashing.d.ts → usb/partial-flashing.d.ts} +15 -7
  151. package/build/cjs/{usb-partial-flashing.js → usb/partial-flashing.js} +64 -119
  152. package/build/cjs/usb/partial-flashing.js.map +1 -0
  153. package/build/cjs/usb/promise-queue.js.map +1 -0
  154. package/build/cjs/usb/promise-queue.test.d.ts +1 -0
  155. package/build/cjs/usb/promise-queue.test.js +68 -0
  156. package/build/cjs/usb/promise-queue.test.js.map +1 -0
  157. package/build/cjs/usb/serial-events.d.ts +21 -0
  158. package/build/cjs/{led.js → usb/serial-events.js} +1 -1
  159. package/build/cjs/usb/serial-events.js.map +1 -0
  160. package/build/cjs/usb/transport.d.ts +42 -0
  161. package/build/cjs/usb/transport.js +155 -0
  162. package/build/cjs/usb/transport.js.map +1 -0
  163. package/build/esm/async-util.js.map +1 -1
  164. package/build/esm/async-util.test.d.ts +1 -0
  165. package/build/esm/async-util.test.js +18 -0
  166. package/build/esm/async-util.test.js.map +1 -0
  167. package/build/esm/availability.js.map +1 -1
  168. package/build/{cjs/bluetooth.d.ts → esm/bluetooth/connection.d.ts} +30 -26
  169. package/build/esm/{bluetooth.js → bluetooth/connection.js} +177 -100
  170. package/build/esm/bluetooth/connection.js.map +1 -0
  171. package/build/esm/bluetooth/connection.test.d.ts +1 -0
  172. package/build/esm/bluetooth/connection.test.js +86 -0
  173. package/build/esm/bluetooth/connection.test.js.map +1 -0
  174. package/build/esm/bluetooth/device-bond-state.js.map +1 -0
  175. package/build/esm/{bluetooth-device-wrapper.d.ts → bluetooth/device-wrapper.d.ts} +22 -11
  176. package/build/esm/{bluetooth-device-wrapper.js → bluetooth/device-wrapper.js} +97 -41
  177. package/build/esm/bluetooth/device-wrapper.js.map +1 -0
  178. package/build/esm/{flashing → bluetooth/flashing}/flashing-full.d.ts +2 -2
  179. package/build/esm/{flashing → bluetooth/flashing}/flashing-full.js +4 -4
  180. package/build/esm/bluetooth/flashing/flashing-full.js.map +1 -0
  181. package/build/esm/bluetooth/flashing/flashing-makecode.d.ts +10 -0
  182. package/build/esm/{flashing → bluetooth/flashing}/flashing-makecode.js +5 -2
  183. package/build/esm/bluetooth/flashing/flashing-makecode.js.map +1 -0
  184. package/build/esm/bluetooth/flashing/flashing-makecode.test.d.ts +1 -0
  185. package/build/esm/bluetooth/flashing/flashing-makecode.test.js +248 -0
  186. package/build/esm/bluetooth/flashing/flashing-makecode.test.js.map +1 -0
  187. package/build/esm/{flashing → bluetooth/flashing}/flashing-partial.d.ts +3 -2
  188. package/build/esm/{flashing → bluetooth/flashing}/flashing-partial.js +17 -3
  189. package/build/esm/bluetooth/flashing/flashing-partial.js.map +1 -0
  190. package/build/esm/bluetooth/flashing/flashing-v1.js.map +1 -0
  191. package/build/esm/{flashing → bluetooth/flashing}/nordic-dfu.d.ts +2 -2
  192. package/build/esm/{flashing → bluetooth/flashing}/nordic-dfu.js +25 -11
  193. package/build/esm/bluetooth/flashing/nordic-dfu.js.map +1 -0
  194. package/build/esm/bluetooth/flashing/zip.js.map +1 -0
  195. package/build/esm/bluetooth/flashing/zip.test.d.ts +1 -0
  196. package/build/esm/bluetooth/flashing/zip.test.js +94 -0
  197. package/build/esm/bluetooth/flashing/zip.test.js.map +1 -0
  198. package/build/esm/bluetooth/index.d.ts +5 -0
  199. package/build/esm/bluetooth/index.js +5 -0
  200. package/build/esm/bluetooth/index.js.map +1 -0
  201. package/build/esm/{bluetooth-profile.d.ts → bluetooth/profile.d.ts} +8 -0
  202. package/build/esm/{bluetooth-profile.js → bluetooth/profile.js} +7 -1
  203. package/build/{cjs/bluetooth-profile.js.map → esm/bluetooth/profile.js.map} +1 -1
  204. package/build/{cjs → esm/bluetooth/services}/accelerometer-service.d.ts +2 -3
  205. package/build/esm/{accelerometer-service.js → bluetooth/services/accelerometer-service.js} +10 -6
  206. package/build/esm/bluetooth/services/accelerometer-service.js.map +1 -0
  207. package/build/{cjs → esm/bluetooth/services}/button-service.d.ts +2 -3
  208. package/build/esm/{button-service.js → bluetooth/services/button-service.js} +10 -9
  209. package/build/esm/bluetooth/services/button-service.js.map +1 -0
  210. package/build/{cjs → esm/bluetooth/services}/device-information-service.d.ts +1 -1
  211. package/build/esm/{device-information-service.js → bluetooth/services/device-information-service.js} +1 -1
  212. package/build/esm/bluetooth/services/device-information-service.js.map +1 -0
  213. package/build/esm/{dfu-service.js → bluetooth/services/dfu-service.js} +1 -1
  214. package/build/esm/bluetooth/services/dfu-service.js.map +1 -0
  215. package/build/esm/{led-service.d.ts → bluetooth/services/led-service.d.ts} +2 -3
  216. package/build/esm/{led-service.js → bluetooth/services/led-service.js} +1 -1
  217. package/build/esm/bluetooth/services/led-service.js.map +1 -0
  218. package/build/esm/{magnetometer-service.d.ts → bluetooth/services/magnetometer-service.d.ts} +2 -3
  219. package/build/esm/{magnetometer-service.js → bluetooth/services/magnetometer-service.js} +10 -6
  220. package/build/esm/bluetooth/services/magnetometer-service.js.map +1 -0
  221. package/build/{cjs → esm/bluetooth/services}/partial-flashing-service.d.ts +1 -1
  222. package/build/esm/{partial-flashing-service.js → bluetooth/services/partial-flashing-service.js} +4 -4
  223. package/build/esm/bluetooth/services/partial-flashing-service.js.map +1 -0
  224. package/build/esm/{uart-service.d.ts → bluetooth/services/uart-service.d.ts} +2 -2
  225. package/build/esm/{uart-service.js → bluetooth/services/uart-service.js} +8 -5
  226. package/build/esm/bluetooth/services/uart-service.js.map +1 -0
  227. package/build/esm/board-id.d.ts +1 -1
  228. package/build/esm/board-id.js.map +1 -1
  229. package/build/esm/device.d.ts +82 -75
  230. package/build/esm/device.js +38 -120
  231. package/build/esm/device.js.map +1 -1
  232. package/build/esm/events.d.ts +9 -108
  233. package/build/esm/events.js +26 -86
  234. package/build/esm/events.js.map +1 -1
  235. package/build/esm/events.test.d.ts +1 -0
  236. package/build/esm/events.test.js +113 -0
  237. package/build/esm/events.test.js.map +1 -0
  238. package/build/esm/hex-util.d.ts +1 -0
  239. package/build/esm/hex-util.js +11 -0
  240. package/build/esm/hex-util.js.map +1 -0
  241. package/build/esm/index.d.ts +7 -16
  242. package/build/esm/index.js +6 -10
  243. package/build/esm/index.js.map +1 -1
  244. package/build/esm/logging.js.map +1 -1
  245. package/build/esm/radio-bridge/connection.d.ts +39 -0
  246. package/build/esm/{usb-radio-bridge.js → radio-bridge/connection.js} +39 -25
  247. package/build/esm/radio-bridge/connection.js.map +1 -0
  248. package/build/esm/radio-bridge/index.d.ts +4 -0
  249. package/build/esm/radio-bridge/index.js +5 -0
  250. package/build/esm/radio-bridge/index.js.map +1 -0
  251. package/build/esm/{usb-serial-protocol.js → radio-bridge/serial-protocol.js} +1 -1
  252. package/build/esm/radio-bridge/serial-protocol.js.map +1 -0
  253. package/build/esm/service-events.d.ts +42 -14
  254. package/build/esm/service-events.js +5 -34
  255. package/build/esm/service-events.js.map +1 -1
  256. package/build/esm/setupTests.js +7 -0
  257. package/build/esm/setupTests.js.map +1 -1
  258. package/build/{cjs/hex-flash-data-source.d.ts → esm/universal-hex/flash-data-source.d.ts} +1 -2
  259. package/build/esm/{hex-flash-data-source.js → universal-hex/flash-data-source.js} +6 -13
  260. package/build/esm/universal-hex/flash-data-source.js.map +1 -0
  261. package/build/esm/universal-hex/index.d.ts +4 -0
  262. package/build/esm/universal-hex/index.js +5 -0
  263. package/build/esm/universal-hex/index.js.map +1 -0
  264. package/build/esm/usb/arm-debug.d.ts +137 -0
  265. package/build/esm/usb/arm-debug.js +409 -0
  266. package/build/esm/usb/arm-debug.js.map +1 -0
  267. package/build/esm/usb/arm-debug.test.d.ts +1 -0
  268. package/build/esm/usb/arm-debug.test.js +331 -0
  269. package/build/esm/usb/arm-debug.test.js.map +1 -0
  270. package/build/esm/{board-serial-info.d.ts → usb/board-serial-info.d.ts} +2 -1
  271. package/build/esm/{board-serial-info.js → usb/board-serial-info.js} +10 -7
  272. package/build/esm/usb/board-serial-info.js.map +1 -0
  273. package/build/esm/usb/board-serial-info.test.d.ts +1 -0
  274. package/build/esm/usb/board-serial-info.test.js +44 -0
  275. package/build/esm/usb/board-serial-info.test.js.map +1 -0
  276. package/build/esm/usb/cdc-saturation.d.ts +36 -0
  277. package/build/esm/usb/cdc-saturation.js +148 -0
  278. package/build/esm/usb/cdc-saturation.js.map +1 -0
  279. package/build/esm/usb/cmsis-dap.d.ts +113 -0
  280. package/build/esm/usb/cmsis-dap.js +342 -0
  281. package/build/esm/usb/cmsis-dap.js.map +1 -0
  282. package/build/esm/usb/cmsis-dap.test.d.ts +1 -0
  283. package/build/esm/usb/cmsis-dap.test.js +348 -0
  284. package/build/esm/usb/cmsis-dap.test.js.map +1 -0
  285. package/build/esm/usb/connection.d.ts +81 -0
  286. package/build/esm/{usb.js → usb/connection.js} +239 -161
  287. package/build/esm/usb/connection.js.map +1 -0
  288. package/build/esm/usb/connection.test.d.ts +1 -0
  289. package/build/esm/usb/connection.test.js +264 -0
  290. package/build/esm/usb/connection.test.js.map +1 -0
  291. package/build/esm/usb/cortex-m.d.ts +72 -0
  292. package/build/esm/usb/cortex-m.js +161 -0
  293. package/build/esm/usb/cortex-m.js.map +1 -0
  294. package/build/esm/usb/cortex-m.test.d.ts +1 -0
  295. package/build/esm/usb/cortex-m.test.js +215 -0
  296. package/build/esm/usb/cortex-m.test.js.map +1 -0
  297. package/build/esm/usb/daplink.d.ts +69 -0
  298. package/build/esm/usb/daplink.js +231 -0
  299. package/build/esm/usb/daplink.js.map +1 -0
  300. package/build/esm/usb/daplink.test.d.ts +1 -0
  301. package/build/esm/usb/daplink.test.js +288 -0
  302. package/build/esm/usb/daplink.test.js.map +1 -0
  303. package/build/esm/usb/device-wrapper.d.ts +34 -0
  304. package/build/esm/usb/device-wrapper.js +98 -0
  305. package/build/esm/usb/device-wrapper.js.map +1 -0
  306. package/build/esm/usb/index.d.ts +5 -0
  307. package/build/esm/usb/index.js +5 -0
  308. package/build/esm/usb/index.js.map +1 -0
  309. package/build/{cjs/usb-partial-flashing-utils.d.ts → esm/usb/partial-flashing-utils.d.ts} +6 -9
  310. package/build/esm/{usb-partial-flashing-utils.js → usb/partial-flashing-utils.js} +4 -44
  311. package/build/esm/usb/partial-flashing-utils.js.map +1 -0
  312. package/build/esm/{usb-partial-flashing.d.ts → usb/partial-flashing.d.ts} +15 -7
  313. package/build/esm/{usb-partial-flashing.js → usb/partial-flashing.js} +62 -94
  314. package/build/esm/usb/partial-flashing.js.map +1 -0
  315. package/build/esm/usb/promise-queue.js.map +1 -0
  316. package/build/esm/usb/promise-queue.test.d.ts +1 -0
  317. package/build/esm/usb/promise-queue.test.js +66 -0
  318. package/build/esm/usb/promise-queue.test.js.map +1 -0
  319. package/build/esm/usb/serial-events.d.ts +21 -0
  320. package/build/esm/usb/serial-events.js +2 -0
  321. package/build/esm/usb/serial-events.js.map +1 -0
  322. package/build/esm/usb/transport.d.ts +42 -0
  323. package/build/esm/usb/transport.js +151 -0
  324. package/build/esm/usb/transport.js.map +1 -0
  325. package/package.json +55 -15
  326. package/LICENSE.md +0 -21
  327. package/README.md +0 -125
  328. package/build/cjs/accelerometer-service.js.map +0 -1
  329. package/build/cjs/accelerometer.d.ts +0 -9
  330. package/build/cjs/accelerometer.js +0 -16
  331. package/build/cjs/accelerometer.js.map +0 -1
  332. package/build/cjs/bluetooth-device-wrapper.js.map +0 -1
  333. package/build/cjs/bluetooth.js.map +0 -1
  334. package/build/cjs/board-serial-info.js.map +0 -1
  335. package/build/cjs/button-service.js.map +0 -1
  336. package/build/cjs/buttons.d.ts +0 -10
  337. package/build/cjs/buttons.js +0 -22
  338. package/build/cjs/buttons.js.map +0 -1
  339. package/build/cjs/constants.d.ts +0 -48
  340. package/build/cjs/constants.js +0 -73
  341. package/build/cjs/constants.js.map +0 -1
  342. package/build/cjs/device-bond-state.js.map +0 -1
  343. package/build/cjs/device-information-service.js.map +0 -1
  344. package/build/cjs/dfu-service.js.map +0 -1
  345. package/build/cjs/flashing/flashing-full.js.map +0 -1
  346. package/build/cjs/flashing/flashing-makecode.d.ts +0 -6
  347. package/build/cjs/flashing/flashing-makecode.js.map +0 -1
  348. package/build/cjs/flashing/flashing-partial.js.map +0 -1
  349. package/build/cjs/flashing/flashing-v1.js.map +0 -1
  350. package/build/cjs/flashing/nordic-dfu.js.map +0 -1
  351. package/build/cjs/flashing/zip.js.map +0 -1
  352. package/build/cjs/hex-flash-data-source.js.map +0 -1
  353. package/build/cjs/led-service.js.map +0 -1
  354. package/build/cjs/led.d.ts +0 -6
  355. package/build/cjs/led.js.map +0 -1
  356. package/build/cjs/magnetometer-service.js.map +0 -1
  357. package/build/cjs/magnetometer.d.ts +0 -9
  358. package/build/cjs/magnetometer.js +0 -16
  359. package/build/cjs/magnetometer.js.map +0 -1
  360. package/build/cjs/partial-flashing-service.js.map +0 -1
  361. package/build/cjs/promise-queue.js.map +0 -1
  362. package/build/cjs/serial-events.d.ts +0 -20
  363. package/build/cjs/serial-events.js +0 -69
  364. package/build/cjs/serial-events.js.map +0 -1
  365. package/build/cjs/uart-service.js.map +0 -1
  366. package/build/cjs/uart.d.ts +0 -4
  367. package/build/cjs/uart.js +0 -16
  368. package/build/cjs/uart.js.map +0 -1
  369. package/build/cjs/usb-device-wrapper.d.ts +0 -47
  370. package/build/cjs/usb-device-wrapper.js +0 -437
  371. package/build/cjs/usb-device-wrapper.js.map +0 -1
  372. package/build/cjs/usb-partial-flashing-utils.js.map +0 -1
  373. package/build/cjs/usb-partial-flashing.js.map +0 -1
  374. package/build/cjs/usb-radio-bridge.d.ts +0 -24
  375. package/build/cjs/usb-radio-bridge.js.map +0 -1
  376. package/build/cjs/usb-serial-protocol.js.map +0 -1
  377. package/build/cjs/usb.d.ts +0 -66
  378. package/build/cjs/usb.js.map +0 -1
  379. package/build/esm/accelerometer-service.js.map +0 -1
  380. package/build/esm/accelerometer.d.ts +0 -9
  381. package/build/esm/accelerometer.js +0 -12
  382. package/build/esm/accelerometer.js.map +0 -1
  383. package/build/esm/bluetooth-device-wrapper.js.map +0 -1
  384. package/build/esm/bluetooth-profile.js.map +0 -1
  385. package/build/esm/bluetooth.js.map +0 -1
  386. package/build/esm/board-serial-info.js.map +0 -1
  387. package/build/esm/button-service.js.map +0 -1
  388. package/build/esm/buttons.d.ts +0 -10
  389. package/build/esm/buttons.js +0 -18
  390. package/build/esm/buttons.js.map +0 -1
  391. package/build/esm/constants.d.ts +0 -48
  392. package/build/esm/constants.js +0 -70
  393. package/build/esm/constants.js.map +0 -1
  394. package/build/esm/device-bond-state.js.map +0 -1
  395. package/build/esm/device-information-service.js.map +0 -1
  396. package/build/esm/dfu-service.js.map +0 -1
  397. package/build/esm/flashing/flashing-full.js.map +0 -1
  398. package/build/esm/flashing/flashing-makecode.d.ts +0 -6
  399. package/build/esm/flashing/flashing-makecode.js.map +0 -1
  400. package/build/esm/flashing/flashing-partial.js.map +0 -1
  401. package/build/esm/flashing/flashing-v1.js.map +0 -1
  402. package/build/esm/flashing/nordic-dfu.js.map +0 -1
  403. package/build/esm/flashing/zip.js.map +0 -1
  404. package/build/esm/hex-flash-data-source.js.map +0 -1
  405. package/build/esm/led-service.js.map +0 -1
  406. package/build/esm/led.d.ts +0 -6
  407. package/build/esm/led.js +0 -2
  408. package/build/esm/led.js.map +0 -1
  409. package/build/esm/magnetometer-service.js.map +0 -1
  410. package/build/esm/magnetometer.d.ts +0 -9
  411. package/build/esm/magnetometer.js +0 -12
  412. package/build/esm/magnetometer.js.map +0 -1
  413. package/build/esm/partial-flashing-service.js.map +0 -1
  414. package/build/esm/promise-queue.js.map +0 -1
  415. package/build/esm/serial-events.d.ts +0 -20
  416. package/build/esm/serial-events.js +0 -61
  417. package/build/esm/serial-events.js.map +0 -1
  418. package/build/esm/uart-service.js.map +0 -1
  419. package/build/esm/uart.d.ts +0 -4
  420. package/build/esm/uart.js +0 -12
  421. package/build/esm/uart.js.map +0 -1
  422. package/build/esm/usb-device-wrapper.d.ts +0 -47
  423. package/build/esm/usb-device-wrapper.js +0 -410
  424. package/build/esm/usb-device-wrapper.js.map +0 -1
  425. package/build/esm/usb-partial-flashing-utils.js.map +0 -1
  426. package/build/esm/usb-partial-flashing.js.map +0 -1
  427. package/build/esm/usb-radio-bridge.d.ts +0 -24
  428. package/build/esm/usb-radio-bridge.js.map +0 -1
  429. package/build/esm/usb-serial-protocol.js.map +0 -1
  430. package/build/esm/usb.d.ts +0 -66
  431. package/build/esm/usb.js.map +0 -1
  432. package/typedoc.json +0 -14
  433. /package/build/cjs/{device-bond-state.d.ts → bluetooth/device-bond-state.d.ts} +0 -0
  434. /package/build/cjs/{device-bond-state.js → bluetooth/device-bond-state.js} +0 -0
  435. /package/build/cjs/{flashing → bluetooth/flashing}/flashing-v1.d.ts +0 -0
  436. /package/build/cjs/{flashing → bluetooth/flashing}/flashing-v1.js +0 -0
  437. /package/build/cjs/{flashing → bluetooth/flashing}/zip.d.ts +0 -0
  438. /package/build/cjs/{flashing → bluetooth/flashing}/zip.js +0 -0
  439. /package/build/cjs/{dfu-service.d.ts → bluetooth/services/dfu-service.d.ts} +0 -0
  440. /package/build/cjs/{usb-serial-protocol.d.ts → radio-bridge/serial-protocol.d.ts} +0 -0
  441. /package/build/cjs/{promise-queue.d.ts → usb/promise-queue.d.ts} +0 -0
  442. /package/build/cjs/{promise-queue.js → usb/promise-queue.js} +0 -0
  443. /package/build/esm/{device-bond-state.d.ts → bluetooth/device-bond-state.d.ts} +0 -0
  444. /package/build/esm/{device-bond-state.js → bluetooth/device-bond-state.js} +0 -0
  445. /package/build/esm/{flashing → bluetooth/flashing}/flashing-v1.d.ts +0 -0
  446. /package/build/esm/{flashing → bluetooth/flashing}/flashing-v1.js +0 -0
  447. /package/build/esm/{flashing → bluetooth/flashing}/zip.d.ts +0 -0
  448. /package/build/esm/{flashing → bluetooth/flashing}/zip.js +0 -0
  449. /package/build/esm/{dfu-service.d.ts → bluetooth/services/dfu-service.d.ts} +0 -0
  450. /package/build/esm/{usb-serial-protocol.d.ts → radio-bridge/serial-protocol.d.ts} +0 -0
  451. /package/build/esm/{promise-queue.d.ts → usb/promise-queue.d.ts} +0 -0
  452. /package/build/esm/{promise-queue.js → usb/promise-queue.js} +0 -0
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,18 @@
1
+ /**
2
+ * (c) 2021, Micro:bit Educational Foundation and contributors
3
+ *
4
+ * SPDX-License-Identifier: MIT
5
+ */
6
+ import { describe, expect, it } from "vitest";
7
+ import { TimeoutError, withTimeout } from "./async-util.js";
8
+ describe("withTimeout", () => {
9
+ it("times out", async () => {
10
+ const neverResolves = new Promise(() => { });
11
+ await expect(() => withTimeout(neverResolves, 0)).rejects.toThrowError(TimeoutError);
12
+ });
13
+ it("returns the value", async () => {
14
+ const resolvesWithValue = async () => "foo";
15
+ expect(await withTimeout(resolvesWithValue(), 10)).toEqual("foo");
16
+ });
17
+ });
18
+ //# sourceMappingURL=async-util.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"async-util.test.js","sourceRoot":"","sources":["../../src/async-util.test.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAE5D,QAAQ,CAAC,aAAa,EAAE,GAAG,EAAE;IAC3B,EAAE,CAAC,WAAW,EAAE,KAAK,IAAI,EAAE;QACzB,MAAM,aAAa,GAAG,IAAI,OAAO,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;QAC5C,MAAM,MAAM,CAAC,GAAG,EAAE,CAAC,WAAW,CAAC,aAAa,EAAE,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,YAAY,CACpE,YAAY,CACb,CAAC;IACJ,CAAC,CAAC,CAAC;IACH,EAAE,CAAC,mBAAmB,EAAE,KAAK,IAAI,EAAE;QACjC,MAAM,iBAAiB,GAAG,KAAK,IAAI,EAAE,CAAC,KAAK,CAAC;QAC5C,MAAM,CAAC,MAAM,WAAW,CAAC,iBAAiB,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IACpE,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"availability.js","sourceRoot":"","sources":["../../lib/availability.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAgC,WAAW,EAAE,MAAM,aAAa,CAAC;AAExE;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAChC,MAAoC,EAC9B,EAAE;IACR,QAAQ,MAAM,EAAE,CAAC;QACf,KAAK,WAAW;YACd,OAAO;QACT,KAAK,aAAa;YAChB,MAAM,IAAI,WAAW,CAAC;gBACpB,IAAI,EAAE,aAAa;gBACnB,OAAO,EAAE,+BAA+B;aACzC,CAAC,CAAC;QACL,KAAK,UAAU;YACb,MAAM,IAAI,WAAW,CAAC;gBACpB,IAAI,EAAE,UAAU;gBAChB,OAAO,EAAE,wBAAwB;aAClC,CAAC,CAAC;QACL,KAAK,mBAAmB;YACtB,MAAM,IAAI,WAAW,CAAC;gBACpB,IAAI,EAAE,mBAAmB;gBACzB,OAAO,EAAE,mBAAmB;aAC7B,CAAC,CAAC;QACL,KAAK,mBAAmB;YACtB,MAAM,IAAI,WAAW,CAAC;gBACpB,IAAI,EAAE,mBAAmB;gBACzB,OAAO,EAAE,4BAA4B;aACtC,CAAC,CAAC;IACP,CAAC;AACH,CAAC,CAAC"}
1
+ {"version":3,"file":"availability.js","sourceRoot":"","sources":["../../src/availability.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAgC,WAAW,EAAE,MAAM,aAAa,CAAC;AAExE;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAChC,MAAoC,EAC9B,EAAE;IACR,QAAQ,MAAM,EAAE,CAAC;QACf,KAAK,WAAW;YACd,OAAO;QACT,KAAK,aAAa;YAChB,MAAM,IAAI,WAAW,CAAC;gBACpB,IAAI,EAAE,aAAa;gBACnB,OAAO,EAAE,+BAA+B;aACzC,CAAC,CAAC;QACL,KAAK,UAAU;YACb,MAAM,IAAI,WAAW,CAAC;gBACpB,IAAI,EAAE,UAAU;gBAChB,OAAO,EAAE,wBAAwB;aAClC,CAAC,CAAC;QACL,KAAK,mBAAmB;YACtB,MAAM,IAAI,WAAW,CAAC;gBACpB,IAAI,EAAE,mBAAmB;gBACzB,OAAO,EAAE,mBAAmB;aAC7B,CAAC,CAAC;QACL,KAAK,mBAAmB;YACtB,MAAM,IAAI,WAAW,CAAC;gBACpB,IAAI,EAAE,mBAAmB;gBACzB,OAAO,EAAE,4BAA4B;aACtC,CAAC,CAAC;IACP,CAAC;AACH,CAAC,CAAC"}
@@ -1,15 +1,12 @@
1
- import { AccelerometerData } from "./accelerometer.js";
2
- import { DeviceConnection, FlashDataSource, FlashOptions } from "./device.js";
3
- import { LedMatrix } from "./led.js";
4
- import { Logging } from "./logging.js";
5
- import { MagnetometerData } from "./magnetometer.js";
6
- import { ServiceConnectionEventMap } from "./service-events.js";
1
+ import { DeviceConnection, FlashDataSource, FlashOptions } from "../device.js";
2
+ import { Logging } from "../logging.js";
3
+ import { AccelerometerData, LedMatrix, MagnetometerData, ServiceConnectionEventMap } from "../service-events.js";
7
4
  import { DeviceBondState } from "./device-bond-state.js";
8
- export interface MicrobitWebBluetoothConnectionOptions {
5
+ export interface MicrobitBluetoothConnectionOptions {
9
6
  logging?: Logging;
10
7
  deviceBondState?: DeviceBondState;
11
8
  }
12
- export interface MicrobitWebBluetoothConnection extends DeviceConnection<ServiceConnectionEventMap> {
9
+ export interface MicrobitBluetoothConnection extends DeviceConnection<ServiceConnectionEventMap> {
13
10
  /**
14
11
  * Sets micro:bit name filter for device requesting.
15
12
  *
@@ -19,96 +16,103 @@ export interface MicrobitWebBluetoothConnection extends DeviceConnection<Service
19
16
  /**
20
17
  * Gets micro:bit accelerometer data.
21
18
  *
22
- * @returns accelerometer data or undefined if there is no connection.
19
+ * @returns accelerometer data.
20
+ * @throws {DeviceError} with code `not-connected` if there is no connection.
23
21
  */
24
- getAccelerometerData(): Promise<AccelerometerData | undefined>;
22
+ getAccelerometerData(): Promise<AccelerometerData>;
25
23
  /**
26
24
  * Gets micro:bit accelerometer period.
27
25
  *
28
- * @returns accelerometer period or undefined if there is no connection.
26
+ * @returns accelerometer period.
27
+ * @throws {DeviceError} with code `not-connected` if there is no connection.
29
28
  */
30
- getAccelerometerPeriod(): Promise<number | undefined>;
29
+ getAccelerometerPeriod(): Promise<number>;
31
30
  /**
32
31
  * Sets micro:bit accelerometer period.
33
32
  *
34
33
  * @param value The accelerometer period.
34
+ * @throws {DeviceError} with code `not-connected` if there is no connection.
35
35
  */
36
36
  setAccelerometerPeriod(value: number): Promise<void>;
37
37
  /**
38
38
  * Sets micro:bit LED text.
39
39
  *
40
40
  * @param text The text displayed on micro:bit LED.
41
+ * @throws {DeviceError} with code `not-connected` if there is no connection.
41
42
  */
42
43
  setLedText(text: string): Promise<void>;
43
44
  /**
44
45
  * Gets micro:bit LED scrolling delay.
45
46
  *
46
47
  * @returns LED scrolling delay in milliseconds.
48
+ * @throws {DeviceError} with code `not-connected` if there is no connection.
47
49
  */
48
- getLedScrollingDelay(): Promise<number | undefined>;
50
+ getLedScrollingDelay(): Promise<number>;
49
51
  /**
50
52
  * Sets micro:bit LED scrolling delay.
51
53
  *
52
54
  * @param delayInMillis LED scrolling delay in milliseconds.
55
+ * @throws {DeviceError} with code `not-connected` if there is no connection.
53
56
  */
54
57
  setLedScrollingDelay(delayInMillis: number): Promise<void>;
55
58
  /**
56
59
  * Gets micro:bit LED matrix.
57
60
  *
58
61
  * @returns a boolean matrix representing the micro:bit LED display.
62
+ * @throws {DeviceError} with code `not-connected` if there is no connection.
59
63
  */
60
- getLedMatrix(): Promise<LedMatrix | undefined>;
64
+ getLedMatrix(): Promise<LedMatrix>;
61
65
  /**
62
66
  * Sets micro:bit LED matrix.
63
67
  *
64
68
  * @param matrix an boolean matrix representing the micro:bit LED display.
69
+ * @throws {DeviceError} with code `not-connected` if there is no connection.
65
70
  */
66
71
  setLedMatrix(matrix: LedMatrix): Promise<void>;
67
72
  /**
68
73
  * Gets micro:bit magnetometer data.
69
74
  *
70
75
  * @returns magnetometer data.
76
+ * @throws {DeviceError} with code `not-connected` if there is no connection.
71
77
  */
72
- getMagnetometerData(): Promise<MagnetometerData | undefined>;
78
+ getMagnetometerData(): Promise<MagnetometerData>;
73
79
  /**
74
80
  * Gets micro:bit magnetometer bearing.
75
81
  *
76
82
  * @returns magnetometer bearing.
83
+ * @throws {DeviceError} with code `not-connected` if there is no connection.
77
84
  */
78
- getMagnetometerBearing(): Promise<number | undefined>;
85
+ getMagnetometerBearing(): Promise<number>;
79
86
  /**
80
87
  * Gets micro:bit magnetometer period.
81
88
  *
82
89
  * @returns magnetometer period.
90
+ * @throws {DeviceError} with code `not-connected` if there is no connection.
83
91
  */
84
- getMagnetometerPeriod(): Promise<number | undefined>;
92
+ getMagnetometerPeriod(): Promise<number>;
85
93
  /**
86
94
  * Sets micro:bit magnetometer period.
87
95
  *
88
96
  * @param value magnetometer period.
97
+ * @throws {DeviceError} with code `not-connected` if there is no connection.
89
98
  */
90
99
  setMagnetometerPeriod(value: number): Promise<void>;
91
100
  /**
92
101
  * Triggers micro:bit magnetometer calibration.
102
+ *
103
+ * @throws {DeviceError} with code `not-connected` if there is no connection.
93
104
  */
94
105
  triggerMagnetometerCalibration(): Promise<void>;
95
106
  /**
96
107
  * Write UART messages.
97
108
  *
98
109
  * @param data UART message.
110
+ * @throws {DeviceError} with code `not-connected` if there is no connection.
99
111
  */
100
112
  uartWrite(data: Uint8Array): Promise<void>;
101
- /**
102
- * Flash the micro:bit.
103
- *
104
- * @param dataSource The data to use.
105
- * @param options Flash options and progress callback.
106
- * @throws {DeviceError} On flash failure. The error.code property indicates the failure type.
107
- * @throws {FlashDataError} If data preparation fails.
108
- */
109
113
  flash(dataSource: FlashDataSource, options: FlashOptions): Promise<void>;
110
114
  }
111
115
  /**
112
116
  * A Bluetooth connection factory.
113
117
  */
114
- export declare const createWebBluetoothConnection: (options?: MicrobitWebBluetoothConnectionOptions) => MicrobitWebBluetoothConnection;
118
+ export declare const createBluetoothConnection: (options?: MicrobitBluetoothConnectionOptions) => MicrobitBluetoothConnection;
@@ -6,38 +6,39 @@
6
6
  import { BleClient } from "@capacitor-community/bluetooth-le";
7
7
  import { Capacitor } from "@capacitor/core";
8
8
  import MemoryMap from "nrf-intel-hex";
9
- import { BluetoothDeviceWrapper, isAndroid, scanningTimeoutInMs, } from "./bluetooth-device-wrapper.js";
10
- import { profile } from "./bluetooth-profile.js";
11
- import { AfterRequestDevice, BeforeRequestDevice, ConnectionStatus, ConnectionStatusEvent, DeviceError, FlashDataError, ProgressStage, } from "./device.js";
12
- import { TypedEventTarget } from "./events.js";
13
- import { ConsoleLogging } from "./logging.js";
9
+ import { BluetoothDeviceWrapper, isAndroid, scanningTimeoutInMs, } from "./device-wrapper.js";
10
+ import { profile } from "./profile.js";
11
+ import { ConnectionStatus, DeviceError, FlashDataError, assertConnected, ProgressStage, } from "../device.js";
12
+ import { TypedEventTarget } from "../events.js";
13
+ import { ConsoleLogging } from "../logging.js";
14
14
  import { fullFlash } from "./flashing/flashing-full.js";
15
15
  import partialFlash, { PartialFlashResult, } from "./flashing/flashing-partial.js";
16
- import { throwIfUnavailable } from "./availability.js";
17
- import { truncateHexAfterEof } from "./hex-flash-data-source.js";
16
+ import { throwIfUnavailable } from "../availability.js";
17
+ import { truncateHexAfterEof } from "../hex-util.js";
18
18
  import { DefaultDeviceBondState, } from "./device-bond-state.js";
19
+ import { TimeoutError } from "../async-util.js";
19
20
  let bleClientInitialized = false;
20
21
  /**
21
22
  * A Bluetooth connection factory.
22
23
  */
23
- export const createWebBluetoothConnection = (options) => new MicrobitWebBluetoothConnectionImpl(options);
24
+ export const createBluetoothConnection = (options) => new MicrobitBluetoothConnectionImpl(options);
24
25
  /**
25
26
  * A Bluetooth connection to a micro:bit device.
26
27
  */
27
- class MicrobitWebBluetoothConnectionImpl extends TypedEventTarget {
28
+ class MicrobitBluetoothConnectionImpl extends TypedEventTarget {
28
29
  constructor(options = {}) {
29
30
  super();
30
31
  Object.defineProperty(this, "status", {
31
32
  enumerable: true,
32
33
  configurable: true,
33
34
  writable: true,
34
- value: ConnectionStatus.NO_AUTHORIZED_DEVICE
35
+ value: ConnectionStatus.NoAuthorizedDevice
35
36
  });
36
37
  /**
37
- * The USB device we last connected to.
38
+ * The BLE device we last connected to.
38
39
  * Cleared if it is disconnected.
39
40
  */
40
- Object.defineProperty(this, "device", {
41
+ Object.defineProperty(this, "bleDevice", {
41
42
  enumerable: true,
42
43
  configurable: true,
43
44
  writable: true,
@@ -55,7 +56,19 @@ class MicrobitWebBluetoothConnectionImpl extends TypedEventTarget {
55
56
  writable: true,
56
57
  value: void 0
57
58
  });
58
- Object.defineProperty(this, "connection", {
59
+ /**
60
+ * Device-specific state. Created on connect, cleared on disconnect.
61
+ */
62
+ Object.defineProperty(this, "device", {
63
+ enumerable: true,
64
+ configurable: true,
65
+ writable: true,
66
+ value: void 0
67
+ });
68
+ /**
69
+ * Cached device property that persists across reconnections until clearDevice.
70
+ */
71
+ Object.defineProperty(this, "cachedBoardVersion", {
59
72
  enumerable: true,
60
73
  configurable: true,
61
74
  writable: true,
@@ -73,15 +86,21 @@ class MicrobitWebBluetoothConnectionImpl extends TypedEventTarget {
73
86
  writable: true,
74
87
  value: void 0
75
88
  });
89
+ Object.defineProperty(this, "waitForPostFlashDisconnectPromise", {
90
+ enumerable: true,
91
+ configurable: true,
92
+ writable: true,
93
+ value: void 0
94
+ });
76
95
  this.logging = options.logging || new ConsoleLogging();
77
96
  this.deviceBondState =
78
97
  options.deviceBondState || new DefaultDeviceBondState();
79
98
  }
80
99
  eventActivated(type) {
81
- this.connection?.startNotifications(type);
100
+ this.device?.startNotifications(type);
82
101
  }
83
102
  eventDeactivated(type) {
84
- this.connection?.stopNotifications(type);
103
+ this.device?.stopNotifications(type);
85
104
  }
86
105
  log(v) {
87
106
  this.logging.log(v);
@@ -149,7 +168,8 @@ class MicrobitWebBluetoothConnectionImpl extends TypedEventTarget {
149
168
  }
150
169
  }
151
170
  getBoardVersion() {
152
- return this.connection?.boardVersion;
171
+ assertConnected(this.cachedBoardVersion);
172
+ return this.cachedBoardVersion;
153
173
  }
154
174
  async connect(options) {
155
175
  const progress = options?.progress ?? (() => { });
@@ -157,21 +177,26 @@ class MicrobitWebBluetoothConnectionImpl extends TypedEventTarget {
157
177
  // because on Android/iOS that's the appropriate time to ask for permissions.
158
178
  progress(ProgressStage.Initializing);
159
179
  throwIfUnavailable(await this.checkAvailability());
160
- if (!this.device || !this.connection) {
180
+ // After partial flashing, we will need to wait for connection to fully
181
+ // disconnect before attempting to connect.
182
+ this.waitForPostFlashDisconnectPromise &&
183
+ (await this.waitForPostFlashDisconnectPromise);
184
+ if (!this.bleDevice || !this.device) {
161
185
  progress(ProgressStage.FindingDevice);
162
186
  const device = await this.requestDevice(options?.signal);
163
- this.connection = new BluetoothDeviceWrapper(device, this.logging, this.deviceBondState, this.dispatchTypedEvent.bind(this), () => this.getActiveEvents(), {
164
- onConnecting: () => this.setStatus(ConnectionStatus.CONNECTING),
165
- onSuccess: () => this.setStatus(ConnectionStatus.CONNECTED),
166
- onDisconnect: () => this.setStatus(ConnectionStatus.DISCONNECTED),
187
+ this.device = new BluetoothDeviceWrapper(device, this.logging, this.deviceBondState, this.dispatchEvent.bind(this), () => this.getActiveEvents(), {
188
+ onConnecting: () => this.setStatus(ConnectionStatus.Connecting),
189
+ onSuccess: () => this.setStatus(ConnectionStatus.Connected),
190
+ onDisconnect: () => this.setStatus(ConnectionStatus.Disconnected),
167
191
  });
168
192
  }
169
- await this.connection.connect(options);
193
+ await this.device.connect(options);
194
+ this.cachedBoardVersion = this.device.boardVersion;
170
195
  }
171
196
  async disconnect() {
172
197
  try {
173
- if (this.connection) {
174
- await this.connection.disconnect();
198
+ if (this.device) {
199
+ await this.device.disconnect();
175
200
  }
176
201
  }
177
202
  catch (e) {
@@ -181,7 +206,7 @@ class MicrobitWebBluetoothConnectionImpl extends TypedEventTarget {
181
206
  });
182
207
  }
183
208
  finally {
184
- this.setStatus(ConnectionStatus.DISCONNECTED);
209
+ this.setStatus(ConnectionStatus.Disconnected);
185
210
  this.logging.event({
186
211
  type: "Bluetooth-info",
187
212
  message: "disconnected",
@@ -193,105 +218,118 @@ class MicrobitWebBluetoothConnectionImpl extends TypedEventTarget {
193
218
  this.status = newStatus;
194
219
  this.log("Bluetooth connection status " + newStatus);
195
220
  if (this.deferredUpdatesPreviousStatus === undefined) {
196
- this.dispatchTypedEvent("status", new ConnectionStatusEvent(newStatus, previousStatus));
197
- }
198
- }
199
- serialWrite(data) {
200
- if (this.connection) {
201
- // TODO
221
+ this.dispatchEvent("status", {
222
+ status: newStatus,
223
+ previousStatus,
224
+ });
202
225
  }
203
- return Promise.resolve();
204
226
  }
205
227
  async clearDevice() {
206
228
  await this.disconnect();
207
- this.device = undefined;
208
- this.setStatus(ConnectionStatus.NO_AUTHORIZED_DEVICE);
229
+ this.bleDevice = undefined;
230
+ this.cachedBoardVersion = undefined;
231
+ this.setStatus(ConnectionStatus.NoAuthorizedDevice);
209
232
  }
210
233
  setNameFilter(name) {
211
234
  this.nameFilter = name;
212
235
  }
213
236
  async requestDevice(signal) {
214
- // TODO: is this possible to reinstate?
237
+ // Support both the default "BBC micro:bit" name and the shorter "uBit"
238
+ // name used by some MakeCode extensions (e.g. bsiever/microbit-pxt-blehid).
215
239
  // See https://github.com/bsiever/microbit-pxt-blehid/issues/31
216
- // namePrefix: this.nameFilter
217
- // ? `uBit [${this.nameFilter}]`
218
- // : "uBit",
219
- const namePrefix = this.nameFilter
220
- ? `BBC micro:bit [${this.nameFilter}]`
221
- : "BBC micro:bit";
240
+ const namePrefixes = this.nameFilter
241
+ ? [`BBC micro:bit [${this.nameFilter}]`, `uBit [${this.nameFilter}]`]
242
+ : ["BBC micro:bit", "uBit"];
222
243
  // If we have a cached device, check if it still matches the current filter.
223
244
  // If not, clear it so we find a new device.
224
- if (this.device) {
225
- if (this.device.name?.startsWith(namePrefix)) {
226
- return this.device;
245
+ if (this.bleDevice) {
246
+ if (namePrefixes.some((p) => this.bleDevice.name?.startsWith(p))) {
247
+ return this.bleDevice;
227
248
  }
228
- this.log(`Cached device "${this.device.name}" doesn't match filter "${namePrefix}", clearing`);
249
+ this.log(`Cached device "${this.bleDevice.name}" doesn't match filters "${namePrefixes.join(", ")}", clearing`);
229
250
  await this.clearDevice();
230
251
  }
231
- this.dispatchTypedEvent("beforerequestdevice", new BeforeRequestDevice());
252
+ this.dispatchEvent("beforerequestdevice");
232
253
  try {
233
- this.device = Capacitor.isNativePlatform()
234
- ? await this.requestDeviceNative(namePrefix, signal)
235
- : await this.requestDeviceWeb(namePrefix);
236
- if (!this.device) {
237
- this.setStatus(ConnectionStatus.NO_AUTHORIZED_DEVICE);
254
+ this.bleDevice = Capacitor.isNativePlatform()
255
+ ? await this.requestDeviceNative(namePrefixes, signal)
256
+ : await this.requestDeviceWeb(namePrefixes);
257
+ if (!this.bleDevice) {
258
+ this.setStatus(ConnectionStatus.NoAuthorizedDevice);
238
259
  throw new DeviceError({
239
260
  code: "no-device-selected",
240
261
  message: "No device selected",
241
262
  });
242
263
  }
243
- return this.device;
264
+ return this.bleDevice;
244
265
  }
245
266
  finally {
246
- this.dispatchTypedEvent("afterrequestdevice", new AfterRequestDevice());
267
+ this.dispatchEvent("afterrequestdevice");
247
268
  }
248
269
  }
249
270
  async getAccelerometerData() {
250
- return this.connection?.accelerometer.getData();
271
+ assertConnected(this.device);
272
+ return this.device.accelerometer.getData();
251
273
  }
252
274
  async getAccelerometerPeriod() {
253
- return this.connection?.accelerometer.getPeriod();
275
+ assertConnected(this.device);
276
+ return this.device.accelerometer.getPeriod();
254
277
  }
255
278
  async setAccelerometerPeriod(value) {
256
- return this.connection?.accelerometer.setPeriod(value);
279
+ assertConnected(this.device);
280
+ return this.device.accelerometer.setPeriod(value);
257
281
  }
258
282
  async setLedText(text) {
259
- return this.connection?.led.setText(text);
283
+ assertConnected(this.device);
284
+ return this.device.led.setText(text);
260
285
  }
261
286
  async getLedScrollingDelay() {
262
- return this.connection?.led.getScrollingDelay();
287
+ assertConnected(this.device);
288
+ return this.device.led.getScrollingDelay();
263
289
  }
264
290
  async setLedScrollingDelay(delayInMillis) {
265
- await this.connection?.led.setScrollingDelay(delayInMillis);
291
+ assertConnected(this.device);
292
+ await this.device.led.setScrollingDelay(delayInMillis);
266
293
  }
267
294
  async getLedMatrix() {
268
- return await this.connection?.led.getLedMatrix();
295
+ assertConnected(this.device);
296
+ return await this.device.led.getLedMatrix();
269
297
  }
270
298
  async setLedMatrix(matrix) {
271
- await this.connection?.led.setLedMatrix(matrix);
299
+ assertConnected(this.device);
300
+ await this.device.led.setLedMatrix(matrix);
272
301
  }
273
302
  async getMagnetometerData() {
274
- return this.connection?.magnetometer.getData();
303
+ assertConnected(this.device);
304
+ return this.device.magnetometer.getData();
275
305
  }
276
306
  async getMagnetometerPeriod() {
277
- return this.connection?.magnetometer.getPeriod();
307
+ assertConnected(this.device);
308
+ return this.device.magnetometer.getPeriod();
278
309
  }
279
310
  async setMagnetometerPeriod(value) {
280
- return this.connection?.magnetometer.setPeriod(value);
311
+ assertConnected(this.device);
312
+ return this.device.magnetometer.setPeriod(value);
281
313
  }
282
314
  async getMagnetometerBearing() {
283
- return this.connection?.magnetometer.getBearing();
315
+ assertConnected(this.device);
316
+ return this.device.magnetometer.getBearing();
284
317
  }
285
318
  async triggerMagnetometerCalibration() {
286
- await this.connection?.magnetometer.triggerCalibration();
319
+ assertConnected(this.device);
320
+ await this.device.magnetometer.triggerCalibration();
287
321
  }
288
322
  async uartWrite(data) {
289
- await this.connection?.uart.writeData(data);
323
+ assertConnected(this.device);
324
+ await this.device.uart.writeData(data);
290
325
  }
291
326
  /**
292
327
  * Flash the micro:bit.
293
328
  *
294
- * Note that this will always leave the connection disconnected.
329
+ * Always leaves the connection in {@link ConnectionStatus.Disconnected} state.
330
+ * Bluetooth connects directly to the application processor, which reboots
331
+ * after flashing, so the connection is necessarily lost. Call {@link connect}
332
+ * again after flashing to reconnect.
295
333
  *
296
334
  * @param dataSource The data to use.
297
335
  * @param options Flash options and progress callback.
@@ -301,10 +339,10 @@ class MicrobitWebBluetoothConnectionImpl extends TypedEventTarget {
301
339
  try {
302
340
  // We'll disconnect/reconnect multiple times due to device resets, but reporting this is unhelpful.
303
341
  this.deferredUpdatesPreviousStatus = this.status;
304
- if (this.status !== ConnectionStatus.CONNECTED) {
342
+ if (this.status !== ConnectionStatus.Connected) {
305
343
  await this.connect({ progress, signal: options.signal });
306
344
  }
307
- const connection = this.connection;
345
+ const connection = this.device;
308
346
  try {
309
347
  const boardVersion = connection.boardVersion;
310
348
  if (!boardVersion) {
@@ -317,7 +355,7 @@ class MicrobitWebBluetoothConnectionImpl extends TypedEventTarget {
317
355
  if (!memoryMap) {
318
356
  throw new FlashDataError("Could not convert hex to memory map");
319
357
  }
320
- if (!this.device) {
358
+ if (!this.bleDevice) {
321
359
  throw new DeviceError({
322
360
  code: "device-disconnected",
323
361
  message: "No device",
@@ -328,10 +366,32 @@ class MicrobitWebBluetoothConnectionImpl extends TypedEventTarget {
328
366
  if (partialFlashResult === PartialFlashResult.AttemptFullFlash) {
329
367
  await fullFlash(connection, boardVersion, memoryMap, progress);
330
368
  }
331
- else if (partialFlashResult === PartialFlashResult.Success) {
332
- if (connection.connected) {
333
- await connection.waitForDisconnect(10_000);
334
- }
369
+ this.dispatchEvent("flash");
370
+ if (partialFlashResult === PartialFlashResult.AlreadyUpToDate ||
371
+ partialFlashResult === PartialFlashResult.Success) {
372
+ this.waitForPostFlashDisconnectPromise = (async () => {
373
+ try {
374
+ if (connection.connected) {
375
+ this.log("Wait for post partial flash disconnect...");
376
+ await connection.waitForDisconnect(10_000);
377
+ }
378
+ }
379
+ catch (e) {
380
+ if (e instanceof TimeoutError) {
381
+ this.log("Wait for post partial flash disconnect timed out.");
382
+ }
383
+ else {
384
+ this.error("Error waiting for post partial flash disconnect", e);
385
+ }
386
+ }
387
+ finally {
388
+ this.waitForPostFlashDisconnectPromise = undefined;
389
+ if (connection.connected) {
390
+ await this.disconnect();
391
+ }
392
+ }
393
+ })();
394
+ this.setStatus(ConnectionStatus.Disconnected);
335
395
  }
336
396
  }
337
397
  catch (e) {
@@ -339,13 +399,18 @@ class MicrobitWebBluetoothConnectionImpl extends TypedEventTarget {
339
399
  throw e;
340
400
  }
341
401
  finally {
342
- await this.disconnect();
402
+ if (!this.waitForPostFlashDisconnectPromise) {
403
+ await this.disconnect();
404
+ }
343
405
  }
344
406
  }
345
407
  finally {
346
408
  const previousStatus = this.deferredUpdatesPreviousStatus;
347
409
  this.deferredUpdatesPreviousStatus = undefined;
348
- this.dispatchTypedEvent("status", new ConnectionStatusEvent(this.status, previousStatus));
410
+ this.dispatchEvent("status", {
411
+ status: this.status,
412
+ previousStatus,
413
+ });
349
414
  }
350
415
  }
351
416
  /**
@@ -353,22 +418,33 @@ class MicrobitWebBluetoothConnectionImpl extends TypedEventTarget {
353
418
  *
354
419
  * @returns device or undefined if user cancels.
355
420
  */
356
- async requestDeviceWeb(namePrefix) {
421
+ async requestDeviceWeb(namePrefixes) {
422
+ const optionalServices = [
423
+ profile.accelerometer.id,
424
+ profile.button.id,
425
+ profile.deviceInformation.id,
426
+ profile.dfuControl.id,
427
+ profile.event.id,
428
+ profile.ioPin.id,
429
+ profile.led.id,
430
+ profile.magnetometer.id,
431
+ profile.temperature.id,
432
+ profile.uart.id,
433
+ ];
434
+ // Temporarily patch navigator.bluetooth.requestDevice to support multiple
435
+ // name prefix filters. The capacitor-ble plugin only supports a single
436
+ // namePrefix, but the Web Bluetooth API supports a filters array.
437
+ // By patching at this level the plugin's internal deviceMap is populated
438
+ // naturally when its own requestDevice completes.
439
+ const orig = navigator.bluetooth.requestDevice.bind(navigator.bluetooth);
357
440
  try {
441
+ navigator.bluetooth.requestDevice = (options) => orig({
442
+ ...options,
443
+ filters: namePrefixes.map((namePrefix) => ({ namePrefix })),
444
+ });
358
445
  return await BleClient.requestDevice({
359
- namePrefix,
360
- optionalServices: [
361
- profile.accelerometer.id,
362
- profile.button.id,
363
- profile.deviceInformation.id,
364
- profile.dfuControl.id,
365
- profile.event.id,
366
- profile.ioPin.id,
367
- profile.led.id,
368
- profile.magnetometer.id,
369
- profile.temperature.id,
370
- profile.uart.id,
371
- ],
446
+ namePrefix: namePrefixes[0],
447
+ optionalServices,
372
448
  });
373
449
  }
374
450
  catch (e) {
@@ -377,6 +453,9 @@ class MicrobitWebBluetoothConnectionImpl extends TypedEventTarget {
377
453
  }
378
454
  throw e;
379
455
  }
456
+ finally {
457
+ navigator.bluetooth.requestDevice = orig;
458
+ }
380
459
  }
381
460
  /**
382
461
  * Finds device with specified name prefix.
@@ -384,19 +463,17 @@ class MicrobitWebBluetoothConnectionImpl extends TypedEventTarget {
384
463
  * @returns device or undefined if none can be found.
385
464
  * @throws DeviceError with code "aborted" if signal is aborted.
386
465
  */
387
- async requestDeviceNative(namePrefix, signal) {
466
+ async requestDeviceNative(namePrefixes, signal) {
388
467
  if (signal?.aborted) {
389
468
  throw new DeviceError({ code: "aborted", message: "Connection aborted" });
390
469
  }
470
+ const matchesAnyPrefix = (name) => !!name && namePrefixes.some((p) => name.startsWith(p));
391
471
  // Check for existing bonded devices.
392
- const bonded = await this.checkBondedDevices((device) => {
393
- const name = device.name;
394
- return !!name && name.startsWith(namePrefix);
395
- });
472
+ const bonded = await this.checkBondedDevices((device) => matchesAnyPrefix(device.name));
396
473
  if (bonded) {
397
474
  return bonded;
398
475
  }
399
- this.log(`Scanning for device - ${namePrefix}`);
476
+ this.log(`Scanning for device - ${namePrefixes.join(", ")}`);
400
477
  let found = false;
401
478
  let aborted = false;
402
479
  const scanPromise = new Promise((resolve) =>
@@ -406,8 +483,8 @@ class MicrobitWebBluetoothConnectionImpl extends TypedEventTarget {
406
483
  // isn't matched by the name filter but the advertising name is in the
407
484
  // localName on the device. So we filter here instead. This happens on
408
485
  // iOS if DFU fails / is interrupted.
409
- if (result.device.name?.startsWith(namePrefix) ||
410
- result.localName?.startsWith(namePrefix)) {
486
+ if (matchesAnyPrefix(result.device.name) ||
487
+ matchesAnyPrefix(result.localName)) {
411
488
  found = true;
412
489
  await BleClient.stopLEScan();
413
490
  resolve(result.device);
@@ -452,4 +529,4 @@ const convertDataToMemoryMap = (data) => {
452
529
  }
453
530
  return MemoryMap.fromHex(truncateHexAfterEof(data));
454
531
  };
455
- //# sourceMappingURL=bluetooth.js.map
532
+ //# sourceMappingURL=connection.js.map