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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (421) hide show
  1. package/README.md +106 -27
  2. package/build/cjs/async-util.d.ts +3 -1
  3. package/build/cjs/async-util.js +5 -1
  4. package/build/cjs/async-util.js.map +1 -1
  5. package/build/cjs/availability.js.map +1 -1
  6. package/build/cjs/bluetooth/ble-error.d.ts +10 -0
  7. package/build/cjs/bluetooth/ble-error.js +47 -0
  8. package/build/cjs/bluetooth/ble-error.js.map +1 -0
  9. package/build/cjs/bluetooth/connection.d.ts +378 -0
  10. package/build/cjs/bluetooth/connection.js +623 -0
  11. package/build/cjs/bluetooth/connection.js.map +1 -0
  12. package/build/cjs/bluetooth/device-bond-state.d.ts +14 -0
  13. package/build/cjs/bluetooth/device-bond-state.js +26 -0
  14. package/build/cjs/bluetooth/device-bond-state.js.map +1 -0
  15. package/build/cjs/{bluetooth-device-wrapper.d.ts → bluetooth/device-wrapper.d.ts} +35 -19
  16. package/build/cjs/{bluetooth-device-wrapper.js → bluetooth/device-wrapper.js} +169 -122
  17. package/build/cjs/bluetooth/device-wrapper.js.map +1 -0
  18. package/build/{esm → cjs/bluetooth}/flashing/flashing-full.d.ts +2 -2
  19. package/build/cjs/{flashing → bluetooth/flashing}/flashing-full.js +6 -5
  20. package/build/cjs/bluetooth/flashing/flashing-full.js.map +1 -0
  21. package/build/cjs/bluetooth/flashing/flashing-makecode.d.ts +10 -0
  22. package/build/cjs/{flashing → bluetooth/flashing}/flashing-makecode.js +5 -2
  23. package/build/cjs/bluetooth/flashing/flashing-makecode.js.map +1 -0
  24. package/build/cjs/bluetooth/flashing/flashing-partial.d.ts +10 -0
  25. package/build/cjs/bluetooth/flashing/flashing-partial.js +145 -0
  26. package/build/cjs/bluetooth/flashing/flashing-partial.js.map +1 -0
  27. package/build/cjs/bluetooth/flashing/flashing-v1.js.map +1 -0
  28. package/build/cjs/{flashing → bluetooth/flashing}/nordic-dfu.d.ts +2 -2
  29. package/build/cjs/{flashing → bluetooth/flashing}/nordic-dfu.js +40 -14
  30. package/build/cjs/bluetooth/flashing/nordic-dfu.js.map +1 -0
  31. package/build/cjs/bluetooth/flashing/zip.js.map +1 -0
  32. package/build/cjs/bluetooth/index.d.ts +5 -0
  33. package/build/cjs/bluetooth/index.js +9 -0
  34. package/build/cjs/bluetooth/index.js.map +1 -0
  35. package/build/cjs/{bluetooth-profile.d.ts → bluetooth/profile.d.ts} +8 -0
  36. package/build/cjs/{bluetooth-profile.js → bluetooth/profile.js} +7 -1
  37. package/build/cjs/bluetooth/profile.js.map +1 -0
  38. package/build/cjs/{accelerometer-service.d.ts → bluetooth/services/accelerometer-service.d.ts} +2 -3
  39. package/build/cjs/{accelerometer-service.js → bluetooth/services/accelerometer-service.js} +17 -12
  40. package/build/cjs/bluetooth/services/accelerometer-service.js.map +1 -0
  41. package/build/{esm → cjs/bluetooth/services}/button-service.d.ts +2 -3
  42. package/build/cjs/{button-service.js → bluetooth/services/button-service.js} +24 -14
  43. package/build/cjs/bluetooth/services/button-service.js.map +1 -0
  44. package/build/{esm → cjs/bluetooth/services}/device-information-service.d.ts +1 -1
  45. package/build/cjs/bluetooth/services/device-information-service.js +29 -0
  46. package/build/cjs/bluetooth/services/device-information-service.js.map +1 -0
  47. package/build/cjs/{dfu-service.js → bluetooth/services/dfu-service.js} +2 -2
  48. package/build/cjs/bluetooth/services/dfu-service.js.map +1 -0
  49. package/build/cjs/bluetooth/services/event-service.d.ts +48 -0
  50. package/build/cjs/bluetooth/services/event-service.js +273 -0
  51. package/build/cjs/bluetooth/services/event-service.js.map +1 -0
  52. package/build/cjs/bluetooth/services/io-pin-service.d.ts +65 -0
  53. package/build/cjs/bluetooth/services/io-pin-service.js +173 -0
  54. package/build/cjs/bluetooth/services/io-pin-service.js.map +1 -0
  55. package/build/{esm → cjs/bluetooth/services}/led-service.d.ts +2 -3
  56. package/build/cjs/{led-service.js → bluetooth/services/led-service.js} +10 -7
  57. package/build/cjs/bluetooth/services/led-service.js.map +1 -0
  58. package/build/cjs/{magnetometer-service.d.ts → bluetooth/services/magnetometer-service.d.ts} +2 -3
  59. package/build/cjs/{magnetometer-service.js → bluetooth/services/magnetometer-service.js} +19 -14
  60. package/build/cjs/bluetooth/services/magnetometer-service.js.map +1 -0
  61. package/build/{esm → cjs/bluetooth/services}/partial-flashing-service.d.ts +1 -1
  62. package/build/cjs/{partial-flashing-service.js → bluetooth/services/partial-flashing-service.js} +8 -8
  63. package/build/cjs/bluetooth/services/partial-flashing-service.js.map +1 -0
  64. package/build/cjs/bluetooth/services/temperature-service.d.ts +14 -0
  65. package/build/cjs/bluetooth/services/temperature-service.js +80 -0
  66. package/build/cjs/bluetooth/services/temperature-service.js.map +1 -0
  67. package/build/cjs/{uart-service.d.ts → bluetooth/services/uart-service.d.ts} +2 -2
  68. package/build/cjs/{uart-service.js → bluetooth/services/uart-service.js} +21 -9
  69. package/build/cjs/bluetooth/services/uart-service.js.map +1 -0
  70. package/build/cjs/board-id.d.ts +1 -1
  71. package/build/cjs/board-id.js.map +1 -1
  72. package/build/cjs/device.d.ts +191 -101
  73. package/build/cjs/device.js +47 -110
  74. package/build/cjs/device.js.map +1 -1
  75. package/build/cjs/events.d.ts +8 -108
  76. package/build/cjs/events.js +27 -88
  77. package/build/cjs/events.js.map +1 -1
  78. package/build/cjs/hex-util.d.ts +1 -0
  79. package/build/cjs/hex-util.js +15 -0
  80. package/build/cjs/hex-util.js.map +1 -0
  81. package/build/cjs/index.d.ts +8 -16
  82. package/build/cjs/index.js +9 -28
  83. package/build/cjs/index.js.map +1 -1
  84. package/build/cjs/logging.js.map +1 -1
  85. package/build/cjs/microbit-events.d.ts +67 -0
  86. package/build/cjs/microbit-events.js +55 -0
  87. package/build/cjs/microbit-events.js.map +1 -0
  88. package/build/cjs/radio-bridge/connection.d.ts +52 -0
  89. package/build/cjs/{usb-radio-bridge.js → radio-bridge/connection.js} +84 -96
  90. package/build/cjs/radio-bridge/connection.js.map +1 -0
  91. package/build/cjs/radio-bridge/index.d.ts +4 -0
  92. package/build/cjs/radio-bridge/index.js +9 -0
  93. package/build/cjs/radio-bridge/index.js.map +1 -0
  94. package/build/cjs/{usb-serial-protocol.js → radio-bridge/serial-protocol.js} +1 -1
  95. package/build/cjs/radio-bridge/serial-protocol.js.map +1 -0
  96. package/build/cjs/service-events.d.ts +92 -15
  97. package/build/cjs/service-events.js +6 -36
  98. package/build/cjs/service-events.js.map +1 -1
  99. package/build/{esm/hex-flash-data-source.d.ts → cjs/universal-hex/flash-data-source.d.ts} +1 -1
  100. package/build/cjs/{hex-flash-data-source.js → universal-hex/flash-data-source.js} +6 -3
  101. package/build/cjs/universal-hex/flash-data-source.js.map +1 -0
  102. package/build/cjs/universal-hex/index.d.ts +4 -0
  103. package/build/cjs/universal-hex/index.js +9 -0
  104. package/build/cjs/universal-hex/index.js.map +1 -0
  105. package/build/cjs/usb/arm-debug.d.ts +137 -0
  106. package/build/cjs/usb/arm-debug.js +414 -0
  107. package/build/cjs/usb/arm-debug.js.map +1 -0
  108. package/build/{esm → cjs/usb}/board-serial-info.d.ts +2 -1
  109. package/build/cjs/{board-serial-info.js → usb/board-serial-info.js} +10 -7
  110. package/build/cjs/usb/board-serial-info.js.map +1 -0
  111. package/build/cjs/usb/cdc-saturation.d.ts +36 -0
  112. package/build/cjs/usb/cdc-saturation.js +151 -0
  113. package/build/cjs/usb/cdc-saturation.js.map +1 -0
  114. package/build/cjs/usb/cmsis-dap.d.ts +113 -0
  115. package/build/cjs/usb/cmsis-dap.js +349 -0
  116. package/build/cjs/usb/cmsis-dap.js.map +1 -0
  117. package/build/cjs/usb/connection.d.ts +96 -0
  118. package/build/cjs/{usb.js → usb/connection.js} +257 -173
  119. package/build/cjs/usb/connection.js.map +1 -0
  120. package/build/cjs/usb/cortex-m.d.ts +72 -0
  121. package/build/cjs/usb/cortex-m.js +165 -0
  122. package/build/cjs/usb/cortex-m.js.map +1 -0
  123. package/build/cjs/usb/daplink.d.ts +69 -0
  124. package/build/cjs/usb/daplink.js +238 -0
  125. package/build/cjs/usb/daplink.js.map +1 -0
  126. package/build/cjs/usb/device-wrapper.d.ts +34 -0
  127. package/build/cjs/usb/device-wrapper.js +102 -0
  128. package/build/cjs/usb/device-wrapper.js.map +1 -0
  129. package/build/cjs/usb/index.d.ts +5 -0
  130. package/build/cjs/usb/index.js +10 -0
  131. package/build/cjs/usb/index.js.map +1 -0
  132. package/build/{esm/usb-partial-flashing-utils.d.ts → cjs/usb/partial-flashing-utils.d.ts} +6 -9
  133. package/build/cjs/{usb-partial-flashing-utils.js → usb/partial-flashing-utils.js} +6 -49
  134. package/build/cjs/usb/partial-flashing-utils.js.map +1 -0
  135. package/build/{esm/usb-partial-flashing.d.ts → cjs/usb/partial-flashing.d.ts} +37 -11
  136. package/build/cjs/{usb-partial-flashing.js → usb/partial-flashing.js} +170 -134
  137. package/build/cjs/usb/partial-flashing.js.map +1 -0
  138. package/build/cjs/usb/promise-queue.js.map +1 -0
  139. package/build/cjs/usb/serial-events.d.ts +16 -0
  140. package/build/cjs/{led.js → usb/serial-events.js} +1 -1
  141. package/build/cjs/usb/serial-events.js.map +1 -0
  142. package/build/cjs/usb/transport.d.ts +42 -0
  143. package/build/cjs/usb/transport.js +155 -0
  144. package/build/cjs/usb/transport.js.map +1 -0
  145. package/build/esm/async-util.d.ts +3 -1
  146. package/build/esm/async-util.js +5 -1
  147. package/build/esm/async-util.js.map +1 -1
  148. package/build/esm/availability.js.map +1 -1
  149. package/build/esm/bluetooth/ble-error.d.ts +10 -0
  150. package/build/esm/bluetooth/ble-error.js +42 -0
  151. package/build/esm/bluetooth/ble-error.js.map +1 -0
  152. package/build/esm/bluetooth/connection.d.ts +378 -0
  153. package/build/esm/bluetooth/connection.js +593 -0
  154. package/build/esm/bluetooth/connection.js.map +1 -0
  155. package/build/esm/bluetooth/device-bond-state.d.ts +14 -0
  156. package/build/esm/bluetooth/device-bond-state.js +22 -0
  157. package/build/esm/bluetooth/device-bond-state.js.map +1 -0
  158. package/build/esm/{bluetooth-device-wrapper.d.ts → bluetooth/device-wrapper.d.ts} +35 -19
  159. package/build/esm/{bluetooth-device-wrapper.js → bluetooth/device-wrapper.js} +167 -121
  160. package/build/esm/bluetooth/device-wrapper.js.map +1 -0
  161. package/build/{cjs → esm/bluetooth}/flashing/flashing-full.d.ts +2 -2
  162. package/build/esm/{flashing → bluetooth/flashing}/flashing-full.js +6 -5
  163. package/build/esm/bluetooth/flashing/flashing-full.js.map +1 -0
  164. package/build/esm/bluetooth/flashing/flashing-makecode.d.ts +10 -0
  165. package/build/esm/{flashing → bluetooth/flashing}/flashing-makecode.js +5 -2
  166. package/build/esm/bluetooth/flashing/flashing-makecode.js.map +1 -0
  167. package/build/esm/bluetooth/flashing/flashing-partial.d.ts +10 -0
  168. package/build/esm/bluetooth/flashing/flashing-partial.js +142 -0
  169. package/build/esm/bluetooth/flashing/flashing-partial.js.map +1 -0
  170. package/build/esm/bluetooth/flashing/flashing-v1.js.map +1 -0
  171. package/build/esm/{flashing → bluetooth/flashing}/nordic-dfu.d.ts +2 -2
  172. package/build/esm/{flashing → bluetooth/flashing}/nordic-dfu.js +40 -14
  173. package/build/esm/bluetooth/flashing/nordic-dfu.js.map +1 -0
  174. package/build/esm/bluetooth/flashing/zip.js.map +1 -0
  175. package/build/esm/bluetooth/index.d.ts +5 -0
  176. package/build/esm/bluetooth/index.js +5 -0
  177. package/build/esm/bluetooth/index.js.map +1 -0
  178. package/build/esm/{bluetooth-profile.d.ts → bluetooth/profile.d.ts} +8 -0
  179. package/build/esm/{bluetooth-profile.js → bluetooth/profile.js} +7 -1
  180. package/build/{cjs/bluetooth-profile.js.map → esm/bluetooth/profile.js.map} +1 -1
  181. package/build/esm/{accelerometer-service.d.ts → bluetooth/services/accelerometer-service.d.ts} +2 -3
  182. package/build/esm/{accelerometer-service.js → bluetooth/services/accelerometer-service.js} +11 -6
  183. package/build/esm/bluetooth/services/accelerometer-service.js.map +1 -0
  184. package/build/{cjs → esm/bluetooth/services}/button-service.d.ts +2 -3
  185. package/build/esm/{button-service.js → bluetooth/services/button-service.js} +20 -10
  186. package/build/esm/bluetooth/services/button-service.js.map +1 -0
  187. package/build/{cjs → esm/bluetooth/services}/device-information-service.d.ts +1 -1
  188. package/build/esm/bluetooth/services/device-information-service.js +25 -0
  189. package/build/esm/bluetooth/services/device-information-service.js.map +1 -0
  190. package/build/esm/{dfu-service.js → bluetooth/services/dfu-service.js} +1 -1
  191. package/build/esm/bluetooth/services/dfu-service.js.map +1 -0
  192. package/build/esm/bluetooth/services/event-service.d.ts +48 -0
  193. package/build/esm/bluetooth/services/event-service.js +269 -0
  194. package/build/esm/bluetooth/services/event-service.js.map +1 -0
  195. package/build/esm/bluetooth/services/io-pin-service.d.ts +65 -0
  196. package/build/esm/bluetooth/services/io-pin-service.js +169 -0
  197. package/build/esm/bluetooth/services/io-pin-service.js.map +1 -0
  198. package/build/{cjs → esm/bluetooth/services}/led-service.d.ts +2 -3
  199. package/build/esm/{led-service.js → bluetooth/services/led-service.js} +4 -1
  200. package/build/esm/bluetooth/services/led-service.js.map +1 -0
  201. package/build/esm/{magnetometer-service.d.ts → bluetooth/services/magnetometer-service.d.ts} +2 -3
  202. package/build/esm/{magnetometer-service.js → bluetooth/services/magnetometer-service.js} +11 -6
  203. package/build/esm/bluetooth/services/magnetometer-service.js.map +1 -0
  204. package/build/{cjs → esm/bluetooth/services}/partial-flashing-service.d.ts +1 -1
  205. package/build/esm/{partial-flashing-service.js → bluetooth/services/partial-flashing-service.js} +4 -4
  206. package/build/esm/bluetooth/services/partial-flashing-service.js.map +1 -0
  207. package/build/esm/bluetooth/services/temperature-service.d.ts +14 -0
  208. package/build/esm/bluetooth/services/temperature-service.js +76 -0
  209. package/build/esm/bluetooth/services/temperature-service.js.map +1 -0
  210. package/build/esm/{uart-service.d.ts → bluetooth/services/uart-service.d.ts} +2 -2
  211. package/build/esm/{uart-service.js → bluetooth/services/uart-service.js} +18 -6
  212. package/build/esm/bluetooth/services/uart-service.js.map +1 -0
  213. package/build/esm/board-id.d.ts +1 -1
  214. package/build/esm/board-id.js.map +1 -1
  215. package/build/esm/device.d.ts +191 -101
  216. package/build/esm/device.js +45 -104
  217. package/build/esm/device.js.map +1 -1
  218. package/build/esm/events.d.ts +8 -108
  219. package/build/esm/events.js +26 -86
  220. package/build/esm/events.js.map +1 -1
  221. package/build/esm/hex-util.d.ts +1 -0
  222. package/build/esm/hex-util.js +11 -0
  223. package/build/esm/hex-util.js.map +1 -0
  224. package/build/esm/index.d.ts +8 -16
  225. package/build/esm/index.js +7 -11
  226. package/build/esm/index.js.map +1 -1
  227. package/build/esm/logging.js.map +1 -1
  228. package/build/esm/microbit-events.d.ts +67 -0
  229. package/build/esm/microbit-events.js +52 -0
  230. package/build/esm/microbit-events.js.map +1 -0
  231. package/build/esm/radio-bridge/connection.d.ts +52 -0
  232. package/build/esm/{usb-radio-bridge.js → radio-bridge/connection.js} +84 -96
  233. package/build/esm/radio-bridge/connection.js.map +1 -0
  234. package/build/esm/radio-bridge/index.d.ts +4 -0
  235. package/build/esm/radio-bridge/index.js +5 -0
  236. package/build/esm/radio-bridge/index.js.map +1 -0
  237. package/build/esm/{usb-serial-protocol.js → radio-bridge/serial-protocol.js} +1 -1
  238. package/build/esm/radio-bridge/serial-protocol.js.map +1 -0
  239. package/build/esm/service-events.d.ts +92 -15
  240. package/build/esm/service-events.js +5 -34
  241. package/build/esm/service-events.js.map +1 -1
  242. package/build/{cjs/hex-flash-data-source.d.ts → esm/universal-hex/flash-data-source.d.ts} +1 -1
  243. package/build/esm/{hex-flash-data-source.js → universal-hex/flash-data-source.js} +6 -3
  244. package/build/esm/universal-hex/flash-data-source.js.map +1 -0
  245. package/build/esm/universal-hex/index.d.ts +4 -0
  246. package/build/esm/universal-hex/index.js +5 -0
  247. package/build/esm/universal-hex/index.js.map +1 -0
  248. package/build/esm/usb/arm-debug.d.ts +137 -0
  249. package/build/esm/usb/arm-debug.js +409 -0
  250. package/build/esm/usb/arm-debug.js.map +1 -0
  251. package/build/{cjs → esm/usb}/board-serial-info.d.ts +2 -1
  252. package/build/esm/{board-serial-info.js → usb/board-serial-info.js} +10 -7
  253. package/build/esm/usb/board-serial-info.js.map +1 -0
  254. package/build/esm/usb/cdc-saturation.d.ts +36 -0
  255. package/build/esm/usb/cdc-saturation.js +148 -0
  256. package/build/esm/usb/cdc-saturation.js.map +1 -0
  257. package/build/esm/usb/cmsis-dap.d.ts +113 -0
  258. package/build/esm/usb/cmsis-dap.js +342 -0
  259. package/build/esm/usb/cmsis-dap.js.map +1 -0
  260. package/build/esm/usb/connection.d.ts +96 -0
  261. package/build/esm/{usb.js → usb/connection.js} +253 -168
  262. package/build/esm/usb/connection.js.map +1 -0
  263. package/build/esm/usb/cortex-m.d.ts +72 -0
  264. package/build/esm/usb/cortex-m.js +161 -0
  265. package/build/esm/usb/cortex-m.js.map +1 -0
  266. package/build/esm/usb/daplink.d.ts +69 -0
  267. package/build/esm/usb/daplink.js +231 -0
  268. package/build/esm/usb/daplink.js.map +1 -0
  269. package/build/esm/usb/device-wrapper.d.ts +34 -0
  270. package/build/esm/usb/device-wrapper.js +98 -0
  271. package/build/esm/usb/device-wrapper.js.map +1 -0
  272. package/build/esm/usb/index.d.ts +5 -0
  273. package/build/esm/usb/index.js +5 -0
  274. package/build/esm/usb/index.js.map +1 -0
  275. package/build/{cjs/usb-partial-flashing-utils.d.ts → esm/usb/partial-flashing-utils.d.ts} +6 -9
  276. package/build/esm/{usb-partial-flashing-utils.js → usb/partial-flashing-utils.js} +4 -44
  277. package/build/esm/usb/partial-flashing-utils.js.map +1 -0
  278. package/build/{cjs/usb-partial-flashing.d.ts → esm/usb/partial-flashing.d.ts} +37 -11
  279. package/build/esm/{usb-partial-flashing.js → usb/partial-flashing.js} +169 -110
  280. package/build/esm/usb/partial-flashing.js.map +1 -0
  281. package/build/esm/usb/promise-queue.js.map +1 -0
  282. package/build/esm/usb/serial-events.d.ts +16 -0
  283. package/build/esm/usb/serial-events.js +2 -0
  284. package/build/esm/usb/serial-events.js.map +1 -0
  285. package/build/esm/usb/transport.d.ts +42 -0
  286. package/build/esm/usb/transport.js +151 -0
  287. package/build/esm/usb/transport.js.map +1 -0
  288. package/package.json +61 -14
  289. package/build/cjs/accelerometer-service.js.map +0 -1
  290. package/build/cjs/accelerometer.d.ts +0 -9
  291. package/build/cjs/accelerometer.js +0 -16
  292. package/build/cjs/accelerometer.js.map +0 -1
  293. package/build/cjs/bluetooth-device-wrapper.js.map +0 -1
  294. package/build/cjs/bluetooth.d.ts +0 -112
  295. package/build/cjs/bluetooth.js +0 -457
  296. package/build/cjs/bluetooth.js.map +0 -1
  297. package/build/cjs/board-serial-info.js.map +0 -1
  298. package/build/cjs/button-service.js.map +0 -1
  299. package/build/cjs/buttons.d.ts +0 -10
  300. package/build/cjs/buttons.js +0 -22
  301. package/build/cjs/buttons.js.map +0 -1
  302. package/build/cjs/constants.d.ts +0 -48
  303. package/build/cjs/constants.js +0 -73
  304. package/build/cjs/constants.js.map +0 -1
  305. package/build/cjs/device-information-service.js +0 -34
  306. package/build/cjs/device-information-service.js.map +0 -1
  307. package/build/cjs/dfu-service.js.map +0 -1
  308. package/build/cjs/flashing/flashing-full.js.map +0 -1
  309. package/build/cjs/flashing/flashing-makecode.d.ts +0 -6
  310. package/build/cjs/flashing/flashing-makecode.js.map +0 -1
  311. package/build/cjs/flashing/flashing-partial.d.ts +0 -9
  312. package/build/cjs/flashing/flashing-partial.js +0 -98
  313. package/build/cjs/flashing/flashing-partial.js.map +0 -1
  314. package/build/cjs/flashing/flashing-v1.js.map +0 -1
  315. package/build/cjs/flashing/nordic-dfu.js.map +0 -1
  316. package/build/cjs/flashing/zip.js.map +0 -1
  317. package/build/cjs/hex-flash-data-source.js.map +0 -1
  318. package/build/cjs/led-service.js.map +0 -1
  319. package/build/cjs/led.d.ts +0 -6
  320. package/build/cjs/led.js.map +0 -1
  321. package/build/cjs/magnetometer-service.js.map +0 -1
  322. package/build/cjs/magnetometer.d.ts +0 -9
  323. package/build/cjs/magnetometer.js +0 -16
  324. package/build/cjs/magnetometer.js.map +0 -1
  325. package/build/cjs/partial-flashing-service.js.map +0 -1
  326. package/build/cjs/promise-queue.js.map +0 -1
  327. package/build/cjs/serial-events.d.ts +0 -20
  328. package/build/cjs/serial-events.js +0 -69
  329. package/build/cjs/serial-events.js.map +0 -1
  330. package/build/cjs/setupTests.d.ts +0 -6
  331. package/build/cjs/setupTests.js.map +0 -1
  332. package/build/cjs/uart-service.js.map +0 -1
  333. package/build/cjs/uart.d.ts +0 -4
  334. package/build/cjs/uart.js +0 -16
  335. package/build/cjs/uart.js.map +0 -1
  336. package/build/cjs/usb-device-wrapper.d.ts +0 -47
  337. package/build/cjs/usb-device-wrapper.js +0 -437
  338. package/build/cjs/usb-device-wrapper.js.map +0 -1
  339. package/build/cjs/usb-partial-flashing-utils.js.map +0 -1
  340. package/build/cjs/usb-partial-flashing.js.map +0 -1
  341. package/build/cjs/usb-radio-bridge.d.ts +0 -24
  342. package/build/cjs/usb-radio-bridge.js.map +0 -1
  343. package/build/cjs/usb-serial-protocol.js.map +0 -1
  344. package/build/cjs/usb.d.ts +0 -66
  345. package/build/cjs/usb.js.map +0 -1
  346. package/build/esm/accelerometer-service.js.map +0 -1
  347. package/build/esm/accelerometer.d.ts +0 -9
  348. package/build/esm/accelerometer.js +0 -12
  349. package/build/esm/accelerometer.js.map +0 -1
  350. package/build/esm/bluetooth-device-wrapper.js.map +0 -1
  351. package/build/esm/bluetooth-profile.js.map +0 -1
  352. package/build/esm/bluetooth.d.ts +0 -112
  353. package/build/esm/bluetooth.js +0 -427
  354. package/build/esm/bluetooth.js.map +0 -1
  355. package/build/esm/board-serial-info.js.map +0 -1
  356. package/build/esm/button-service.js.map +0 -1
  357. package/build/esm/buttons.d.ts +0 -10
  358. package/build/esm/buttons.js +0 -18
  359. package/build/esm/buttons.js.map +0 -1
  360. package/build/esm/constants.d.ts +0 -48
  361. package/build/esm/constants.js +0 -70
  362. package/build/esm/constants.js.map +0 -1
  363. package/build/esm/device-information-service.js +0 -30
  364. package/build/esm/device-information-service.js.map +0 -1
  365. package/build/esm/dfu-service.js.map +0 -1
  366. package/build/esm/flashing/flashing-full.js.map +0 -1
  367. package/build/esm/flashing/flashing-makecode.d.ts +0 -6
  368. package/build/esm/flashing/flashing-makecode.js.map +0 -1
  369. package/build/esm/flashing/flashing-partial.d.ts +0 -9
  370. package/build/esm/flashing/flashing-partial.js +0 -95
  371. package/build/esm/flashing/flashing-partial.js.map +0 -1
  372. package/build/esm/flashing/flashing-v1.js.map +0 -1
  373. package/build/esm/flashing/nordic-dfu.js.map +0 -1
  374. package/build/esm/flashing/zip.js.map +0 -1
  375. package/build/esm/hex-flash-data-source.js.map +0 -1
  376. package/build/esm/led-service.js.map +0 -1
  377. package/build/esm/led.d.ts +0 -6
  378. package/build/esm/led.js +0 -2
  379. package/build/esm/led.js.map +0 -1
  380. package/build/esm/magnetometer-service.js.map +0 -1
  381. package/build/esm/magnetometer.d.ts +0 -9
  382. package/build/esm/magnetometer.js +0 -12
  383. package/build/esm/magnetometer.js.map +0 -1
  384. package/build/esm/partial-flashing-service.js.map +0 -1
  385. package/build/esm/promise-queue.js.map +0 -1
  386. package/build/esm/serial-events.d.ts +0 -20
  387. package/build/esm/serial-events.js +0 -61
  388. package/build/esm/serial-events.js.map +0 -1
  389. package/build/esm/setupTests.d.ts +0 -6
  390. package/build/esm/setupTests.js.map +0 -1
  391. package/build/esm/uart-service.js.map +0 -1
  392. package/build/esm/uart.d.ts +0 -4
  393. package/build/esm/uart.js +0 -12
  394. package/build/esm/uart.js.map +0 -1
  395. package/build/esm/usb-device-wrapper.d.ts +0 -47
  396. package/build/esm/usb-device-wrapper.js +0 -410
  397. package/build/esm/usb-device-wrapper.js.map +0 -1
  398. package/build/esm/usb-partial-flashing-utils.js.map +0 -1
  399. package/build/esm/usb-partial-flashing.js.map +0 -1
  400. package/build/esm/usb-radio-bridge.d.ts +0 -24
  401. package/build/esm/usb-radio-bridge.js.map +0 -1
  402. package/build/esm/usb-serial-protocol.js.map +0 -1
  403. package/build/esm/usb.d.ts +0 -66
  404. package/build/esm/usb.js.map +0 -1
  405. package/typedoc.json +0 -14
  406. /package/build/cjs/{flashing → bluetooth/flashing}/flashing-v1.d.ts +0 -0
  407. /package/build/cjs/{flashing → bluetooth/flashing}/flashing-v1.js +0 -0
  408. /package/build/cjs/{flashing → bluetooth/flashing}/zip.d.ts +0 -0
  409. /package/build/cjs/{flashing → bluetooth/flashing}/zip.js +0 -0
  410. /package/build/cjs/{dfu-service.d.ts → bluetooth/services/dfu-service.d.ts} +0 -0
  411. /package/build/cjs/{usb-serial-protocol.d.ts → radio-bridge/serial-protocol.d.ts} +0 -0
  412. /package/build/cjs/{promise-queue.d.ts → usb/promise-queue.d.ts} +0 -0
  413. /package/build/cjs/{promise-queue.js → usb/promise-queue.js} +0 -0
  414. /package/build/esm/{flashing → bluetooth/flashing}/flashing-v1.d.ts +0 -0
  415. /package/build/esm/{flashing → bluetooth/flashing}/flashing-v1.js +0 -0
  416. /package/build/esm/{flashing → bluetooth/flashing}/zip.d.ts +0 -0
  417. /package/build/esm/{flashing → bluetooth/flashing}/zip.js +0 -0
  418. /package/build/esm/{dfu-service.d.ts → bluetooth/services/dfu-service.d.ts} +0 -0
  419. /package/build/esm/{usb-serial-protocol.d.ts → radio-bridge/serial-protocol.d.ts} +0 -0
  420. /package/build/esm/{promise-queue.d.ts → usb/promise-queue.d.ts} +0 -0
  421. /package/build/esm/{promise-queue.js → usb/promise-queue.js} +0 -0
