@microbit/microbit-connection 0.0.0-tab.change.177 → 0.9.0-apps.alpha.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 (292) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +94 -5
  3. package/build/cjs/accelerometer-service.d.ts +18 -0
  4. package/build/cjs/accelerometer-service.js +105 -0
  5. package/build/cjs/accelerometer-service.js.map +1 -0
  6. package/build/cjs/accelerometer.js +16 -0
  7. package/build/cjs/accelerometer.js.map +1 -0
  8. package/build/{async-util.d.ts → cjs/async-util.d.ts} +9 -0
  9. package/build/cjs/async-util.js +47 -0
  10. package/build/cjs/async-util.js.map +1 -0
  11. package/build/cjs/bluetooth-device-wrapper.d.ts +97 -0
  12. package/build/cjs/bluetooth-device-wrapper.js +486 -0
  13. package/build/cjs/bluetooth-device-wrapper.js.map +1 -0
  14. package/build/{bluetooth-profile.d.ts → cjs/bluetooth-profile.d.ts} +43 -35
  15. package/build/cjs/bluetooth-profile.js +92 -0
  16. package/build/cjs/bluetooth-profile.js.map +1 -0
  17. package/build/cjs/bluetooth.d.ts +112 -0
  18. package/build/cjs/bluetooth.js +458 -0
  19. package/build/cjs/bluetooth.js.map +1 -0
  20. package/build/cjs/board-id.js +81 -0
  21. package/build/cjs/board-id.js.map +1 -0
  22. package/build/cjs/board-serial-info.js +51 -0
  23. package/build/cjs/board-serial-info.js.map +1 -0
  24. package/build/cjs/button-service.d.ts +13 -0
  25. package/build/cjs/button-service.js +66 -0
  26. package/build/cjs/button-service.js.map +1 -0
  27. package/build/cjs/buttons.js +22 -0
  28. package/build/cjs/buttons.js.map +1 -0
  29. package/build/cjs/constants.js +73 -0
  30. package/build/cjs/constants.js.map +1 -0
  31. package/build/cjs/device-information-service.d.ts +6 -0
  32. package/build/cjs/device-information-service.js +34 -0
  33. package/build/cjs/device-information-service.js.map +1 -0
  34. package/build/{device.d.ts → cjs/device.d.ts} +71 -39
  35. package/build/cjs/device.js +147 -0
  36. package/build/cjs/device.js.map +1 -0
  37. package/build/cjs/dfu-service.d.ts +9 -0
  38. package/build/cjs/dfu-service.js +26 -0
  39. package/build/cjs/dfu-service.js.map +1 -0
  40. package/build/{events.d.ts → cjs/events.d.ts} +1 -2
  41. package/build/cjs/events.js +109 -0
  42. package/build/cjs/events.js.map +1 -0
  43. package/build/cjs/flashing/flashing-full.d.ts +14 -0
  44. package/build/cjs/flashing/flashing-full.js +87 -0
  45. package/build/cjs/flashing/flashing-full.js.map +1 -0
  46. package/build/cjs/flashing/flashing-makecode.d.ts +6 -0
  47. package/build/cjs/flashing/flashing-makecode.js +48 -0
  48. package/build/cjs/flashing/flashing-makecode.js.map +1 -0
  49. package/build/cjs/flashing/flashing-partial.d.ts +9 -0
  50. package/build/cjs/flashing/flashing-partial.js +98 -0
  51. package/build/cjs/flashing/flashing-partial.js.map +1 -0
  52. package/build/cjs/flashing/flashing-v1.d.ts +11 -0
  53. package/build/cjs/flashing/flashing-v1.js +24 -0
  54. package/build/cjs/flashing/flashing-v1.js.map +1 -0
  55. package/build/cjs/flashing/nordic-dfu.d.ts +3 -0
  56. package/build/cjs/flashing/nordic-dfu.js +214 -0
  57. package/build/cjs/flashing/nordic-dfu.js.map +1 -0
  58. package/build/cjs/flashing/zip.d.ts +12 -0
  59. package/build/cjs/flashing/zip.js +177 -0
  60. package/build/cjs/flashing/zip.js.map +1 -0
  61. package/build/cjs/hex-flash-data-source.js +26 -0
  62. package/build/cjs/hex-flash-data-source.js.map +1 -0
  63. package/build/cjs/index.d.ts +17 -0
  64. package/build/cjs/index.js +37 -0
  65. package/build/cjs/index.js.map +1 -0
  66. package/build/cjs/led-service.d.ts +18 -0
  67. package/build/cjs/led-service.js +89 -0
  68. package/build/cjs/led-service.js.map +1 -0
  69. package/build/cjs/led.js +3 -0
  70. package/build/cjs/led.js.map +1 -0
  71. package/build/{logging.d.ts → cjs/logging.d.ts} +4 -4
  72. package/build/cjs/logging.js +16 -0
  73. package/build/cjs/logging.js.map +1 -0
  74. package/build/cjs/magnetometer-service.d.ts +18 -0
  75. package/build/cjs/magnetometer-service.js +94 -0
  76. package/build/cjs/magnetometer-service.js.map +1 -0
  77. package/build/cjs/magnetometer.d.ts +9 -0
  78. package/build/cjs/magnetometer.js +16 -0
  79. package/build/cjs/magnetometer.js.map +1 -0
  80. package/build/cjs/package.json +1 -0
  81. package/build/cjs/partial-flashing-service.d.ts +45 -0
  82. package/build/cjs/partial-flashing-service.js +110 -0
  83. package/build/cjs/partial-flashing-service.js.map +1 -0
  84. package/build/cjs/promise-queue.js +78 -0
  85. package/build/cjs/promise-queue.js.map +1 -0
  86. package/build/cjs/serial-events.d.ts +20 -0
  87. package/build/cjs/serial-events.js +69 -0
  88. package/build/cjs/serial-events.js.map +1 -0
  89. package/build/{service-events.d.ts → cjs/service-events.d.ts} +4 -0
  90. package/build/cjs/service-events.js +39 -0
  91. package/build/cjs/service-events.js.map +1 -0
  92. package/build/cjs/setupTests.js.map +1 -0
  93. package/build/cjs/uart-service.d.ts +12 -0
  94. package/build/cjs/uart-service.js +55 -0
  95. package/build/cjs/uart-service.js.map +1 -0
  96. package/build/cjs/uart.d.ts +4 -0
  97. package/build/cjs/uart.js +16 -0
  98. package/build/cjs/uart.js.map +1 -0
  99. package/build/{usb-device-wrapper.d.ts → cjs/usb-device-wrapper.d.ts} +1 -6
  100. package/build/cjs/usb-device-wrapper.js +437 -0
  101. package/build/cjs/usb-device-wrapper.js.map +1 -0
  102. package/build/cjs/usb-partial-flashing-utils.js +133 -0
  103. package/build/cjs/usb-partial-flashing-utils.js.map +1 -0
  104. package/build/{usb-partial-flashing.d.ts → cjs/usb-partial-flashing.d.ts} +3 -5
  105. package/build/cjs/usb-partial-flashing.js +342 -0
  106. package/build/cjs/usb-partial-flashing.js.map +1 -0
  107. package/build/cjs/usb-radio-bridge.d.ts +24 -0
  108. package/build/cjs/usb-radio-bridge.js +515 -0
  109. package/build/cjs/usb-radio-bridge.js.map +1 -0
  110. package/build/cjs/usb-serial-protocol.js +183 -0
  111. package/build/cjs/usb-serial-protocol.js.map +1 -0
  112. package/build/cjs/usb.d.ts +66 -0
  113. package/build/cjs/usb.js +662 -0
  114. package/build/cjs/usb.js.map +1 -0
  115. package/build/esm/accelerometer-service.d.ts +18 -0
  116. package/build/esm/accelerometer-service.js +101 -0
  117. package/build/esm/accelerometer-service.js.map +1 -0
  118. package/build/esm/accelerometer.d.ts +9 -0
  119. package/build/esm/accelerometer.js.map +1 -0
  120. package/build/esm/async-util.d.ts +22 -0
  121. package/build/esm/async-util.js +38 -0
  122. package/build/esm/async-util.js.map +1 -0
  123. package/build/esm/bluetooth-device-wrapper.d.ts +97 -0
  124. package/build/esm/bluetooth-device-wrapper.js +481 -0
  125. package/build/esm/bluetooth-device-wrapper.js.map +1 -0
  126. package/build/esm/bluetooth-profile.d.ts +147 -0
  127. package/build/{bluetooth-profile.js → esm/bluetooth-profile.js} +35 -29
  128. package/build/esm/bluetooth-profile.js.map +1 -0
  129. package/build/esm/bluetooth.d.ts +112 -0
  130. package/build/esm/bluetooth.js +428 -0
  131. package/build/esm/bluetooth.js.map +1 -0
  132. package/build/esm/board-id.d.ts +36 -0
  133. package/build/esm/board-id.js.map +1 -0
  134. package/build/esm/board-serial-info.d.ts +14 -0
  135. package/build/esm/board-serial-info.js.map +1 -0
  136. package/build/esm/button-service.d.ts +13 -0
  137. package/build/esm/button-service.js +62 -0
  138. package/build/esm/button-service.js.map +1 -0
  139. package/build/esm/buttons.d.ts +10 -0
  140. package/build/esm/buttons.js.map +1 -0
  141. package/build/esm/constants.d.ts +48 -0
  142. package/build/esm/constants.js.map +1 -0
  143. package/build/esm/device-information-service.d.ts +6 -0
  144. package/build/esm/device-information-service.js +30 -0
  145. package/build/esm/device-information-service.js.map +1 -0
  146. package/build/esm/device.d.ts +238 -0
  147. package/build/{device.js → esm/device.js} +16 -58
  148. package/build/esm/device.js.map +1 -0
  149. package/build/esm/dfu-service.d.ts +9 -0
  150. package/build/esm/dfu-service.js +22 -0
  151. package/build/esm/dfu-service.js.map +1 -0
  152. package/build/esm/events.d.ts +110 -0
  153. package/build/esm/events.js.map +1 -0
  154. package/build/esm/flashing/flashing-full.d.ts +14 -0
  155. package/build/esm/flashing/flashing-full.js +84 -0
  156. package/build/esm/flashing/flashing-full.js.map +1 -0
  157. package/build/esm/flashing/flashing-makecode.d.ts +6 -0
  158. package/build/esm/flashing/flashing-makecode.js +44 -0
  159. package/build/esm/flashing/flashing-makecode.js.map +1 -0
  160. package/build/esm/flashing/flashing-partial.d.ts +9 -0
  161. package/build/esm/flashing/flashing-partial.js +95 -0
  162. package/build/esm/flashing/flashing-partial.js.map +1 -0
  163. package/build/esm/flashing/flashing-v1.d.ts +11 -0
  164. package/build/esm/flashing/flashing-v1.js +20 -0
  165. package/build/esm/flashing/flashing-v1.js.map +1 -0
  166. package/build/esm/flashing/nordic-dfu.d.ts +3 -0
  167. package/build/esm/flashing/nordic-dfu.js +211 -0
  168. package/build/esm/flashing/nordic-dfu.js.map +1 -0
  169. package/build/esm/flashing/zip.d.ts +12 -0
  170. package/build/esm/flashing/zip.js +174 -0
  171. package/build/esm/flashing/zip.js.map +1 -0
  172. package/build/esm/hex-flash-data-source.d.ts +7 -0
  173. package/build/esm/hex-flash-data-source.js.map +1 -0
  174. package/build/esm/index.d.ts +17 -0
  175. package/build/esm/index.js +12 -0
  176. package/build/esm/index.js.map +1 -0
  177. package/build/esm/led-service.d.ts +18 -0
  178. package/build/esm/led-service.js +85 -0
  179. package/build/esm/led-service.js.map +1 -0
  180. package/build/esm/led.d.ts +6 -0
  181. package/build/esm/led.js.map +1 -0
  182. package/build/esm/logging.d.ts +21 -0
  183. package/build/{logging.js → esm/logging.js} +1 -1
  184. package/build/esm/logging.js.map +1 -0
  185. package/build/esm/magnetometer-service.d.ts +18 -0
  186. package/build/esm/magnetometer-service.js +90 -0
  187. package/build/esm/magnetometer-service.js.map +1 -0
  188. package/build/esm/magnetometer.d.ts +9 -0
  189. package/build/esm/magnetometer.js +12 -0
  190. package/build/esm/magnetometer.js.map +1 -0
  191. package/build/esm/package.json +1 -0
  192. package/build/esm/partial-flashing-service.d.ts +45 -0
  193. package/build/esm/partial-flashing-service.js +106 -0
  194. package/build/esm/partial-flashing-service.js.map +1 -0
  195. package/build/esm/promise-queue.d.ts +27 -0
  196. package/build/esm/promise-queue.js.map +1 -0
  197. package/build/esm/serial-events.d.ts +20 -0
  198. package/build/esm/serial-events.js +61 -0
  199. package/build/esm/serial-events.js.map +1 -0
  200. package/build/esm/service-events.d.ts +17 -0
  201. package/build/{service-events.js → esm/service-events.js} +12 -0
  202. package/build/esm/service-events.js.map +1 -0
  203. package/build/esm/setupTests.d.ts +6 -0
  204. package/build/{setupTests.js.map → esm/setupTests.js.map} +1 -1
  205. package/build/esm/uart-service.d.ts +12 -0
  206. package/build/esm/uart-service.js +51 -0
  207. package/build/esm/uart-service.js.map +1 -0
  208. package/build/esm/uart.d.ts +4 -0
  209. package/build/esm/uart.js +12 -0
  210. package/build/esm/uart.js.map +1 -0
  211. package/build/esm/usb-device-wrapper.d.ts +47 -0
  212. package/build/{usb-device-wrapper.js → esm/usb-device-wrapper.js} +43 -17
  213. package/build/esm/usb-device-wrapper.js.map +1 -0
  214. package/build/esm/usb-partial-flashing-utils.d.ts +17 -0
  215. package/build/esm/usb-partial-flashing-utils.js.map +1 -0
  216. package/build/esm/usb-partial-flashing.d.ts +67 -0
  217. package/build/{usb-partial-flashing.js → esm/usb-partial-flashing.js} +12 -13
  218. package/build/esm/usb-partial-flashing.js.map +1 -0
  219. package/build/esm/usb-radio-bridge.d.ts +24 -0
  220. package/build/{usb-radio-bridge.js → esm/usb-radio-bridge.js} +13 -7
  221. package/build/esm/usb-radio-bridge.js.map +1 -0
  222. package/build/esm/usb-serial-protocol.d.ts +66 -0
  223. package/build/esm/usb-serial-protocol.js.map +1 -0
  224. package/build/esm/usb.d.ts +66 -0
  225. package/build/{usb.js → esm/usb.js} +257 -49
  226. package/build/esm/usb.js.map +1 -0
  227. package/package.json +25 -8
  228. package/typedoc.json +14 -0
  229. package/build/accelerometer-service.d.ts +0 -18
  230. package/build/accelerometer-service.js +0 -102
  231. package/build/accelerometer-service.js.map +0 -1
  232. package/build/accelerometer.js.map +0 -1
  233. package/build/async-util.js +0 -22
  234. package/build/async-util.js.map +0 -1
  235. package/build/bluetooth-device-wrapper.d.ts +0 -57
  236. package/build/bluetooth-device-wrapper.js +0 -433
  237. package/build/bluetooth-device-wrapper.js.map +0 -1
  238. package/build/bluetooth-profile.js.map +0 -1
  239. package/build/bluetooth.d.ts +0 -54
  240. package/build/bluetooth.js +0 -243
  241. package/build/bluetooth.js.map +0 -1
  242. package/build/board-id.js.map +0 -1
  243. package/build/board-serial-info.js.map +0 -1
  244. package/build/button-service.d.ts +0 -13
  245. package/build/button-service.js +0 -76
  246. package/build/button-service.js.map +0 -1
  247. package/build/buttons.js.map +0 -1
  248. package/build/constants.js.map +0 -1
  249. package/build/device.js.map +0 -1
  250. package/build/events.js.map +0 -1
  251. package/build/hex-flash-data-source.js.map +0 -1
  252. package/build/index.d.ts +0 -10
  253. package/build/index.js +0 -8
  254. package/build/index.js.map +0 -1
  255. package/build/led-service.d.ts +0 -20
  256. package/build/led-service.js +0 -116
  257. package/build/led-service.js.map +0 -1
  258. package/build/led.js.map +0 -1
  259. package/build/logging.js.map +0 -1
  260. package/build/promise-queue.js.map +0 -1
  261. package/build/service-events.js.map +0 -1
  262. package/build/usb-device-wrapper.js.map +0 -1
  263. package/build/usb-partial-flashing-utils.js.map +0 -1
  264. package/build/usb-partial-flashing.js.map +0 -1
  265. package/build/usb-radio-bridge.d.ts +0 -41
  266. package/build/usb-radio-bridge.js.map +0 -1
  267. package/build/usb-serial-protocol.js.map +0 -1
  268. package/build/usb.d.ts +0 -54
  269. package/build/usb.js.map +0 -1
  270. package/vite.config.ts +0 -34
  271. /package/build/{accelerometer.d.ts → cjs/accelerometer.d.ts} +0 -0
  272. /package/build/{board-id.d.ts → cjs/board-id.d.ts} +0 -0
  273. /package/build/{board-serial-info.d.ts → cjs/board-serial-info.d.ts} +0 -0
  274. /package/build/{buttons.d.ts → cjs/buttons.d.ts} +0 -0
  275. /package/build/{constants.d.ts → cjs/constants.d.ts} +0 -0
  276. /package/build/{hex-flash-data-source.d.ts → cjs/hex-flash-data-source.d.ts} +0 -0
  277. /package/build/{led.d.ts → cjs/led.d.ts} +0 -0
  278. /package/build/{promise-queue.d.ts → cjs/promise-queue.d.ts} +0 -0
  279. /package/build/{setupTests.d.ts → cjs/setupTests.d.ts} +0 -0
  280. /package/build/{usb-partial-flashing-utils.d.ts → cjs/usb-partial-flashing-utils.d.ts} +0 -0
  281. /package/build/{usb-serial-protocol.d.ts → cjs/usb-serial-protocol.d.ts} +0 -0
  282. /package/build/{accelerometer.js → esm/accelerometer.js} +0 -0
  283. /package/build/{board-id.js → esm/board-id.js} +0 -0
  284. /package/build/{board-serial-info.js → esm/board-serial-info.js} +0 -0
  285. /package/build/{buttons.js → esm/buttons.js} +0 -0
  286. /package/build/{constants.js → esm/constants.js} +0 -0
  287. /package/build/{events.js → esm/events.js} +0 -0
  288. /package/build/{hex-flash-data-source.js → esm/hex-flash-data-source.js} +0 -0
  289. /package/build/{led.js → esm/led.js} +0 -0
  290. /package/build/{promise-queue.js → esm/promise-queue.js} +0 -0
  291. /package/build/{usb-partial-flashing-utils.js → esm/usb-partial-flashing-utils.js} +0 -0
  292. /package/build/{usb-serial-protocol.js → esm/usb-serial-protocol.js} +0 -0
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.profile = void 0;
4
+ exports.profile = {
5
+ // Alphabetised
6
+ accelerometer: {
7
+ id: "e95d0753-251d-470a-a062-fa1922dfa9a8",
8
+ characteristics: {
9
+ data: { id: "e95dca4b-251d-470a-a062-fa1922dfa9a8" },
10
+ period: { id: "e95dfb24-251d-470a-a062-fa1922dfa9a8" },
11
+ },
12
+ },
13
+ button: {
14
+ id: "e95d9882-251d-470a-a062-fa1922dfa9a8",
15
+ characteristics: {
16
+ a: { id: "e95dda90-251d-470a-a062-fa1922dfa9a8" },
17
+ b: { id: "e95dda91-251d-470a-a062-fa1922dfa9a8" },
18
+ },
19
+ },
20
+ deviceInformation: {
21
+ id: "0000180a-0000-1000-8000-00805f9b34fb",
22
+ characteristics: {
23
+ firmwareRevision: { id: "00002a26-0000-1000-8000-00805f9b34fb" },
24
+ hardwareRevision: { id: "00002a27-0000-1000-8000-00805f9b34fb" },
25
+ manufacturer: { id: "00002a29-0000-1000-8000-00805f9b34fb" },
26
+ modelNumber: { id: "00002a24-0000-1000-8000-00805f9b34fb" },
27
+ serialNumber: { id: "00002a25-0000-1000-8000-00805f9b34fb" },
28
+ },
29
+ },
30
+ dfuControl: {
31
+ id: "e95d93b0-251d-470a-a062-fa1922dfa9a8",
32
+ characteristics: {
33
+ control: { id: "e95d93b1-251d-470a-a062-fa1922dfa9a8" },
34
+ },
35
+ },
36
+ event: {
37
+ id: "e95d93af-251d-470a-a062-fa1922dfa9a8",
38
+ characteristics: {
39
+ clientEvent: { id: "e95d5404-251d-470a-a062-fa1922dfa9a8" },
40
+ clientRequirements: { id: "e95d23c4-251d-470a-a062-fa1922dfa9a8" },
41
+ microBitEvent: { id: "e95d9775-251d-470a-a062-fa1922dfa9a8" },
42
+ microBitRequirements: { id: "e95db84c-251d-470a-a062-fa1922dfa9a8" },
43
+ },
44
+ },
45
+ ioPin: {
46
+ id: "e95d127b-251d-470a-a062-fa1922dfa9a8",
47
+ characteristics: {
48
+ pinAdConfiguration: { id: "e95d5899-251d-470a-a062-fa1922dfa9a8" },
49
+ pinData: { id: "e95d8d00-251d-470a-a062-fa1922dfa9a8" },
50
+ pinIoConfiguration: { id: "e95db9fe-251d-470a-a062-fa1922dfa9a8" },
51
+ pwmControl: { id: "e95dd822-251d-470a-a062-fa1922dfa9a8" },
52
+ },
53
+ },
54
+ led: {
55
+ id: "e95dd91d-251d-470a-a062-fa1922dfa9a8",
56
+ characteristics: {
57
+ matrixState: { id: "e95d7b77-251d-470a-a062-fa1922dfa9a8" },
58
+ scrollingDelay: { id: "e95d0d2d-251d-470a-a062-fa1922dfa9a8" },
59
+ text: { id: "e95d93ee-251d-470a-a062-fa1922dfa9a8" },
60
+ },
61
+ },
62
+ magnetometer: {
63
+ id: "e95df2d8-251d-470a-a062-fa1922dfa9a8",
64
+ characteristics: {
65
+ data: { id: "e95dfb11-251d-470a-a062-fa1922dfa9a8" },
66
+ period: { id: "e95d386c-251d-470a-a062-fa1922dfa9a8" },
67
+ bearing: { id: "e95d9715-251d-470a-a062-fa1922dfa9a8" },
68
+ calibration: { id: "e95db358-251d-470a-a062-fa1922dfa9a8" },
69
+ },
70
+ },
71
+ partialFlashing: {
72
+ id: "e97dd91d-251d-470a-a062-fa1922dfa9a8",
73
+ characteristics: {
74
+ partialFlash: { id: "e97d3b10-251d-470a-a062-fa1922dfa9a8" },
75
+ },
76
+ },
77
+ temperature: {
78
+ id: "e95d6100-251d-470a-a062-fa1922dfa9a8",
79
+ characteristics: {
80
+ data: { id: "e95d9250-251d-470a-a062-fa1922dfa9a8" },
81
+ period: { id: "e95d1b25-251d-470a-a062-fa1922dfa9a8" },
82
+ },
83
+ },
84
+ uart: {
85
+ id: "6e400001-b5a3-f393-e0a9-e50e24dcca9e",
86
+ characteristics: {
87
+ rx: { id: "6e400003-b5a3-f393-e0a9-e50e24dcca9e" },
88
+ tx: { id: "6e400002-b5a3-f393-e0a9-e50e24dcca9e" },
89
+ },
90
+ },
91
+ };
92
+ //# sourceMappingURL=bluetooth-profile.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bluetooth-profile.js","sourceRoot":"","sources":["../../lib/bluetooth-profile.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,112 @@
1
+ import { AccelerometerData } from "./accelerometer.js";
2
+ import { DeviceConnection, FlashDataSource, FlashOptions } from "./device.js";
3
+ import { LedMatrix } from "./led.js";
4
+ import { Logging } from "./logging.js";
5
+ import { MagnetometerData } from "./magnetometer.js";
6
+ import { ServiceConnectionEventMap } from "./service-events.js";
7
+ export interface MicrobitWebBluetoothConnectionOptions {
8
+ logging?: Logging;
9
+ }
10
+ export interface MicrobitWebBluetoothConnection extends DeviceConnection<ServiceConnectionEventMap> {
11
+ /**
12
+ * Sets micro:bit name filter for device requesting.
13
+ *
14
+ * @param name The name of the micro:bit.
15
+ */
16
+ setNameFilter(name: string): void;
17
+ /**
18
+ * Gets micro:bit accelerometer data.
19
+ *
20
+ * @returns accelerometer data or undefined if there is no connection.
21
+ */
22
+ getAccelerometerData(): Promise<AccelerometerData | undefined>;
23
+ /**
24
+ * Gets micro:bit accelerometer period.
25
+ *
26
+ * @returns accelerometer period or undefined if there is no connection.
27
+ */
28
+ getAccelerometerPeriod(): Promise<number | undefined>;
29
+ /**
30
+ * Sets micro:bit accelerometer period.
31
+ *
32
+ * @param value The accelerometer period.
33
+ */
34
+ setAccelerometerPeriod(value: number): Promise<void>;
35
+ /**
36
+ * Sets micro:bit LED text.
37
+ *
38
+ * @param text The text displayed on micro:bit LED.
39
+ */
40
+ setLedText(text: string): Promise<void>;
41
+ /**
42
+ * Gets micro:bit LED scrolling delay.
43
+ *
44
+ * @returns LED scrolling delay in milliseconds.
45
+ */
46
+ getLedScrollingDelay(): Promise<number | undefined>;
47
+ /**
48
+ * Sets micro:bit LED scrolling delay.
49
+ *
50
+ * @param delayInMillis LED scrolling delay in milliseconds.
51
+ */
52
+ setLedScrollingDelay(delayInMillis: number): Promise<void>;
53
+ /**
54
+ * Gets micro:bit LED matrix.
55
+ *
56
+ * @returns a boolean matrix representing the micro:bit LED display.
57
+ */
58
+ getLedMatrix(): Promise<LedMatrix | undefined>;
59
+ /**
60
+ * Sets micro:bit LED matrix.
61
+ *
62
+ * @param matrix an boolean matrix representing the micro:bit LED display.
63
+ */
64
+ setLedMatrix(matrix: LedMatrix): Promise<void>;
65
+ /**
66
+ * Gets micro:bit magnetometer data.
67
+ *
68
+ * @returns magnetometer data.
69
+ */
70
+ getMagnetometerData(): Promise<MagnetometerData | undefined>;
71
+ /**
72
+ * Gets micro:bit magnetometer bearing.
73
+ *
74
+ * @returns magnetometer bearing.
75
+ */
76
+ getMagnetometerBearing(): Promise<number | undefined>;
77
+ /**
78
+ * Gets micro:bit magnetometer period.
79
+ *
80
+ * @returns magnetometer period.
81
+ */
82
+ getMagnetometerPeriod(): Promise<number | undefined>;
83
+ /**
84
+ * Sets micro:bit magnetometer period.
85
+ *
86
+ * @param value magnetometer period.
87
+ */
88
+ setMagnetometerPeriod(value: number): Promise<void>;
89
+ /**
90
+ * Triggers micro:bit magnetometer calibration.
91
+ */
92
+ triggerMagnetometerCalibration(): Promise<void>;
93
+ /**
94
+ * Write UART messages.
95
+ *
96
+ * @param data UART message.
97
+ */
98
+ uartWrite(data: Uint8Array): Promise<void>;
99
+ /**
100
+ * Flash the micro:bit.
101
+ *
102
+ * @param dataSource The data to use.
103
+ * @param options Flash options and progress callback.
104
+ * @throws {DeviceError} On flash failure. The error.code property indicates the failure type.
105
+ * @throws {FlashDataError} If data preparation fails.
106
+ */
107
+ flash(dataSource: FlashDataSource, options: FlashOptions): Promise<void>;
108
+ }
109
+ /**
110
+ * A Bluetooth connection factory.
111
+ */
112
+ export declare const createWebBluetoothConnection: (options?: MicrobitWebBluetoothConnectionOptions) => MicrobitWebBluetoothConnection;
@@ -0,0 +1,458 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.createWebBluetoothConnection = void 0;
30
+ /**
31
+ * (c) 2021, Micro:bit Educational Foundation and contributors
32
+ *
33
+ * SPDX-License-Identifier: MIT
34
+ */
35
+ const bluetooth_le_1 = require("@capacitor-community/bluetooth-le");
36
+ const core_1 = require("@capacitor/core");
37
+ const nrf_intel_hex_1 = __importDefault(require("nrf-intel-hex"));
38
+ const bluetooth_device_wrapper_js_1 = require("./bluetooth-device-wrapper.js");
39
+ const bluetooth_profile_js_1 = require("./bluetooth-profile.js");
40
+ const device_js_1 = require("./device.js");
41
+ const events_js_1 = require("./events.js");
42
+ const logging_js_1 = require("./logging.js");
43
+ const flashing_full_js_1 = require("./flashing/flashing-full.js");
44
+ const flashing_partial_js_1 = __importStar(require("./flashing/flashing-partial.js"));
45
+ let bleClientInitialized = false;
46
+ /**
47
+ * A Bluetooth connection factory.
48
+ */
49
+ const createWebBluetoothConnection = (options) => new MicrobitWebBluetoothConnectionImpl(options);
50
+ exports.createWebBluetoothConnection = createWebBluetoothConnection;
51
+ /**
52
+ * A Bluetooth connection to a micro:bit device.
53
+ */
54
+ class MicrobitWebBluetoothConnectionImpl extends events_js_1.TypedEventTarget {
55
+ constructor(options = {}) {
56
+ super();
57
+ Object.defineProperty(this, "status", {
58
+ enumerable: true,
59
+ configurable: true,
60
+ writable: true,
61
+ value: device_js_1.ConnectionStatus.SUPPORT_NOT_KNOWN
62
+ });
63
+ /**
64
+ * The USB device we last connected to.
65
+ * Cleared if it is disconnected.
66
+ */
67
+ Object.defineProperty(this, "device", {
68
+ enumerable: true,
69
+ configurable: true,
70
+ writable: true,
71
+ value: void 0
72
+ });
73
+ Object.defineProperty(this, "logging", {
74
+ enumerable: true,
75
+ configurable: true,
76
+ writable: true,
77
+ value: void 0
78
+ });
79
+ Object.defineProperty(this, "connection", {
80
+ enumerable: true,
81
+ configurable: true,
82
+ writable: true,
83
+ value: void 0
84
+ });
85
+ Object.defineProperty(this, "availabilityListener", {
86
+ enumerable: true,
87
+ configurable: true,
88
+ writable: true,
89
+ value: (e) => {
90
+ // TODO: is this called? is `value` correct?
91
+ const value = e.value;
92
+ this.availability = value;
93
+ }
94
+ });
95
+ Object.defineProperty(this, "availability", {
96
+ enumerable: true,
97
+ configurable: true,
98
+ writable: true,
99
+ value: void 0
100
+ });
101
+ Object.defineProperty(this, "nameFilter", {
102
+ enumerable: true,
103
+ configurable: true,
104
+ writable: true,
105
+ value: void 0
106
+ });
107
+ Object.defineProperty(this, "deferStatusUpdates", {
108
+ enumerable: true,
109
+ configurable: true,
110
+ writable: true,
111
+ value: false
112
+ });
113
+ this.logging = options.logging || new logging_js_1.ConsoleLogging();
114
+ }
115
+ eventActivated(type) {
116
+ this.connection?.startNotifications(type);
117
+ }
118
+ eventDeactivated(type) {
119
+ this.connection?.stopNotifications(type);
120
+ }
121
+ log(v) {
122
+ this.logging.log(v);
123
+ }
124
+ error(message, e) {
125
+ this.logging.error(message, e);
126
+ }
127
+ async initialize() {
128
+ navigator.bluetooth?.addEventListener("availabilitychanged", this.availabilityListener);
129
+ this.availability = await navigator.bluetooth?.getAvailability();
130
+ this.setStatus(this.availability
131
+ ? device_js_1.ConnectionStatus.NO_AUTHORIZED_DEVICE
132
+ : device_js_1.ConnectionStatus.NOT_SUPPORTED);
133
+ }
134
+ dispose() {
135
+ navigator.bluetooth?.removeEventListener("availabilitychanged", this.availabilityListener);
136
+ }
137
+ getBoardVersion() {
138
+ return this.connection?.boardVersion;
139
+ }
140
+ async connect(options) {
141
+ const progress = options?.progress ?? (() => { });
142
+ progress(device_js_1.ProgressStage.Initializing);
143
+ await this.preConnectInitialization();
144
+ if (!this.connection) {
145
+ progress(device_js_1.ProgressStage.FindingDevice);
146
+ const device = await this.requestDevice();
147
+ this.connection = new bluetooth_device_wrapper_js_1.BluetoothDeviceWrapper(device, this.logging, this.dispatchTypedEvent.bind(this), () => this.getActiveEvents(), {
148
+ onConnecting: () => this.setStatus(device_js_1.ConnectionStatus.CONNECTING),
149
+ onReconnecting: () => this.setStatus(device_js_1.ConnectionStatus.RECONNECTING),
150
+ onSuccess: () => this.setStatus(device_js_1.ConnectionStatus.CONNECTED),
151
+ onFail: () => {
152
+ this.setStatus(device_js_1.ConnectionStatus.DISCONNECTED);
153
+ this.connection = undefined;
154
+ },
155
+ });
156
+ }
157
+ progress(device_js_1.ProgressStage.Connecting);
158
+ await this.connection.connect();
159
+ }
160
+ /**
161
+ * Initializes BLE.
162
+ *
163
+ * This must happen before requesting a device or connecting.
164
+ *
165
+ * We do this just before use not at connection initialize because on Android/iOS
166
+ * that's the appropriate time to ask for permissions.
167
+ */
168
+ async preConnectInitialization() {
169
+ try {
170
+ if ((0, bluetooth_device_wrapper_js_1.isAndroid)()) {
171
+ const isLocationEnabled = await bluetooth_le_1.BleClient.isLocationEnabled();
172
+ if (!isLocationEnabled) {
173
+ throw new device_js_1.DeviceError({
174
+ code: "bluetooth-missing-permissions",
175
+ message: "Location services is disabled",
176
+ });
177
+ }
178
+ }
179
+ if (!bleClientInitialized) {
180
+ await bluetooth_le_1.BleClient.initialize({ androidNeverForLocation: true });
181
+ bleClientInitialized = true;
182
+ }
183
+ const isBluetoothEnabled = await bluetooth_le_1.BleClient.isEnabled();
184
+ if (!isBluetoothEnabled) {
185
+ throw new device_js_1.DeviceError({
186
+ code: "bluetooth-disabled",
187
+ message: "Bluetooth is disabled",
188
+ });
189
+ }
190
+ }
191
+ catch (e) {
192
+ this.error("Error initializing Bluetooth", e);
193
+ const error = e;
194
+ if (error.message === "BLE permission denied") {
195
+ // Error thrown for iOS platform.
196
+ throw new device_js_1.DeviceError({
197
+ code: "bluetooth-disabled",
198
+ message: "Bluetooth is disabled",
199
+ });
200
+ }
201
+ throw new device_js_1.DeviceError({
202
+ code: "bluetooth-missing-permissions",
203
+ message: "Missing permissions",
204
+ });
205
+ }
206
+ }
207
+ async disconnect() {
208
+ try {
209
+ if (this.connection) {
210
+ await this.connection.disconnect();
211
+ }
212
+ }
213
+ catch (e) {
214
+ this.logging.event({
215
+ type: "Bluetooth-error",
216
+ message: "error-disconnecting",
217
+ });
218
+ }
219
+ finally {
220
+ this.connection = undefined;
221
+ this.setStatus(device_js_1.ConnectionStatus.DISCONNECTED);
222
+ this.logging.event({
223
+ type: "Bluetooth-info",
224
+ message: "disconnected",
225
+ });
226
+ }
227
+ }
228
+ setStatus(newStatus) {
229
+ this.status = newStatus;
230
+ this.log("Bluetooth connection status " + newStatus);
231
+ if (!this.deferStatusUpdates) {
232
+ this.dispatchTypedEvent("status", new device_js_1.ConnectionStatusEvent(newStatus));
233
+ }
234
+ }
235
+ serialWrite(data) {
236
+ if (this.connection) {
237
+ // TODO
238
+ }
239
+ return Promise.resolve();
240
+ }
241
+ async clearDevice() {
242
+ await this.disconnect();
243
+ this.device = undefined;
244
+ this.setStatus(device_js_1.ConnectionStatus.NO_AUTHORIZED_DEVICE);
245
+ }
246
+ setNameFilter(name) {
247
+ this.nameFilter = name;
248
+ }
249
+ async requestDevice() {
250
+ if (this.device) {
251
+ return this.device;
252
+ }
253
+ this.dispatchTypedEvent("beforerequestdevice", new device_js_1.BeforeRequestDevice());
254
+ try {
255
+ const namePrefix = this.nameFilter
256
+ ? `BBC micro:bit [${this.nameFilter}]`
257
+ : "BBC micro:bit";
258
+ if (core_1.Capacitor.isNativePlatform()) {
259
+ this.device = await this.requestDeviceNative(namePrefix);
260
+ }
261
+ else {
262
+ this.device = await this.requestDeviceWeb(namePrefix);
263
+ }
264
+ if (!this.device) {
265
+ this.setStatus(device_js_1.ConnectionStatus.NO_AUTHORIZED_DEVICE);
266
+ throw new device_js_1.DeviceError({
267
+ code: "timeout-error",
268
+ message: "Timeout scanning for device",
269
+ });
270
+ }
271
+ return this.device;
272
+ }
273
+ finally {
274
+ this.dispatchTypedEvent("afterrequestdevice", new device_js_1.AfterRequestDevice());
275
+ }
276
+ }
277
+ async getAccelerometerData() {
278
+ return this.connection?.accelerometer.getData();
279
+ }
280
+ async getAccelerometerPeriod() {
281
+ return this.connection?.accelerometer.getPeriod();
282
+ }
283
+ async setAccelerometerPeriod(value) {
284
+ return this.connection?.accelerometer.setPeriod(value);
285
+ }
286
+ async setLedText(text) {
287
+ return this.connection?.led.setText(text);
288
+ }
289
+ async getLedScrollingDelay() {
290
+ return this.connection?.led.getScrollingDelay();
291
+ }
292
+ async setLedScrollingDelay(delayInMillis) {
293
+ await this.connection?.led.setScrollingDelay(delayInMillis);
294
+ }
295
+ async getLedMatrix() {
296
+ return await this.connection?.led.getLedMatrix();
297
+ }
298
+ async setLedMatrix(matrix) {
299
+ await this.connection?.led.setLedMatrix(matrix);
300
+ }
301
+ async getMagnetometerData() {
302
+ return this.connection?.magnetometer.getData();
303
+ }
304
+ async getMagnetometerPeriod() {
305
+ return this.connection?.magnetometer.getPeriod();
306
+ }
307
+ async setMagnetometerPeriod(value) {
308
+ return this.connection?.magnetometer.setPeriod(value);
309
+ }
310
+ async getMagnetometerBearing() {
311
+ return this.connection?.magnetometer.getBearing();
312
+ }
313
+ async triggerMagnetometerCalibration() {
314
+ await this.connection?.magnetometer.triggerCalibration();
315
+ }
316
+ async uartWrite(data) {
317
+ await this.connection?.uart.writeData(data);
318
+ }
319
+ /**
320
+ * Flash the micro:bit.
321
+ *
322
+ * Note that this will always leave the connection disconnected.
323
+ *
324
+ * @param dataSource The data to use.
325
+ * @param options Flash options and progress callback.
326
+ */
327
+ async flash(dataSource, options = {}) {
328
+ const progress = options.progress ?? (() => { });
329
+ try {
330
+ // We'll disconnect/reconnect multiple times due to device resets, but reporting this is unhelpful.
331
+ this.deferStatusUpdates = true;
332
+ if (this.status !== device_js_1.ConnectionStatus.CONNECTED) {
333
+ await this.connect({ progress });
334
+ }
335
+ const connection = this.connection;
336
+ try {
337
+ const boardVersion = connection.boardVersion;
338
+ if (!boardVersion) {
339
+ throw new device_js_1.DeviceError({
340
+ code: "device-disconnected",
341
+ message: "No board version found",
342
+ });
343
+ }
344
+ const memoryMap = convertDataToMemoryMap(await dataSource(boardVersion));
345
+ if (!memoryMap) {
346
+ throw new device_js_1.FlashDataError("Could not convert hex to memory map");
347
+ }
348
+ if (!this.device) {
349
+ throw new device_js_1.DeviceError({
350
+ code: "device-disconnected",
351
+ message: "No device",
352
+ });
353
+ }
354
+ this.log(`Got board version ${boardVersion}`);
355
+ const partialFlashResult = await (0, flashing_partial_js_1.default)(connection, memoryMap, progress);
356
+ if (partialFlashResult === flashing_partial_js_1.PartialFlashResult.AttemptFullFlash) {
357
+ await (0, flashing_full_js_1.fullFlash)(connection, boardVersion, memoryMap, progress);
358
+ }
359
+ }
360
+ catch (e) {
361
+ this.error("Failed to flash", e);
362
+ throw e;
363
+ }
364
+ finally {
365
+ await this.disconnect();
366
+ }
367
+ }
368
+ finally {
369
+ this.deferStatusUpdates = false;
370
+ this.dispatchTypedEvent("status", new device_js_1.ConnectionStatusEvent(this.status));
371
+ }
372
+ }
373
+ async requestDeviceWeb(namePrefix) {
374
+ return await bluetooth_le_1.BleClient.requestDevice({
375
+ namePrefix: this.nameFilter
376
+ ? `BBC micro:bit [${namePrefix}]`
377
+ : "BBC micro:bit",
378
+ // TODO: is this possible to reinstate?
379
+ // See https://github.com/bsiever/microbit-pxt-blehid/issues/31
380
+ //namePrefix: this.nameFilter
381
+ // ? `uBit [${this.nameFilter}]`
382
+ // : "uBit",
383
+ optionalServices: [
384
+ bluetooth_profile_js_1.profile.accelerometer.id,
385
+ bluetooth_profile_js_1.profile.button.id,
386
+ bluetooth_profile_js_1.profile.deviceInformation.id,
387
+ bluetooth_profile_js_1.profile.dfuControl.id,
388
+ bluetooth_profile_js_1.profile.event.id,
389
+ bluetooth_profile_js_1.profile.ioPin.id,
390
+ bluetooth_profile_js_1.profile.led.id,
391
+ bluetooth_profile_js_1.profile.magnetometer.id,
392
+ bluetooth_profile_js_1.profile.temperature.id,
393
+ bluetooth_profile_js_1.profile.uart.id,
394
+ ],
395
+ });
396
+ }
397
+ /**
398
+ * Finds device with specified name prefix.
399
+ *
400
+ * @returns device or undefined if none can be found.
401
+ */
402
+ async requestDeviceNative(namePrefix) {
403
+ // Check for existing bonded devices.
404
+ const bonded = await this.checkBondedDevices((device) => {
405
+ const name = device.name;
406
+ return !!name && name.startsWith(namePrefix);
407
+ });
408
+ if (bonded) {
409
+ return bonded;
410
+ }
411
+ this.log(`Scanning for device - ${namePrefix}`);
412
+ let found = false;
413
+ const scanPromise = new Promise((resolve) =>
414
+ // This only resolves when we stop the scan.
415
+ void bluetooth_le_1.BleClient.requestLEScan({}, async (result) => {
416
+ // For a V1 in the Nordic bootloader, we see a name of "DfuTarg" that
417
+ // isn't matched by the name filter but the advertising name is in the
418
+ // localName on the device. So we filter here instead. This happens on
419
+ // iOS if DFU fails / is interrupted.
420
+ if (result.device.name?.startsWith(namePrefix) ||
421
+ result.localName?.startsWith(namePrefix)) {
422
+ found = true;
423
+ await bluetooth_le_1.BleClient.stopLEScan();
424
+ resolve(result.device);
425
+ }
426
+ }));
427
+ const scanTimeoutPromise = new Promise((resolve) => setTimeout(async () => {
428
+ if (!found) {
429
+ await bluetooth_le_1.BleClient.stopLEScan();
430
+ this.log("Timeout scanning for device");
431
+ resolve(undefined);
432
+ }
433
+ }, bluetooth_device_wrapper_js_1.scanningTimeoutInMs));
434
+ return await Promise.race([scanPromise, scanTimeoutPromise]);
435
+ }
436
+ async checkBondedDevices(predicate) {
437
+ if (!(0, bluetooth_device_wrapper_js_1.isAndroid)()) {
438
+ // Not supported.
439
+ return undefined;
440
+ }
441
+ const bondedDevices = await bluetooth_le_1.BleClient.getBondedDevices();
442
+ const result = bondedDevices.find(predicate);
443
+ this.log(result === undefined
444
+ ? "No matching bonded device"
445
+ : "Found matching bonded device");
446
+ return result;
447
+ }
448
+ }
449
+ const convertDataToMemoryMap = (data) => {
450
+ if (data instanceof nrf_intel_hex_1.default) {
451
+ return data;
452
+ }
453
+ if (data instanceof Uint8Array) {
454
+ return nrf_intel_hex_1.default.fromPaddedUint8Array(data);
455
+ }
456
+ return nrf_intel_hex_1.default.fromHex(data);
457
+ };
458
+ //# sourceMappingURL=bluetooth.js.map