@microbit/microbit-connection 0.9.0-apps.alpha.16 → 0.9.0-apps.alpha.18

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 (457) hide show
  1. package/build/cjs/async-util.d.ts +3 -1
  2. package/build/cjs/async-util.js +5 -1
  3. package/build/cjs/async-util.js.map +1 -1
  4. package/build/cjs/bluetooth/ble-error.d.ts +10 -0
  5. package/build/cjs/bluetooth/ble-error.js +47 -0
  6. package/build/cjs/bluetooth/ble-error.js.map +1 -0
  7. package/build/cjs/bluetooth/connection.d.ts +137 -0
  8. package/build/cjs/{bluetooth.js → bluetooth/connection.js} +158 -106
  9. package/build/cjs/bluetooth/connection.js.map +1 -0
  10. package/build/cjs/{bluetooth.test.js → bluetooth/connection.test.js} +9 -9
  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} +11 -11
  14. package/build/cjs/{bluetooth-device-wrapper.js → bluetooth/device-wrapper.js} +38 -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 +6 -5
  18. package/build/cjs/bluetooth/flashing/flashing-full.js.map +1 -0
  19. package/build/cjs/{flashing → bluetooth/flashing}/flashing-makecode.d.ts +1 -1
  20. package/build/cjs/bluetooth/flashing/flashing-makecode.js.map +1 -0
  21. package/build/cjs/{flashing → bluetooth/flashing}/flashing-makecode.test.js +3 -3
  22. package/build/cjs/bluetooth/flashing/flashing-makecode.test.js.map +1 -0
  23. package/build/cjs/{flashing → bluetooth/flashing}/flashing-partial.d.ts +2 -2
  24. package/build/cjs/{flashing → bluetooth/flashing}/flashing-partial.js +7 -6
  25. package/build/cjs/bluetooth/flashing/flashing-partial.js.map +1 -0
  26. package/build/cjs/bluetooth/flashing/flashing-v1.js.map +1 -0
  27. package/build/cjs/{flashing → bluetooth/flashing}/nordic-dfu.d.ts +2 -2
  28. package/build/cjs/{flashing → bluetooth/flashing}/nordic-dfu.js +15 -11
  29. package/build/cjs/bluetooth/flashing/nordic-dfu.js.map +1 -0
  30. package/build/cjs/bluetooth/flashing/zip.js.map +1 -0
  31. package/build/cjs/bluetooth/flashing/zip.test.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.js → bluetooth/profile.js} +1 -1
  36. package/build/cjs/bluetooth/profile.js.map +1 -0
  37. package/build/cjs/{accelerometer-service.d.ts → bluetooth/services/accelerometer-service.d.ts} +2 -3
  38. package/build/cjs/{accelerometer-service.js → bluetooth/services/accelerometer-service.js} +17 -12
  39. package/build/cjs/bluetooth/services/accelerometer-service.js.map +1 -0
  40. package/build/{esm → cjs/bluetooth/services}/button-service.d.ts +2 -3
  41. package/build/cjs/{button-service.js → bluetooth/services/button-service.js} +24 -14
  42. package/build/cjs/bluetooth/services/button-service.js.map +1 -0
  43. package/build/{esm → cjs/bluetooth/services}/device-information-service.d.ts +1 -1
  44. package/build/cjs/bluetooth/services/device-information-service.js +29 -0
  45. package/build/cjs/bluetooth/services/device-information-service.js.map +1 -0
  46. package/build/cjs/{dfu-service.js → bluetooth/services/dfu-service.js} +2 -2
  47. package/build/cjs/bluetooth/services/dfu-service.js.map +1 -0
  48. package/build/{esm → cjs/bluetooth/services}/led-service.d.ts +2 -3
  49. package/build/cjs/{led-service.js → bluetooth/services/led-service.js} +10 -7
  50. package/build/cjs/bluetooth/services/led-service.js.map +1 -0
  51. package/build/cjs/{magnetometer-service.d.ts → bluetooth/services/magnetometer-service.d.ts} +2 -3
  52. package/build/cjs/{magnetometer-service.js → bluetooth/services/magnetometer-service.js} +19 -14
  53. package/build/cjs/bluetooth/services/magnetometer-service.js.map +1 -0
  54. package/build/{esm → cjs/bluetooth/services}/partial-flashing-service.d.ts +1 -1
  55. package/build/cjs/{partial-flashing-service.js → bluetooth/services/partial-flashing-service.js} +8 -8
  56. package/build/cjs/bluetooth/services/partial-flashing-service.js.map +1 -0
  57. package/build/cjs/{uart-service.d.ts → bluetooth/services/uart-service.d.ts} +2 -2
  58. package/build/cjs/{uart-service.js → bluetooth/services/uart-service.js} +21 -9
  59. package/build/cjs/bluetooth/services/uart-service.js.map +1 -0
  60. package/build/cjs/board-id.d.ts +1 -1
  61. package/build/cjs/board-id.js.map +1 -1
  62. package/build/cjs/device.d.ts +145 -123
  63. package/build/cjs/device.js +47 -128
  64. package/build/cjs/device.js.map +1 -1
  65. package/build/cjs/events.d.ts +8 -108
  66. package/build/cjs/events.js +27 -88
  67. package/build/cjs/events.js.map +1 -1
  68. package/build/cjs/events.test.js +54 -48
  69. package/build/cjs/events.test.js.map +1 -1
  70. package/build/cjs/hex-util.d.ts +1 -0
  71. package/build/cjs/hex-util.js +15 -0
  72. package/build/cjs/hex-util.js.map +1 -0
  73. package/build/cjs/index.d.ts +7 -17
  74. package/build/cjs/index.js +6 -28
  75. package/build/cjs/index.js.map +1 -1
  76. package/build/cjs/radio-bridge/connection.d.ts +52 -0
  77. package/build/cjs/{usb-radio-bridge.js → radio-bridge/connection.js} +69 -37
  78. package/build/cjs/radio-bridge/connection.js.map +1 -0
  79. package/build/cjs/radio-bridge/index.d.ts +4 -0
  80. package/build/cjs/radio-bridge/index.js +9 -0
  81. package/build/cjs/radio-bridge/index.js.map +1 -0
  82. package/build/cjs/{usb-serial-protocol.js → radio-bridge/serial-protocol.js} +1 -1
  83. package/build/cjs/radio-bridge/serial-protocol.js.map +1 -0
  84. package/build/cjs/service-events.d.ts +43 -14
  85. package/build/cjs/service-events.js +6 -36
  86. package/build/cjs/service-events.js.map +1 -1
  87. package/build/{esm/hex-flash-data-source.d.ts → cjs/universal-hex/flash-data-source.d.ts} +1 -2
  88. package/build/cjs/{hex-flash-data-source.js → universal-hex/flash-data-source.js} +7 -15
  89. package/build/cjs/universal-hex/flash-data-source.js.map +1 -0
  90. package/build/cjs/universal-hex/index.d.ts +4 -0
  91. package/build/cjs/universal-hex/index.js +9 -0
  92. package/build/cjs/universal-hex/index.js.map +1 -0
  93. package/build/cjs/usb/arm-debug.d.ts +137 -0
  94. package/build/cjs/usb/arm-debug.js +414 -0
  95. package/build/cjs/usb/arm-debug.js.map +1 -0
  96. package/build/cjs/usb/arm-debug.test.js +333 -0
  97. package/build/cjs/usb/arm-debug.test.js.map +1 -0
  98. package/build/{esm → cjs/usb}/board-serial-info.d.ts +2 -1
  99. package/build/cjs/{board-serial-info.js → usb/board-serial-info.js} +10 -7
  100. package/build/cjs/usb/board-serial-info.js.map +1 -0
  101. package/build/cjs/{board-serial-info.test.js → usb/board-serial-info.test.js} +2 -4
  102. package/build/cjs/usb/board-serial-info.test.js.map +1 -0
  103. package/build/cjs/usb/cdc-saturation.d.ts +36 -0
  104. package/build/cjs/usb/cdc-saturation.js +151 -0
  105. package/build/cjs/usb/cdc-saturation.js.map +1 -0
  106. package/build/cjs/usb/cmsis-dap.d.ts +113 -0
  107. package/build/cjs/usb/cmsis-dap.js +349 -0
  108. package/build/cjs/usb/cmsis-dap.js.map +1 -0
  109. package/build/cjs/usb/cmsis-dap.test.js +350 -0
  110. package/build/cjs/usb/cmsis-dap.test.js.map +1 -0
  111. package/build/cjs/usb/connection.d.ts +96 -0
  112. package/build/cjs/{usb.js → usb/connection.js} +257 -173
  113. package/build/cjs/usb/connection.js.map +1 -0
  114. package/build/cjs/{usb.test.js → usb/connection.test.js} +52 -42
  115. package/build/cjs/usb/connection.test.js.map +1 -0
  116. package/build/cjs/usb/cortex-m.d.ts +72 -0
  117. package/build/cjs/usb/cortex-m.js +165 -0
  118. package/build/cjs/usb/cortex-m.js.map +1 -0
  119. package/build/cjs/usb/cortex-m.test.js +217 -0
  120. package/build/cjs/usb/cortex-m.test.js.map +1 -0
  121. package/build/cjs/usb/daplink.d.ts +69 -0
  122. package/build/cjs/usb/daplink.js +238 -0
  123. package/build/cjs/usb/daplink.js.map +1 -0
  124. package/build/cjs/usb/daplink.test.js +290 -0
  125. package/build/cjs/usb/daplink.test.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 -135
  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/promise-queue.test.js.map +1 -0
  140. package/build/cjs/usb/serial-events.d.ts +16 -0
  141. package/build/cjs/{led.js → usb/serial-events.js} +1 -1
  142. package/build/cjs/usb/serial-events.js.map +1 -0
  143. package/build/cjs/usb/transport.d.ts +42 -0
  144. package/build/cjs/usb/transport.js +155 -0
  145. package/build/cjs/usb/transport.js.map +1 -0
  146. package/build/esm/async-util.d.ts +3 -1
  147. package/build/esm/async-util.js +5 -1
  148. package/build/esm/async-util.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 +137 -0
  153. package/build/esm/{bluetooth.js → bluetooth/connection.js} +152 -100
  154. package/build/esm/bluetooth/connection.js.map +1 -0
  155. package/build/esm/{bluetooth.test.js → bluetooth/connection.test.js} +9 -9
  156. package/build/esm/bluetooth/connection.test.js.map +1 -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} +11 -11
  159. package/build/esm/{bluetooth-device-wrapper.js → bluetooth/device-wrapper.js} +35 -39
  160. package/build/esm/bluetooth/device-wrapper.js.map +1 -0
  161. package/build/esm/{flashing → 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/{flashing → bluetooth/flashing}/flashing-makecode.d.ts +1 -1
  165. package/build/esm/bluetooth/flashing/flashing-makecode.js.map +1 -0
  166. package/build/esm/{flashing → bluetooth/flashing}/flashing-makecode.test.js +2 -2
  167. package/build/esm/bluetooth/flashing/flashing-makecode.test.js.map +1 -0
  168. package/build/esm/{flashing → bluetooth/flashing}/flashing-partial.d.ts +2 -2
  169. package/build/esm/{flashing → bluetooth/flashing}/flashing-partial.js +6 -5
  170. package/build/esm/bluetooth/flashing/flashing-partial.js.map +1 -0
  171. package/build/esm/bluetooth/flashing/flashing-v1.js.map +1 -0
  172. package/build/esm/{flashing → bluetooth/flashing}/nordic-dfu.d.ts +2 -2
  173. package/build/esm/{flashing → bluetooth/flashing}/nordic-dfu.js +15 -11
  174. package/build/esm/bluetooth/flashing/nordic-dfu.js.map +1 -0
  175. package/build/esm/bluetooth/flashing/zip.js.map +1 -0
  176. package/build/esm/bluetooth/flashing/zip.test.d.ts +1 -0
  177. package/build/esm/bluetooth/flashing/zip.test.js.map +1 -0
  178. package/build/esm/bluetooth/index.d.ts +5 -0
  179. package/build/esm/bluetooth/index.js +5 -0
  180. package/build/esm/bluetooth/index.js.map +1 -0
  181. package/build/esm/{bluetooth-profile.js → bluetooth/profile.js} +1 -1
  182. package/build/{cjs/bluetooth-profile.js.map → esm/bluetooth/profile.js.map} +1 -1
  183. package/build/esm/{accelerometer-service.d.ts → bluetooth/services/accelerometer-service.d.ts} +2 -3
  184. package/build/esm/{accelerometer-service.js → bluetooth/services/accelerometer-service.js} +11 -6
  185. package/build/esm/bluetooth/services/accelerometer-service.js.map +1 -0
  186. package/build/{cjs → esm/bluetooth/services}/button-service.d.ts +2 -3
  187. package/build/esm/{button-service.js → bluetooth/services/button-service.js} +20 -10
  188. package/build/esm/bluetooth/services/button-service.js.map +1 -0
  189. package/build/{cjs → esm/bluetooth/services}/device-information-service.d.ts +1 -1
  190. package/build/esm/bluetooth/services/device-information-service.js +25 -0
  191. package/build/esm/bluetooth/services/device-information-service.js.map +1 -0
  192. package/build/esm/{dfu-service.js → bluetooth/services/dfu-service.js} +1 -1
  193. package/build/esm/bluetooth/services/dfu-service.js.map +1 -0
  194. package/build/{cjs → esm/bluetooth/services}/led-service.d.ts +2 -3
  195. package/build/esm/{led-service.js → bluetooth/services/led-service.js} +4 -1
  196. package/build/esm/bluetooth/services/led-service.js.map +1 -0
  197. package/build/esm/{magnetometer-service.d.ts → bluetooth/services/magnetometer-service.d.ts} +2 -3
  198. package/build/esm/{magnetometer-service.js → bluetooth/services/magnetometer-service.js} +11 -6
  199. package/build/esm/bluetooth/services/magnetometer-service.js.map +1 -0
  200. package/build/{cjs → esm/bluetooth/services}/partial-flashing-service.d.ts +1 -1
  201. package/build/esm/{partial-flashing-service.js → bluetooth/services/partial-flashing-service.js} +4 -4
  202. package/build/esm/bluetooth/services/partial-flashing-service.js.map +1 -0
  203. package/build/esm/{uart-service.d.ts → bluetooth/services/uart-service.d.ts} +2 -2
  204. package/build/esm/{uart-service.js → bluetooth/services/uart-service.js} +18 -6
  205. package/build/esm/bluetooth/services/uart-service.js.map +1 -0
  206. package/build/esm/board-id.d.ts +1 -1
  207. package/build/esm/board-id.js.map +1 -1
  208. package/build/esm/device.d.ts +145 -123
  209. package/build/esm/device.js +45 -122
  210. package/build/esm/device.js.map +1 -1
  211. package/build/esm/events.d.ts +8 -108
  212. package/build/esm/events.js +26 -86
  213. package/build/esm/events.js.map +1 -1
  214. package/build/esm/events.test.js +55 -49
  215. package/build/esm/events.test.js.map +1 -1
  216. package/build/esm/hex-util.d.ts +1 -0
  217. package/build/esm/hex-util.js +11 -0
  218. package/build/esm/hex-util.js.map +1 -0
  219. package/build/esm/index.d.ts +7 -17
  220. package/build/esm/index.js +6 -11
  221. package/build/esm/index.js.map +1 -1
  222. package/build/esm/radio-bridge/connection.d.ts +52 -0
  223. package/build/esm/{usb-radio-bridge.js → radio-bridge/connection.js} +69 -37
  224. package/build/esm/radio-bridge/connection.js.map +1 -0
  225. package/build/esm/radio-bridge/index.d.ts +4 -0
  226. package/build/esm/radio-bridge/index.js +5 -0
  227. package/build/esm/radio-bridge/index.js.map +1 -0
  228. package/build/esm/{usb-serial-protocol.js → radio-bridge/serial-protocol.js} +1 -1
  229. package/build/esm/radio-bridge/serial-protocol.js.map +1 -0
  230. package/build/esm/service-events.d.ts +43 -14
  231. package/build/esm/service-events.js +5 -34
  232. package/build/esm/service-events.js.map +1 -1
  233. package/build/{cjs/hex-flash-data-source.d.ts → esm/universal-hex/flash-data-source.d.ts} +1 -2
  234. package/build/esm/{hex-flash-data-source.js → universal-hex/flash-data-source.js} +6 -13
  235. package/build/esm/universal-hex/flash-data-source.js.map +1 -0
  236. package/build/esm/universal-hex/index.d.ts +4 -0
  237. package/build/esm/universal-hex/index.js +5 -0
  238. package/build/esm/universal-hex/index.js.map +1 -0
  239. package/build/esm/usb/arm-debug.d.ts +137 -0
  240. package/build/esm/usb/arm-debug.js +409 -0
  241. package/build/esm/usb/arm-debug.js.map +1 -0
  242. package/build/esm/usb/arm-debug.test.d.ts +1 -0
  243. package/build/esm/usb/arm-debug.test.js +331 -0
  244. package/build/esm/usb/arm-debug.test.js.map +1 -0
  245. package/build/{cjs → esm/usb}/board-serial-info.d.ts +2 -1
  246. package/build/esm/{board-serial-info.js → usb/board-serial-info.js} +10 -7
  247. package/build/esm/usb/board-serial-info.js.map +1 -0
  248. package/build/esm/usb/board-serial-info.test.d.ts +1 -0
  249. package/build/esm/{board-serial-info.test.js → usb/board-serial-info.test.js} +2 -4
  250. package/build/esm/usb/board-serial-info.test.js.map +1 -0
  251. package/build/esm/usb/cdc-saturation.d.ts +36 -0
  252. package/build/esm/usb/cdc-saturation.js +148 -0
  253. package/build/esm/usb/cdc-saturation.js.map +1 -0
  254. package/build/esm/usb/cmsis-dap.d.ts +113 -0
  255. package/build/esm/usb/cmsis-dap.js +342 -0
  256. package/build/esm/usb/cmsis-dap.js.map +1 -0
  257. package/build/esm/usb/cmsis-dap.test.d.ts +1 -0
  258. package/build/esm/usb/cmsis-dap.test.js +348 -0
  259. package/build/esm/usb/cmsis-dap.test.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/connection.test.d.ts +1 -0
  264. package/build/esm/{usb.test.js → usb/connection.test.js} +47 -37
  265. package/build/esm/usb/connection.test.js.map +1 -0
  266. package/build/esm/usb/cortex-m.d.ts +72 -0
  267. package/build/esm/usb/cortex-m.js +161 -0
  268. package/build/esm/usb/cortex-m.js.map +1 -0
  269. package/build/esm/usb/cortex-m.test.d.ts +1 -0
  270. package/build/esm/usb/cortex-m.test.js +215 -0
  271. package/build/esm/usb/cortex-m.test.js.map +1 -0
  272. package/build/esm/usb/daplink.d.ts +69 -0
  273. package/build/esm/usb/daplink.js +231 -0
  274. package/build/esm/usb/daplink.js.map +1 -0
  275. package/build/esm/usb/daplink.test.d.ts +1 -0
  276. package/build/esm/usb/daplink.test.js +288 -0
  277. package/build/esm/usb/daplink.test.js.map +1 -0
  278. package/build/esm/usb/device-wrapper.d.ts +34 -0
  279. package/build/esm/usb/device-wrapper.js +98 -0
  280. package/build/esm/usb/device-wrapper.js.map +1 -0
  281. package/build/esm/usb/index.d.ts +5 -0
  282. package/build/esm/usb/index.js +5 -0
  283. package/build/esm/usb/index.js.map +1 -0
  284. package/build/{cjs/usb-partial-flashing-utils.d.ts → esm/usb/partial-flashing-utils.d.ts} +6 -9
  285. package/build/esm/{usb-partial-flashing-utils.js → usb/partial-flashing-utils.js} +4 -44
  286. package/build/esm/usb/partial-flashing-utils.js.map +1 -0
  287. package/build/{cjs/usb-partial-flashing.d.ts → esm/usb/partial-flashing.d.ts} +37 -11
  288. package/build/esm/{usb-partial-flashing.js → usb/partial-flashing.js} +169 -111
  289. package/build/esm/usb/partial-flashing.js.map +1 -0
  290. package/build/esm/usb/promise-queue.js.map +1 -0
  291. package/build/esm/usb/promise-queue.test.d.ts +1 -0
  292. package/build/esm/usb/promise-queue.test.js.map +1 -0
  293. package/build/esm/usb/serial-events.d.ts +16 -0
  294. package/build/esm/usb/serial-events.js +2 -0
  295. package/build/esm/usb/serial-events.js.map +1 -0
  296. package/build/esm/usb/transport.d.ts +42 -0
  297. package/build/esm/usb/transport.js +151 -0
  298. package/build/esm/usb/transport.js.map +1 -0
  299. package/package.json +43 -2
  300. package/build/cjs/accelerometer-service.js.map +0 -1
  301. package/build/cjs/accelerometer.d.ts +0 -9
  302. package/build/cjs/accelerometer.js +0 -16
  303. package/build/cjs/accelerometer.js.map +0 -1
  304. package/build/cjs/bluetooth-device-wrapper.js.map +0 -1
  305. package/build/cjs/bluetooth.d.ts +0 -114
  306. package/build/cjs/bluetooth.js.map +0 -1
  307. package/build/cjs/bluetooth.test.js.map +0 -1
  308. package/build/cjs/board-serial-info.js.map +0 -1
  309. package/build/cjs/board-serial-info.test.js.map +0 -1
  310. package/build/cjs/button-service.js.map +0 -1
  311. package/build/cjs/buttons.d.ts +0 -10
  312. package/build/cjs/buttons.js +0 -22
  313. package/build/cjs/buttons.js.map +0 -1
  314. package/build/cjs/constants.d.ts +0 -48
  315. package/build/cjs/constants.js +0 -73
  316. package/build/cjs/constants.js.map +0 -1
  317. package/build/cjs/device-bond-state.js.map +0 -1
  318. package/build/cjs/device-information-service.js +0 -34
  319. package/build/cjs/device-information-service.js.map +0 -1
  320. package/build/cjs/dfu-service.js.map +0 -1
  321. package/build/cjs/flashing/flashing-full.js.map +0 -1
  322. package/build/cjs/flashing/flashing-makecode.js.map +0 -1
  323. package/build/cjs/flashing/flashing-makecode.test.js.map +0 -1
  324. package/build/cjs/flashing/flashing-partial.js.map +0 -1
  325. package/build/cjs/flashing/flashing-v1.js.map +0 -1
  326. package/build/cjs/flashing/nordic-dfu.js.map +0 -1
  327. package/build/cjs/flashing/zip.js.map +0 -1
  328. package/build/cjs/flashing/zip.test.js.map +0 -1
  329. package/build/cjs/hex-flash-data-source.js.map +0 -1
  330. package/build/cjs/led-service.js.map +0 -1
  331. package/build/cjs/led.d.ts +0 -6
  332. package/build/cjs/led.js.map +0 -1
  333. package/build/cjs/magnetometer-service.js.map +0 -1
  334. package/build/cjs/magnetometer.d.ts +0 -9
  335. package/build/cjs/magnetometer.js +0 -16
  336. package/build/cjs/magnetometer.js.map +0 -1
  337. package/build/cjs/partial-flashing-service.js.map +0 -1
  338. package/build/cjs/promise-queue.js.map +0 -1
  339. package/build/cjs/promise-queue.test.js.map +0 -1
  340. package/build/cjs/serial-events.d.ts +0 -20
  341. package/build/cjs/serial-events.js +0 -69
  342. package/build/cjs/serial-events.js.map +0 -1
  343. package/build/cjs/uart-service.js.map +0 -1
  344. package/build/cjs/uart.d.ts +0 -4
  345. package/build/cjs/uart.js +0 -16
  346. package/build/cjs/uart.js.map +0 -1
  347. package/build/cjs/usb-device-wrapper.d.ts +0 -47
  348. package/build/cjs/usb-device-wrapper.js +0 -437
  349. package/build/cjs/usb-device-wrapper.js.map +0 -1
  350. package/build/cjs/usb-partial-flashing-utils.js.map +0 -1
  351. package/build/cjs/usb-partial-flashing.js.map +0 -1
  352. package/build/cjs/usb-radio-bridge.d.ts +0 -24
  353. package/build/cjs/usb-radio-bridge.js.map +0 -1
  354. package/build/cjs/usb-serial-protocol.js.map +0 -1
  355. package/build/cjs/usb.d.ts +0 -66
  356. package/build/cjs/usb.js.map +0 -1
  357. package/build/cjs/usb.test.js.map +0 -1
  358. package/build/esm/accelerometer-service.js.map +0 -1
  359. package/build/esm/accelerometer.d.ts +0 -9
  360. package/build/esm/accelerometer.js +0 -12
  361. package/build/esm/accelerometer.js.map +0 -1
  362. package/build/esm/bluetooth-device-wrapper.js.map +0 -1
  363. package/build/esm/bluetooth-profile.js.map +0 -1
  364. package/build/esm/bluetooth.d.ts +0 -114
  365. package/build/esm/bluetooth.js.map +0 -1
  366. package/build/esm/bluetooth.test.js.map +0 -1
  367. package/build/esm/board-serial-info.js.map +0 -1
  368. package/build/esm/board-serial-info.test.js.map +0 -1
  369. package/build/esm/button-service.js.map +0 -1
  370. package/build/esm/buttons.d.ts +0 -10
  371. package/build/esm/buttons.js +0 -18
  372. package/build/esm/buttons.js.map +0 -1
  373. package/build/esm/constants.d.ts +0 -48
  374. package/build/esm/constants.js +0 -70
  375. package/build/esm/constants.js.map +0 -1
  376. package/build/esm/device-bond-state.js.map +0 -1
  377. package/build/esm/device-information-service.js +0 -30
  378. package/build/esm/device-information-service.js.map +0 -1
  379. package/build/esm/dfu-service.js.map +0 -1
  380. package/build/esm/flashing/flashing-full.js.map +0 -1
  381. package/build/esm/flashing/flashing-makecode.js.map +0 -1
  382. package/build/esm/flashing/flashing-makecode.test.js.map +0 -1
  383. package/build/esm/flashing/flashing-partial.js.map +0 -1
  384. package/build/esm/flashing/flashing-v1.js.map +0 -1
  385. package/build/esm/flashing/nordic-dfu.js.map +0 -1
  386. package/build/esm/flashing/zip.js.map +0 -1
  387. package/build/esm/flashing/zip.test.js.map +0 -1
  388. package/build/esm/hex-flash-data-source.js.map +0 -1
  389. package/build/esm/led-service.js.map +0 -1
  390. package/build/esm/led.d.ts +0 -6
  391. package/build/esm/led.js +0 -2
  392. package/build/esm/led.js.map +0 -1
  393. package/build/esm/magnetometer-service.js.map +0 -1
  394. package/build/esm/magnetometer.d.ts +0 -9
  395. package/build/esm/magnetometer.js +0 -12
  396. package/build/esm/magnetometer.js.map +0 -1
  397. package/build/esm/partial-flashing-service.js.map +0 -1
  398. package/build/esm/promise-queue.js.map +0 -1
  399. package/build/esm/promise-queue.test.js.map +0 -1
  400. package/build/esm/serial-events.d.ts +0 -20
  401. package/build/esm/serial-events.js +0 -61
  402. package/build/esm/serial-events.js.map +0 -1
  403. package/build/esm/uart-service.js.map +0 -1
  404. package/build/esm/uart.d.ts +0 -4
  405. package/build/esm/uart.js +0 -12
  406. package/build/esm/uart.js.map +0 -1
  407. package/build/esm/usb-device-wrapper.d.ts +0 -47
  408. package/build/esm/usb-device-wrapper.js +0 -410
  409. package/build/esm/usb-device-wrapper.js.map +0 -1
  410. package/build/esm/usb-partial-flashing-utils.js.map +0 -1
  411. package/build/esm/usb-partial-flashing.js.map +0 -1
  412. package/build/esm/usb-radio-bridge.d.ts +0 -24
  413. package/build/esm/usb-radio-bridge.js.map +0 -1
  414. package/build/esm/usb-serial-protocol.js.map +0 -1
  415. package/build/esm/usb.d.ts +0 -66
  416. package/build/esm/usb.js.map +0 -1
  417. package/build/esm/usb.test.js.map +0 -1
  418. /package/build/cjs/{bluetooth.test.d.ts → bluetooth/connection.test.d.ts} +0 -0
  419. /package/build/cjs/{device-bond-state.d.ts → bluetooth/device-bond-state.d.ts} +0 -0
  420. /package/build/cjs/{device-bond-state.js → bluetooth/device-bond-state.js} +0 -0
  421. /package/build/cjs/{flashing → bluetooth/flashing}/flashing-makecode.js +0 -0
  422. /package/build/cjs/{flashing → bluetooth/flashing}/flashing-makecode.test.d.ts +0 -0
  423. /package/build/cjs/{flashing → bluetooth/flashing}/flashing-v1.d.ts +0 -0
  424. /package/build/cjs/{flashing → bluetooth/flashing}/flashing-v1.js +0 -0
  425. /package/build/cjs/{flashing → bluetooth/flashing}/zip.d.ts +0 -0
  426. /package/build/cjs/{flashing → bluetooth/flashing}/zip.js +0 -0
  427. /package/build/cjs/{flashing → bluetooth/flashing}/zip.test.d.ts +0 -0
  428. /package/build/cjs/{flashing → bluetooth/flashing}/zip.test.js +0 -0
  429. /package/build/cjs/{bluetooth-profile.d.ts → bluetooth/profile.d.ts} +0 -0
  430. /package/build/cjs/{dfu-service.d.ts → bluetooth/services/dfu-service.d.ts} +0 -0
  431. /package/build/cjs/{usb-serial-protocol.d.ts → radio-bridge/serial-protocol.d.ts} +0 -0
  432. /package/build/cjs/{board-serial-info.test.d.ts → usb/arm-debug.test.d.ts} +0 -0
  433. /package/build/{esm → cjs/usb}/board-serial-info.test.d.ts +0 -0
  434. /package/build/cjs/{promise-queue.test.d.ts → usb/cmsis-dap.test.d.ts} +0 -0
  435. /package/build/cjs/{usb.test.d.ts → usb/connection.test.d.ts} +0 -0
  436. /package/build/{esm/bluetooth.test.d.ts → cjs/usb/cortex-m.test.d.ts} +0 -0
  437. /package/build/{esm/flashing/flashing-makecode.test.d.ts → cjs/usb/daplink.test.d.ts} +0 -0
  438. /package/build/cjs/{promise-queue.d.ts → usb/promise-queue.d.ts} +0 -0
  439. /package/build/cjs/{promise-queue.js → usb/promise-queue.js} +0 -0
  440. /package/build/{esm → cjs/usb}/promise-queue.test.d.ts +0 -0
  441. /package/build/cjs/{promise-queue.test.js → usb/promise-queue.test.js} +0 -0
  442. /package/build/esm/{flashing/zip.test.d.ts → bluetooth/connection.test.d.ts} +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-makecode.js +0 -0
  446. /package/build/esm/{usb.test.d.ts → bluetooth/flashing/flashing-makecode.test.d.ts} +0 -0
  447. /package/build/esm/{flashing → bluetooth/flashing}/flashing-v1.d.ts +0 -0
  448. /package/build/esm/{flashing → bluetooth/flashing}/flashing-v1.js +0 -0
  449. /package/build/esm/{flashing → bluetooth/flashing}/zip.d.ts +0 -0
  450. /package/build/esm/{flashing → bluetooth/flashing}/zip.js +0 -0
  451. /package/build/esm/{flashing → bluetooth/flashing}/zip.test.js +0 -0
  452. /package/build/esm/{bluetooth-profile.d.ts → bluetooth/profile.d.ts} +0 -0
  453. /package/build/esm/{dfu-service.d.ts → bluetooth/services/dfu-service.d.ts} +0 -0
  454. /package/build/esm/{usb-serial-protocol.d.ts → radio-bridge/serial-protocol.d.ts} +0 -0
  455. /package/build/esm/{promise-queue.d.ts → usb/promise-queue.d.ts} +0 -0
  456. /package/build/esm/{promise-queue.js → usb/promise-queue.js} +0 -0
  457. /package/build/esm/{promise-queue.test.js → usb/promise-queue.test.js} +0 -0
@@ -1,57 +1,55 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.applyDeviceFilters = exports.createWebUSBConnection = exports.DeviceSelectionMode = exports.isChromeOS105 = void 0;
3
+ exports.applyDeviceFilters = exports.createUSBConnection = exports.DeviceSelectionMode = void 0;
4
4
  /**
5
5
  * (c) 2021, Micro:bit Educational Foundation and contributors
6
6
  *
7
7
  * SPDX-License-Identifier: MIT
8
8
  */
9
- const async_util_js_1 = require("./async-util.js");
10
- const availability_js_1 = require("./availability.js");
11
- const device_js_1 = require("./device.js");
12
- const events_js_1 = require("./events.js");
13
- const logging_js_1 = require("./logging.js");
9
+ const async_util_js_1 = require("../async-util.js");
10
+ const availability_js_1 = require("../availability.js");
11
+ const device_js_1 = require("../device.js");
12
+ const events_js_1 = require("../events.js");
13
+ const logging_js_1 = require("../logging.js");
14
14
  const promise_queue_js_1 = require("./promise-queue.js");
15
- const serial_events_js_1 = require("./serial-events.js");
16
- const usb_device_wrapper_js_1 = require("./usb-device-wrapper.js");
17
- const usb_partial_flashing_js_1 = require("./usb-partial-flashing.js");
18
- // Temporary workaround for ChromeOS 105 bug.
19
- // See https://bugs.chromium.org/p/chromium/issues/detail?id=1363712&q=usb&can=2
20
- const isChromeOS105 = () => {
21
- const userAgent = navigator.userAgent;
22
- return /CrOS/.test(userAgent) && /Chrome\/105\b/.test(userAgent);
23
- };
24
- exports.isChromeOS105 = isChromeOS105;
15
+ const device_wrapper_js_1 = require("./device-wrapper.js");
16
+ const partial_flashing_js_1 = require("./partial-flashing.js");
17
+ const cdc_saturation_js_1 = require("./cdc-saturation.js");
25
18
  const defaultFilters = [{ vendorId: 0x0d28, productId: 0x0204 }];
26
- var DeviceSelectionMode;
27
- (function (DeviceSelectionMode) {
19
+ exports.DeviceSelectionMode = {
28
20
  /**
29
21
  * Attempts to connect to known device, otherwise asks which device to
30
22
  * connect to.
31
23
  */
32
- DeviceSelectionMode["AlwaysAsk"] = "AlwaysAsk";
24
+ AlwaysAsk: "AlwaysAsk",
33
25
  /**
34
26
  * Attempts to connect to known device, otherwise attempts to connect to any
35
27
  * allowed devices. If that fails, asks which device to connect to.
36
28
  */
37
- DeviceSelectionMode["UseAnyAllowed"] = "UseAnyAllowed";
38
- })(DeviceSelectionMode || (exports.DeviceSelectionMode = DeviceSelectionMode = {}));
29
+ UseAnyAllowed: "UseAnyAllowed",
30
+ };
39
31
  /**
40
32
  * A WebUSB connection factory.
41
33
  */
42
- const createWebUSBConnection = (options) => new MicrobitWebUSBConnectionImpl(options);
43
- exports.createWebUSBConnection = createWebUSBConnection;
34
+ const createUSBConnection = (options) => new MicrobitUSBConnectionImpl(options);
35
+ exports.createUSBConnection = createUSBConnection;
44
36
  /**
45
37
  * A WebUSB connection to a micro:bit device.
46
38
  */
47
- class MicrobitWebUSBConnectionImpl extends events_js_1.TypedEventTarget {
39
+ class MicrobitUSBConnectionImpl extends events_js_1.TypedEventTarget {
48
40
  constructor(options = {}) {
49
41
  super();
42
+ Object.defineProperty(this, "type", {
43
+ enumerable: true,
44
+ configurable: true,
45
+ writable: true,
46
+ value: "usb"
47
+ });
50
48
  Object.defineProperty(this, "status", {
51
49
  enumerable: true,
52
50
  configurable: true,
53
51
  writable: true,
54
- value: device_js_1.ConnectionStatus.NO_AUTHORIZED_DEVICE
52
+ value: device_js_1.ConnectionStatus.NoAuthorizedDevice
55
53
  });
56
54
  Object.defineProperty(this, "exclusionFilters", {
57
55
  enumerable: true,
@@ -60,9 +58,18 @@ class MicrobitWebUSBConnectionImpl extends events_js_1.TypedEventTarget {
60
58
  value: void 0
61
59
  });
62
60
  /**
63
- * The USB device we last connected to.
61
+ * The raw USB device we last connected to.
64
62
  * Cleared if it is disconnected.
65
63
  */
64
+ Object.defineProperty(this, "usbDevice", {
65
+ enumerable: true,
66
+ configurable: true,
67
+ writable: true,
68
+ value: void 0
69
+ });
70
+ /**
71
+ * Device-specific state. Created on connect, cleared on disconnect.
72
+ */
66
73
  Object.defineProperty(this, "device", {
67
74
  enumerable: true,
68
75
  configurable: true,
@@ -70,14 +77,37 @@ class MicrobitWebUSBConnectionImpl extends events_js_1.TypedEventTarget {
70
77
  value: void 0
71
78
  });
72
79
  /**
73
- * The connection to the device.
80
+ * Cached device properties that persist across reconnections until clearDevice.
74
81
  */
75
- Object.defineProperty(this, "connection", {
82
+ Object.defineProperty(this, "cachedConnectionInfo", {
83
+ enumerable: true,
84
+ configurable: true,
85
+ writable: true,
86
+ value: void 0
87
+ });
88
+ Object.defineProperty(this, "loggedBoardSerialInfo", {
76
89
  enumerable: true,
77
90
  configurable: true,
78
91
  writable: true,
79
92
  value: void 0
80
93
  });
94
+ /**
95
+ * Whether CDC pipeline saturation has been performed for this physical
96
+ * USB connection. Once saturated, the buffers stay full until the device
97
+ * is physically disconnected.
98
+ */
99
+ Object.defineProperty(this, "cdcSaturated", {
100
+ enumerable: true,
101
+ configurable: true,
102
+ writable: true,
103
+ value: false
104
+ });
105
+ /**
106
+ * Whether the serial read loop is running.
107
+ *
108
+ * This is false even if we have serial listeners when we're disconnected or flashing.
109
+ * The serial reads interfere with the flash process.
110
+ */
81
111
  Object.defineProperty(this, "serialState", {
82
112
  enumerable: true,
83
113
  configurable: true,
@@ -95,7 +125,7 @@ class MicrobitWebUSBConnectionImpl extends events_js_1.TypedEventTarget {
95
125
  configurable: true,
96
126
  writable: true,
97
127
  value: (data) => {
98
- this.dispatchTypedEvent("serialdata", new serial_events_js_1.SerialDataEvent(data));
128
+ this.dispatchEvent("serialdata", { data });
99
129
  }
100
130
  });
101
131
  Object.defineProperty(this, "flashing", {
@@ -118,19 +148,20 @@ class MicrobitWebUSBConnectionImpl extends events_js_1.TypedEventTarget {
118
148
  if (document.visibilityState === "visible") {
119
149
  // We may not have actually paused when we became hidden due to an in-progress flash.
120
150
  this.pauseAfterFlash = false;
121
- if (this.status === device_js_1.ConnectionStatus.PAUSED) {
151
+ if (this.status === device_js_1.ConnectionStatus.Paused) {
122
152
  if (!this.flashing) {
123
153
  this.log("Reconnecting visible tab");
124
- this.connect();
154
+ // withEnrichedErrors already disconnects and logs on failure.
155
+ this.connect().catch(() => { });
125
156
  }
126
157
  }
127
158
  }
128
159
  else {
129
- if (!this.unloading && this.status === device_js_1.ConnectionStatus.CONNECTED) {
160
+ if (!this.unloading && this.status === device_js_1.ConnectionStatus.Connected) {
130
161
  if (!this.flashing) {
131
162
  this.log("Pausing connection for hidden tab");
132
163
  // Transition to PAUSED not DISCONNECTED
133
- this.disconnect(false, device_js_1.ConnectionStatus.PAUSED);
164
+ this.disconnect(false, device_js_1.ConnectionStatus.Paused);
134
165
  }
135
166
  else {
136
167
  this.log("Scheduling disconnect of hidden tab for after flash");
@@ -161,9 +192,9 @@ class MicrobitWebUSBConnectionImpl extends events_js_1.TypedEventTarget {
161
192
  window.addEventListener("focus", () => {
162
193
  const assumePageIsStayingOpenDelay = 1000;
163
194
  setTimeout(() => {
164
- if (this.status === device_js_1.ConnectionStatus.CONNECTED) {
195
+ if (this.status === device_js_1.ConnectionStatus.Connected) {
165
196
  this.unloading = false;
166
- if (this.addedListeners.serialdata) {
197
+ if (this.hasSerialEventListeners()) {
167
198
  this.startSerialInternal();
168
199
  }
169
200
  }
@@ -183,29 +214,29 @@ class MicrobitWebUSBConnectionImpl extends events_js_1.TypedEventTarget {
183
214
  writable: true,
184
215
  value: void 0
185
216
  });
186
- Object.defineProperty(this, "addedListeners", {
217
+ Object.defineProperty(this, "pauseOnHidden", {
187
218
  enumerable: true,
188
219
  configurable: true,
189
220
  writable: true,
190
- value: {
191
- serialdata: 0,
192
- }
221
+ value: void 0
193
222
  });
194
223
  Object.defineProperty(this, "handleDisconnect", {
195
224
  enumerable: true,
196
225
  configurable: true,
197
226
  writable: true,
198
227
  value: (event) => {
199
- if (event.device === this.device) {
200
- this.connection = undefined;
228
+ if (event.device === this.usbDevice) {
229
+ this.cdcSaturated = false;
201
230
  this.device = undefined;
202
- this.setStatus(device_js_1.ConnectionStatus.NO_AUTHORIZED_DEVICE);
231
+ this.usbDevice = undefined;
232
+ this.setStatus(device_js_1.ConnectionStatus.NoAuthorizedDevice);
203
233
  }
204
234
  }
205
235
  });
206
236
  this.logging = options.logging || new logging_js_1.ConsoleLogging();
207
237
  this.deviceSelectionMode =
208
- options.deviceSelectionMode || DeviceSelectionMode.AlwaysAsk;
238
+ options.deviceSelectionMode || exports.DeviceSelectionMode.AlwaysAsk;
239
+ this.pauseOnHidden = options.pauseOnHidden ?? true;
209
240
  }
210
241
  log(v) {
211
242
  this.logging.log(v);
@@ -216,13 +247,13 @@ class MicrobitWebUSBConnectionImpl extends events_js_1.TypedEventTarget {
216
247
  }
217
248
  if (typeof window !== "undefined") {
218
249
  window.addEventListener("beforeunload", this.beforeUnloadListener);
219
- if (window.document) {
250
+ if (this.pauseOnHidden && window.document) {
220
251
  window.document.addEventListener("visibilitychange", this.visibilityChangeListener);
221
252
  }
222
253
  }
223
254
  }
224
255
  async checkAvailability() {
225
- if (!navigator.usb || (0, exports.isChromeOS105)()) {
256
+ if (!navigator.usb) {
226
257
  return "unsupported";
227
258
  }
228
259
  return "available";
@@ -233,7 +264,7 @@ class MicrobitWebUSBConnectionImpl extends events_js_1.TypedEventTarget {
233
264
  }
234
265
  if (typeof window !== "undefined") {
235
266
  window.removeEventListener("beforeunload", this.beforeUnloadListener);
236
- if (window.document) {
267
+ if (this.pauseOnHidden && window.document) {
237
268
  window.document.removeEventListener("visibilitychange", this.visibilityChangeListener);
238
269
  }
239
270
  }
@@ -248,20 +279,22 @@ class MicrobitWebUSBConnectionImpl extends events_js_1.TypedEventTarget {
248
279
  });
249
280
  }
250
281
  getDeviceId() {
251
- return this.connection?.deviceId;
282
+ (0, device_js_1.assertConnected)(this.cachedConnectionInfo);
283
+ return this.cachedConnectionInfo.deviceId;
252
284
  }
253
285
  getDevice() {
254
- return this.device;
286
+ return this.usbDevice;
255
287
  }
256
288
  getBoardVersion() {
257
- return this.connection?.boardSerialInfo?.id.toBoardVersion();
289
+ (0, device_js_1.assertConnected)(this.cachedConnectionInfo);
290
+ return this.cachedConnectionInfo.boardSerialInfo.id.toBoardVersion();
258
291
  }
259
292
  async flash(dataSource, options) {
260
293
  this.flashing = true;
261
294
  try {
262
295
  const startTime = new Date().getTime();
263
296
  await this.withEnrichedErrors(() => this.flashInternal(dataSource, options));
264
- this.dispatchTypedEvent("flash", new serial_events_js_1.FlashEvent());
297
+ this.dispatchEvent("flash");
265
298
  const flashTime = new Date().getTime() - startTime;
266
299
  this.logging.event({
267
300
  type: "WebUSB-time",
@@ -282,16 +315,41 @@ class MicrobitWebUSBConnectionImpl extends events_js_1.TypedEventTarget {
282
315
  await this.stopSerialInternal();
283
316
  this.log("Reconnecting before flash");
284
317
  await this.connectInternal(progress);
285
- if (!this.connection) {
318
+ if (!this.device) {
286
319
  throw new device_js_1.DeviceError({
287
- code: "device-disconnected",
320
+ code: "connection-error",
288
321
  message: "Must be connected now",
289
322
  });
290
323
  }
291
- const boardId = this.connection.boardSerialInfo.id;
292
- const boardVersion = boardId.toBoardVersion();
324
+ // Saturate DAPLink's CDC buffers on the first flash after physical
325
+ // connection, but only if someone is listening for serial data.
326
+ // Once saturated, the buffers stay full until physical disconnect.
327
+ if (!this.cdcSaturated && this.hasSerialEventListeners()) {
328
+ // Ensure DAPLink's UART is at 115200 before saturation.
329
+ // V1 DAPLink defaults to 9600 on fresh connection.
330
+ // setBaudrate may reset the target, so reinit SWD afterwards.
331
+ const currentBaud = await this.device.serial.getBaudrate();
332
+ if (currentBaud !== 115200) {
333
+ this.log(`Setting DAPLink baud from ${currentBaud} to 115200`);
334
+ await this.device.serial.setBaudrate(115200);
335
+ await this.device.adi.reinit();
336
+ }
337
+ this.log("Halting target");
338
+ await this.device.cortexM.halt();
339
+ const boardVersion = this.cachedConnectionInfo.boardSerialInfo.id.toBoardVersion();
340
+ await (0, cdc_saturation_js_1.saturateCdcPipeline)(this.device, boardVersion, this.logging);
341
+ this.cdcSaturated = true;
342
+ await this.device.serial.drain();
343
+ }
344
+ // Halt unconditionally — flash needs the target stopped.
345
+ if (!(await this.device.cortexM.isHalted())) {
346
+ this.log("Halting target");
347
+ await this.device.cortexM.halt();
348
+ }
349
+ const { boardSerialInfo, pageSize, numPages } = this.cachedConnectionInfo;
350
+ const boardVersion = boardSerialInfo.id.toBoardVersion();
293
351
  const data = await dataSource(boardVersion);
294
- const flashing = new usb_partial_flashing_js_1.PartialFlashing(this.connection, this.logging, boardVersion);
352
+ const flashing = new partial_flashing_js_1.PartialFlashing(this.device, this.logging, boardVersion, pageSize, numPages);
295
353
  let wasPartial = false;
296
354
  try {
297
355
  if (partial) {
@@ -306,14 +364,27 @@ class MicrobitWebUSBConnectionImpl extends events_js_1.TypedEventTarget {
306
364
  if (this.pauseAfterFlash) {
307
365
  this.log("Disconnecting after flash due to tab visibility");
308
366
  this.pauseAfterFlash = false;
309
- await this.disconnect(false, device_js_1.ConnectionStatus.PAUSED);
367
+ await this.disconnect(false, device_js_1.ConnectionStatus.Paused);
310
368
  }
311
369
  else {
312
- if (this.addedListeners.serialdata) {
370
+ await this.device.adi.reinit();
371
+ // Start serial before resetting so we capture startup output.
372
+ // For full flash FLASH_CLOSE already reset the target, so its
373
+ // early output accumulates in DAPLink's 512-byte serial ring
374
+ // buffer until the first read here.
375
+ if (this.hasSerialEventListeners()) {
313
376
  this.log("Reinstating serial after flash");
314
- if (this.connection.daplink) {
315
- await this.connection.daplink.connect();
316
- await this.startSerialInternal();
377
+ await this.startSerialInternal();
378
+ }
379
+ if (wasPartial) {
380
+ // Partial flash writes pages via SWD without resetting.
381
+ // Full flash already resets via FLASH_CLOSE.
382
+ this.log("Resetting micro:bit to run new program");
383
+ try {
384
+ await this.device.cortexM.reset();
385
+ }
386
+ catch (e) {
387
+ // Allow errors on resetting, user can always manually reset if necessary.
317
388
  }
318
389
  }
319
390
  }
@@ -321,38 +392,51 @@ class MicrobitWebUSBConnectionImpl extends events_js_1.TypedEventTarget {
321
392
  }
322
393
  async startSerialInternal() {
323
394
  return this.serialStateChangeQueue.add(async () => {
324
- if (!this.connection || this.serialState) {
395
+ if (!this.device || this.serialState) {
325
396
  return;
326
397
  }
327
398
  this.log("Starting serial");
328
399
  this.serialState = true;
329
- this.connection
330
- .startSerial(this.serialListener)
400
+ const serial = this.device.serial;
401
+ const currentBaud = await serial.getBaudrate();
402
+ if (currentBaud !== 115200) {
403
+ // Changing the baud rate causes a micro:bit reset, so only do it if necessary
404
+ await serial.setBaudrate(115200);
405
+ }
406
+ serial
407
+ .startPolling(this.serialListener, 1)
331
408
  .then(() => {
332
409
  this.log("Finished listening for serial data");
333
410
  })
334
411
  .catch((e) => {
335
- this.dispatchTypedEvent("serialerror", new serial_events_js_1.SerialErrorEvent(e));
412
+ this.dispatchEvent("backgrounderror", {
413
+ error: enrichedError(e),
414
+ event: "serialdata",
415
+ });
336
416
  })
337
417
  .finally(() => {
338
418
  this.serialState = false;
419
+ // Don't reset when paused — the same program is still running and
420
+ // serial will resume when the tab becomes visible again.
421
+ if (this.status !== device_js_1.ConnectionStatus.Paused) {
422
+ this.dispatchEvent("serialreset");
423
+ }
339
424
  });
340
425
  });
341
426
  }
342
427
  async stopSerialInternal() {
343
428
  return this.serialStateChangeQueue.add(async () => {
344
- if (!this.connection || !this.serialState) {
429
+ if (!this.device || !this.serialState) {
345
430
  return;
346
431
  }
347
- this.connection.stopSerial(this.serialListener);
348
- this.dispatchTypedEvent("serialreset", new serial_events_js_1.SerialResetEvent());
432
+ this.device.serial.stopPolling();
349
433
  });
350
434
  }
351
- async disconnect(quiet, finalStatus = device_js_1.ConnectionStatus.DISCONNECTED) {
435
+ async disconnect(quiet, finalStatus = device_js_1.ConnectionStatus.Disconnected) {
352
436
  try {
353
- if (this.connection) {
437
+ if (this.device) {
354
438
  await this.stopSerialInternal();
355
- await this.connection.disconnectAsync();
439
+ await this.device.disconnect();
356
440
  }
357
441
  }
358
442
  catch (e) {
@@ -365,7 +449,7 @@ class MicrobitWebUSBConnectionImpl extends events_js_1.TypedEventTarget {
365
449
  }
366
450
  }
367
451
  finally {
368
- this.connection = undefined;
452
+ this.device = undefined;
369
453
  this.setStatus(finalStatus);
370
454
  if (!quiet) {
371
455
  this.logging.log("Disconnection complete");
@@ -380,7 +464,27 @@ class MicrobitWebUSBConnectionImpl extends events_js_1.TypedEventTarget {
380
464
  const previousStatus = this.status;
381
465
  this.status = newStatus;
382
466
  this.log("USB connection status " + newStatus);
383
- this.dispatchTypedEvent("status", new device_js_1.ConnectionStatusEvent(newStatus, previousStatus));
467
+ this.dispatchEvent("status", {
468
+ status: newStatus,
469
+ previousStatus,
470
+ });
471
+ }
472
+ logBoardInfo(info) {
473
+ this.logging.event({
474
+ type: "WebUSB-info",
475
+ message: "connected",
476
+ });
477
+ if (!this.loggedBoardSerialInfo || !this.loggedBoardSerialInfo.eq(info)) {
478
+ this.loggedBoardSerialInfo = info;
479
+ this.logging.event({
480
+ type: "WebUSB-info",
481
+ message: "board-id/" + info.id,
482
+ });
483
+ this.logging.event({
484
+ type: "WebUSB-info",
485
+ message: "board-family-hic/" + info.familyId + info.hic,
486
+ });
487
+ }
384
488
  }
385
489
  async withEnrichedErrors(f) {
386
490
  try {
@@ -414,70 +518,75 @@ class MicrobitWebUSBConnectionImpl extends events_js_1.TypedEventTarget {
414
518
  }
415
519
  }
416
520
  serialWrite(data) {
521
+ (0, device_js_1.assertConnected)(this.device);
522
+ const device = this.device;
417
523
  return this.withEnrichedErrors(async () => {
418
- if (this.connection) {
419
- // Using WebUSB/DAPJs we're limited to 64 byte packet size with a two byte header.
420
- // https://github.com/microbit-foundation/python-editor-v3/issues/215
421
- const maxSerialWrite = 62;
422
- let start = 0;
423
- while (start < data.length) {
424
- const end = Math.min(start + maxSerialWrite, data.length);
425
- const chunkData = data.slice(start, end);
426
- await this.connection.daplink.serialWrite(chunkData);
427
- start = end;
428
- }
524
+ // WebUSB packets are 64 bytes with a two byte header.
525
+ // https://github.com/microbit-foundation/python-editor-v3/issues/215
526
+ const maxSerialWrite = 62;
527
+ let start = 0;
528
+ while (start < data.length) {
529
+ const end = Math.min(start + maxSerialWrite, data.length);
530
+ const chunkData = data.slice(start, end);
531
+ await device.serial.write(chunkData);
532
+ start = end;
429
533
  }
430
534
  });
431
535
  }
432
536
  async softwareReset() {
433
- return this.serialStateChangeQueue.add(async () => await this.connection?.softwareReset());
537
+ (0, device_js_1.assertConnected)(this.device);
538
+ const device = this.device;
539
+ return this.serialStateChangeQueue.add(async () => await device.cortexM.softwareReset());
434
540
  }
435
541
  async clearDevice() {
436
542
  await this.disconnect();
437
- this.device = undefined;
438
- this.setStatus(device_js_1.ConnectionStatus.NO_AUTHORIZED_DEVICE);
543
+ this.usbDevice = undefined;
544
+ this.cachedConnectionInfo = undefined;
545
+ this.cdcSaturated = false;
546
+ this.setStatus(device_js_1.ConnectionStatus.NoAuthorizedDevice);
439
547
  }
440
548
  async connectInternal(progress) {
441
549
  const reportProgress = progress ?? (() => { });
442
550
  reportProgress(device_js_1.ProgressStage.Initializing);
443
551
  (0, availability_js_1.throwIfUnavailable)(await this.checkAvailability());
444
- if (!this.connection && this.device) {
552
+ if (!this.device && this.usbDevice) {
445
553
  reportProgress(device_js_1.ProgressStage.Connecting);
446
- this.connection = new usb_device_wrapper_js_1.DAPWrapper(this.device, this.logging);
447
- await (0, async_util_js_1.withTimeout)(this.connection.reconnectAsync(), 10_000);
554
+ this.device = new device_wrapper_js_1.USBDeviceWrapper(this.usbDevice, this.logging);
555
+ this.cachedConnectionInfo = await (0, async_util_js_1.withTimeout)(this.device.reconnect(), 10_000);
448
556
  }
449
- else if (!this.connection) {
557
+ else if (!this.device) {
450
558
  await this.connectWithOtherDevice(reportProgress);
451
559
  }
452
560
  else {
453
561
  reportProgress(device_js_1.ProgressStage.Connecting);
454
- await (0, async_util_js_1.withTimeout)(this.connection.reconnectAsync(), 10_000);
562
+ this.cachedConnectionInfo = await (0, async_util_js_1.withTimeout)(this.device.reconnect(), 10_000);
455
563
  }
456
- if (this.addedListeners.serialdata && !this.flashing) {
564
+ this.logBoardInfo(this.cachedConnectionInfo.boardSerialInfo);
565
+ if (this.hasSerialEventListeners() && !this.flashing) {
457
566
  this.startSerialInternal();
458
567
  }
459
- this.setStatus(device_js_1.ConnectionStatus.CONNECTED);
568
+ this.setStatus(device_js_1.ConnectionStatus.Connected);
460
569
  }
461
570
  async connectWithOtherDevice(progress) {
462
- if (this.deviceSelectionMode === DeviceSelectionMode.UseAnyAllowed) {
571
+ if (this.deviceSelectionMode === exports.DeviceSelectionMode.UseAnyAllowed) {
463
572
  await this.attemptConnectAllowedDevices();
464
573
  }
465
- if (!this.connection) {
574
+ if (!this.device) {
466
575
  progress(device_js_1.ProgressStage.FindingDevice);
467
- this.device = await this.chooseDevice();
576
+ this.usbDevice = await this.chooseDevice();
468
577
  progress(device_js_1.ProgressStage.Connecting);
469
- this.connection = new usb_device_wrapper_js_1.DAPWrapper(this.device, this.logging);
470
- await (0, async_util_js_1.withTimeout)(this.connection.reconnectAsync(), 10_000);
578
+ this.device = new device_wrapper_js_1.USBDeviceWrapper(this.usbDevice, this.logging);
579
+ this.cachedConnectionInfo = await (0, async_util_js_1.withTimeout)(this.device.reconnect(), 10_000);
471
580
  }
472
581
  }
473
582
  // Based on: https://github.com/microsoft/pxt/blob/ab97a2422879824c730f009b15d4bf446b0e8547/pxtlib/webusb.ts#L361
474
583
  async attemptConnectAllowedDevices() {
475
584
  const pairedDevices = await this.getFilteredAllowedDevices();
476
- for (const device of pairedDevices) {
477
- const connection = await this.attemptDeviceConnection(device);
478
- if (connection) {
585
+ for (const usbDevice of pairedDevices) {
586
+ const device = await this.attemptDeviceConnection(usbDevice);
587
+ if (device) {
588
+ this.usbDevice = usbDevice;
479
589
  this.device = device;
480
- this.connection = connection;
481
590
  return;
482
591
  }
483
592
  }
@@ -492,34 +601,33 @@ class MicrobitWebUSBConnectionImpl extends events_js_1.TypedEventTarget {
492
601
  const filteredDevices = devices.filter((device) => (0, exports.applyDeviceFilters)(device, defaultFilters, this.exclusionFilters ?? []));
493
602
  return filteredDevices;
494
603
  }
495
- async attemptDeviceConnection(device) {
496
- this.log(`Attempting connection to: ${device.manufacturerName} ${device.productName}`);
497
- this.log(`Serial number: ${device.serialNumber}`);
498
- const connection = new usb_device_wrapper_js_1.DAPWrapper(device, this.logging);
499
- await (0, async_util_js_1.withTimeout)(connection.reconnectAsync(), 10_000);
500
- return connection;
604
+ async attemptDeviceConnection(usbDevice) {
605
+ this.log(`Attempting connection to: ${usbDevice.manufacturerName} ${usbDevice.productName}`);
606
+ this.log(`Serial number: ${usbDevice.serialNumber}`);
607
+ const device = new device_wrapper_js_1.USBDeviceWrapper(usbDevice, this.logging);
608
+ this.cachedConnectionInfo = await (0, async_util_js_1.withTimeout)(device.reconnect(), 10_000);
609
+ return device;
501
610
  }
502
611
  async chooseDevice() {
503
- this.dispatchTypedEvent("beforerequestdevice", new device_js_1.BeforeRequestDevice());
612
+ this.dispatchEvent("beforerequestdevice");
504
613
  try {
505
- this.device = await navigator.usb.requestDevice({
614
+ this.usbDevice = await navigator.usb.requestDevice({
506
615
  exclusionFilters: this.exclusionFilters,
507
616
  filters: defaultFilters,
508
617
  });
509
618
  }
510
619
  finally {
511
- this.dispatchTypedEvent("afterrequestdevice", new device_js_1.AfterRequestDevice());
620
+ this.dispatchEvent("afterrequestdevice");
512
621
  }
513
- return this.device;
622
+ return this.usbDevice;
514
623
  }
515
624
  eventActivated(type) {
516
625
  switch (type) {
517
626
  case "serialdata": {
518
- // Prevent starting serial if already started and when flashing.
519
- if (!this.addedListeners.serialdata && !this.flashing) {
627
+ // Prevent starting serial when flashing. We'll reinstate later.
628
+ if (!this.flashing) {
520
629
  this.startSerialInternal();
521
630
  }
522
- this.addedListeners.serialdata++;
523
631
  break;
524
632
  }
525
633
  }
@@ -527,14 +635,14 @@ class MicrobitWebUSBConnectionImpl extends events_js_1.TypedEventTarget {
527
635
  async eventDeactivated(type) {
528
636
  switch (type) {
529
637
  case "serialdata": {
530
- this.addedListeners.serialdata--;
531
- if (!this.addedListeners.serialdata) {
532
- this.stopSerialInternal();
533
- }
638
+ this.stopSerialInternal();
534
639
  break;
535
640
  }
536
641
  }
537
642
  }
643
+ hasSerialEventListeners() {
644
+ return this.getActiveEvents().includes("serialdata");
645
+ }
538
646
  }
539
647
  /**
540
648
  * Applying WebUSB device filter. Exported for testing.
@@ -580,66 +688,42 @@ const hasMatchingInterface = (device, filter) => {
580
688
  });
581
689
  });
582
690
  };
583
- const genericErrorSuggestingReconnect = (e) => new device_js_1.DeviceError({
584
- code: "reconnect-microbit",
585
- message: e.message,
586
- });
587
- // tslint:disable-next-line: no-any
588
691
  const enrichedError = (err) => {
589
692
  if (err instanceof device_js_1.DeviceError) {
590
693
  return err;
591
694
  }
592
- if (err instanceof async_util_js_1.TimeoutError) {
593
- return new device_js_1.DeviceError({
594
- code: "timeout-error",
595
- message: err.message,
596
- });
597
- }
598
- switch (typeof err) {
599
- case "object":
600
- // We might get Error objects as Promise rejection arguments
601
- if (!err.message && err.promise && err.reason) {
602
- err = err.reason;
603
- }
604
- // This is somewhat fragile but worth it for scenario specific errors.
605
- // These messages changed to be prefixed in 2023 so we've relaxed the checks.
606
- if (/No valid interfaces found/.test(err.message)) {
607
- // This comes from DAPjs's WebUSB open.
608
- return new device_js_1.DeviceError({
609
- code: "update-req",
610
- message: err.message,
611
- });
612
- }
613
- else if (/No device selected/.test(err.message)) {
614
- return new device_js_1.DeviceError({
615
- code: "no-device-selected",
616
- message: err.message,
617
- });
618
- }
619
- else if (/Unable to claim interface/.test(err.message)) {
620
- return new device_js_1.DeviceError({
621
- code: "clear-connect",
622
- message: err.message,
623
- });
624
- }
625
- else if (err.name === "device-disconnected") {
626
- return new device_js_1.DeviceError({
627
- code: "device-disconnected",
628
- message: err.message,
629
- });
630
- }
631
- else {
632
- // Unhandled error. User will need to reconnect their micro:bit
633
- return genericErrorSuggestingReconnect(err);
634
- }
635
- case "string": {
636
- // Caught a string. Example case: "Flash error" from DAPjs
637
- return genericErrorSuggestingReconnect(err);
695
+ if (err instanceof Error) {
696
+ // Match Chromium WebUSB DOMException messages for user-friendly error codes.
697
+ // These are hardcoded English strings in Chromium (not localized).
698
+ // https://chromium.googlesource.com/chromium/src/+/main/third_party/blink/renderer/modules/webusb/usb.cc
699
+ if (/No device selected/.test(err.message)) {
700
+ return new device_js_1.DeviceError({
701
+ code: "no-device-selected",
702
+ message: err.message,
703
+ cause: err,
704
+ });
705
+ }
706
+ // https://chromium.googlesource.com/chromium/src/+/main/third_party/blink/renderer/modules/webusb/usb_device.cc
707
+ if (/Unable to claim interface/.test(err.message)) {
708
+ return new device_js_1.DeviceError({
709
+ code: "device-in-use",
710
+ message: err.message,
711
+ cause: err,
712
+ });
638
713
  }
639
- default: {
640
- return genericErrorSuggestingReconnect(err);
714
+ if (/The device was disconnected/.test(err.message)) {
715
+ return new device_js_1.DeviceError({
716
+ code: "device-disconnected",
717
+ message: err.message,
718
+ cause: err,
719
+ });
641
720
  }
642
721
  }
722
+ return new device_js_1.DeviceError({
723
+ code: "connection-error",
724
+ message: err.message,
725
+ cause: err,
726
+ });
643
727
  };
644
728
  const rateLimitProgress = (minimumProgressIncrement, callback) => {
645
729
  let lastCallValue = -1;
@@ -656,4 +740,4 @@ const rateLimitProgress = (minimumProgressIncrement, callback) => {
656
740
  }
657
741
  };
658
742
  };
659
- //# sourceMappingURL=usb.js.map
743
+ //# sourceMappingURL=connection.js.map