@@ -2,9 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ButtonService = void 0;
4
4
  const bluetooth_le_1 = require("@capacitor-community/bluetooth-le");
5
- const bluetooth_profile_js_1 = require("./bluetooth-profile.js");
6
- const buttons_js_1 = require("./buttons.js");
7
- const device_js_1 = require("./device.js");
5
+ const profile_js_1 = require("../profile.js");
6
+ const ble_error_js_1 = require("../ble-error.js");
8
7
  class ButtonService {
9
8
  constructor(deviceId, dispatchTypedEvent) {
10
9
  Object.defineProperty(this, "deviceId", {
@@ -23,27 +22,30 @@ class ButtonService {
23
22
  enumerable: true,
24
23
  configurable: true,
25
24
  writable: true,
26
- value: bluetooth_profile_js_1.profile.button.id
25
+ value: profile_js_1.profile.button.id
27
26
  });
28
27
  }
29
28
  getRelevantEvents() {
30
29
  return ["buttonachanged", "buttonbchanged"];
31
30
  }
32
- dataViewToButtonState(dataView) {
33
- return dataView.getUint8(0);
34
- }
35
31
  async startNotifications(type) {
36
32
  switch (type) {
37
33
  case "buttonachanged":
38
34
  case "buttonbchanged": {
39
35
  try {
40
- await bluetooth_le_1.BleClient.startNotifications(this.deviceId, bluetooth_profile_js_1.profile.button.id, this.characteristicForButtonEventType(type).id, (value) => {
41
- const data = this.dataViewToButtonState(value);
42
- this.dispatchTypedEvent(type, new buttons_js_1.ButtonEvent(type, data));
36
+ await bluetooth_le_1.BleClient.startNotifications(this.deviceId, profile_js_1.profile.button.id, this.characteristicForButtonEventType(type).id, (value) => {
37
+ const state = value.getUint8(0);
38
+ this.dispatchTypedEvent(type, {
39
+ button: type === "buttonachanged" ? "A" : "B",
40
+ state,
41
+ });
43
42
  });
44
43
  }
45
44
  catch (e) {
46
- this.dispatchTypedEvent("backgrounderror", new device_js_1.BackgroundErrorEvent("Failed to start notifications", e));
45
+ this.dispatchTypedEvent("backgrounderror", {
46
+ error: (0, ble_error_js_1.mapBleError)(e),
47
+ event: type,
48
+ });
47
49
  }
48
50
  }
49
51
  }
@@ -52,14 +54,22 @@ class ButtonService {
52
54
  switch (type) {
53
55
  case "buttonachanged":
54
56
  case "buttonbchanged": {
55
- await bluetooth_le_1.BleClient.stopNotifications(this.deviceId, bluetooth_profile_js_1.profile.button.id, this.characteristicForButtonEventType(type).id);
57
+ try {
58
+ await bluetooth_le_1.BleClient.stopNotifications(this.deviceId, profile_js_1.profile.button.id, this.characteristicForButtonEventType(type).id);
59
+ }
60
+ catch (e) {
61
+ this.dispatchTypedEvent("backgrounderror", {
62
+ error: (0, ble_error_js_1.mapBleError)(e),
63
+ event: type,
64
+ });
65
+ }
56
66
  }
57
67
  }
58
68
  }
59
69
  characteristicForButtonEventType(type) {
60
70
  return type === "buttonachanged"
61
- ? bluetooth_profile_js_1.profile.button.characteristics.a
62
- : bluetooth_profile_js_1.profile.button.characteristics.b;
71
+ ? profile_js_1.profile.button.characteristics.a
72
+ : profile_js_1.profile.button.characteristics.b;
63
73
  }
64
74
  }
65
75
  exports.ButtonService = ButtonService;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"button-service.js","sourceRoot":"","sources":["../../../../src/bluetooth/services/button-service.ts"],"names":[],"mappings":";;;AAAA,oEAA8D;AAE9D,8CAAwC;AAMxC,kDAA8C;AAE9C,MAAa,aAAa;IAGxB,YACU,QAAgB,EAChB,kBAA+C;QADvD;;;;mBAAQ,QAAQ;WAAQ;QACxB;;;;mBAAQ,kBAAkB;WAA6B;QAJzD;;;;mBAAO,oBAAO,CAAC,MAAM,CAAC,EAAE;WAAC;IAKtB,CAAC;IAEJ,iBAAiB;QACf,OAAO,CAAC,gBAAgB,EAAE,gBAAgB,CAAC,CAAC;IAC9C,CAAC;IAED,KAAK,CAAC,kBAAkB,CAAC,IAAuB;QAC9C,QAAQ,IAAI,EAAE,CAAC;YACb,KAAK,gBAAgB,CAAC;YACtB,KAAK,gBAAgB,CAAC,CAAC,CAAC;gBACtB,IAAI,CAAC;oBACH,MAAM,wBAAS,CAAC,kBAAkB,CAChC,IAAI,CAAC,QAAQ,EACb,oBAAO,CAAC,MAAM,CAAC,EAAE,EACjB,IAAI,CAAC,gCAAgC,CAAC,IAAI,CAAC,CAAC,EAAE,EAC9C,CAAC,KAAK,EAAE,EAAE;wBACR,MAAM,KAAK,GAAG,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAgB,CAAC;wBAC/C,IAAI,CAAC,kBAAkB,CA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.js";
2
2
  export declare class DeviceInformationService {
3
3
  private deviceId;
4
4
  constructor(deviceId: string);
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DeviceInformationService = void 0;
4
+ const bluetooth_le_1 = require("@capacitor-community/bluetooth-le");
5
+ const profile_js_1 = require("../profile.js");
6
+ class DeviceInformationService {
7
+ constructor(deviceId) {
8
+ Object.defineProperty(this, "deviceId", {
9
+ enumerable: true,
10
+ configurable: true,
11
+ writable: true,
12
+ value: deviceId
13
+ });
14
+ }
15
+ async getBoardVersion() {
16
+ const serviceMeta = profile_js_1.profile.deviceInformation;
17
+ const modelNumberBytes = await bluetooth_le_1.BleClient.read(this.deviceId, serviceMeta.id, serviceMeta.characteristics.modelNumber.id);
18
+ const modelNumber = new TextDecoder().decode(modelNumberBytes);
19
+ if (modelNumber.toLowerCase() === "BBC micro:bit".toLowerCase()) {
20
+ return "V1";
21
+ }
22
+ if (modelNumber.toLowerCase().includes("BBC micro:bit v2".toLowerCase())) {
23
+ return "V2";
24
+ }
25
+ throw new Error(`Unexpected model number: ${modelNumber}`);
26
+ }
27
+ }
28
+ exports.DeviceInformationService = DeviceInformationService;
29
+ //# sourceMappingURL=device-information-service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"device-information-service.js","sourceRoot":"","sources":["../../../../src/bluetooth/services/device-information-service.ts"],"names":[],"mappings":";;;AAAA,oEAA8D;AAE9D,8CAAwC;AAExC,MAAa,wBAAwB;IACnC,YAAoB,QAAgB;QAAxB;;;;mBAAQ,QAAQ;WAAQ;IAAG,CAAC;IAExC,KAAK,CAAC,eAAe;QACnB,MAAM,WAAW,GAAG,oBAAO,CAAC,iBAAiB,CAAC;QAC9C,MAAM,gBAAgB,GAAG,MAAM,wBAAS,CAAC,IAAI,CAC3C,IAAI,CAAC,QAAQ,EACb,WAAW,CAAC,EAAE,EACd,WAAW,CAAC,eAAe,CAAC,WAAW,CAAC,EAAE,CAC3C,CAAC;QACF,MAAM,WAAW,GAAG,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC;QAC/D,IAAI,WAAW,CAAC,WAAW,EAAE,KAAK,eAAe,CAAC,WAAW,EAAE,EAAE,CAAC;YAChE,OAAO,IAAI,CAAC;QACd,CAAC;QACD,IAAI,WAAW,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,kBAAkB,CAAC,WAAW,EAAE,CAAC,EAAE,CAAC;YACzE,OAAO,IAAI,CAAC;QACd,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,4BAA4B,WAAW,EAAE,CAAC,CAAC;IAC7D,CAAC;CACF;AAnBD,4DAmBC"}
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DfuService = exports.NORDIC_DFU_SERVICE = void 0;
4
4
  const bluetooth_le_1 = require("@capacitor-community/bluetooth-le");
5
- const bluetooth_profile_js_1 = require("./bluetooth-profile.js");
5
+ const profile_js_1 = require("../profile.js");
6
6
  // This is the service that should be available on V1 after the reboot.
7
7
  // We don't use it directly (the Nordic DFU library does) but we check it's there.
8
8
  exports.NORDIC_DFU_SERVICE = "00001530-1212-EFDE-1523-785FEABCD123";
@@ -19,7 +19,7 @@ class DfuService {
19
19
  * We do this for V1 only.
20
20
  */
21
21
  async requestRebootToBootloader() {
22
- await bluetooth_le_1.BleClient.write(this.deviceId, bluetooth_profile_js_1.profile.dfuControl.id, bluetooth_profile_js_1.profile.dfuControl.characteristics.control.id, (0, bluetooth_le_1.numbersToDataView)([0x01]));
22
+ await bluetooth_le_1.BleClient.write(this.deviceId, profile_js_1.profile.dfuControl.id, profile_js_1.profile.dfuControl.characteristics.control.id, (0, bluetooth_le_1.numbersToDataView)([0x01]));
23
23
  }
24
24
  }
25
25
  exports.DfuService = DfuService;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dfu-service.js","sourceRoot":"","sources":["../../../../src/bluetooth/services/dfu-service.ts"],"names":[],"mappings":";;;AAAA,oEAG2C;AAC3C,8CAAwC;AAExC,uEAAuE;AACvE,kFAAkF;AACrE,QAAA,kBAAkB,GAAG,sCAAsC,CAAC;AAEzE,MAAa,UAAU;IACrB,YAAoB,QAAgB;QAAxB;;;;mBAAQ,QAAQ;WAAQ;IAAG,CAAC;IAExC;;OAEG;IACH,KAAK,CAAC,yBAAyB;QAC7B,MAAM,wBAAS,CAAC,KAAK,CACnB,IAAI,CAAC,QAAQ,EACb,oBAAO,CAAC,UAAU,CAAC,EAAE,EACrB,oBAAO,CAAC,UAAU,CAAC,eAAe,CAAC,OAAO,CAAC,EAAE,EAC7C,IAAA,gCAAiB,EAAC,CAAC,IAAI,CAAC,CAAC,CAC1B,CAAC;IACJ,CAAC;CACF;AAdD,gCAcC"}
@@ -0,0 +1,48 @@
1
+ import { Service } from "../device-wrapper.js";
2
+ import { TypedServiceEvent, TypedServiceEventDispatcher } from "../../service-events.js";
3
+ import { BoardVersion } from "../../device.js";
4
+ export declare class EventService implements Service {
5
+ private deviceId;
6
+ private dispatchTypedEvent;
7
+ private getBoardVersion;
8
+ uuid: string;
9
+ private activeEventTypes;
10
+ /**
11
+ * Filters registered via named events (gestures, buttons), keyed as "source:value".
12
+ * Persists across reconnects so we can replay them.
13
+ */
14
+ private namedRequirements;
15
+ /**
16
+ * Filters registered via explicit {@link subscribeToEvent} calls, keyed as "source:value".
17
+ * Only events matching these are dispatched as `microbitevent`.
18
+ * Persists across reconnects so we can replay them.
19
+ */
20
+ private explicitSubscriptions;
21
+ /**
22
+ * Tracks which named event types contributed which filter keys,
23
+ * so we can clean up when a named event is stopped.
24
+ */
25
+ private namedEventFilters;
26
+ constructor(deviceId: string, dispatchTypedEvent: TypedServiceEventDispatcher, getBoardVersion: () => BoardVersion | undefined);
27
+ getRelevantEvents(): TypedServiceEvent[];
28
+ startNotifications(type: TypedServiceEvent): Promise<void>;
29
+ stopNotifications(type: TypedServiceEvent): Promise<void>;
30
+ /**
31
+ * Register interest in a specific micro:bit message bus event.
32
+ * Tells the micro:bit to forward matching message bus traffic over BLE.
33
+ * Matching events are dispatched as `microbitevent`.
34
+ * Use 0 as the value to match all events from a source.
35
+ */
36
+ subscribeToEvent(source: number, value: number): Promise<void>;
37
+ /**
38
+ * Send an event to the micro:bit's message bus.
39
+ */
40
+ sendEvent(source: number, value: number): Promise<void>;
41
+ private handleNotification;
42
+ private demuxToNamedEvents;
43
+ private writeRequirementsForNamedEvent;
44
+ private matchesExplicitSubscription;
45
+ private replayAllRequirements;
46
+ private writeClientRequirement;
47
+ private getSourceIds;
48
+ }
@@ -0,0 +1,273 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EventService = void 0;
4
+ const bluetooth_le_1 = require("@capacitor-community/bluetooth-le");
5
+ const profile_js_1 = require("../profile.js");
6
+ const ble_error_js_1 = require("../ble-error.js");
7
+ const microbit_events_js_1 = require("../../microbit-events.js");
8
+ const NAMED_EVENTS = [
9
+ "gesturechanged",
10
+ "buttonaaction",
11
+ "buttonbaction",
12
+ "buttonabaction",
13
+ "logoaction",
14
+ ];
15
+ function isNamedEvent(type) {
16
+ return NAMED_EVENTS.includes(type);
17
+ }
18
+ class EventService {
19
+ constructor(deviceId, dispatchTypedEvent, getBoardVersion) {
20
+ Object.defineProperty(this, "deviceId", {
21
+ enumerable: true,
22
+ configurable: true,
23
+ writable: true,
24
+ value: deviceId
25
+ });
26
+ Object.defineProperty(this, "dispatchTypedEvent", {
27
+ enumerable: true,
28
+ configurable: true,
29
+ writable: true,
30
+ value: dispatchTypedEvent
31
+ });
32
+ Object.defineProperty(this, "getBoardVersion", {
33
+ enumerable: true,
34
+ configurable: true,
35
+ writable: true,
36
+ value: getBoardVersion
37
+ });
38
+ Object.defineProperty(this, "uuid", {
39
+ enumerable: true,
40
+ configurable: true,
41
+ writable: true,
42
+ value: profile_js_1.profile.event.id
43
+ });
44
+ Object.defineProperty(this, "activeEventTypes", {
45
+ enumerable: true,
46
+ configurable: true,
47
+ writable: true,
48
+ value: new Set()
49
+ });
50
+ /**
51
+ * Filters registered via named events (gestures, buttons), keyed as "source:value".
52
+ * Persists across reconnects so we can replay them.
53
+ */
54
+ Object.defineProperty(this, "namedRequirements", {
55
+ enumerable: true,
56
+ configurable: true,
57
+ writable: true,
58
+ value: new Set()
59
+ });
60
+ /**
61
+ * Filters registered via explicit {@link subscribeToEvent} calls, keyed as "source:value".
62
+ * Only events matching these are dispatched as `microbitevent`.
63
+ * Persists across reconnects so we can replay them.
64
+ */
65
+ Object.defineProperty(this, "explicitSubscriptions", {
66
+ enumerable: true,
67
+ configurable: true,
68
+ writable: true,
69
+ value: new Set()
70
+ });
71
+ /**
72
+ * Tracks which named event types contributed which filter keys,
73
+ * so we can clean up when a named event is stopped.
74
+ */
75
+ Object.defineProperty(this, "namedEventFilters", {
76
+ enumerable: true,
77
+ configurable: true,
78
+ writable: true,
79
+ value: new Map()
80
+ });
81
+ }
82
+ getRelevantEvents() {
83
+ return [
84
+ "gesturechanged",
85
+ "buttonaaction",
86
+ "buttonbaction",
87
+ "buttonabaction",
88
+ "logoaction",
89
+ "microbitevent",
90
+ ];
91
+ }
92
+ async startNotifications(type) {
93
+ if (!this.getRelevantEvents().includes(type)) {
94
+ return;
95
+ }
96
+ this.activeEventTypes.add(type);
97
+ try {
98
+ // Always (re-)register the BLE notification. After a reconnect the
99
+ // previous subscription is gone even though the service instance is
100
+ // reused, so we cannot skip this.
101
+ await bluetooth_le_1.BleClient.startNotifications(this.deviceId, profile_js_1.profile.event.id, profile_js_1.profile.event.characteristics.microBitEvent.id, (value) => this.handleNotification(value));
102
+ if (isNamedEvent(type)) {
103
+ this.writeRequirementsForNamedEvent(type);
104
+ }
105
+ // Replay all filters (handles reconnect case where the micro:bit
106
+ // has lost its listener registrations).
107
+ await this.replayAllRequirements();
108
+ }
109
+ catch (e) {
110
+ this.dispatchTypedEvent("backgrounderror", {
111
+ error: (0, ble_error_js_1.mapBleError)(e),
112
+ event: type,
113
+ });
114
+ }
115
+ }
116
+ async stopNotifications(type) {
117
+ if (!this.getRelevantEvents().includes(type)) {
118
+ return;
119
+ }
120
+ this.activeEventTypes.delete(type);
121
+ // Remove filters contributed by this named event type
122
+ if (isNamedEvent(type)) {
123
+ const keys = this.namedEventFilters.get(type) ?? [];
124
+ for (const key of keys) {
125
+ this.namedRequirements.delete(key);
126
+ }
127
+ this.namedEventFilters.delete(type);
128
+ }
129
+ if (this.activeEventTypes.size === 0) {
130
+ try {
131
+ await bluetooth_le_1.BleClient.stopNotifications(this.deviceId, profile_js_1.profile.event.id, profile_js_1.profile.event.characteristics.microBitEvent.id);
132
+ }
133
+ catch (e) {
134
+ this.dispatchTypedEvent("backgrounderror", {
135
+ error: (0, ble_error_js_1.mapBleError)(e),
136
+ event: type,
137
+ });
138
+ }
139
+ }
140
+ }
141
+ /**
142
+ * Register interest in a specific micro:bit message bus event.
143
+ * Tells the micro:bit to forward matching message bus traffic over BLE.
144
+ * Matching events are dispatched as `microbitevent`.
145
+ * Use 0 as the value to match all events from a source.
146
+ */
147
+ async subscribeToEvent(source, value) {
148
+ const key = filterKey(source, value);
149
+ if (!this.explicitSubscriptions.has(key)) {
150
+ this.explicitSubscriptions.add(key);
151
+ await this.writeClientRequirement(source, value);
152
+ }
153
+ }
154
+ /**
155
+ * Send an event to the micro:bit's message bus.
156
+ */
157
+ async sendEvent(source, value) {
158
+ const data = new DataView(new ArrayBuffer(4));
159
+ data.setUint16(0, source, true);
160
+ data.setUint16(2, value, true);
161
+ await bluetooth_le_1.BleClient.writeWithoutResponse(this.deviceId, profile_js_1.profile.event.id, profile_js_1.profile.event.characteristics.clientEvent.id, data);
162
+ }
163
+ handleNotification(dataView) {
164
+ for (let offset = 0; offset + 4 <= dataView.byteLength; offset += 4) {
165
+ const source = dataView.getUint16(offset, true);
166
+ const value = dataView.getUint16(offset + 2, true);
167
+ if (this.activeEventTypes.has("microbitevent") &&
168
+ this.matchesExplicitSubscription(source, value)) {
169
+ this.dispatchTypedEvent("microbitevent", { source, value });
170
+ }
171
+ this.demuxToNamedEvents(source, value);
172
+ }
173
+ }
174
+ demuxToNamedEvents(source, value) {
175
+ const src = this.getSourceIds();
176
+ if (!src)
177
+ return;
178
+ if (source === src.Gesture && this.activeEventTypes.has("gesturechanged")) {
179
+ this.dispatchTypedEvent("gesturechanged", {
180
+ gesture: value,
181
+ });
182
+ }
183
+ if (source === src.ButtonA && this.activeEventTypes.has("buttonaaction")) {
184
+ this.dispatchTypedEvent("buttonaaction", {
185
+ button: "A",
186
+ action: value,
187
+ });
188
+ }
189
+ if (source === src.ButtonB && this.activeEventTypes.has("buttonbaction")) {
190
+ this.dispatchTypedEvent("buttonbaction", {
191
+ button: "B",
192
+ action: value,
193
+ });
194
+ }
195
+ if (source === src.ButtonAB &&
196
+ this.activeEventTypes.has("buttonabaction")) {
197
+ this.dispatchTypedEvent("buttonabaction", {
198
+ button: "AB",
199
+ action: value,
200
+ });
201
+ }
202
+ if (source === microbit_events_js_1.V2Source.Logo && this.activeEventTypes.has("logoaction")) {
203
+ this.dispatchTypedEvent("logoaction", {
204
+ button: "Logo",
205
+ action: value,
206
+ });
207
+ }
208
+ }
209
+ writeRequirementsForNamedEvent(type) {
210
+ const src = this.getSourceIds();
211
+ if (!src)
212
+ return;
213
+ const filters = [];
214
+ switch (type) {
215
+ case "gesturechanged":
216
+ filters.push([src.Gesture, 0]);
217
+ break;
218
+ case "buttonaaction":
219
+ filters.push([src.ButtonA, 0]);
220
+ break;
221
+ case "buttonbaction":
222
+ filters.push([src.ButtonB, 0]);
223
+ break;
224
+ case "buttonabaction":
225
+ filters.push([src.ButtonAB, 0]);
226
+ break;
227
+ case "logoaction":
228
+ filters.push([microbit_events_js_1.V2Source.Logo, 0]);
229
+ break;
230
+ }
231
+ const keys = [];
232
+ for (const [source, value] of filters) {
233
+ const key = filterKey(source, value);
234
+ keys.push(key);
235
+ this.namedRequirements.add(key);
236
+ }
237
+ this.namedEventFilters.set(type, keys);
238
+ }
239
+ matchesExplicitSubscription(source, value) {
240
+ if (this.explicitSubscriptions.has(filterKey(source, value)))
241
+ return true;
242
+ if (this.explicitSubscriptions.has(filterKey(source, 0)))
243
+ return true;
244
+ return false;
245
+ }
246
+ async replayAllRequirements() {
247
+ for (const key of this.namedRequirements) {
248
+ const [source, value] = key.split(":").map(Number);
249
+ await this.writeClientRequirement(source, value);
250
+ }
251
+ for (const key of this.explicitSubscriptions) {
252
+ const [source, value] = key.split(":").map(Number);
253
+ await this.writeClientRequirement(source, value);
254
+ }
255
+ }
256
+ async writeClientRequirement(source, value) {
257
+ const data = new DataView(new ArrayBuffer(4));
258
+ data.setUint16(0, source, true);
259
+ data.setUint16(2, value, true);
260
+ await bluetooth_le_1.BleClient.write(this.deviceId, profile_js_1.profile.event.id, profile_js_1.profile.event.characteristics.clientRequirements.id, data);
261
+ }
262
+ getSourceIds() {
263
+ const version = this.getBoardVersion();
264
+ if (!version)
265
+ return undefined;
266
+ return version === "V1" ? microbit_events_js_1.EventSource.v1 : microbit_events_js_1.EventSource.v2;
267
+ }
268
+ }
269
+ exports.EventService = EventService;
270
+ function filterKey(source, value) {
271
+ return `${source}:${value}`;
272
+ }
273
+ //# sourceMappingURL=event-service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event-service.js","sourceRoot":"","sources":["../../../../src/bluetooth/services/event-service.ts"],"names":[],"mappings":";;;AAAA,oEAA8D;AAM9D,8CAAwC;AACxC,kDAA8C;AAE9C,iEAKkC;AAIlC,MAAM,YAAY,GAAG;IACnB,gBAAgB;IAChB,eAAe;IACf,eAAe;IACf,gBAAgB;IAChB,YAAY;CACJ,CAAC;AAIX,SAAS,YAAY,CAAC,IAAY;IAChC,OAAQ,YAAkC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;AAC5D,CAAC;AAED,MAAa,YAAY;IAqBvB,YACU,QAAgB,EAChB,kBAA+C,EAC/C,eAA+C;QAFvD;;;;mBAAQ,QAAQ;WAAQ;QACxB;;;;mBAAQ,kBA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SAAS,CAAC,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;QAChC,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;QAC/B,MAAM,wBAAS,CAAC,KAAK,CACnB,IAAI,CAAC,QAAQ,EACb,oBAAO,CAAC,KAAK,CAAC,EAAE,EAChB,oBAAO,CAAC,KAAK,CAAC,eAAe,CAAC,kBAAkB,CAAC,EAAE,EACnD,IAAI,CACL,CAAC;IACJ,CAAC;IAEO,YAAY;QAClB,MAAM,OAAO,GAAG,IAAI,CAAC,eAAe,EAAE,CAAC;QACvC,IAAI,CAAC,OAAO;YAAE,OAAO,SAAS,CAAC;QAC/B,OAAO,OAAO,KAAK,IAAI,CAAC,CAAC,CAAC,gCAAW,CAAC,EAAE,CAAC,CAAC,CAAC,gCAAW,CAAC,EAAE,CAAC;IAC5D,CAAC;CACF;AA7PD,oCA6PC;AAED,SAAS,SAAS,CAAC,MAAc,EAAE,KAAa;IAC9C,OAAO,GAAG,MAAM,IAAI,KAAK,EAAE,CAAC;AAC9B,CAAC"}
@@ -0,0 +1,65 @@
1
+ import { Service } from "../device-wrapper.js";
2
+ import { PinValue, TypedServiceEvent, TypedServiceEventDispatcher } from "../../service-events.js";
3
+ export declare class IoPinService implements Service {
4
+ private deviceId;
5
+ private dispatchTypedEvent;
6
+ uuid: string;
7
+ constructor(deviceId: string, dispatchTypedEvent: TypedServiceEventDispatcher);
8
+ getRelevantEvents(): TypedServiceEvent[];
9
+ /**
10
+ * Gets which pins are configured as analog.
11
+ * All other pins are digital (the default).
12
+ *
13
+ * @returns array of pin numbers (0-18) configured as analog.
14
+ */
15
+ getAnalogPins(): Promise<number[]>;
16
+ /**
17
+ * Sets which pins are configured as analog.
18
+ * All other pins become digital (the default).
19
+ *
20
+ * @param pins array of pin numbers (0-18) to configure as analog.
21
+ */
22
+ setAnalogPins(pins: number[]): Promise<void>;
23
+ /**
24
+ * Gets which pins are configured as inputs.
25
+ * Input pins are monitored by the service and their values reported
26
+ * via notifications and reads of the pin data characteristic.
27
+ * All other pins are outputs (the default).
28
+ *
29
+ * @returns array of pin numbers (0-18) configured as inputs.
30
+ */
31
+ getInputPins(): Promise<number[]>;
32
+ /**
33
+ * Sets which pins are configured as inputs.
34
+ * Input pins are monitored by the service and their values reported
35
+ * via notifications and reads of the pin data characteristic.
36
+ * All other pins become outputs (the default).
37
+ *
38
+ * @param pins array of pin numbers (0-18) to configure as inputs.
39
+ */
40
+ setInputPins(pins: number[]): Promise<void>;
41
+ /**
42
+ * Reads pin data for all active input pins.
43
+ * For digital pins, value is 0 or 1.
44
+ * For analog pins, value is 0-255 (10-bit analog value >> 2).
45
+ */
46
+ readPins(): Promise<PinValue[]>;
47
+ /**
48
+ * Writes pin data for output pins.
49
+ * Only pins configured as outputs (not active inputs) will be affected.
50
+ * For digital pins, value is 0 or 1.
51
+ * For analog pins, value 0-255 is scaled to 0-1023 on the device.
52
+ */
53
+ writePins(data: PinValue[]): Promise<void>;
54
+ /**
55
+ * Sets PWM output on a pin.
56
+ *
57
+ * @param pin Pin number (0-18).
58
+ * @param value Analog value (0-1024).
59
+ * @param period Period in microseconds.
60
+ */
61
+ setPwm(pin: number, value: number, period: number): Promise<void>;
62
+ startNotifications(type: TypedServiceEvent): Promise<void>;
63
+ stopNotifications(type: TypedServiceEvent): Promise<void>;
64
+ private dataViewToPinData;
65
+ }