@microbit/microbit-connection 0.0.0-tab.change.177 → 0.1.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 (227) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +94 -5
  3. package/build/cjs/accelerometer-service.js +106 -0
  4. package/build/cjs/accelerometer-service.js.map +1 -0
  5. package/build/cjs/accelerometer.js +16 -0
  6. package/build/cjs/accelerometer.js.map +1 -0
  7. package/build/cjs/async-util.js +27 -0
  8. package/build/cjs/async-util.js.map +1 -0
  9. package/build/{bluetooth-device-wrapper.d.ts → cjs/bluetooth-device-wrapper.d.ts} +7 -1
  10. package/build/cjs/bluetooth-device-wrapper.js +467 -0
  11. package/build/cjs/bluetooth-device-wrapper.js.map +1 -0
  12. package/build/cjs/bluetooth-profile.js +86 -0
  13. package/build/cjs/bluetooth-profile.js.map +1 -0
  14. package/build/cjs/bluetooth.d.ts +108 -0
  15. package/build/cjs/bluetooth.js +272 -0
  16. package/build/cjs/bluetooth.js.map +1 -0
  17. package/build/cjs/board-id.js +81 -0
  18. package/build/cjs/board-id.js.map +1 -0
  19. package/build/cjs/board-serial-info.js +51 -0
  20. package/build/cjs/board-serial-info.js.map +1 -0
  21. package/build/cjs/button-service.js +80 -0
  22. package/build/cjs/button-service.js.map +1 -0
  23. package/build/cjs/buttons.js +22 -0
  24. package/build/cjs/buttons.js.map +1 -0
  25. package/build/cjs/constants.js +73 -0
  26. package/build/cjs/constants.js.map +1 -0
  27. package/build/{device.d.ts → cjs/device.d.ts} +6 -31
  28. package/build/cjs/device.js +133 -0
  29. package/build/cjs/device.js.map +1 -0
  30. package/build/{events.d.ts → cjs/events.d.ts} +1 -2
  31. package/build/cjs/events.js +109 -0
  32. package/build/cjs/events.js.map +1 -0
  33. package/build/cjs/hex-flash-data-source.js +26 -0
  34. package/build/cjs/hex-flash-data-source.js.map +1 -0
  35. package/build/cjs/index.d.ts +17 -0
  36. package/build/cjs/index.js +36 -0
  37. package/build/cjs/index.js.map +1 -0
  38. package/build/cjs/led-service.js +120 -0
  39. package/build/{led-service.js.map → cjs/led-service.js.map} +1 -1
  40. package/build/cjs/led.js +3 -0
  41. package/build/cjs/led.js.map +1 -0
  42. package/build/{logging.d.ts → cjs/logging.d.ts} +3 -3
  43. package/build/cjs/logging.js +16 -0
  44. package/build/cjs/logging.js.map +1 -0
  45. package/build/cjs/magnetometer-service.d.ts +22 -0
  46. package/build/cjs/magnetometer-service.js +129 -0
  47. package/build/cjs/magnetometer-service.js.map +1 -0
  48. package/build/cjs/magnetometer.d.ts +9 -0
  49. package/build/cjs/magnetometer.js +16 -0
  50. package/build/cjs/magnetometer.js.map +1 -0
  51. package/build/cjs/package.json +1 -0
  52. package/build/cjs/promise-queue.js +78 -0
  53. package/build/cjs/promise-queue.js.map +1 -0
  54. package/build/cjs/serial-events.d.ts +20 -0
  55. package/build/cjs/serial-events.js +69 -0
  56. package/build/cjs/serial-events.js.map +1 -0
  57. package/build/{service-events.d.ts → cjs/service-events.d.ts} +4 -0
  58. package/build/cjs/service-events.js +39 -0
  59. package/build/cjs/service-events.js.map +1 -0
  60. package/build/cjs/setupTests.js.map +1 -0
  61. package/build/cjs/uart-service.d.ts +13 -0
  62. package/build/cjs/uart-service.js +76 -0
  63. package/build/cjs/uart-service.js.map +1 -0
  64. package/build/cjs/uart.d.ts +4 -0
  65. package/build/cjs/uart.js +16 -0
  66. package/build/cjs/uart.js.map +1 -0
  67. package/build/{usb-device-wrapper.d.ts → cjs/usb-device-wrapper.d.ts} +1 -6
  68. package/build/cjs/usb-device-wrapper.js +412 -0
  69. package/build/cjs/usb-device-wrapper.js.map +1 -0
  70. package/build/cjs/usb-partial-flashing-utils.js +133 -0
  71. package/build/cjs/usb-partial-flashing-utils.js.map +1 -0
  72. package/build/{usb-partial-flashing.d.ts → cjs/usb-partial-flashing.d.ts} +3 -3
  73. package/build/cjs/usb-partial-flashing.js +341 -0
  74. package/build/cjs/usb-partial-flashing.js.map +1 -0
  75. package/build/cjs/usb-radio-bridge.d.ts +24 -0
  76. package/build/cjs/usb-radio-bridge.js +516 -0
  77. package/build/cjs/usb-radio-bridge.js.map +1 -0
  78. package/build/cjs/usb-serial-protocol.js +183 -0
  79. package/build/cjs/usb-serial-protocol.js.map +1 -0
  80. package/build/cjs/usb.d.ts +64 -0
  81. package/build/cjs/usb.js +647 -0
  82. package/build/cjs/usb.js.map +1 -0
  83. package/build/esm/accelerometer-service.d.ts +18 -0
  84. package/build/{accelerometer-service.js → esm/accelerometer-service.js} +1 -1
  85. package/build/esm/accelerometer-service.js.map +1 -0
  86. package/build/esm/accelerometer.d.ts +9 -0
  87. package/build/esm/accelerometer.js.map +1 -0
  88. package/build/esm/async-util.d.ts +13 -0
  89. package/build/esm/async-util.js.map +1 -0
  90. package/build/esm/bluetooth-device-wrapper.d.ts +63 -0
  91. package/build/{bluetooth-device-wrapper.js → esm/bluetooth-device-wrapper.js} +39 -10
  92. package/build/esm/bluetooth-device-wrapper.js.map +1 -0
  93. package/build/esm/bluetooth-profile.d.ts +139 -0
  94. package/build/esm/bluetooth-profile.js.map +1 -0
  95. package/build/esm/bluetooth.d.ts +108 -0
  96. package/build/{bluetooth.js → esm/bluetooth.js} +29 -4
  97. package/build/esm/bluetooth.js.map +1 -0
  98. package/build/esm/board-id.d.ts +36 -0
  99. package/build/esm/board-id.js.map +1 -0
  100. package/build/esm/board-serial-info.d.ts +14 -0
  101. package/build/esm/board-serial-info.js.map +1 -0
  102. package/build/esm/button-service.d.ts +13 -0
  103. package/build/esm/button-service.js.map +1 -0
  104. package/build/esm/buttons.d.ts +10 -0
  105. package/build/esm/buttons.js.map +1 -0
  106. package/build/esm/constants.d.ts +48 -0
  107. package/build/esm/constants.js.map +1 -0
  108. package/build/esm/device.d.ts +181 -0
  109. package/build/{device.js → esm/device.js} +1 -57
  110. package/build/esm/device.js.map +1 -0
  111. package/build/esm/events.d.ts +110 -0
  112. package/build/esm/events.js.map +1 -0
  113. package/build/esm/hex-flash-data-source.d.ts +7 -0
  114. package/build/esm/hex-flash-data-source.js.map +1 -0
  115. package/build/esm/index.d.ts +17 -0
  116. package/build/esm/index.js +12 -0
  117. package/build/esm/index.js.map +1 -0
  118. package/build/esm/led-service.d.ts +20 -0
  119. package/build/esm/led-service.js.map +1 -0
  120. package/build/esm/led.d.ts +6 -0
  121. package/build/esm/led.js.map +1 -0
  122. package/build/esm/logging.d.ts +21 -0
  123. package/build/esm/logging.js.map +1 -0
  124. package/build/esm/magnetometer-service.d.ts +22 -0
  125. package/build/esm/magnetometer-service.js +125 -0
  126. package/build/esm/magnetometer-service.js.map +1 -0
  127. package/build/esm/magnetometer.d.ts +9 -0
  128. package/build/esm/magnetometer.js +12 -0
  129. package/build/esm/magnetometer.js.map +1 -0
  130. package/build/esm/package.json +1 -0
  131. package/build/esm/promise-queue.d.ts +27 -0
  132. package/build/esm/promise-queue.js.map +1 -0
  133. package/build/esm/serial-events.d.ts +20 -0
  134. package/build/esm/serial-events.js +61 -0
  135. package/build/esm/serial-events.js.map +1 -0
  136. package/build/esm/service-events.d.ts +17 -0
  137. package/build/{service-events.js → esm/service-events.js} +12 -0
  138. package/build/esm/service-events.js.map +1 -0
  139. package/build/esm/setupTests.d.ts +6 -0
  140. package/build/{setupTests.js.map → esm/setupTests.js.map} +1 -1
  141. package/build/esm/uart-service.d.ts +13 -0
  142. package/build/esm/uart-service.js +72 -0
  143. package/build/esm/uart-service.js.map +1 -0
  144. package/build/esm/uart.d.ts +4 -0
  145. package/build/esm/uart.js +12 -0
  146. package/build/esm/uart.js.map +1 -0
  147. package/build/esm/usb-device-wrapper.d.ts +47 -0
  148. package/build/{usb-device-wrapper.js → esm/usb-device-wrapper.js} +10 -9
  149. package/build/esm/usb-device-wrapper.js.map +1 -0
  150. package/build/esm/usb-partial-flashing-utils.d.ts +17 -0
  151. package/build/esm/usb-partial-flashing-utils.js.map +1 -0
  152. package/build/esm/usb-partial-flashing.d.ts +69 -0
  153. package/build/{usb-partial-flashing.js → esm/usb-partial-flashing.js} +8 -10
  154. package/build/esm/usb-partial-flashing.js.map +1 -0
  155. package/build/esm/usb-radio-bridge.d.ts +24 -0
  156. package/build/{usb-radio-bridge.js → esm/usb-radio-bridge.js} +11 -4
  157. package/build/esm/usb-radio-bridge.js.map +1 -0
  158. package/build/esm/usb-serial-protocol.d.ts +66 -0
  159. package/build/esm/usb-serial-protocol.js.map +1 -0
  160. package/build/esm/usb.d.ts +64 -0
  161. package/build/{usb.js → esm/usb.js} +228 -35
  162. package/build/esm/usb.js.map +1 -0
  163. package/package.json +21 -8
  164. package/typedoc.json +14 -0
  165. package/build/accelerometer-service.js.map +0 -1
  166. package/build/accelerometer.js.map +0 -1
  167. package/build/async-util.js.map +0 -1
  168. package/build/bluetooth-device-wrapper.js.map +0 -1
  169. package/build/bluetooth-profile.js.map +0 -1
  170. package/build/bluetooth.d.ts +0 -54
  171. package/build/bluetooth.js.map +0 -1
  172. package/build/board-id.js.map +0 -1
  173. package/build/board-serial-info.js.map +0 -1
  174. package/build/button-service.js.map +0 -1
  175. package/build/buttons.js.map +0 -1
  176. package/build/constants.js.map +0 -1
  177. package/build/device.js.map +0 -1
  178. package/build/events.js.map +0 -1
  179. package/build/hex-flash-data-source.js.map +0 -1
  180. package/build/index.d.ts +0 -10
  181. package/build/index.js +0 -8
  182. package/build/index.js.map +0 -1
  183. package/build/led.js.map +0 -1
  184. package/build/logging.js.map +0 -1
  185. package/build/promise-queue.js.map +0 -1
  186. package/build/service-events.js.map +0 -1
  187. package/build/usb-device-wrapper.js.map +0 -1
  188. package/build/usb-partial-flashing-utils.js.map +0 -1
  189. package/build/usb-partial-flashing.js.map +0 -1
  190. package/build/usb-radio-bridge.d.ts +0 -41
  191. package/build/usb-radio-bridge.js.map +0 -1
  192. package/build/usb-serial-protocol.js.map +0 -1
  193. package/build/usb.d.ts +0 -54
  194. package/build/usb.js.map +0 -1
  195. package/vite.config.ts +0 -34
  196. /package/build/{accelerometer-service.d.ts → cjs/accelerometer-service.d.ts} +0 -0
  197. /package/build/{accelerometer.d.ts → cjs/accelerometer.d.ts} +0 -0
  198. /package/build/{async-util.d.ts → cjs/async-util.d.ts} +0 -0
  199. /package/build/{bluetooth-profile.d.ts → cjs/bluetooth-profile.d.ts} +0 -0
  200. /package/build/{board-id.d.ts → cjs/board-id.d.ts} +0 -0
  201. /package/build/{board-serial-info.d.ts → cjs/board-serial-info.d.ts} +0 -0
  202. /package/build/{button-service.d.ts → cjs/button-service.d.ts} +0 -0
  203. /package/build/{buttons.d.ts → cjs/buttons.d.ts} +0 -0
  204. /package/build/{constants.d.ts → cjs/constants.d.ts} +0 -0
  205. /package/build/{hex-flash-data-source.d.ts → cjs/hex-flash-data-source.d.ts} +0 -0
  206. /package/build/{led-service.d.ts → cjs/led-service.d.ts} +0 -0
  207. /package/build/{led.d.ts → cjs/led.d.ts} +0 -0
  208. /package/build/{promise-queue.d.ts → cjs/promise-queue.d.ts} +0 -0
  209. /package/build/{setupTests.d.ts → cjs/setupTests.d.ts} +0 -0
  210. /package/build/{usb-partial-flashing-utils.d.ts → cjs/usb-partial-flashing-utils.d.ts} +0 -0
  211. /package/build/{usb-serial-protocol.d.ts → cjs/usb-serial-protocol.d.ts} +0 -0
  212. /package/build/{accelerometer.js → esm/accelerometer.js} +0 -0
  213. /package/build/{async-util.js → esm/async-util.js} +0 -0
  214. /package/build/{bluetooth-profile.js → esm/bluetooth-profile.js} +0 -0
  215. /package/build/{board-id.js → esm/board-id.js} +0 -0
  216. /package/build/{board-serial-info.js → esm/board-serial-info.js} +0 -0
  217. /package/build/{button-service.js → esm/button-service.js} +0 -0
  218. /package/build/{buttons.js → esm/buttons.js} +0 -0
  219. /package/build/{constants.js → esm/constants.js} +0 -0
  220. /package/build/{events.js → esm/events.js} +0 -0
  221. /package/build/{hex-flash-data-source.js → esm/hex-flash-data-source.js} +0 -0
  222. /package/build/{led-service.js → esm/led-service.js} +0 -0
  223. /package/build/{led.js → esm/led.js} +0 -0
  224. /package/build/{logging.js → esm/logging.js} +0 -0
  225. /package/build/{promise-queue.js → esm/promise-queue.js} +0 -0
  226. /package/build/{usb-partial-flashing-utils.js → esm/usb-partial-flashing-utils.js} +0 -0
  227. /package/build/{usb-serial-protocol.js → esm/usb-serial-protocol.js} +0 -0
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ /**
3
+ * (c) 2021, Micro:bit Educational Foundation and contributors
4
+ *
5
+ * SPDX-License-Identifier: MIT
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.CortexSpecialReg = exports.ApReg = exports.DapVal = exports.Csw = exports.DapCmd = exports.FICR = void 0;
9
+ // https://github.com/mmoskal/dapjs/blob/a32f11f54e9e76a9c61896ddd425c1cb1a29c143/src/dap/constants.ts
10
+ // https://github.com/mmoskal/dapjs/blob/a32f11f54e9e76a9c61896ddd425c1cb1a29c143/src/cortex/constants.ts
11
+ // CRA's build tooling doesn't support const enums so we've converted them to prefixed constants here.
12
+ // If we move this to a separate library then we can replace them.
13
+ // In the meantime we should prune the list below to what we actually use.
14
+ // FICR Registers
15
+ exports.FICR = {
16
+ CODEPAGESIZE: 0x10000000 | 0x10,
17
+ CODESIZE: 0x10000000 | 0x14,
18
+ DEVICE_ID_1: 0x10000000 | 0x64,
19
+ };
20
+ exports.DapCmd = {
21
+ DAP_INFO: 0x00,
22
+ DAP_CONNECT: 0x02,
23
+ DAP_DISCONNECT: 0x03,
24
+ DAP_TRANSFER: 0x05,
25
+ DAP_TRANSFER_BLOCK: 0x06,
26
+ // Many more.
27
+ };
28
+ exports.Csw = {
29
+ CSW_SIZE: 0x00000007,
30
+ CSW_SIZE32: 0x00000002,
31
+ CSW_ADDRINC: 0x00000030,
32
+ CSW_SADDRINC: 0x00000010,
33
+ CSW_DBGSTAT: 0x00000040,
34
+ CSW_HPROT: 0x02000000,
35
+ CSW_MSTRDBG: 0x20000000,
36
+ CSW_RESERVED: 0x01000000,
37
+ CSW_VALUE: -1, // see below
38
+ // Many more.
39
+ };
40
+ exports.Csw.CSW_VALUE =
41
+ exports.Csw.CSW_RESERVED |
42
+ exports.Csw.CSW_MSTRDBG |
43
+ exports.Csw.CSW_HPROT |
44
+ exports.Csw.CSW_DBGSTAT |
45
+ exports.Csw.CSW_SADDRINC;
46
+ exports.DapVal = {
47
+ AP_ACC: 1 << 0,
48
+ READ: 1 << 1,
49
+ WRITE: 0 << 1,
50
+ // More.
51
+ };
52
+ exports.ApReg = {
53
+ CSW: 0x00,
54
+ TAR: 0x04,
55
+ DRW: 0x0c,
56
+ // More.
57
+ };
58
+ exports.CortexSpecialReg = {
59
+ // Debug Exception and Monitor Control Register
60
+ DEMCR: 0xe000edfc,
61
+ // DWTENA in armv6 architecture reference manual
62
+ DEMCR_VC_CORERESET: 1 << 0,
63
+ // CPUID Register
64
+ CPUID: 0xe000ed00,
65
+ // Debug Halting Control and Status Register
66
+ DHCSR: 0xe000edf0,
67
+ S_RESET_ST: 1 << 25,
68
+ NVIC_AIRCR: 0xe000ed0c,
69
+ NVIC_AIRCR_VECTKEY: 0x5fa << 16,
70
+ NVIC_AIRCR_SYSRESETREQ: 1 << 2,
71
+ // Many more.
72
+ };
73
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../lib/constants.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAEH,sGAAsG;AACtG,yGAAyG;AAEzG,sGAAsG;AACtG,kEAAkE;AAClE,0EAA0E;AAE1E,iBAAiB;AACJ,QAAA,IAAI,GAAG;IAClB,YAAY,EAAE,UAAU,GAAG,IAAI;IAC/B,QAAQ,EAAE,UAAU,GAAG,IAAI;IAE3B,WAAW,EAAE,UAAU,GAAG,IAAI;CAC/B,CAAC;AAEW,QAAA,MAAM,GAAG;IACpB,QAAQ,EAAE,IAAI;IACd,WAAW,EAAE,IAAI;IACjB,cAAc,EAAE,IAAI;IACpB,YAAY,EAAE,IAAI;IAClB,kBAAkB,EAAE,IAAI;IACxB,aAAa;CACd,CAAC;AAEW,QAAA,GAAG,GAAG;IACjB,QAAQ,EAAE,UAAU;IACpB,UAAU,EAAE,UAAU;IACtB,WAAW,EAAE,UAAU;IACvB,YAAY,EAAE,UAAU;IACxB,WAAW,EAAE,UAAU;IACvB,SAAS,EAAE,UAAU;IACrB,WAAW,EAAE,UAAU;IACvB,YAAY,EAAE,UAAU;IACxB,SAAS,EAAE,CAAC,CAAC,EAAE,YAAY;IAC3B,aAAa;CACd,CAAC;AACF,WAAG,CAAC,SAAS;IACX,WAAG,CAAC,YAAY;QAChB,WAAG,CAAC,WAAW;QACf,WAAG,CAAC,SAAS;QACb,WAAG,CAAC,WAAW;QACf,WAAG,CAAC,YAAY,CAAC;AAEN,QAAA,MAAM,GAAG;IACpB,MAAM,EAAE,CAAC,IAAI,CAAC;IACd,IAAI,EAAE,CAAC,IAAI,CAAC;IACZ,KAAK,EAAE,CAAC,IAAI,CAAC;IACb,QAAQ;CACT,CAAC;AAEW,QAAA,KAAK,GAAG;IACnB,GAAG,EAAE,IAAI;IACT,GAAG,EAAE,IAAI;IACT,GAAG,EAAE,IAAI;IACT,QAAQ;CACT,CAAC;AAEW,QAAA,gBAAgB,GAAG;IAC9B,+CAA+C;IAC/C,KAAK,EAAE,UAAU;IACjB,gDAAgD;IAChD,kBAAkB,EAAE,CAAC,IAAI,CAAC;IAE1B,iBAAiB;IACjB,KAAK,EAAE,UAAU;IAEjB,4CAA4C;IAC5C,KAAK,EAAE,UAAU;IACjB,UAAU,EAAE,CAAC,IAAI,EAAE;IAEnB,UAAU,EAAE,UAAU;IACtB,kBAAkB,EAAE,KAAK,IAAI,EAAE;IAC/B,sBAAsB,EAAE,CAAC,IAAI,CAAC;IAE9B,aAAa;CACd,CAAC"}
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * SPDX-License-Identifier: MIT
5
5
  */
