@microbit/microbit-connection 0.0.0-alpha.1

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 (68) hide show
  1. package/README.md +36 -0
  2. package/build/accelerometer-service.d.ts +17 -0
  3. package/build/accelerometer-service.js +84 -0
  4. package/build/accelerometer-service.js.map +1 -0
  5. package/build/accelerometer.d.ts +9 -0
  6. package/build/accelerometer.js +12 -0
  7. package/build/accelerometer.js.map +1 -0
  8. package/build/async-util.d.ts +13 -0
  9. package/build/async-util.js +22 -0
  10. package/build/async-util.js.map +1 -0
  11. package/build/bluetooth-device-wrapper.d.ts +39 -0
  12. package/build/bluetooth-device-wrapper.js +316 -0
  13. package/build/bluetooth-device-wrapper.js.map +1 -0
  14. package/build/bluetooth-profile.d.ts +139 -0
  15. package/build/bluetooth-profile.js +83 -0
  16. package/build/bluetooth-profile.js.map +1 -0
  17. package/build/bluetooth.d.ts +50 -0
  18. package/build/bluetooth.js +247 -0
  19. package/build/bluetooth.js.map +1 -0
  20. package/build/board-id.d.ts +35 -0
  21. package/build/board-id.js +69 -0
  22. package/build/board-id.js.map +1 -0
  23. package/build/board-serial-info.d.ts +14 -0
  24. package/build/board-serial-info.js +47 -0
  25. package/build/board-serial-info.js.map +1 -0
  26. package/build/constants.d.ts +47 -0
  27. package/build/constants.js +69 -0
  28. package/build/constants.js.map +1 -0
  29. package/build/device.d.ts +202 -0
  30. package/build/device.js +153 -0
  31. package/build/device.js.map +1 -0
  32. package/build/events.d.ts +101 -0
  33. package/build/events.js +19 -0
  34. package/build/events.js.map +1 -0
  35. package/build/hex-flash-data-source.d.ts +9 -0
  36. package/build/hex-flash-data-source.js +50 -0
  37. package/build/hex-flash-data-source.js.map +1 -0
  38. package/build/index.d.ts +7 -0
  39. package/build/index.js +7 -0
  40. package/build/index.js.map +1 -0
  41. package/build/logging.d.ts +21 -0
  42. package/build/logging.js +10 -0
  43. package/build/logging.js.map +1 -0
  44. package/build/service-events.d.ts +9 -0
  45. package/build/service-events.js +11 -0
  46. package/build/service-events.js.map +1 -0
  47. package/build/setupTests.d.ts +6 -0
  48. package/build/setupTests.js.map +1 -0
  49. package/build/usb-device-wrapper.d.ts +46 -0
  50. package/build/usb-device-wrapper.js +347 -0
  51. package/build/usb-device-wrapper.js.map +1 -0
  52. package/build/usb-partial-flashing-utils.d.ts +17 -0
  53. package/build/usb-partial-flashing-utils.js +122 -0
  54. package/build/usb-partial-flashing-utils.js.map +1 -0
  55. package/build/usb-partial-flashing.d.ts +63 -0
  56. package/build/usb-partial-flashing.js +270 -0
  57. package/build/usb-partial-flashing.js.map +1 -0
  58. package/build/usb-radio-bridge.d.ts +28 -0
  59. package/build/usb-radio-bridge.js +318 -0
  60. package/build/usb-radio-bridge.js.map +1 -0
  61. package/build/usb-serial-protocol.d.ts +66 -0
  62. package/build/usb-serial-protocol.js +171 -0
  63. package/build/usb-serial-protocol.js.map +1 -0
  64. package/build/usb.d.ts +61 -0
  65. package/build/usb.js +451 -0
  66. package/build/usb.js.map +1 -0
  67. package/package.json +32 -0
  68. package/vite.config.ts +32 -0
