@microbit/microbit-connection 0.0.0-alpha.9 → 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 (229) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +94 -5
  3. package/build/{accelerometer-service.d.ts → cjs/accelerometer-service.d.ts} +3 -3
  4. package/build/cjs/accelerometer-service.js +106 -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/cjs/async-util.js +27 -0
  9. package/build/cjs/async-util.js.map +1 -0
  10. package/build/{bluetooth-device-wrapper.d.ts → cjs/bluetooth-device-wrapper.d.ts} +23 -15
  11. package/build/cjs/bluetooth-device-wrapper.js +467 -0
  12. package/build/cjs/bluetooth-device-wrapper.js.map +1 -0
  13. package/build/cjs/bluetooth-profile.js +86 -0
  14. package/build/cjs/bluetooth-profile.js.map +1 -0
  15. package/build/cjs/bluetooth.d.ts +108 -0
  16. package/build/cjs/bluetooth.js +272 -0
  17. package/build/cjs/bluetooth.js.map +1 -0
  18. package/build/cjs/board-id.js +81 -0
  19. package/build/cjs/board-id.js.map +1 -0
  20. package/build/cjs/board-serial-info.js +51 -0
  21. package/build/cjs/board-serial-info.js.map +1 -0
  22. package/build/{button-service.d.ts → cjs/button-service.d.ts} +2 -2
  23. package/build/cjs/button-service.js +80 -0
  24. package/build/cjs/button-service.js.map +1 -0
  25. package/build/cjs/buttons.js +22 -0
  26. package/build/cjs/buttons.js.map +1 -0
  27. package/build/cjs/constants.js +73 -0
  28. package/build/cjs/constants.js.map +1 -0
  29. package/build/{device.d.ts → cjs/device.d.ts} +35 -46
  30. package/build/cjs/device.js +133 -0
  31. package/build/cjs/device.js.map +1 -0
  32. package/build/{events.d.ts → cjs/events.d.ts} +12 -3
  33. package/build/cjs/events.js +109 -0
  34. package/build/cjs/events.js.map +1 -0
  35. package/build/cjs/hex-flash-data-source.js +26 -0
  36. package/build/cjs/hex-flash-data-source.js.map +1 -0
  37. package/build/cjs/index.d.ts +17 -0
  38. package/build/cjs/index.js +36 -0
  39. package/build/cjs/index.js.map +1 -0
  40. package/build/cjs/led-service.d.ts +20 -0
  41. package/build/cjs/led-service.js +120 -0
  42. package/build/cjs/led-service.js.map +1 -0
  43. package/build/cjs/led.d.ts +6 -0
  44. package/build/cjs/led.js +3 -0
  45. package/build/cjs/led.js.map +1 -0
  46. package/build/{logging.d.ts → cjs/logging.d.ts} +3 -3
  47. package/build/cjs/logging.js +16 -0
  48. package/build/cjs/logging.js.map +1 -0
  49. package/build/cjs/magnetometer-service.d.ts +22 -0
  50. package/build/cjs/magnetometer-service.js +129 -0
  51. package/build/cjs/magnetometer-service.js.map +1 -0
  52. package/build/cjs/magnetometer.d.ts +9 -0
  53. package/build/cjs/magnetometer.js +16 -0
  54. package/build/cjs/magnetometer.js.map +1 -0
  55. package/build/cjs/package.json +1 -0
  56. package/build/cjs/promise-queue.d.ts +27 -0
  57. package/build/cjs/promise-queue.js +78 -0
  58. package/build/cjs/promise-queue.js.map +1 -0
  59. package/build/cjs/serial-events.d.ts +20 -0
  60. package/build/cjs/serial-events.js +69 -0
  61. package/build/cjs/serial-events.js.map +1 -0
  62. package/build/{service-events.d.ts → cjs/service-events.d.ts} +4 -0
  63. package/build/cjs/service-events.js +39 -0
  64. package/build/cjs/service-events.js.map +1 -0
  65. package/build/cjs/setupTests.js.map +1 -0
  66. package/build/cjs/uart-service.d.ts +13 -0
  67. package/build/cjs/uart-service.js +76 -0
  68. package/build/cjs/uart-service.js.map +1 -0
  69. package/build/cjs/uart.d.ts +4 -0
  70. package/build/cjs/uart.js +16 -0
  71. package/build/cjs/uart.js.map +1 -0
  72. package/build/{usb-device-wrapper.d.ts → cjs/usb-device-wrapper.d.ts} +2 -6
  73. package/build/cjs/usb-device-wrapper.js +412 -0
  74. package/build/cjs/usb-device-wrapper.js.map +1 -0
  75. package/build/cjs/usb-partial-flashing-utils.js +133 -0
  76. package/build/cjs/usb-partial-flashing-utils.js.map +1 -0
  77. package/build/{usb-partial-flashing.d.ts → cjs/usb-partial-flashing.d.ts} +3 -3
  78. package/build/cjs/usb-partial-flashing.js +341 -0
  79. package/build/cjs/usb-partial-flashing.js.map +1 -0
  80. package/build/cjs/usb-radio-bridge.d.ts +24 -0
  81. package/build/cjs/usb-radio-bridge.js +516 -0
  82. package/build/cjs/usb-radio-bridge.js.map +1 -0
  83. package/build/cjs/usb-serial-protocol.js +183 -0
  84. package/build/cjs/usb-serial-protocol.js.map +1 -0
  85. package/build/cjs/usb.d.ts +64 -0
  86. package/build/cjs/usb.js +647 -0
  87. package/build/cjs/usb.js.map +1 -0
  88. package/build/esm/accelerometer-service.d.ts +18 -0
  89. package/build/{accelerometer-service.js → esm/accelerometer-service.js} +4 -20
  90. package/build/esm/accelerometer-service.js.map +1 -0
  91. package/build/esm/accelerometer.d.ts +9 -0
  92. package/build/esm/accelerometer.js.map +1 -0
  93. package/build/esm/async-util.d.ts +13 -0
  94. package/build/esm/async-util.js.map +1 -0
  95. package/build/esm/bluetooth-device-wrapper.d.ts +63 -0
  96. package/build/{bluetooth-device-wrapper.js → esm/bluetooth-device-wrapper.js} +105 -75
  97. package/build/esm/bluetooth-device-wrapper.js.map +1 -0
  98. package/build/esm/bluetooth-profile.d.ts +139 -0
  99. package/build/esm/bluetooth-profile.js.map +1 -0
  100. package/build/esm/bluetooth.d.ts +108 -0
  101. package/build/{bluetooth.js → esm/bluetooth.js} +73 -36
  102. package/build/esm/bluetooth.js.map +1 -0
  103. package/build/esm/board-id.d.ts +36 -0
  104. package/build/esm/board-id.js.map +1 -0
  105. package/build/esm/board-serial-info.d.ts +14 -0
  106. package/build/esm/board-serial-info.js.map +1 -0
  107. package/build/esm/button-service.d.ts +13 -0
  108. package/build/esm/button-service.js.map +1 -0
  109. package/build/esm/buttons.d.ts +10 -0
  110. package/build/esm/buttons.js.map +1 -0
  111. package/build/esm/constants.d.ts +48 -0
  112. package/build/esm/constants.js.map +1 -0
  113. package/build/esm/device.d.ts +181 -0
  114. package/build/{device.js → esm/device.js} +11 -58
  115. package/build/esm/device.js.map +1 -0
  116. package/build/esm/events.d.ts +110 -0
  117. package/build/esm/events.js +104 -0
  118. package/build/esm/events.js.map +1 -0
  119. package/build/esm/hex-flash-data-source.d.ts +7 -0
  120. package/build/esm/hex-flash-data-source.js.map +1 -0
  121. package/build/esm/index.d.ts +17 -0
  122. package/build/esm/index.js +12 -0
  123. package/build/esm/index.js.map +1 -0
  124. package/build/esm/led-service.d.ts +20 -0
  125. package/build/esm/led-service.js +116 -0
  126. package/build/esm/led-service.js.map +1 -0
  127. package/build/esm/led.d.ts +6 -0
  128. package/build/esm/led.js +2 -0
  129. package/build/esm/led.js.map +1 -0
  130. package/build/esm/logging.d.ts +21 -0
  131. package/build/esm/logging.js.map +1 -0
  132. package/build/esm/magnetometer-service.d.ts +22 -0
  133. package/build/esm/magnetometer-service.js +125 -0
  134. package/build/esm/magnetometer-service.js.map +1 -0
  135. package/build/esm/magnetometer.d.ts +9 -0
  136. package/build/esm/magnetometer.js +12 -0
  137. package/build/esm/magnetometer.js.map +1 -0
  138. package/build/esm/package.json +1 -0
  139. package/build/esm/promise-queue.d.ts +27 -0
  140. package/build/esm/promise-queue.js +74 -0
  141. package/build/esm/promise-queue.js.map +1 -0
  142. package/build/esm/serial-events.d.ts +20 -0
  143. package/build/esm/serial-events.js +61 -0
  144. package/build/esm/serial-events.js.map +1 -0
  145. package/build/esm/service-events.d.ts +17 -0
  146. package/build/{service-events.js → esm/service-events.js} +12 -0
  147. package/build/esm/service-events.js.map +1 -0
  148. package/build/esm/setupTests.d.ts +6 -0
  149. package/build/{setupTests.js.map → esm/setupTests.js.map} +1 -1
  150. package/build/esm/uart-service.d.ts +13 -0
  151. package/build/esm/uart-service.js +72 -0
  152. package/build/esm/uart-service.js.map +1 -0
  153. package/build/esm/uart.d.ts +4 -0
  154. package/build/esm/uart.js +12 -0
  155. package/build/esm/uart.js.map +1 -0
  156. package/build/esm/usb-device-wrapper.d.ts +47 -0
  157. package/build/{usb-device-wrapper.js → esm/usb-device-wrapper.js} +36 -12
  158. package/build/esm/usb-device-wrapper.js.map +1 -0
  159. package/build/esm/usb-partial-flashing-utils.d.ts +17 -0
  160. package/build/esm/usb-partial-flashing-utils.js.map +1 -0
  161. package/build/esm/usb-partial-flashing.d.ts +69 -0
  162. package/build/{usb-partial-flashing.js → esm/usb-partial-flashing.js} +8 -10
  163. package/build/esm/usb-partial-flashing.js.map +1 -0
  164. package/build/esm/usb-radio-bridge.d.ts +24 -0
  165. package/build/{usb-radio-bridge.js → esm/usb-radio-bridge.js} +133 -47
  166. package/build/esm/usb-radio-bridge.js.map +1 -0
  167. package/build/esm/usb-serial-protocol.d.ts +66 -0
  168. package/build/esm/usb-serial-protocol.js.map +1 -0
  169. package/build/esm/usb.d.ts +64 -0
  170. package/build/{usb.js → esm/usb.js} +188 -67
  171. package/build/esm/usb.js.map +1 -0
  172. package/package.json +23 -9
  173. package/typedoc.json +14 -0
  174. package/build/accelerometer-service.js.map +0 -1
  175. package/build/accelerometer.js.map +0 -1
  176. package/build/async-util.js.map +0 -1
  177. package/build/bluetooth-device-wrapper.js.map +0 -1
  178. package/build/bluetooth-profile.js.map +0 -1
  179. package/build/bluetooth-utils.d.ts +0 -5
  180. package/build/bluetooth-utils.js +0 -14
  181. package/build/bluetooth-utils.js.map +0 -1
  182. package/build/bluetooth.d.ts +0 -49
  183. package/build/bluetooth.js.map +0 -1
  184. package/build/board-id.js.map +0 -1
  185. package/build/board-serial-info.js.map +0 -1
  186. package/build/button-service.js.map +0 -1
  187. package/build/buttons.js.map +0 -1
  188. package/build/constants.js.map +0 -1
  189. package/build/device.js.map +0 -1
  190. package/build/events.js +0 -19
  191. package/build/events.js.map +0 -1
  192. package/build/hex-flash-data-source.js.map +0 -1
  193. package/build/index.d.ts +0 -10
  194. package/build/index.js +0 -8
  195. package/build/index.js.map +0 -1
  196. package/build/logging.js.map +0 -1
  197. package/build/service-events.js.map +0 -1
  198. package/build/usb-device-wrapper.js.map +0 -1
  199. package/build/usb-partial-flashing-utils.js.map +0 -1
  200. package/build/usb-partial-flashing.js.map +0 -1
  201. package/build/usb-radio-bridge.d.ts +0 -37
  202. package/build/usb-radio-bridge.js.map +0 -1
  203. package/build/usb-serial-protocol.js.map +0 -1
  204. package/build/usb.d.ts +0 -60
  205. package/build/usb.js.map +0 -1
  206. package/vite.config.ts +0 -32
  207. /package/build/{accelerometer.d.ts → cjs/accelerometer.d.ts} +0 -0
  208. /package/build/{async-util.d.ts → cjs/async-util.d.ts} +0 -0
  209. /package/build/{bluetooth-profile.d.ts → cjs/bluetooth-profile.d.ts} +0 -0
  210. /package/build/{board-id.d.ts → cjs/board-id.d.ts} +0 -0
  211. /package/build/{board-serial-info.d.ts → cjs/board-serial-info.d.ts} +0 -0
  212. /package/build/{buttons.d.ts → cjs/buttons.d.ts} +0 -0
  213. /package/build/{constants.d.ts → cjs/constants.d.ts} +0 -0
  214. /package/build/{hex-flash-data-source.d.ts → cjs/hex-flash-data-source.d.ts} +0 -0
  215. /package/build/{setupTests.d.ts → cjs/setupTests.d.ts} +0 -0
  216. /package/build/{usb-partial-flashing-utils.d.ts → cjs/usb-partial-flashing-utils.d.ts} +0 -0
  217. /package/build/{usb-serial-protocol.d.ts → cjs/usb-serial-protocol.d.ts} +0 -0
  218. /package/build/{accelerometer.js → esm/accelerometer.js} +0 -0
  219. /package/build/{async-util.js → esm/async-util.js} +0 -0
  220. /package/build/{bluetooth-profile.js → esm/bluetooth-profile.js} +0 -0
  221. /package/build/{board-id.js → esm/board-id.js} +0 -0
  222. /package/build/{board-serial-info.js → esm/board-serial-info.js} +0 -0
  223. /package/build/{button-service.js → esm/button-service.js} +0 -0
  224. /package/build/{buttons.js → esm/buttons.js} +0 -0
  225. /package/build/{constants.js → esm/constants.js} +0 -0
  226. /package/build/{hex-flash-data-source.js → esm/hex-flash-data-source.js} +0 -0
  227. /package/build/{logging.js → esm/logging.js} +0 -0
  228. /package/build/{usb-partial-flashing-utils.js → esm/usb-partial-flashing-utils.js} +0 -0
  229. /package/build/{usb-serial-protocol.js → esm/usb-serial-protocol.js} +0 -0