6
- import { TypedEventTarget } from "./events.js";
6
+ import { TypedEventTarget, ValueIsEvent } from "./events.js";
7
7
  /**
8
8
  * Specific identified error types.
9
9
  *
@@ -122,20 +122,6 @@ export declare class ConnectionStatusEvent extends Event {
122
122
  readonly status: ConnectionStatus;
123
123
  constructor(status: ConnectionStatus);
124
124
  }
125
- export declare class SerialDataEvent extends Event {
126
- readonly data: string;
127
- constructor(data: string);
128
- }
129
- export declare class SerialResetEvent extends Event {
130
- constructor();
131
- }
132
- export declare class SerialErrorEvent extends Event {
133
- readonly error: unknown;
134
- constructor(error: unknown);
135
- }
136
- export declare class FlashEvent extends Event {
137
- constructor();
138
- }
139
125
  export declare class BeforeRequestDevice extends Event {
140
126
  constructor();
141
127
  }
@@ -148,15 +134,11 @@ export declare class BackgroundErrorEvent extends Event {
148
134
  }
149
135
  export declare class DeviceConnectionEventMap {
150
136
  "status": ConnectionStatusEvent;
151
- "serialdata": SerialDataEvent;
152
- "serialreset": Event;
153
- "serialerror": Event;
154
- "flash": Event;
137
+ "backgrounderror": BackgroundErrorEvent;
155
138
  "beforerequestdevice": Event;
156
139
  "afterrequestdevice": Event;
157
- "backgrounderror": BackgroundErrorEvent;
158
140
  }
159
- export interface DeviceConnection extends TypedEventTarget<DeviceConnectionEventMap> {
141
+ export interface DeviceConnection<M extends ValueIsEvent<M>> extends TypedEventTarget<DeviceConnectionEventMap & M> {
160
142
  status: ConnectionStatus;
161
143
  /**
162
144
  * Initializes the device.
@@ -176,16 +158,9 @@ export interface DeviceConnection extends TypedEventTarget<DeviceConnectionEvent
176
158
  /**
177
159
  * Get the board version.
178
160
  *
179
- * @returns the board version or null if there is no connection.
161
+ * @returns the board version or undefined if there is no connection.
180
162
  */