@@ -0,0 +1,47 @@
1
+ /**
2
+ * (c) 2021, Micro:bit Educational Foundation and contributors
3
+ *
4
+ * SPDX-License-Identifier: MIT
5
+ */
6
+ import { BoardId } from "./board-id";
7
+ export class BoardSerialInfo {
8
+ constructor(id, familyId, hic) {
9
+ Object.defineProperty(this, "id", {
10
+ enumerable: true,
11
+ configurable: true,
12
+ writable: true,
13
+ value: id
14
+ });
15
+ Object.defineProperty(this, "familyId", {
16
+ enumerable: true,
17
+ configurable: true,
18
+ writable: true,
19
+ value: familyId
20
+ });
21
+ Object.defineProperty(this, "hic", {
22
+ enumerable: true,
23
+ configurable: true,
24
+ writable: true,
25
+ value: hic
26
+ });
27
+ }
28
+ static parse(device, log) {
29
+ const serial = device.serialNumber;
30
+ if (!serial) {
31
+ throw new Error("Could not detected ID from connected board.");
32
+ }
33
+ if (serial.length !== 48) {
34
+ log(`USB serial number unexpected length: ${serial.length}`);
35
+ }
36
+ const id = serial.substring(0, 4);
37
+ const familyId = serial.substring(4, 8);
38
+ const hic = serial.slice(-8);
39
+ return new BoardSerialInfo(BoardId.parse(id), familyId, hic);
40
+ }
41
+ eq(other) {
42
+ return (other.id === this.id &&
43
+ other.familyId === this.familyId &&
44
+ other.hic === this.hic);
45
+ }
46
+ }
47
+ //# sourceMappingURL=board-serial-info.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"board-serial-info.js","sourceRoot":"","sources":["../lib/board-serial-info.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAErC,MAAM,OAAO,eAAe;IAC1B,YACS,EAAW,EACX,QAAgB,EAChB,GAAW;QAFlB;;;;mBAAO,EAAE;WAAS;QAClB;;;;mBAAO,QAAQ;WAAQ;QACvB;;;;mBAAO,GAAG;WAAQ;IACjB,CAAC;IACJ,MAAM,CAAC,KAAK,CAAC,MAAiB,EAAE,GAA0B;QACxD,MAAM,MAAM,GAAG,MAAM,CAAC,YAAY,CAAC;QACnC,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAC;QACjE,CAAC;QACD,IAAI,MAAM,CAAC,MAAM,KAAK,EAAE,EAAE,CAAC;YACzB,GAAG,CAAC,wCAAwC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC;QAC/D,CAAC;QACD,MAAM,EAAE,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QAClC,MAAM,QAAQ,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QACxC,MAAM,GAAG,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;QAC7B,OAAO,IAAI,eAAe,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,EAAE,QAAQ,EAAE,GAAG,CAAC,CAAC;IAC/D,CAAC;IAED,EAAE,CAAC,KAAsB;QACvB,OAAO,CACL,KAAK,CAAC,EAAE,KAAK,IAAI,CAAC,EAAE;YACpB,KAAK,CAAC,QAAQ,KAAK,IAAI,CAAC,QAAQ;YAChC,KAAK,CAAC,GAAG,KAAK,IAAI,CAAC,GAAG,CACvB,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,47 @@
1
+ /**
2
+ * (c) 2021, Micro:bit Educational Foundation and contributors
3
+ *
4
+ * SPDX-License-Identifier: MIT
5
+ */
6
+ export declare const FICR: {
7
+ CODEPAGESIZE: number;
8
+ CODESIZE: number;
9
+ };
10
+ export declare const DapCmd: {
11
+ DAP_INFO: number;
12
+ DAP_CONNECT: number;
13
+ DAP_DISCONNECT: number;
14
+ DAP_TRANSFER: number;
15
+ DAP_TRANSFER_BLOCK: number;
16
+ };
17
+ export declare const Csw: {
18
+ CSW_SIZE: number;
19
+ CSW_SIZE32: number;
20
+ CSW_ADDRINC: number;
21
+ CSW_SADDRINC: number;
22
+ CSW_DBGSTAT: number;
23
+ CSW_HPROT: number;
24
+ CSW_MSTRDBG: number;
25
+ CSW_RESERVED: number;
26
+ CSW_VALUE: number;
27
+ };
28
+ export declare const DapVal: {
29
+ AP_ACC: number;
30
+ READ: number;
31
+ WRITE: number;
32
+ };
33
+ export declare const ApReg: {
34
+ CSW: number;
35
+ TAR: number;
36
+ DRW: number;
37
+ };
38
+ export declare const CortexSpecialReg: {
39
+ DEMCR: number;
40
+ DEMCR_VC_CORERESET: number;
41
+ CPUID: number;
42
+ DHCSR: number;
43
+ S_RESET_ST: number;
44
+ NVIC_AIRCR: number;
45
+ NVIC_AIRCR_VECTKEY: number;
46
+ NVIC_AIRCR_SYSRESETREQ: number;
47
+ };
@@ -0,0 +1,69 @@
1
+ /**
2
+ * (c) 2021, Micro:bit Educational Foundation and contributors
3
+ *
4
+ * SPDX-License-Identifier: MIT
5
+ */
6
+ // https://github.com/mmoskal/dapjs/blob/a32f11f54e9e76a9c61896ddd425c1cb1a29c143/src/dap/constants.ts
7
+ // https://github.com/mmoskal/dapjs/blob/a32f11f54e9e76a9c61896ddd425c1cb1a29c143/src/cortex/constants.ts
8
+ // CRA's build tooling doesn't support const enums so we've converted them to prefixed constants here.
9
+ // If we move this to a separate library then we can replace them.
10
+ // In the meantime we should prune the list below to what we actually use.
11
+ // FICR Registers
12
+ export const FICR = {
13
+ CODEPAGESIZE: 0x10000000 | 0x10,
14
+ CODESIZE: 0x10000000 | 0x14,
15
+ };
16
+ export const DapCmd = {
17
+ DAP_INFO: 0x00,
18
+ DAP_CONNECT: 0x02,
19
+ DAP_DISCONNECT: 0x03,
20
+ DAP_TRANSFER: 0x05,
21
+ DAP_TRANSFER_BLOCK: 0x06,
22
+ // Many more.
23
+ };
24
+ export const Csw = {
25
+ CSW_SIZE: 0x00000007,
26
+ CSW_SIZE32: 0x00000002,
27
+ CSW_ADDRINC: 0x00000030,
28
+ CSW_SADDRINC: 0x00000010,
29
+ CSW_DBGSTAT: 0x00000040,
30
+ CSW_HPROT: 0x02000000,
31
+ CSW_MSTRDBG: 0x20000000,
32
+ CSW_RESERVED: 0x01000000,
33
+ CSW_VALUE: -1, // see below
34
+ // Many more.
35
+ };
36
+ Csw.CSW_VALUE =
37
+ Csw.CSW_RESERVED |
38
+ Csw.CSW_MSTRDBG |
39
+ Csw.CSW_HPROT |
40
+ Csw.CSW_DBGSTAT |
41
+ Csw.CSW_SADDRINC;
42
+ export const DapVal = {
43
+ AP_ACC: 1 << 0,
44
+ READ: 1 << 1,
45
+ WRITE: 0 << 1,
46
+ // More.
47
+ };
48
+ export const ApReg = {
49
+ CSW: 0x00,
50
+ TAR: 0x04,
51
+ DRW: 0x0c,
52
+ // More.
53
+ };
54
+ export const CortexSpecialReg = {
55
+ // Debug Exception and Monitor Control Register
56
+ DEMCR: 0xe000edfc,
57
+ // DWTENA in armv6 architecture reference manual
58
+ DEMCR_VC_CORERESET: 1 << 0,
59
+ // CPUID Register
60
+ CPUID: 0xe000ed00,
61
+ // Debug Halting Control and Status Register
62
+ DHCSR: 0xe000edf0,
63
+ S_RESET_ST: 1 << 25,
64
+ NVIC_AIRCR: 0xe000ed0c,
65
+ NVIC_AIRCR_VECTKEY: 0x5fa << 16,
66
+ NVIC_AIRCR_SYSRESETREQ: 1 << 2,
67
+ // Many more.
68
+ };
69
+ //# 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;AACjB,MAAM,CAAC,MAAM,IAAI,GAAG;IAClB,YAAY,EAAE,UAAU,GAAG,IAAI;IAC/B,QAAQ,EAAE,UAAU,GAAG,IAAI;CAC5B,CAAC;AAEF,MAAM,CAAC,MAAM,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;AAEF,MAAM,CAAC,MAAM,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,GAAG,CAAC,SAAS;IACX,GAAG,CAAC,YAAY;QAChB,GAAG,CAAC,WAAW;QACf,GAAG,CAAC,SAAS;QACb,GAAG,CAAC,WAAW;QACf,GAAG,CAAC,YAAY,CAAC;AAEnB,MAAM,CAAC,MAAM,MAAM,GAAG;IACpB,MAAM,EAAE,CAAC,IAAI,CAAC;IACd,IAAI,EAAE,CAAC,IAAI,CAAC;IACZ,KAAK,EAAE,CAAC,IAAI,CAAC;IACb,QAAQ;CACT,CAAC;AAEF,MAAM,CAAC,MAAM,KAAK,GAAG;IACnB,GAAG,EAAE,IAAI;IACT,GAAG,EAAE,IAAI;IACT,GAAG,EAAE,IAAI;IACT,QAAQ;CACT,CAAC;AAEF,MAAM,CAAC,MAAM,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"}
@@ -0,0 +1,202 @@
1
+ /**
2
+ * (c) 2021, Micro:bit Educational Foundation and contributors
3
+ *
4
+ * SPDX-License-Identifier: MIT
5
+ */
6
+ import { TypedEventTarget } from "./events";
7
+ import { BoardId } from "./board-id";
8
+ /**
9
+ * Specific identified error types.
10
+ *
11
+ * New members may be added over time.
12
+ */
13
+ export type DeviceErrorCode =
14
+ /**
15
+ * Device not selected, e.g. because the user cancelled the dialog.
16
+ */
17
+ "no-device-selected"
18
+ /**
19
+ * Device not found, perhaps because it doesn't have new enough firmware (for V1).
20
+ */
21
+ | "update-req"
22
+ /**
23
+ * Unable to claim the interface, usually because it's in use in another tab/window.
24
+ */
25
+ | "clear-connect"
26
+ /**
27
+ * The device was found to be disconnected.
28
+ */
29
+ | "device-disconnected"
30
+ /**
31
+ * A communication timeout occurred.
32
+ */
33
+ | "timeout-error"
34
+ /**
35
+ * This is the fallback error case suggesting that the user reconnects their device.
36
+ */
37
+ | "reconnect-microbit";
38
+ /**
39
+ * Error type used for all interactions with this module.
40
+ *
41
+ * The code indicates the error type and may be suitable for providing
42
+ * translated error messages.
43
+ *
44
+ * The message is the underlying message text and will usually be in
45
+ * English.
46
+ */
47
+ export declare class DeviceError extends Error {
48
+ code: DeviceErrorCode;
49
+ constructor({ code, message }: {
50
+ code: DeviceErrorCode;
51
+ message?: string;
52
+ });
53
+ }
54
+ /**
55
+ * Tracks connection status,
56
+ */
57
+ export declare enum ConnectionStatus {
58
+ /**
59
+ * Determining whether the connection type is supported requires
60
+ * initialize() to complete.
61
+ */
62
+ SUPPORT_NOT_KNOWN = 0,
63
+ /**
64
+ * Not supported.
65
+ */
66
+ NOT_SUPPORTED = "NOT_SUPPORTED",
67
+ /**
68
+ * Supported but no device available.
69
+ *
70
+ * This will be the case even when a device is physically connected
71
+ * but has not been connected via the browser security UI.
72
+ */
73
+ NO_AUTHORIZED_DEVICE = "NO_DEVICE",
74
+ /**
75
+ * Authorized device available but we haven't connected to it.
76
+ */
77
+ NOT_CONNECTED = "NOT_CONNECTED",
78
+ /**
79
+ * Connected.
80
+ */
81
+ CONNECTED = "CONNECTED"
82
+ }
83
+ export declare class FlashDataError extends Error {
84
+ }
85
+ export interface FlashDataSource {
86
+ /**
87
+ * For now we only support partially flashing contiguous data.
88
+ * This can be generated from microbit-fs directly (via getIntelHexBytes())
89
+ * or from an existing Intel Hex via slicePad.
90
+ *
91
+ * This interface is quite confusing and worth revisiting.
92
+ *
93
+ * @param boardId the id of the board.
94
+ * @throws FlashDataError if we cannot generate hex data.
95
+ */
96
+ partialFlashData(boardId: BoardId): Promise<Uint8Array>;
97
+ /**
98
+ * @param boardId the id of the board.
99
+ * @returns A board-specific (non-universal) Intel Hex file for the given board id.
100
+ * @throws FlashDataError if we cannot generate hex data.
101
+ */
102
+ fullFlashData(boardId: BoardId): Promise<string>;
103
+ }
104
+ export interface ConnectOptions {
105
+ serial?: boolean;
106
+ name?: string;
107
+ }
108
+ export type BoardVersion = "V1" | "V2";
109
+ export declare class ConnectionStatusEvent extends Event {
110
+ readonly status: ConnectionStatus;
111
+ constructor(status: ConnectionStatus);
112
+ }
113
+ export declare class SerialDataEvent extends Event {
114
+ readonly data: string;
115
+ constructor(data: string);
116
+ }
117
+ export declare class SerialResetEvent extends Event {
118
+ constructor();
119
+ }
120
+ export declare class SerialErrorEvent extends Event {
121
+ readonly error: unknown;
122
+ constructor(error: unknown);
123
+ }
124
+ export declare class FlashEvent extends Event {
125
+ constructor();
126
+ }
127
+ export declare class BeforeRequestDevice extends Event {
128
+ constructor();
129
+ }
130
+ export declare class AfterRequestDevice extends Event {
131
+ constructor();
132
+ }
133
+ export declare class DeviceConnectionEventMap {
134
+ "status": ConnectionStatusEvent;
135
+ "serialdata": SerialDataEvent;
136
+ "serialreset": Event;
137
+ "serialerror": Event;
138
+ "flash": Event;
139
+ "beforerequestdevice": Event;
140
+ "afterrequestdevice": Event;
141
+ }
142
+ export interface DeviceConnection extends TypedEventTarget<DeviceConnectionEventMap> {
143
+ status: ConnectionStatus;
144
+ /**
145
+ * Initializes the device.
146
+ */
147
+ initialize(): Promise<void>;
148
+ /**
149
+ * Removes all listeners.
150
+ */
151
+ dispose(): void;
152
+ /**
153
+ * Connects to a currently paired device or requests pairing.
154
+ * Throws on error.
155
+ *
156
+ * @returns the final connection status.
157
+ */
158
+ connect(options?: ConnectOptions): Promise<ConnectionStatus>;
159
+ /**
160
+ * Get the board version.
161
+ *
162
+ * @returns the board version or null if there is no connection.
163
+ */
164
+ getBoardVersion(): BoardVersion | undefined;
165
+ /**
166
+ * Flash the micro:bit.
167
+ *
168
+ * @param dataSource The data to use.
169
+ * @param options Flash options and progress callback.
170
+ */
171
+ flash?(dataSource: FlashDataSource, options: {
172
+ /**
173
+ * True to use a partial flash where possible, false to force a full flash.
174
+ */
175
+ partial: boolean;
176
+ /**
177
+ * A progress callback. Called with undefined when the process is complete or has failed.
178
+ *
179
+ * Requesting a partial flash doesn't guarantee one is performed. Partial flashes are avoided
180
+ * if too many blocks have changed and failed partial flashes are retried as full flashes.
181
+ * The partial parameter reports the flash type currently in progress.
182
+ */
183
+ progress: (percentage: number | undefined, partial: boolean) => void;
184
+ }): Promise<void>;
185
+ /**
186
+ * Disconnect from the device.
187
+ */
188
+ disconnect(): Promise<void>;
189
+ /**
190
+ * Write serial data to the device.
191
+ *
192
+ * Does nothting if there is no connection.
193
+ *
194
+ * @param data The data to write.
195
+ * @returns A promise that resolves when the write is complete.
196
+ */
197
+ serialWrite(data: string): Promise<void>;
198
+ /**
199
+ * Clear device to enable chooseDevice.
200
+ */
201
+ clearDevice(): void;
202
+ }
@@ -0,0 +1,153 @@
1
+ /**
2
+ * Error type used for all interactions with this module.
3
+ *
4
+ * The code indicates the error type and may be suitable for providing
5
+ * translated error messages.
6
+ *
7
+ * The message is the underlying message text and will usually be in
8
+ * English.
9
+ */
10
+ export class DeviceError extends Error {
11
+ constructor({ code, message }) {
12
+ super(message);
13
+ Object.defineProperty(this, "code", {
14
+ enumerable: true,
15
+ configurable: true,
16
+ writable: true,
17
+ value: void 0
18
+ });
19
+ this.code = code;
20
+ }
21
+ }
22
+ /**
23
+ * Tracks connection status,
24
+ */
25
+ export var ConnectionStatus;
26
+ (function (ConnectionStatus) {
27
+ /**
28
+ * Determining whether the connection type is supported requires
29
+ * initialize() to complete.
30
+ */
31
+ ConnectionStatus[ConnectionStatus["SUPPORT_NOT_KNOWN"] = 0] = "SUPPORT_NOT_KNOWN";
32
+ /**
33
+ * Not supported.
34
+ */
35
+ ConnectionStatus["NOT_SUPPORTED"] = "NOT_SUPPORTED";
36
+ /**
37
+ * Supported but no device available.
38
+ *
39
+ * This will be the case even when a device is physically connected
40
+ * but has not been connected via the browser security UI.
41
+ */
42
+ ConnectionStatus["NO_AUTHORIZED_DEVICE"] = "NO_DEVICE";
43
+ /**
44
+ * Authorized device available but we haven't connected to it.
45
+ */
46
+ ConnectionStatus["NOT_CONNECTED"] = "NOT_CONNECTED";
47
+ /**
48
+ * Connected.
49
+ */
50
+ ConnectionStatus["CONNECTED"] = "CONNECTED";
51
+ })(ConnectionStatus || (ConnectionStatus = {}));
52
+ export class FlashDataError extends Error {
53
+ }
54
+ export class ConnectionStatusEvent extends Event {
55
+ constructor(status) {
56
+ super("status");
57
+ Object.defineProperty(this, "status", {
58
+ enumerable: true,
59
+ configurable: true,
60
+ writable: true,
61
+ value: status
62
+ });
63
+ }
64
+ }
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
+ export class BeforeRequestDevice extends Event {
98
+ constructor() {
99
+ super("beforerequestdevice");
100
+ }
101
+ }
102
+ export class AfterRequestDevice extends Event {
103
+ constructor() {
104
+ super("afterrequestdevice");
105
+ }
106
+ }
107
+ export class DeviceConnectionEventMap {
108
+ constructor() {
109
+ Object.defineProperty(this, "status", {
110
+ enumerable: true,
111
+ configurable: true,
112
+ writable: true,
113
+ value: void 0
114
+ });
115
+ Object.defineProperty(this, "serialdata", {
116
+ enumerable: true,
117
+ configurable: true,
118
+ writable: true,
119
+ value: void 0
120
+ });
121
+ Object.defineProperty(this, "serialreset", {
122
+ enumerable: true,
123
+ configurable: true,
124
+ writable: true,
125
+ value: void 0
126
+ });
127
+ Object.defineProperty(this, "serialerror", {
128
+ enumerable: true,
129
+ configurable: true,
130
+ writable: true,
131
+ value: void 0
132
+ });
133
+ Object.defineProperty(this, "flash", {
134
+ enumerable: true,
135
+ configurable: true,
136
+ writable: true,
137
+ value: void 0
138
+ });
139
+ Object.defineProperty(this, "beforerequestdevice", {
140
+ enumerable: true,
141
+ configurable: true,
142
+ writable: true,
143
+ value: void 0
144
+ });
145
+ Object.defineProperty(this, "afterrequestdevice", {
146
+ enumerable: true,
147
+ configurable: true,
148
+ writable: true,
149
+ value: void 0
150
+ });
151
+ }
152
+ }
153
+ //# sourceMappingURL=device.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"device.js","sourceRoot":"","sources":["../lib/device.ts"],"names":[],"mappings":"AAuCA;;;;;;;;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,gBAyBX;AAzBD,WAAY,gBAAgB;IAC1B;;;OAGG;IACH,iFAAiB,CAAA;IACjB;;OAEG;IACH,mDAA+B,CAAA;IAC/B;;;;;OAKG;IACH,sDAAkC,CAAA;IAClC;;OAEG;IACH,mDAA+B,CAAA;IAC/B;;OAEG;IACH,2CAAuB,CAAA;AACzB,CAAC,EAzBW,gBAAgB,KAAhB,gBAAgB,QAyB3B;AAED,MAAM,OAAO,cAAe,SAAQ,KAAK;CAAG;AA+B5C,MAAM,OAAO,qBAAsB,SAAQ,KAAK;IAC9C,YAA4B,MAAwB;QAClD,KAAK,CAAC,QAAQ,CAAC,CAAC;QADN;;;;mBAAgB,MAAM;WAAkB;IAEpD,CAAC;CACF;AAED,MAAM,OAAO,eAAgB,SAAQ,KAAK;IACxC,YAA4B,IAAY;QACtC,KAAK,CAAC,YAAY,CAAC,CAAC;QADV;;;;mBAAgB,IAAI;WAAQ;IAExC,CAAC;CACF;AAED,MAAM,OAAO,gBAAiB,SAAQ,KAAK;IACzC;QACE,KAAK,CAAC,aAAa,CAAC,CAAC;IACvB,CAAC;CACF;AAED,MAAM,OAAO,gBAAiB,SAAQ,KAAK;IACzC,YAA4B,KAAc;QACxC,KAAK,CAAC,aAAa,CAAC,CAAC;QADX;;;;mBAAgB,KAAK;WAAS;IAE1C,CAAC;CACF;AAED,MAAM,OAAO,UAAW,SAAQ,KAAK;IACnC;QACE,KAAK,CAAC,OAAO,CAAC,CAAC;IACjB,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,wBAAwB;IAArC;QACE,4BAAA,QAAQ;;;;;WAAwB;QAChC,4BAAA,YAAY;;;;;WAAkB;QAC9B,4BAAA,aAAa;;;;;WAAQ;QACrB,4BAAA,aAAa;;;;;WAAQ;QACrB,4BAAA,OAAO;;;;;WAAQ;QACf,4BAAA,qBAAqB;;;;;WAAQ;QAC7B,4BAAA,oBAAoB;;;;;WAAQ;IAC9B,CAAC;CAAA"}
@@ -0,0 +1,101 @@
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
+ 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 TypedEventTarget<M extends ValueIsEvent<M>> extends EventTarget {
94
+ /**
95
+ * Dispatches a synthetic event event to target and returns true if either
96
+ * event's cancelable attribute value is false or its preventDefault() method
97
+ * was not invoked, and false otherwise.
98
+ */
99
+ dispatchTypedEvent<T extends keyof M>(_type: T, event: M[T]): boolean;
100
+ }
101
+ export {};
@@ -0,0 +1,19 @@
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
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
9
+ export class TypedEventTarget extends EventTarget {
10
+ /**
11
+ * Dispatches a synthetic event event to target and returns true if either
12
+ * event's cancelable attribute value is false or its preventDefault() method
13
+ * was not invoked, and false otherwise.
14
+ */
15
+ dispatchTypedEvent(_type, event) {
16
+ return super.dispatchEvent(event);
17
+ }
18
+ }
19
+ //# sourceMappingURL=events.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"events.js","sourceRoot":"","sources":["../lib/events.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAyGH,4EAA4E;AAC5E,MAAM,OAAO,gBAA4C,SAAQ,WAAW;IAC1E;;;;OAIG;IACI,kBAAkB,CAAoB,KAAQ,EAAE,KAAW;QAChE,OAAO,KAAK,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC;CACF"}
@@ -0,0 +1,9 @@
1
+ import { BoardId } from "./board-id";
2
+ import { FlashDataSource } from "./device";
3
+ export declare class HexFlashDataSource implements FlashDataSource {
4
+ private hex;
5
+ constructor(hex: string);
6
+ partialFlashData(boardId: BoardId): Promise<Uint8Array>;
7
+ fullFlashData(boardId: BoardId): Promise<string>;
8
+ private matchingPart;
9
+ }