@@ -43,11 +43,20 @@ export var ConnectionStatus;
43
43
  /**
44
44
  * Authorized device available but we haven't connected to it.
45
45
  */
46
- ConnectionStatus["NOT_CONNECTED"] = "NOT_CONNECTED";
46
+ ConnectionStatus["DISCONNECTED"] = "DISCONNECTED";
47
47
  /**
48
48
  * Connected.
49
49
  */
50
50
  ConnectionStatus["CONNECTED"] = "CONNECTED";
51
+ /**
52
+ * Connecting.
53
+ */
54
+ ConnectionStatus["CONNECTING"] = "CONNECTING";
55
+ /**
56
+ * Reconnecting. When there is unexpected disruption in the connection,
57
+ * a reconnection is attempted.
58
+ */
59
+ ConnectionStatus["RECONNECTING"] = "RECONNECTING";
51
60
  })(ConnectionStatus || (ConnectionStatus = {}));
52
61
  export class FlashDataError extends Error {
53
62
  }
@@ -62,38 +71,6 @@ export class ConnectionStatusEvent extends Event {
62
71
  });
63
72
  }
64
73
  }
65
- export class SerialDataEvent extends Event {
66
- constructor(data) {
67
- super("serialdata");
68
- Object.defineProperty(this, "data", {
69
- enumerable: true,
70
- configurable: true,
71
- writable: true,
72
- value: data
73
- });
74
- }
75
- }
76
- export class SerialResetEvent extends Event {
77
- constructor() {
78
- super("serialreset");
79
- }
80
- }
81
- export class SerialErrorEvent extends Event {
82
- constructor(error) {
83
- super("serialerror");
84
- Object.defineProperty(this, "error", {
85
- enumerable: true,
86
- configurable: true,
87
- writable: true,
88
- value: error
89
- });
90
- }
91
- }
92
- export class FlashEvent extends Event {
93
- constructor() {
94
- super("flash");
95
- }
96
- }
97
74
  export class BeforeRequestDevice extends Event {
98
75
  constructor() {
99
76
  super("beforerequestdevice");
@@ -123,25 +100,7 @@ export class DeviceConnectionEventMap {
123
100
  writable: true,
124
101
  value: void 0
125
102
  });
126
- Object.defineProperty(this, "serialdata", {
127
- enumerable: true,
128
- configurable: true,
129
- writable: true,
130
- value: void 0
131
- });
132
- Object.defineProperty(this, "serialreset", {
133
- enumerable: true,
134
- configurable: true,
135
- writable: true,
136
- value: void 0
137
- });
138
- Object.defineProperty(this, "serialerror", {
139
- enumerable: true,
140
- configurable: true,
141
- writable: true,
142
- value: void 0
143
- });
144
- Object.defineProperty(this, "flash", {
103
+ Object.defineProperty(this, "backgrounderror", {
145
104
  enumerable: true,
146
105
  configurable: true,
147
106
  writable: true,
@@ -159,12 +118,6 @@ export class DeviceConnectionEventMap {
159
118
  writable: true,
160
119
  value: void 0
161
120
  });
162
- Object.defineProperty(this, "backgrounderror", {
163
- enumerable: true,
164
- configurable: true,
165
- writable: true,
166
- value: void 0
167
- });
168
121
  }
169
122
  }
170
123
  //# sourceMappingURL=device.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"device.js","sourceRoot":"","sources":["../../lib/device.ts"],"names":[],"mappings":"AA8CA;;;;;;;;GAQG;AACH,MAAM,OAAO,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;AAED;;GAEG;AACH,MAAM,CAAN,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,KAAhB,gBAAgB,QAkC3B;AAqBD,MAAM,OAAO,cAAe,SAAQ,KAAK;CAAG;AAQ5C,MAAM,OAAO,qBAAsB,SAAQ,KAAK;IAC9C,YAA4B,MAAwB;QAClD,KAAK,CAAC,QAAQ,CAAC,CAAC;QADN;;;;mBAAgB,MAAM;WAAkB;IAEpD,CAAC;CACF;AAED,MAAM,OAAO,mBAAoB,SAAQ,KAAK;IAC5C;QACE,KAAK,CAAC,qBAAqB,CAAC,CAAC;IAC/B,CAAC;CACF;AAED,MAAM,OAAO,kBAAmB,SAAQ,KAAK;IAC3C;QACE,KAAK,CAAC,oBAAoB,CAAC,CAAC;IAC9B,CAAC;CACF;AAED,MAAM,OAAO,oBAAqB,SAAQ,KAAK;IAC7C,YAA4B,YAAoB;QAC9C,KAAK,CAAC,iBAAiB,CAAC,CAAC;QADf;;;;mBAAgB,YAAY;WAAQ;IAEhD,CAAC;CACF;AAED,MAAM,OAAO,wBAAwB;IAArC;QACE,4BAAA,QAAQ;;;;;WAAwB;QAChC,4BAAA,iBAAiB;;;;;WAAuB;QACxC,4BAAA,qBAAqB;;;;;WAAQ;QAC7B,4BAAA,oBAAoB;;;;;WAAQ;IAC9B,CAAC;CAAA"}
@@ -0,0 +1,110 @@
1
+ /**
2
+ * Copyright (c) 2022 Jonas "DerZade" Schade
3
+ *
4
+ * SPDX-License-Identifier: MIT
5
+ *
6
+ * https://github.com/DerZade/typescript-event-target/blob/master/src/TypedEventTarget.ts
7
+ */
8
+ /**
9
+ * A function that can be passed to the `listener` parameter of {@link TypedEventTarget.addEventListener} and {@link TypedEventTarget.removeEventListener}.
10
+ *
11
+ * @template M A map of event types to their respective event classes.
12
+ * @template T The type of event to listen for (has to be keyof `M`).
13
+ */
14
+ export type TypedEventListener<M, T extends keyof M> = (evt: M[T]) => void | Promise<void>;
15
+ /**
16
+ * An object that can be passed to the `listener` parameter of {@link TypedEventTarget.addEventListener} and {@link TypedEventTarget.removeEventListener}.
17
+ *
18
+ * @template M A map of event types to their respective event classes.
19
+ * @template T The type of event to listen for (has to be keyof `M`).
20
+ */
21
+ export interface TypedEventListenerObject<M, T extends keyof M> {
22
+ handleEvent: (evt: M[T]) => void | Promise<void>;
23
+ }
24
+ /**
25
+ * Type of parameter `listener` in {@link TypedEventTarget.addEventListener} and {@link TypedEventTarget.removeEventListener}.
26
+ *
27
+ * The object that receives a notification (an object that implements the Event interface) when an event of the specified type occurs.
28
+ *
29
+ * Can be either an object with a handleEvent() method, or a JavaScript function.
30
+ *
31
+ * @template M A map of event types to their respective event classes.
32
+ * @template T The type of event to listen for (has to be keyof `M`).
33
+ */
34
+ export type TypedEventListenerOrEventListenerObject<M, T extends keyof M> = TypedEventListener<M, T> | TypedEventListenerObject<M, T>;
35
+ export type ValueIsEvent<T> = {
36
+ [key in keyof T]: Event;
37
+ };
38
+ /**
39
+ * Typescript friendly version of {@link EventTarget}
40
+ *
41
+ * @template M A map of event types to their respective event classes.
42
+ *
43
+ * @example
44
+ * ```typescript
45
+ * interface MyEventMap {
46
+ * hello: Event;
47
+ * time: CustomEvent<number>;
48
+ * }
49
+ *
50
+ * const eventTarget = new TypedEventTarget<MyEventMap>();
51
+ *
52
+ * eventTarget.addEventListener('time', (event) => {
53
+ * // event is of type CustomEvent<number>
54
+ * });
55
+ * ```
56
+ */
57
+ export interface TypedEventTarget<M extends ValueIsEvent<M>> {
58
+ /** Appends an event listener for events whose type attribute value is type.
59
+ * The callback argument sets the callback that will be invoked when the event
60
+ * is dispatched.
61
+ *
62
+ * The options argument sets listener-specific options. For compatibility this
63
+ * can be a boolean, in which case the method behaves exactly as if the value
64
+ * was specified as options's capture.
65
+ *
66
+ * When set to true, options's capture prevents callback from being invoked
67
+ * when the event's eventPhase attribute value is BUBBLING_PHASE. When false
68
+ * (or not present), callback will not be invoked when event's eventPhase
69
+ * attribute value is CAPTURING_PHASE. Either way, callback will be invoked if
70
+ * event's eventPhase attribute value is AT_TARGET.
71
+ *
72
+ * When set to true, options's passive indicates that the callback will not
73
+ * cancel the event by invoking preventDefault(). This is used to enable
74
+ * performance optimizations described in § 2.8 Observing event listeners.
75
+ *
76
+ * When set to true, options's once indicates that the callback will only be
77
+ * invoked once after which the event listener will be removed.
78
+ *
79
+ * The event listener is appended to target's event listener list and is not
80
+ * appended if it has the same type, callback, and capture. */
81
+ addEventListener: <T extends keyof M & string>(type: T, listener: TypedEventListenerOrEventListenerObject<M, T> | null, options?: boolean | AddEventListenerOptions) => void;
82
+ /** Removes the event listener in target's event listener list with the same
83
+ * type, callback, and options. */
84
+ removeEventListener: <T extends keyof M & string>(type: T, callback: TypedEventListenerOrEventListenerObject<M, T> | null, options?: EventListenerOptions | boolean) => void;
85
+ /**
86
+ * Dispatches a synthetic event event to target and returns true if either
87
+ * event's cancelable attribute value is false or its preventDefault() method
88
+ * was not invoked, and false otherwise.
89
+ * @deprecated To ensure type safety use `dispatchTypedEvent` instead.
90
+ */
91
+ dispatchEvent: (event: Event) => boolean;
92
+ }
93
+ export declare class TrackingEventTarget extends EventTarget {
94
+ private activeEventTracking;
95
+ addEventListener(type: string, callback: EventListenerOrEventListenerObject | null, options?: AddEventListenerOptions | boolean): void;
96
+ removeEventListener(type: string, callback: EventListenerOrEventListenerObject | null, options?: EventListenerOptions | boolean): void;
97
+ dispatchEvent(event: Event): boolean;
98
+ private filterRegistrations;
99
+ protected eventActivated(type: string): void;
100
+ protected eventDeactivated(type: string): void;
101
+ protected getActiveEvents(): string[];
102
+ }
103
+ export declare class TypedEventTarget<M extends ValueIsEvent<M>> extends TrackingEventTarget {
104
+ /**
105
+ * Dispatches a synthetic event event to target and returns true if either
106
+ * event's cancelable attribute value is false or its preventDefault() method
107
+ * was not invoked, and false otherwise.
108
+ */
109
+ dispatchTypedEvent<T extends keyof M>(_type: T, event: M[T]): boolean;
110
+ }
@@ -0,0 +1,104 @@
1
+ /**
2
+ * Copyright (c) 2022 Jonas "DerZade" Schade
3
+ *
4
+ * SPDX-License-Identifier: MIT
5
+ *
6
+ * https://github.com/DerZade/typescript-event-target/blob/master/src/TypedEventTarget.ts
7
+ */
8
+ // We've added this in to keep track of what events are active.
9
+ // Having done this it's questionable whether it's worth the reimplementation
10
+ // just to use an EventTarget API.
11
+ export class TrackingEventTarget extends EventTarget {
12
+ constructor() {
13
+ super(...arguments);
14
+ Object.defineProperty(this, "activeEventTracking", {
15
+ enumerable: true,
16
+ configurable: true,
17
+ writable: true,
18
+ value: new Map()
19
+ });
20
+ }
21
+ addEventListener(type, callback, options) {
22
+ if (callback !== null) {
23
+ const registrations = this.activeEventTracking.get(type) ?? [];
24
+ const wasEmpty = registrations.length === 0;
25
+ const registration = new Registration(callback, options ?? false);
26
+ if (!registrations.find((r) => r.eq(registration))) {
27
+ registrations.push(registration);
28
+ this.activeEventTracking.set(type, registrations);
29
+ if (wasEmpty) {
30
+ this.eventActivated(type);
31
+ }
32
+ }
33
+ }
34
+ super.addEventListener(type, callback, options);
35
+ }
36
+ removeEventListener(type, callback, options) {
37
+ if (callback !== null) {
38
+ const registration = new Registration(callback, options ?? false);
39
+ this.filterRegistrations(type, (r) => !r.eq(registration));
40
+ }
41
+ super.removeEventListener(type, callback, options);
42
+ }
43
+ dispatchEvent(event) {
44
+ const result = super.dispatchEvent(event);
45
+ this.filterRegistrations(event.type, (r) => !r.isOnce());
46
+ return result;
47
+ }
48
+ filterRegistrations(type, predicate) {
49
+ let registrations = this.activeEventTracking.get(type) ?? [];
50
+ registrations = registrations.filter(predicate);
51
+ if (registrations.length === 0) {
52
+ this.activeEventTracking.delete(type);
53
+ this.eventDeactivated(type);
54
+ }
55
+ else {
56
+ this.activeEventTracking.set(type, registrations);
57
+ }
58
+ }
59
+ eventActivated(type) { }
60
+ eventDeactivated(type) { }
61
+ getActiveEvents() {
62
+ return [...this.activeEventTracking.keys()];
63
+ }
64
+ }
65
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
66
+ export class TypedEventTarget extends TrackingEventTarget {
67
+ /**
68
+ * Dispatches a synthetic event event to target and returns true if either
69
+ * event's cancelable attribute value is false or its preventDefault() method
70
+ * was not invoked, and false otherwise.
71
+ */
72
+ dispatchTypedEvent(_type, event) {
73
+ return super.dispatchEvent(event);
74
+ }
75
+ }
76
+ class Registration {
77
+ constructor(callback, options) {
78
+ Object.defineProperty(this, "callback", {
79
+ enumerable: true,
80
+ configurable: true,
81
+ writable: true,
82
+ value: callback
83
+ });
84
+ Object.defineProperty(this, "options", {
85
+ enumerable: true,
86
+ configurable: true,
87
+ writable: true,
88
+ value: options
89
+ });
90
+ }
91
+ isOnce() {
92
+ return typeof this.options === "object" && this.options.once === true;
93
+ }
94
+ eq(other) {
95
+ return (other.callback === this.callback &&
96
+ eqUseCapture(this.options, other.options));
97
+ }
98
+ }
99
+ const eqUseCapture = (left, right) => {
100
+ const leftValue = typeof left === "boolean" ? left : left.capture ?? false;
101
+ const rightValue = typeof right === "boolean" ? right : right.capture ?? false;
102
+ return leftValue === rightValue;
103
+ };
104
+ //# sourceMappingURL=events.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"events.js","sourceRoot":"","sources":["../../lib/events.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AA0GH,+DAA+D;AAC/D,6EAA6E;AAC7E,kCAAkC;AAClC,MAAM,OAAO,mBAAoB,SAAQ,WAAW;IAApD;;QACU;;;;mBAAmD,IAAI,GAAG,EAAE;WAAC;IA6DvE,CAAC;IA3DC,gBAAgB,CACd,IAAY,EACZ,QAAmD,EACnD,OAA2C;QAE3C,IAAI,QAAQ,KAAK,IAAI,EAAE,CAAC;YACtB,MAAM,aAAa,GAAG,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;YAC/D,MAAM,QAAQ,GAAG,aAAa,CAAC,MAAM,KAAK,CAAC,CAAC;YAC5C,MAAM,YAAY,GAAG,IAAI,YAAY,CAAC,QAAQ,EAAE,OAAO,IAAI,KAAK,CAAC,CAAC;YAClE,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,YAAY,CAAC,CAAC,EAAE,CAAC;gBACnD,aAA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,UAAU,GACd,OAAO,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,IAAI,KAAK,CAAC;IAC9D,OAAO,SAAS,KAAK,UAAU,CAAC;AAClC,CAAC,CAAC"}
@@ -0,0 +1,7 @@
1
+ import { FlashDataSource } from "./device.js";
2
+ /**
3
+ * A flash data source that converts universal hex files as needed.
4
+ *
5
+ * @param universalHex A hex file, potentially universal.
6
+ */
7
+ export declare const createUniversalHexFlashDataSource: (universalHex: string) => FlashDataSource;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hex-flash-data-source.js","sourceRoot":"","sources":["../../lib/hex-flash-data-source.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EACL,cAAc,IAAI,cAAc,GAGjC,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,cAAc,EACd,oBAAoB,GACrB,MAAM,kCAAkC,CAAC;AAE1C;;;;GAIG;AACH,MAAM,CAAC,MAAM,iCAAiC,GAAG,CAC/C,YAAoB,EACH,EAAE;IACnB,OAAO,CAAC,YAA0B,EAAE,EAAE;QACpC,IAAI,cAAc,CAAC,YAAY,CAAC,EAAE,CAAC;YACjC,MAAM,KAAK,GAAG,oBAAoB,CAAC,YAAY,CAAC,CAAC;YACjD,MAAM,QAAQ,GAAG,KAAK,CAAC,IAAI,CACzB,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,IAAI,OAAO,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC,EAAE,CACxD,CAAC;YACF,IAAI,CAAC,QAAQ,EAAE,CAAC;gBACd,MAAM,IAAI,cAAc,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"}
@@ -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,12 @@
1
+ import { createWebBluetoothConnection, } from "./bluetooth.js";
2
+ import { BoardId } from "./board-id.js";
3
+ import { AfterRequestDevice, BackgroundErrorEvent, BeforeRequestDevice, ConnectionStatus, ConnectionStatusEvent, DeviceConnectionEventMap, DeviceError, FlashDataError, } from "./device.js";
4
+ import { TypedEventTarget } from "./events.js";
5
+ import { createUniversalHexFlashDataSource } from "./hex-flash-data-source.js";
6
+ import { FlashEvent, SerialConnectionEventMap, SerialDataEvent, SerialErrorEvent, SerialResetEvent, } from "./serial-events.js";
7
+ import { ServiceConnectionEventMap } from "./service-events.js";
8
+ import { UARTDataEvent } from "./uart.js";
9
+ import { createRadioBridgeConnection, } from "./usb-radio-bridge.js";
10
+ import { createWebUSBConnection, DeviceSelectionMode, } from "./usb.js";
11
+ export { AfterRequestDevice, BackgroundErrorEvent, BeforeRequestDevice, BoardId, ConnectionStatus, ConnectionStatusEvent, createRadioBridgeConnection, createUniversalHexFlashDataSource, createWebBluetoothConnection, createWebUSBConnection, DeviceConnectionEventMap, DeviceSelectionMode, DeviceError, FlashDataError, FlashEvent, SerialConnectionEventMap, SerialDataEvent, SerialErrorEvent, SerialResetEvent, ServiceConnectionEventMap, TypedEventTarget, UARTDataEvent, };
12
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,4BAA4B,GAG7B,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAExC,OAAO,EACL,kBAAkB,EAClB,oBAAoB,EACpB,mBAAmB,EAEnB,gBAAgB,EAChB,qBAAqB,EAErB,wBAAwB,EACxB,WAAW,EAEX,cAAc,GAGf,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,iCAAiC,EAAE,MAAM,4BAA4B,CAAC;AAI/E,OAAO,EACL,UAAU,EACV,wBAAwB,EACxB,eAAe,EACf,gBAAgB,EAChB,gBAAgB,GACjB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AAChE,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EACL,2BAA2B,GAG5B,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,sBAAsB,EACtB,mBAAmB,GAGpB,MAAM,UAAU,CAAC;AAElB,OAAO,EACL,kBAAkB,EAClB,oBAAoB,EACpB,mBAAmB,EACnB,OAAO,EACP,gBAAgB,EAChB,qBAAqB,EACrB,2BAA2B,EAC3B,iCAAiC,EACjC,4BAA4B,EAC5B,sBAAsB,EACtB,wBAAwB,EACxB,mBAAmB,EACnB,WAAW,EACX,cAAc,EACd,UAAU,EACV,wBAAwB,EACxB,eAAe,EACf,gBAAgB,EAChB,gBAAgB,EAChB,yBAAyB,EACzB,gBAAgB,EAChB,aAAa,GACd,CAAC"}
@@ -0,0 +1,20 @@
1
+ import { Service } from "./bluetooth-device-wrapper.js";
2
+ import { LedMatrix } from "./led.js";
3
+ import { TypedServiceEvent, TypedServiceEventDispatcher } from "./service-events.js";
4
+ export declare class LedService implements Service {
5
+ private matrixStateCharacteristic;
6
+ private scrollingDelayCharacteristic;
7
+ private textCharactertistic;
8
+ private queueGattOperation;
9
+ constructor(matrixStateCharacteristic: BluetoothRemoteGATTCharacteristic, scrollingDelayCharacteristic: BluetoothRemoteGATTCharacteristic, textCharactertistic: BluetoothRemoteGATTCharacteristic, queueGattOperation: <R>(action: () => Promise<R>) => Promise<R>);
10
+ static createService(gattServer: BluetoothRemoteGATTServer, dispatcher: TypedServiceEventDispatcher, queueGattOperation: <R>(action: () => Promise<R>) => Promise<R>, listenerInit: boolean): Promise<LedService | undefined>;
11
+ getLedMatrix(): Promise<LedMatrix>;
12
+ setLedMatrix(value: LedMatrix): Promise<void>;
13
+ private dataViewToLedMatrix;
14
+ private ledMatrixToDataView;
15
+ setText(text: string): Promise<void>;
16
+ setScrollingDelay(value: number): Promise<void>;
17
+ getScrollingDelay(): Promise<number>;
18
+ startNotifications(type: TypedServiceEvent): Promise<void>;
19
+ stopNotifications(type: TypedServiceEvent): Promise<void>;
20
+ }
@@ -0,0 +1,116 @@
1
+ import { profile } from "./bluetooth-profile.js";
2
+ import { BackgroundErrorEvent, DeviceError } from "./device.js";
3
+ const createLedMatrix = () => {
4
+ return [
5
+ [false, false, false, false, false],
6
+ [false, false, false, false, false],
7
+ [false, false, false, false, false],
8
+ [false, false, false, false, false],
9
+ [false, false, false, false, false],
10
+ ];
11
+ };
12
+ export class LedService {
13
+ constructor(matrixStateCharacteristic, scrollingDelayCharacteristic, textCharactertistic, queueGattOperation) {
14
+ Object.defineProperty(this, "matrixStateCharacteristic", {
15
+ enumerable: true,
16
+ configurable: true,
17
+ writable: true,
18
+ value: matrixStateCharacteristic
19
+ });
20
+ Object.defineProperty(this, "scrollingDelayCharacteristic", {
21
+ enumerable: true,
22
+ configurable: true,
23
+ writable: true,
24
+ value: scrollingDelayCharacteristic
25
+ });
26
+ Object.defineProperty(this, "textCharactertistic", {
27
+ enumerable: true,
28
+ configurable: true,
29
+ writable: true,
30
+ value: textCharactertistic
31
+ });
32
+ Object.defineProperty(this, "queueGattOperation", {
33
+ enumerable: true,
34
+ configurable: true,
35
+ writable: true,
36
+ value: queueGattOperation
37
+ });
38
+ }
39
+ static async createService(gattServer, dispatcher, queueGattOperation, listenerInit) {
40
+ let ledService;
41
+ try {
42
+ ledService = await gattServer.getPrimaryService(profile.led.id);
43
+ }
44
+ catch (err) {
45
+ if (listenerInit) {
46
+ dispatcher("backgrounderror", new BackgroundErrorEvent(err));
47
+ return;
48
+ }
49
+ else {
50
+ throw new DeviceError({
51
+ code: "service-missing",
52
+ message: err,
53
+ });
54
+ }
55
+ }
56
+ const matrixStateCharacteristic = await ledService.getCharacteristic(profile.led.characteristics.matrixState.id);
57
+ const scrollingDelayCharacteristic = await ledService.getCharacteristic(profile.led.characteristics.scrollingDelay.id);
58
+ const textCharacteristic = await ledService.getCharacteristic(profile.led.characteristics.text.id);
59
+ return new LedService(matrixStateCharacteristic, scrollingDelayCharacteristic, textCharacteristic, queueGattOperation);
60
+ }
61
+ async getLedMatrix() {
62
+ const dataView = await this.queueGattOperation(() => this.matrixStateCharacteristic.readValue());
63
+ return this.dataViewToLedMatrix(dataView);
64
+ }
65
+ async setLedMatrix(value) {
66
+ const dataView = this.ledMatrixToDataView(value);
67
+ return this.queueGattOperation(() => this.matrixStateCharacteristic.writeValue(dataView));
68
+ }
69
+ dataViewToLedMatrix(dataView) {
70
+ if (dataView.byteLength !== 5) {
71
+ throw new Error("Unexpected LED matrix byte length");
72
+ }
73
+ const matrix = createLedMatrix();
74
+ for (let row = 0; row < 5; ++row) {
75
+ const rowByte = dataView.getUint8(row);
76
+ for (let column = 0; column < 5; ++column) {
77
+ const columnMask = 0x1 << (4 - column);
78
+ matrix[row][column] = (rowByte & columnMask) != 0;
79
+ }
80
+ }
81
+ return matrix;
82
+ }
83
+ ledMatrixToDataView(matrix) {
84
+ const dataView = new DataView(new ArrayBuffer(5));
85
+ for (let row = 0; row < 5; ++row) {
86
+ let rowByte = 0;
87
+ for (let column = 0; column < 5; ++column) {
88
+ const columnMask = 0x1 << (4 - column);
89
+ if (matrix[row][column]) {
90
+ rowByte |= columnMask;
91
+ }
92
+ }
93
+ dataView.setUint8(row, rowByte);
94
+ }
95
+ return dataView;
96
+ }
97
+ async setText(text) {
98
+ const bytes = new TextEncoder().encode(text);
99
+ if (bytes.length > 20) {
100
+ throw new Error("Text must be <= 20 bytes when encoded as UTF-8");
101
+ }
102
+ return this.queueGattOperation(() => this.textCharactertistic.writeValue(bytes));
103
+ }
104
+ async setScrollingDelay(value) {
105
+ const dataView = new DataView(new ArrayBuffer(2));
106
+ dataView.setUint16(0, value, true);
107
+ return this.queueGattOperation(() => this.scrollingDelayCharacteristic.writeValue(dataView));
108
+ }
109
+ async getScrollingDelay() {
110
+ const dataView = await this.queueGattOperation(() => this.scrollingDelayCharacteristic.readValue());
111
+ return dataView.getUint16(0, true);
112
+ }
113
+ async startNotifications(type) { }
114
+ async stopNotifications(type) { }
115
+ }
116
+ //# sourceMappingURL=led-service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"led-service.js","sourceRoot":"","sources":["../../lib/led-service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,oBAAoB,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAOhE,MAAM,eAAe,GAAG,GAAc,EAAE;IACtC,OAAO;QACL,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC;QACnC,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC;QACnC,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC;QACnC,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC;QACnC,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC;KACpC,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,OAAO,UAAU;IACrB,YACU,yBAA4D,EAC5D,4BAA+D,EAC/D,mBAAsD,EACtD,kBAA+D;QAHvE;;;;mBAAQ,yBAAyB;WAAmC;QACpE;;;;mBAAQ,4BAA4B;WAAmC;QACvE;;;;mBAAQ,mBAA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F,OAAO,QAAQ,CAAC,SAAS,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;IACrC,CAAC;IAED,KAAK,CAAC,kBAAkB,CAAC,IAAuB,IAAkB,CAAC;IAEnE,KAAK,CAAC,iBAAiB,CAAC,IAAuB,IAAkB,CAAC;CACnE"}
@@ -0,0 +1,6 @@
1
+ type FixedArray<T, L extends number> = T[] & {
2
+ length: L;
3
+ };
4
+ type LedRow = FixedArray<boolean, 5>;
5
+ export type LedMatrix = FixedArray<LedRow, 5>;
6
+ export {};
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=led.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"led.js","sourceRoot":"","sources":["../../lib/led.ts"],"names":[],"mappings":""}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * (c) 2024, Micro:bit Educational Foundation and contributors
3
+ *
4
+ * SPDX-License-Identifier: MIT
5
+ */
6
+ export interface LoggingEvent {
7
+ type: string;
8
+ message?: string;
9
+ value?: number;
10
+ detail?: any;
11
+ }
12
+ export interface Logging {
13
+ event(event: LoggingEvent): void;
14
+ error(message: string, e: unknown): void;
15
+ log(e: any): void;
16
+ }
17
+ export declare class NullLogging implements Logging {
18
+ event(_event: LoggingEvent): void;
19
+ error(_m: string, _e: unknown): void;
20
+ log(_e: any): void;
21
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logging.js","sourceRoot":"","sources":["../../lib/logging.ts"],"names":[],"mappings":"AAkBA,MAAM,OAAO,WAAW;IACtB,KAAK,CAAC,MAAoB;QACxB,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IACtB,CAAC;IACD,KAAK,CAAC,EAAU,EAAE,EAAW;QAC3B,OAAO,CAAC,KAAK,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;IACxB,CAAC;IACD,GAAG,CAAC,EAAO;QACT,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAClB,CAAC;CACF"}
@@ -0,0 +1,22 @@
1
+ import { MagnetometerData } from "./magnetometer.js";
2
+ import { Service } from "./bluetooth-device-wrapper.js";
3
+ import { TypedServiceEvent, TypedServiceEventDispatcher } from "./service-events.js";
4
+ export declare class MagnetometerService implements Service {
5
+ private magnetometerDataCharacteristic;
6
+ private magnetometerPeriodCharacteristic;
7
+ private magnetometerBearingCharacteristic;
8
+ private magnetometerCalibrationCharacteristic;
9
+ private dispatchTypedEvent;
10
+ private queueGattOperation;
11
+ constructor(magnetometerDataCharacteristic: BluetoothRemoteGATTCharacteristic, magnetometerPeriodCharacteristic: BluetoothRemoteGATTCharacteristic, magnetometerBearingCharacteristic: BluetoothRemoteGATTCharacteristic, magnetometerCalibrationCharacteristic: BluetoothRemoteGATTCharacteristic, dispatchTypedEvent: TypedServiceEventDispatcher, queueGattOperation: <R>(action: () => Promise<R>) => Promise<R>);
12
+ static createService(gattServer: BluetoothRemoteGATTServer, dispatcher: TypedServiceEventDispatcher, queueGattOperation: <R>(action: () => Promise<R>) => Promise<R>, listenerInit: boolean): Promise<MagnetometerService | undefined>;
13
+ private dataViewToData;
14
+ getData(): Promise<MagnetometerData>;
15
+ getPeriod(): Promise<number>;
16
+ setPeriod(value: number): Promise<void>;
17
+ getBearing(): Promise<number>;
18
+ triggerCalibration(): Promise<void>;
19
+ startNotifications(type: TypedServiceEvent): Promise<void>;
20
+ stopNotifications(type: TypedServiceEvent): Promise<void>;
21
+ private characteristicForEvent;
22
+ }