181
163
  getBoardVersion(): BoardVersion | undefined;
182
- /**
183
- * Flash the micro:bit.
184
- *
185
- * @param dataSource The data to use.
186
- * @param options Flash options and progress callback.
187
- */
188
- flash?(dataSource: FlashDataSource, options: {}): Promise<void>;
189
164
  /**
190
165
  * Disconnect from the device.
191
166
  */
@@ -193,7 +168,7 @@ export interface DeviceConnection extends TypedEventTarget<DeviceConnectionEvent
193
168
  /**
194
169
  * Write serial data to the device.
195
170
  *
196
- * Does nothting if there is no connection.
171
+ * Does nothing if there is no connection.
197
172
  *
198
173
  * @param data The data to write.
199
174
  * @returns A promise that resolves when the write is complete.
@@ -202,5 +177,5 @@ export interface DeviceConnection extends TypedEventTarget<DeviceConnectionEvent
202
177
  /**
203
178
  * Clear device to enable chooseDevice.
204
179
  */
205
- clearDevice(): void;
180
+ clearDevice(): Promise<void> | void;
206
181
  }
@@ -0,0 +1,133 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DeviceConnectionEventMap = exports.BackgroundErrorEvent = exports.AfterRequestDevice = exports.BeforeRequestDevice = exports.ConnectionStatusEvent = exports.FlashDataError = exports.ConnectionStatus = exports.DeviceError = void 0;
4
+ /**
5
+ * Error type used for all interactions with this module.
6
+ *
7
+ * The code indicates the error type and may be suitable for providing
8
+ * translated error messages.
9
+ *
10
+ * The message is the underlying message text and will usually be in
11
+ * English.
12
+ */
13
+ class DeviceError extends Error {
14
+ constructor({ code, message }) {
15
+ super(message);
16
+ Object.defineProperty(this, "code", {
17
+ enumerable: true,
18
+ configurable: true,
19
+ writable: true,
20
+ value: void 0
21
+ });
22
+ this.code = code;
23
+ }
24
+ }
25
+ exports.DeviceError = DeviceError;
26
+ /**
27
+ * Tracks connection status,
28
+ */
29
+ var ConnectionStatus;
30
+ (function (ConnectionStatus) {
31
+ /**
32
+ * Determining whether the connection type is supported requires
33
+ * initialize() to complete.
34
+ */
35
+ ConnectionStatus["SUPPORT_NOT_KNOWN"] = "SUPPORT_NOT_KNOWN";
36
+ /**
37
+ * Not supported.
38
+ */
39
+ ConnectionStatus["NOT_SUPPORTED"] = "NOT_SUPPORTED";
40
+ /**
41
+ * Supported but no device available.
42
+ *
43
+ * This will be the case even when a device is physically connected
44
+ * but has not been connected via the browser security UI.
45
+ */
46
+ ConnectionStatus["NO_AUTHORIZED_DEVICE"] = "NO_AUTHORIZED_DEVICE";
47
+ /**
48
+ * Authorized device available but we haven't connected to it.
49
+ */
50
+ ConnectionStatus["DISCONNECTED"] = "DISCONNECTED";
51
+ /**
52
+ * Connected.
53
+ */
54
+ ConnectionStatus["CONNECTED"] = "CONNECTED";
55
+ /**
56
+ * Connecting.
57
+ */
58
+ ConnectionStatus["CONNECTING"] = "CONNECTING";
59
+ /**
60
+ * Reconnecting. When there is unexpected disruption in the connection,
61
+ * a reconnection is attempted.
62
+ */
63
+ ConnectionStatus["RECONNECTING"] = "RECONNECTING";
64
+ })(ConnectionStatus || (exports.ConnectionStatus = ConnectionStatus = {}));
65
+ class FlashDataError extends Error {
66
+ }
67
+ exports.FlashDataError = FlashDataError;
68
+ class ConnectionStatusEvent extends Event {
69
+ constructor(status) {
70
+ super("status");
71
+ Object.defineProperty(this, "status", {
72
+ enumerable: true,
73
+ configurable: true,
74
+ writable: true,
75
+ value: status
76
+ });
77
+ }
78
+ }
79
+ exports.ConnectionStatusEvent = ConnectionStatusEvent;
80
+ class BeforeRequestDevice extends Event {
81
+ constructor() {
82
+ super("beforerequestdevice");
83
+ }
84
+ }
85
+ exports.BeforeRequestDevice = BeforeRequestDevice;
86
+ class AfterRequestDevice extends Event {
87
+ constructor() {
88
+ super("afterrequestdevice");
89
+ }
90
+ }
91
+ exports.AfterRequestDevice = AfterRequestDevice;
92
+ class BackgroundErrorEvent extends Event {
93
+ constructor(errorMessage) {
94
+ super("backgrounderror");
95
+ Object.defineProperty(this, "errorMessage", {
96
+ enumerable: true,
97
+ configurable: true,
98
+ writable: true,
99
+ value: errorMessage
100
+ });
101
+ }
102
+ }
103
+ exports.BackgroundErrorEvent = BackgroundErrorEvent;
104
+ class DeviceConnectionEventMap {
105
+ constructor() {
106
+ Object.defineProperty(this, "status", {
107
+ enumerable: true,
108
+ configurable: true,
109
+ writable: true,
110
+ value: void 0
111
+ });
112
+ Object.defineProperty(this, "backgrounderror", {
113
+ enumerable: true,
114
+ configurable: true,
115
+ writable: true,
116
+ value: void 0
117
+ });
118
+ Object.defineProperty(this, "beforerequestdevice", {
119
+ enumerable: true,
120
+ configurable: true,
121
+ writable: true,
122
+ value: void 0
123
+ });
124
+ Object.defineProperty(this, "afterrequestdevice", {
125
+ enumerable: true,
126
+ configurable: true,
127
+ writable: true,
128
+ value: void 0
129
+ });
130
+ }
131
+ }
132
+ exports.DeviceConnectionEventMap = DeviceConnectionEventMap;
133
+ //# sourceMappingURL=device.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"device.js","sourceRoot":"","sources":["../../lib/device.ts"],"names":[],"mappings":";;;AA8CA;;;;;;;;GAQG;AACH,MAAa,WAAY,SAAQ,KAAK;IAEpC,YAAY,EAAE,IAAI,EAAE,OAAO,EAA+C;QACxE,KAAK,CAAC,OAAO,CAAC,CAAC;QAFjB;;;;;WAAsB;QAGpB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF;AAND,kCAMC;AAED;;GAEG;AACH,IAAY,gBAkCX;AAlCD,WAAY,gBAAgB;IAC1B;;;OAGG;IACH,2DAAuC,CAAA;IACvC;;OAEG;IACH,mDAA+B,CAAA;IAC/B;;;;;OAKG;IACH,iEAA6C,CAAA;IAC7C;;OAEG;IACH,iDAA6B,CAAA;IAC7B;;OAEG;IACH,2CAAuB,CAAA;IACvB;;OAEG;IACH,6CAAyB,CAAA;IACzB;;;OAGG;IACH,iDAA6B,CAAA;AAC/B,CAAC,EAlCW,gBAAgB,gCAAhB,gBAAgB,QAkC3B;AAqBD,MAAa,cAAe,SAAQ,KAAK;CAAG;AAA5C,wCAA4C;AAQ5C,MAAa,qBAAsB,SAAQ,KAAK;IAC9C,YAA4B,MAAwB;QAClD,KAAK,CAAC,QAAQ,CAAC,CAAC;QADN;;;;mBAAgB,MAAM;WAAkB;IAEpD,CAAC;CACF;AAJD,sDAIC;AAED,MAAa,mBAAoB,SAAQ,KAAK;IAC5C;QACE,KAAK,CAAC,qBAAqB,CAAC,CAAC;IAC/B,CAAC;CACF;AAJD,kDAIC;AAED,MAAa,kBAAmB,SAAQ,KAAK;IAC3C;QACE,KAAK,CAAC,oBAAoB,CAAC,CAAC;IAC9B,CAAC;CACF;AAJD,gDAIC;AAED,MAAa,oBAAqB,SAAQ,KAAK;IAC7C,YAA4B,YAAoB;QAC9C,KAAK,CAAC,iBAAiB,CAAC,CAAC;QADf;;;;mBAAgB,YAAY;WAAQ;IAEhD,CAAC;CACF;AAJD,oDAIC;AAED,MAAa,wBAAwB;IAArC;QACE,4BAAA,QAAQ;;;;;WAAwB;QAChC,4BAAA,iBAAiB;;;;;WAAuB;QACxC,4BAAA,qBAAqB;;;;;WAAQ;QAC7B,4BAAA,oBAAoB;;;;;WAAQ;IAC9B,CAAC;CAAA;AALD,4DAKC"}
@@ -32,7 +32,7 @@ export interface TypedEventListenerObject<M, T extends keyof M> {
32
32
  * @template T The type of event to listen for (has to be keyof `M`).
33
33
  */
34
34
  export type TypedEventListenerOrEventListenerObject<M, T extends keyof M> = TypedEventListener<M, T> | TypedEventListenerObject<M, T>;
35
- type ValueIsEvent<T> = {
35
+ export type ValueIsEvent<T> = {
36
36
  [key in keyof T]: Event;
37
37
  };
38
38
  /**
@@ -108,4 +108,3 @@ export declare class TypedEventTarget<M extends ValueIsEvent<M>> extends Trackin
108
108
  */
109
109
  dispatchTypedEvent<T extends keyof M>(_type: T, event: M[T]): boolean;
110
110
  }
111
- export {};
@@ -0,0 +1,109 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) 2022 Jonas "DerZade" Schade
4
+ *
5
+ * SPDX-License-Identifier: MIT
6
+ *
7
+ * https://github.com/DerZade/typescript-event-target/blob/master/src/TypedEventTarget.ts
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.TypedEventTarget = exports.TrackingEventTarget = void 0;
11
+ // We've added this in to keep track of what events are active.
12
+ // Having done this it's questionable whether it's worth the reimplementation
13
+ // just to use an EventTarget API.
14
+ class TrackingEventTarget extends EventTarget {
15
+ constructor() {
16
+ super(...arguments);
17
+ Object.defineProperty(this, "activeEventTracking", {
18
+ enumerable: true,
19
+ configurable: true,
20
+ writable: true,
21
+ value: new Map()
22
+ });
23
+ }
24
+ addEventListener(type, callback, options) {
25
+ if (callback !== null) {
26
+ const registrations = this.activeEventTracking.get(type) ?? [];
27
+ const wasEmpty = registrations.length === 0;
28
+ const registration = new Registration(callback, options ?? false);
29
+ if (!registrations.find((r) => r.eq(registration))) {
30
+ registrations.push(registration);
31
+ this.activeEventTracking.set(type, registrations);
32
+ if (wasEmpty) {
33
+ this.eventActivated(type);
34
+ }
35
+ }
36
+ }
37
+ super.addEventListener(type, callback, options);
38
+ }
39
+ removeEventListener(type, callback, options) {
40
+ if (callback !== null) {
41
+ const registration = new Registration(callback, options ?? false);
42
+ this.filterRegistrations(type, (r) => !r.eq(registration));
43
+ }
44
+ super.removeEventListener(type, callback, options);
45
+ }
46
+ dispatchEvent(event) {
47
+ const result = super.dispatchEvent(event);
48
+ this.filterRegistrations(event.type, (r) => !r.isOnce());
49
+ return result;
50
+ }
51
+ filterRegistrations(type, predicate) {
52
+ let registrations = this.activeEventTracking.get(type) ?? [];
53
+ registrations = registrations.filter(predicate);
54
+ if (registrations.length === 0) {
55
+ this.activeEventTracking.delete(type);
56
+ this.eventDeactivated(type);
57
+ }
58
+ else {
59
+ this.activeEventTracking.set(type, registrations);
60
+ }
61
+ }
62
+ eventActivated(type) { }
63
+ eventDeactivated(type) { }
64
+ getActiveEvents() {
65
+ return [...this.activeEventTracking.keys()];
66
+ }
67
+ }
68
+ exports.TrackingEventTarget = TrackingEventTarget;
69
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
70
+ class TypedEventTarget extends TrackingEventTarget {
71
+ /**
72
+ * Dispatches a synthetic event event to target and returns true if either
73
+ * event's cancelable attribute value is false or its preventDefault() method
74
+ * was not invoked, and false otherwise.
75
+ */
76
+ dispatchTypedEvent(_type, event) {
77
+ return super.dispatchEvent(event);
78
+ }
79
+ }
80
+ exports.TypedEventTarget = TypedEventTarget;
81
+ class Registration {
82
+ constructor(callback, options) {
83
+ Object.defineProperty(this, "callback", {
84
+ enumerable: true,
85
+ configurable: true,
86
+ writable: true,
87
+ value: callback
88
+ });
89
+ Object.defineProperty(this, "options", {
90
+ enumerable: true,
91
+ configurable: true,
92
+ writable: true,
93
+ value: options
94
+ });
95
+ }
96
+ isOnce() {
97
+ return typeof this.options === "object" && this.options.once === true;
98
+ }
99
+ eq(other) {
100
+ return (other.callback === this.callback &&
101
+ eqUseCapture(this.options, other.options));
102
+ }
103
+ }
104
+ const eqUseCapture = (left, right) => {
105
+ const leftValue = typeof left === "boolean" ? left : left.capture ?? false;
106
+ const rightValue = typeof right === "boolean" ? right : right.capture ?? false;
107
+ return leftValue === rightValue;
108
+ };
109
+ //# sourceMappingURL=events.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"events.js","sourceRoot":"","sources":["../../lib/events.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createUniversalHexFlashDataSource = void 0;
4
+ const board_id_js_1 = require("./board-id.js");
5
+ const device_js_1 = require("./device.js");
6
+ const microbit_universal_hex_1 = require("@microbit/microbit-universal-hex");
7
+ /**
8
+ * A flash data source that converts universal hex files as needed.
9
+ *
10
+ * @param universalHex A hex file, potentially universal.
11
+ */
12
+ const createUniversalHexFlashDataSource = (universalHex) => {
13
+ return (boardVersion) => {
14
+ if ((0, microbit_universal_hex_1.isUniversalHex)(universalHex)) {
15
+ const parts = (0, microbit_universal_hex_1.separateUniversalHex)(universalHex);
16
+ const matching = parts.find((p) => p.boardId == board_id_js_1.BoardId.forVersion(boardVersion).id);
17
+ if (!matching) {
18
+ throw new device_js_1.FlashDataError("No matching part");
19
+ }
20
+ return Promise.resolve(matching.hex);
21
+ }
22
+ return Promise.resolve(universalHex);
23
+ };
24
+ };
25
+ exports.createUniversalHexFlashDataSource = createUniversalHexFlashDataSource;
26
+ //# sourceMappingURL=hex-flash-data-source.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hex-flash-data-source.js","sourceRoot":"","sources":["../../lib/hex-flash-data-source.ts"],"names":[],"mappings":";;;AAAA,+CAAwC;AACxC,2CAIqB;AACrB,6EAG0C;AAE1C;;;;GAIG;AACI,MAAM,iCAAiC,GAAG,CAC/C,YAAoB,EACH,EAAE;IACnB,OAAO,CAAC,YAA0B,EAAE,EAAE;QACpC,IAAI,IAAA,uCAAc,EAAC,YAAY,CAAC,EAAE,CAAC;YACjC,MAAM,KAAK,GAAG,IAAA,6CAAoB,EAAC,YAAY,CAAC,CAAC;YACjD,MAAM,QAAQ,GAAG,KAAK,CAAC,IAAI,CACzB,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,IAAI,qBAAO,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC,EAAE,CACxD,CAAC;YACF,IAAI,CAAC,QAAQ,EAAE,CAAC;gBACd,MAAM,IAAI,0BAAc,CAAC,kBAAkB,CAAC,CAAC;YAC/C,CAAC;YACD,OAAO,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;QACvC,CAAC;QACD,OAAO,OAAO,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;IACvC,CAAC,CAAC;AACJ,CAAC,CAAC;AAhBW,QAAA,iCAAiC,qCAgB5C"}
@@ -0,0 +1,17 @@
1
+ import { AccelerometerData, AccelerometerDataEvent } from "./accelerometer.js";
2
+ import { createWebBluetoothConnection, MicrobitWebBluetoothConnection, MicrobitWebBluetoothConnectionOptions } from "./bluetooth.js";
3
+ import { BoardId } from "./board-id.js";
4
+ import { ButtonEvent, ButtonEventType, ButtonState } from "./buttons.js";
5
+ import { AfterRequestDevice, BackgroundErrorEvent, BeforeRequestDevice, BoardVersion, ConnectionStatus, ConnectionStatusEvent, DeviceConnection, DeviceConnectionEventMap, DeviceError, DeviceErrorCode, FlashDataError, FlashDataSource, FlashOptions } from "./device.js";
6
+ import { TypedEventTarget } from "./events.js";
7
+ import { createUniversalHexFlashDataSource } from "./hex-flash-data-source.js";
8
+ import { LedMatrix } from "./led.js";
9
+ import { Logging, LoggingEvent } from "./logging.js";
10
+ import { MagnetometerData, MagnetometerDataEvent } from "./magnetometer.js";
11
+ import { FlashEvent, SerialConnectionEventMap, SerialDataEvent, SerialErrorEvent, SerialResetEvent } from "./serial-events.js";
12
+ import { ServiceConnectionEventMap } from "./service-events.js";
13
+ import { UARTDataEvent } from "./uart.js";
14
+ import { createRadioBridgeConnection, MicrobitRadioBridgeConnection, MicrobitRadioBridgeConnectionOptions } from "./usb-radio-bridge.js";
15
+ import { createWebUSBConnection, DeviceSelectionMode, MicrobitWebUSBConnection, MicrobitWebUSBConnectionOptions } from "./usb.js";
16
+ export { AfterRequestDevice, BackgroundErrorEvent, BeforeRequestDevice, BoardId, ConnectionStatus, ConnectionStatusEvent, createRadioBridgeConnection, createUniversalHexFlashDataSource, createWebBluetoothConnection, createWebUSBConnection, DeviceConnectionEventMap, DeviceSelectionMode, DeviceError, FlashDataError, FlashEvent, SerialConnectionEventMap, SerialDataEvent, SerialErrorEvent, SerialResetEvent, ServiceConnectionEventMap, TypedEventTarget, UARTDataEvent, };
17
+ export type { AccelerometerData, AccelerometerDataEvent, BoardVersion, ButtonEvent, ButtonEventType, ButtonState, DeviceConnection, DeviceErrorCode, FlashDataSource, FlashOptions, LedMatrix, Logging, LoggingEvent, MagnetometerData, MagnetometerDataEvent, MicrobitRadioBridgeConnection, MicrobitRadioBridgeConnectionOptions, MicrobitWebBluetoothConnection, MicrobitWebBluetoothConnectionOptions, MicrobitWebUSBConnection, MicrobitWebUSBConnectionOptions, };
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UARTDataEvent = exports.TypedEventTarget = exports.ServiceConnectionEventMap = exports.SerialResetEvent = exports.SerialErrorEvent = exports.SerialDataEvent = exports.SerialConnectionEventMap = exports.FlashEvent = exports.FlashDataError = exports.DeviceError = exports.DeviceSelectionMode = exports.DeviceConnectionEventMap = exports.createWebUSBConnection = exports.createWebBluetoothConnection = exports.createUniversalHexFlashDataSource = exports.createRadioBridgeConnection = exports.ConnectionStatusEvent = exports.ConnectionStatus = exports.BoardId = exports.BeforeRequestDevice = exports.BackgroundErrorEvent = exports.AfterRequestDevice = void 0;
4
+ const bluetooth_js_1 = require("./bluetooth.js");
5
+ Object.defineProperty(exports, "createWebBluetoothConnection", { enumerable: true, get: function () { return bluetooth_js_1.createWebBluetoothConnection; } });
6
+ const board_id_js_1 = require("./board-id.js");
7
+ Object.defineProperty(exports, "BoardId", { enumerable: true, get: function () { return board_id_js_1.BoardId; } });
8
+ const device_js_1 = require("./device.js");
9
+ Object.defineProperty(exports, "AfterRequestDevice", { enumerable: true, get: function () { return device_js_1.AfterRequestDevice; } });
10
+ Object.defineProperty(exports, "BackgroundErrorEvent", { enumerable: true, get: function () { return device_js_1.BackgroundErrorEvent; } });
11
+ Object.defineProperty(exports, "BeforeRequestDevice", { enumerable: true, get: function () { return device_js_1.BeforeRequestDevice; } });
12
+ Object.defineProperty(exports, "ConnectionStatus", { enumerable: true, get: function () { return device_js_1.ConnectionStatus; } });
13
+ Object.defineProperty(exports, "ConnectionStatusEvent", { enumerable: true, get: function () { return device_js_1.ConnectionStatusEvent; } });
14
+ Object.defineProperty(exports, "DeviceConnectionEventMap", { enumerable: true, get: function () { return device_js_1.DeviceConnectionEventMap; } });
15
+ Object.defineProperty(exports, "DeviceError", { enumerable: true, get: function () { return device_js_1.DeviceError; } });
16
+ Object.defineProperty(exports, "FlashDataError", { enumerable: true, get: function () { return device_js_1.FlashDataError; } });
17
+ const events_js_1 = require("./events.js");
18
+ Object.defineProperty(exports, "TypedEventTarget", { enumerable: true, get: function () { return events_js_1.TypedEventTarget; } });
19
+ const hex_flash_data_source_js_1 = require("./hex-flash-data-source.js");
20
+ Object.defineProperty(exports, "createUniversalHexFlashDataSource", { enumerable: true, get: function () { return hex_flash_data_source_js_1.createUniversalHexFlashDataSource; } });
21
+ const serial_events_js_1 = require("./serial-events.js");
22
+ Object.defineProperty(exports, "FlashEvent", { enumerable: true, get: function () { return serial_events_js_1.FlashEvent; } });
23
+ Object.defineProperty(exports, "SerialConnectionEventMap", { enumerable: true, get: function () { return serial_events_js_1.SerialConnectionEventMap; } });
24
+ Object.defineProperty(exports, "SerialDataEvent", { enumerable: true, get: function () { return serial_events_js_1.SerialDataEvent; } });
25
+ Object.defineProperty(exports, "SerialErrorEvent", { enumerable: true, get: function () { return serial_events_js_1.SerialErrorEvent; } });
26
+ Object.defineProperty(exports, "SerialResetEvent", { enumerable: true, get: function () { return serial_events_js_1.SerialResetEvent; } });
27
+ const service_events_js_1 = require("./service-events.js");
28
+ Object.defineProperty(exports, "ServiceConnectionEventMap", { enumerable: true, get: function () { return service_events_js_1.ServiceConnectionEventMap; } });
29
+ const uart_js_1 = require("./uart.js");
30
+ Object.defineProperty(exports, "UARTDataEvent", { enumerable: true, get: function () { return uart_js_1.UARTDataEvent; } });
31
+ const usb_radio_bridge_js_1 = require("./usb-radio-bridge.js");
32
+ Object.defineProperty(exports, "createRadioBridgeConnection", { enumerable: true, get: function () { return usb_radio_bridge_js_1.createRadioBridgeConnection; } });
33
+ const usb_js_1 = require("./usb.js");
34
+ Object.defineProperty(exports, "createWebUSBConnection", { enumerable: true, get: function () { return usb_js_1.createWebUSBConnection; } });
35
+ Object.defineProperty(exports, "DeviceSelectionMode", { enumerable: true, get: function () { return usb_js_1.DeviceSelectionMode; } });
36
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/index.ts"],"names":[],"mappings":";;;AACA,iDAIwB;AAqDtB,6GAxDA,2CAA4B,OAwDA;AApD9B,+CAAwC;AA+CtC,wFA/CO,qBAAO,OA+CP;AA7CT,2CAcqB;AA4BnB,mGAzCA,8BAAkB,OAyCA;AAClB,qGAzCA,gCAAoB,OAyCA;AACpB,oGAzCA,+BAAmB,OAyCA;AAEnB,iGAzCA,4BAAgB,OAyCA;AAChB,sGAzCA,iCAAqB,OAyCA;AAKrB,yGA5CA,oCAAwB,OA4CA;AAExB,4FA7CA,uBAAW,OA6CA;AACX,+FA5CA,0BAAc,OA4CA;AAxChB,2CAA+C;AA+C7C,iGA/CO,4BAAgB,OA+CP;AA9ClB,yEAA+E;AAiC7E,kHAjCO,4DAAiC,OAiCP;AA7BnC,yDAM4B;AA8B1B,2FAnCA,6BAAU,OAmCA;AACV,yGAnCA,2CAAwB,OAmCA;AACxB,gGAnCA,kCAAe,OAmCA;AACf,iGAnCA,mCAAgB,OAmCA;AAChB,iGAnCA,mCAAgB,OAmCA;AAjClB,2DAAgE;AAkC9D,0GAlCO,6CAAyB,OAkCP;AAjC3B,uCAA0C;AAmCxC,8FAnCO,uBAAa,OAmCP;AAlCf,+DAI+B;AAe7B,4GAlBA,iDAA2B,OAkBA;AAd7B,qCAKkB;AAYhB,uGAhBA,+BAAsB,OAgBA;AAEtB,oGAjBA,4BAAmB,OAiBA"}
@@ -0,0 +1,120 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LedService = void 0;
4
+ const bluetooth_profile_js_1 = require("./bluetooth-profile.js");
5
+ const device_js_1 = require("./device.js");
6
+ const createLedMatrix = () => {
7
+ return [
8
+ [false, false, false, false, false],
9
+ [false, false, false, false, false],
10
+ [false, false, false, false, false],
11
+ [false, false, false, false, false],
12
+ [false, false, false, false, false],
13
+ ];
14
+ };
15
+ class LedService {
16
+ constructor(matrixStateCharacteristic, scrollingDelayCharacteristic, textCharactertistic, queueGattOperation) {
17
+ Object.defineProperty(this, "matrixStateCharacteristic", {
18
+ enumerable: true,
19
+ configurable: true,
20
+ writable: true,
21
+ value: matrixStateCharacteristic
22
+ });
23
+ Object.defineProperty(this, "scrollingDelayCharacteristic", {
24
+ enumerable: true,
25
+ configurable: true,
26
+ writable: true,
27
+ value: scrollingDelayCharacteristic
28
+ });
29
+ Object.defineProperty(this, "textCharactertistic", {
30
+ enumerable: true,
31
+ configurable: true,
32
+ writable: true,
33
+ value: textCharactertistic
34
+ });
35
+ Object.defineProperty(this, "queueGattOperation", {
36
+ enumerable: true,
37
+ configurable: true,
38
+ writable: true,
39
+ value: queueGattOperation
40
+ });
41
+ }
42
+ static async createService(gattServer, dispatcher, queueGattOperation, listenerInit) {
43
+ let ledService;
44
+ try {
45
+ ledService = await gattServer.getPrimaryService(bluetooth_profile_js_1.profile.led.id);
46
+ }
47
+ catch (err) {
48
+ if (listenerInit) {
49
+ dispatcher("backgrounderror", new device_js_1.BackgroundErrorEvent(err));
50
+ return;
51
+ }
52
+ else {
53
+ throw new device_js_1.DeviceError({
54
+ code: "service-missing",
55
+ message: err,
56
+ });
57
+ }
58
+ }
59
+ const matrixStateCharacteristic = await ledService.getCharacteristic(bluetooth_profile_js_1.profile.led.characteristics.matrixState.id);
60
+ const scrollingDelayCharacteristic = await ledService.getCharacteristic(bluetooth_profile_js_1.profile.led.characteristics.scrollingDelay.id);
61
+ const textCharacteristic = await ledService.getCharacteristic(bluetooth_profile_js_1.profile.led.characteristics.text.id);
62
+ return new LedService(matrixStateCharacteristic, scrollingDelayCharacteristic, textCharacteristic, queueGattOperation);
63
+ }
64
+ async getLedMatrix() {
65
+ const dataView = await this.queueGattOperation(() => this.matrixStateCharacteristic.readValue());
66
+ return this.dataViewToLedMatrix(dataView);
67
+ }
68
+ async setLedMatrix(value) {
69
+ const dataView = this.ledMatrixToDataView(value);
70
+ return this.queueGattOperation(() => this.matrixStateCharacteristic.writeValue(dataView));
71
+ }
72
+ dataViewToLedMatrix(dataView) {
73
+ if (dataView.byteLength !== 5) {
74
+ throw new Error("Unexpected LED matrix byte length");
75
+ }
76
+ const matrix = createLedMatrix();
77
+ for (let row = 0; row < 5; ++row) {
78
+ const rowByte = dataView.getUint8(row);
79
+ for (let column = 0; column < 5; ++column) {
80
+ const columnMask = 0x1 << (4 - column);
81
+ matrix[row][column] = (rowByte & columnMask) != 0;
82
+ }
83
+ }
84
+ return matrix;
85
+ }
86
+ ledMatrixToDataView(matrix) {
87
+ const dataView = new DataView(new ArrayBuffer(5));
88
+ for (let row = 0; row < 5; ++row) {
89
+ let rowByte = 0;
90
+ for (let column = 0; column < 5; ++column) {
91
+ const columnMask = 0x1 << (4 - column);
92
+ if (matrix[row][column]) {
93
+ rowByte |= columnMask;
94
+ }
95
+ }
96
+ dataView.setUint8(row, rowByte);
97
+ }
98
+ return dataView;
99
+ }
100
+ async setText(text) {
101
+ const bytes = new TextEncoder().encode(text);
102
+ if (bytes.length > 20) {
103
+ throw new Error("Text must be <= 20 bytes when encoded as UTF-8");
104
+ }
105
+ return this.queueGattOperation(() => this.textCharactertistic.writeValue(bytes));
106
+ }
107
+ async setScrollingDelay(value) {
108
+ const dataView = new DataView(new ArrayBuffer(2));
109
+ dataView.setUint16(0, value, true);
110
+ return this.queueGattOperation(() => this.scrollingDelayCharacteristic.writeValue(dataView));
111
+ }
112
+ async getScrollingDelay() {
113
+ const dataView = await this.queueGattOperation(() => this.scrollingDelayCharacteristic.readValue());
114
+ return dataView.getUint16(0, true);
115
+ }
116
+ async startNotifications(type) { }
117
+ async stopNotifications(type) { }
118
+ }
119
+ exports.LedService = LedService;
120
+ //# sourceMappingURL=led-service.js.map