usb 2.5.1 → 2.5.2
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.
- package/CHANGELOG.md +10 -0
- package/dist/index.d.ts +10 -6
- package/dist/index.js +27 -11
- package/dist/index.js.map +1 -1
- package/dist/webusb/webusb-device.d.ts +1 -1
- package/dist/webusb/webusb-device.js +4 -9
- package/dist/webusb/webusb-device.js.map +1 -1
- package/package.json +1 -1
- package/prebuilds/darwin-x64+arm64/node.napi.node +0 -0
- package/prebuilds/win32-ia32/node.napi.node +0 -0
- package/prebuilds/win32-x64/node.napi.node +0 -0
- package/src/hotplug/windows.cc +11 -6
- package/.eslintignore +0 -4
- package/.eslintrc.json +0 -87
- package/.gitattributes +0 -1
- package/.gitmodules +0 -3
- package/.vscode/launch.json +0 -15
- package/.vscode/tasks.json +0 -23
- package/libusb/.gitattributes +0 -7
- package/libusb/msvc/.gitattributes +0 -3
- package/tsc/index.ts +0 -75
- package/tsc/usb/bindings.ts +0 -310
- package/tsc/usb/capability.ts +0 -22
- package/tsc/usb/descriptors.ts +0 -180
- package/tsc/usb/device.ts +0 -331
- package/tsc/usb/endpoint.ts +0 -229
- package/tsc/usb/index.ts +0 -149
- package/tsc/usb/interface.ts +0 -167
- package/tsc/webusb/index.ts +0 -374
- package/tsc/webusb/webusb-device.ts +0 -490
- package/tsconfig.json +0 -17
- package/typedoc.json +0 -9
|
@@ -1,490 +0,0 @@
|
|
|
1
|
-
import * as usb from '../usb';
|
|
2
|
-
import { promisify } from 'util';
|
|
3
|
-
import { Endpoint, InEndpoint, OutEndpoint } from '../usb/endpoint';
|
|
4
|
-
|
|
5
|
-
const LIBUSB_TRANSFER_TYPE_MASK = 0x03;
|
|
6
|
-
const ENDPOINT_NUMBER_MASK = 0x7f;
|
|
7
|
-
const CLEAR_FEATURE = 0x01;
|
|
8
|
-
const ENDPOINT_HALT = 0x00;
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Wrapper to make a node-usb device look like a webusb device
|
|
12
|
-
*/
|
|
13
|
-
export class WebUSBDevice implements USBDevice {
|
|
14
|
-
public static async createInstance(device: usb.Device): Promise<WebUSBDevice | undefined> {
|
|
15
|
-
try {
|
|
16
|
-
const instance = new WebUSBDevice(device);
|
|
17
|
-
await instance.initialize();
|
|
18
|
-
return instance;
|
|
19
|
-
} catch {
|
|
20
|
-
return undefined;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
public readonly usbVersionMajor: number;
|
|
25
|
-
public readonly usbVersionMinor: number;
|
|
26
|
-
public readonly usbVersionSubminor: number;
|
|
27
|
-
public readonly deviceClass: number;
|
|
28
|
-
public readonly deviceSubclass: number;
|
|
29
|
-
public readonly deviceProtocol: number;
|
|
30
|
-
public readonly vendorId: number;
|
|
31
|
-
public readonly productId: number;
|
|
32
|
-
public readonly deviceVersionMajor: number;
|
|
33
|
-
public readonly deviceVersionMinor: number;
|
|
34
|
-
public readonly deviceVersionSubminor: number;
|
|
35
|
-
|
|
36
|
-
public manufacturerName?: string | undefined;
|
|
37
|
-
public productName?: string | undefined;
|
|
38
|
-
public serialNumber?: string | undefined;
|
|
39
|
-
public configurations: USBConfiguration[] = [];
|
|
40
|
-
|
|
41
|
-
private constructor(private device: usb.Device) {
|
|
42
|
-
const usbVersion = this.decodeVersion(device.deviceDescriptor.bcdUSB);
|
|
43
|
-
this.usbVersionMajor = usbVersion.major;
|
|
44
|
-
this.usbVersionMinor = usbVersion.minor;
|
|
45
|
-
this.usbVersionSubminor = usbVersion.sub;
|
|
46
|
-
|
|
47
|
-
this.deviceClass = device.deviceDescriptor.bDeviceClass;
|
|
48
|
-
this.deviceSubclass = device.deviceDescriptor.bDeviceSubClass;
|
|
49
|
-
this.deviceProtocol = device.deviceDescriptor.bDeviceProtocol;
|
|
50
|
-
this.vendorId = device.deviceDescriptor.idVendor;
|
|
51
|
-
this.productId = device.deviceDescriptor.idProduct;
|
|
52
|
-
|
|
53
|
-
const deviceVersion = this.decodeVersion(device.deviceDescriptor.bcdDevice);
|
|
54
|
-
this.deviceVersionMajor = deviceVersion.major;
|
|
55
|
-
this.deviceVersionMinor = deviceVersion.minor;
|
|
56
|
-
this.deviceVersionSubminor = deviceVersion.sub;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
public get configuration(): USBConfiguration | undefined {
|
|
60
|
-
if (!this.device.configDescriptor) {
|
|
61
|
-
return undefined;
|
|
62
|
-
}
|
|
63
|
-
const currentConfiguration = this.device.configDescriptor.bConfigurationValue;
|
|
64
|
-
return this.configurations.find(configuration => configuration.configurationValue === currentConfiguration);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
public get opened(): boolean {
|
|
68
|
-
return (!!this.device.interfaces);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
public async open(): Promise<void> {
|
|
72
|
-
try {
|
|
73
|
-
if (this.opened) {
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
this.device.open();
|
|
78
|
-
} catch (error) {
|
|
79
|
-
throw new Error(`open error: ${error}`);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
public async close(): Promise<void> {
|
|
84
|
-
try {
|
|
85
|
-
if (!this.opened) {
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
try {
|
|
90
|
-
if (this.configuration) {
|
|
91
|
-
for (const iface of this.configuration?.interfaces) {
|
|
92
|
-
await this._releaseInterface(iface.interfaceNumber);
|
|
93
|
-
// Re-create the USBInterface to set the claimed attribute
|
|
94
|
-
this.configuration.interfaces[this.configuration.interfaces.indexOf(iface)] = {
|
|
95
|
-
interfaceNumber: iface.interfaceNumber,
|
|
96
|
-
alternate: iface.alternate,
|
|
97
|
-
alternates: iface.alternates,
|
|
98
|
-
claimed: false
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
} catch (_error) {
|
|
103
|
-
// Ignore
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
this.device.close();
|
|
107
|
-
} catch (error) {
|
|
108
|
-
throw new Error(`close error: ${error}`);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
public async selectConfiguration(configurationValue: number): Promise<void> {
|
|
113
|
-
if (!this.opened || !this.device.configDescriptor) {
|
|
114
|
-
throw new Error('selectConfiguration error: invalid state');
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
if (this.device.configDescriptor.bConfigurationValue === configurationValue) {
|
|
118
|
-
return;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
const config = this.configurations.find(configuration => configuration.configurationValue === configurationValue);
|
|
122
|
-
if (!config) {
|
|
123
|
-
throw new Error('selectConfiguration error: configuration not found');
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
try {
|
|
127
|
-
const setConfiguration = promisify(this.device.setConfiguration).bind(this.device);
|
|
128
|
-
await setConfiguration(configurationValue);
|
|
129
|
-
} catch (error) {
|
|
130
|
-
throw new Error(`selectConfiguration error: ${error}`);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
public async claimInterface(interfaceNumber: number): Promise<void> {
|
|
135
|
-
if (!this.opened) {
|
|
136
|
-
throw new Error('claimInterface error: invalid state');
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
if (!this.configuration) {
|
|
140
|
-
throw new Error('claimInterface error: interface not found');
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
const iface = this.configuration.interfaces.find(usbInterface => usbInterface.interfaceNumber === interfaceNumber);
|
|
144
|
-
if (!iface) {
|
|
145
|
-
throw new Error('claimInterface error: interface not found');
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
if (iface.claimed) {
|
|
149
|
-
return;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
try {
|
|
153
|
-
this.device.interface(interfaceNumber).claim();
|
|
154
|
-
|
|
155
|
-
// Re-create the USBInterface to set the claimed attribute
|
|
156
|
-
this.configuration.interfaces[this.configuration.interfaces.indexOf(iface)] = {
|
|
157
|
-
interfaceNumber,
|
|
158
|
-
alternate: iface.alternate,
|
|
159
|
-
alternates: iface.alternates,
|
|
160
|
-
claimed: true
|
|
161
|
-
};
|
|
162
|
-
} catch (error) {
|
|
163
|
-
throw new Error(`claimInterface error: ${error}`);
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
public async releaseInterface(interfaceNumber: number): Promise<void> {
|
|
168
|
-
await this._releaseInterface(interfaceNumber);
|
|
169
|
-
|
|
170
|
-
if (this.configuration) {
|
|
171
|
-
const iface = this.configuration.interfaces.find(usbInterface => usbInterface.interfaceNumber === interfaceNumber);
|
|
172
|
-
if (iface) {
|
|
173
|
-
// Re-create the USBInterface to set the claimed attribute
|
|
174
|
-
this.configuration.interfaces[this.configuration.interfaces.indexOf(iface)] = {
|
|
175
|
-
interfaceNumber,
|
|
176
|
-
alternate: iface.alternate,
|
|
177
|
-
alternates: iface.alternates,
|
|
178
|
-
claimed: false
|
|
179
|
-
};
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
public async selectAlternateInterface(interfaceNumber: number, alternateSetting: number): Promise<void> {
|
|
185
|
-
if (!this.opened) {
|
|
186
|
-
throw new Error('selectAlternateInterface error: invalid state');
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
if (!this.configuration) {
|
|
190
|
-
throw new Error('selectAlternateInterface error: interface not found');
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
const iface = this.configuration.interfaces.find(usbInterface => usbInterface.interfaceNumber === interfaceNumber);
|
|
194
|
-
if (!iface) {
|
|
195
|
-
throw new Error('selectAlternateInterface error: interface not found');
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
if (!iface.claimed) {
|
|
199
|
-
throw new Error('selectAlternateInterface error: invalid state');
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
try {
|
|
203
|
-
const iface = this.device.interface(interfaceNumber);
|
|
204
|
-
const setAltSetting = promisify(iface.setAltSetting).bind(iface);
|
|
205
|
-
await setAltSetting(alternateSetting);
|
|
206
|
-
} catch (error) {
|
|
207
|
-
throw new Error(`selectAlternateInterface error: ${error}`);
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
public async controlTransferIn(setup: USBControlTransferParameters, length: number): Promise<USBInTransferResult> {
|
|
212
|
-
try {
|
|
213
|
-
const type = this.controlTransferParamsToType(setup, usb.LIBUSB_ENDPOINT_IN);
|
|
214
|
-
const controlTransfer = promisify(this.device.controlTransfer).bind(this.device);
|
|
215
|
-
const result = await controlTransfer(type, setup.request, setup.value, setup.index, length);
|
|
216
|
-
|
|
217
|
-
return {
|
|
218
|
-
data: result ? new DataView(new Uint8Array(result as Buffer).buffer) : undefined,
|
|
219
|
-
status: 'ok'
|
|
220
|
-
};
|
|
221
|
-
} catch (error) {
|
|
222
|
-
if (error.errno === usb.LIBUSB_TRANSFER_STALL) {
|
|
223
|
-
return {
|
|
224
|
-
status: 'stall'
|
|
225
|
-
};
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
if (error.errno === usb.LIBUSB_TRANSFER_OVERFLOW) {
|
|
229
|
-
return {
|
|
230
|
-
status: 'babble'
|
|
231
|
-
};
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
throw new Error(`controlTransferIn error: ${error}`);
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
public async controlTransferOut(setup: USBControlTransferParameters, data?: ArrayBuffer): Promise<USBOutTransferResult> {
|
|
239
|
-
try {
|
|
240
|
-
const type = this.controlTransferParamsToType(setup, usb.LIBUSB_ENDPOINT_OUT);
|
|
241
|
-
const controlTransfer = promisify(this.device.controlTransfer).bind(this.device);
|
|
242
|
-
const buffer = data ? Buffer.from(data) : Buffer.alloc(0);
|
|
243
|
-
const bytesWritten = <number>await controlTransfer(type, setup.request, setup.value, setup.index, buffer);
|
|
244
|
-
|
|
245
|
-
return {
|
|
246
|
-
bytesWritten,
|
|
247
|
-
status: 'ok'
|
|
248
|
-
};
|
|
249
|
-
} catch (error) {
|
|
250
|
-
if (error.errno === usb.LIBUSB_TRANSFER_STALL) {
|
|
251
|
-
return {
|
|
252
|
-
bytesWritten: 0,
|
|
253
|
-
status: 'stall'
|
|
254
|
-
};
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
throw new Error(`controlTransferOut error: ${error}`);
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
public async clearHalt(direction: USBDirection, endpointNumber: number): Promise<void> {
|
|
262
|
-
try {
|
|
263
|
-
const wIndex = endpointNumber | (direction === 'in' ? usb.LIBUSB_ENDPOINT_IN : usb.LIBUSB_ENDPOINT_OUT);
|
|
264
|
-
const controlTransfer = promisify(this.device.controlTransfer).bind(this.device);
|
|
265
|
-
await controlTransfer(usb.LIBUSB_RECIPIENT_ENDPOINT, CLEAR_FEATURE, ENDPOINT_HALT, wIndex, 0);
|
|
266
|
-
} catch (error) {
|
|
267
|
-
throw new Error(`clearHalt error: ${error}`);
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
public async transferIn(endpointNumber: number, length: number): Promise<USBInTransferResult> {
|
|
272
|
-
try {
|
|
273
|
-
const endpoint = this.getEndpoint(endpointNumber | usb.LIBUSB_ENDPOINT_IN) as InEndpoint;
|
|
274
|
-
const transfer = promisify(endpoint.transfer).bind(endpoint);
|
|
275
|
-
const result = await transfer(length);
|
|
276
|
-
|
|
277
|
-
return {
|
|
278
|
-
data: result ? new DataView(new Uint8Array(result).buffer) : undefined,
|
|
279
|
-
status: 'ok'
|
|
280
|
-
};
|
|
281
|
-
} catch (error) {
|
|
282
|
-
if (error.errno === usb.LIBUSB_TRANSFER_STALL) {
|
|
283
|
-
return {
|
|
284
|
-
status: 'stall'
|
|
285
|
-
};
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
if (error.errno === usb.LIBUSB_TRANSFER_OVERFLOW) {
|
|
289
|
-
return {
|
|
290
|
-
status: 'babble'
|
|
291
|
-
};
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
throw new Error(`transferIn error: ${error}`);
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
public async transferOut(endpointNumber: number, data: ArrayBuffer): Promise<USBOutTransferResult> {
|
|
299
|
-
try {
|
|
300
|
-
const endpoint = this.getEndpoint(endpointNumber | usb.LIBUSB_ENDPOINT_OUT) as OutEndpoint;
|
|
301
|
-
const transfer = promisify(endpoint.transfer).bind(endpoint);
|
|
302
|
-
const buffer = Buffer.from(data);
|
|
303
|
-
const bytesWritten = await transfer(buffer);
|
|
304
|
-
|
|
305
|
-
return {
|
|
306
|
-
bytesWritten,
|
|
307
|
-
status: 'ok'
|
|
308
|
-
};
|
|
309
|
-
} catch (error) {
|
|
310
|
-
if (error.errno === usb.LIBUSB_TRANSFER_STALL) {
|
|
311
|
-
return {
|
|
312
|
-
bytesWritten: 0,
|
|
313
|
-
status: 'stall'
|
|
314
|
-
};
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
throw new Error(`transferOut error: ${error}`);
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
public async reset(): Promise<void> {
|
|
322
|
-
try {
|
|
323
|
-
const reset = promisify(this.device.reset).bind(this.device);
|
|
324
|
-
await reset();
|
|
325
|
-
} catch (error) {
|
|
326
|
-
throw new Error(`reset error: ${error}`);
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
public async isochronousTransferIn(_endpointNumber: number, _packetLengths: number[]): Promise<USBIsochronousInTransferResult> {
|
|
331
|
-
throw new Error('isochronousTransferIn error: method not implemented');
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
public async isochronousTransferOut(_endpointNumber: number, _data: BufferSource, _packetLengths: number[]): Promise<USBIsochronousOutTransferResult> {
|
|
335
|
-
throw new Error('isochronousTransferOut error: method not implemented');
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
public async forget(): Promise<void> {
|
|
339
|
-
throw new Error('forget error: method not implemented');
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
private async initialize(): Promise<void> {
|
|
343
|
-
try {
|
|
344
|
-
if (!this.opened) {
|
|
345
|
-
this.device.open();
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
this.manufacturerName = await this.getStringDescriptor(this.device.deviceDescriptor.iManufacturer);
|
|
349
|
-
this.productName = await this.getStringDescriptor(this.device.deviceDescriptor.iProduct);
|
|
350
|
-
this.serialNumber = await this.getStringDescriptor(this.device.deviceDescriptor.iSerialNumber);
|
|
351
|
-
this.configurations = await this.getConfigurations();
|
|
352
|
-
} catch (error) {
|
|
353
|
-
throw new Error(`initialize error: ${error}`);
|
|
354
|
-
} finally {
|
|
355
|
-
if (this.opened) {
|
|
356
|
-
this.device.close();
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
private decodeVersion(version: number): { [key: string]: number } {
|
|
362
|
-
const hex = `0000${version.toString(16)}`.slice(-4);
|
|
363
|
-
return {
|
|
364
|
-
major: parseInt(hex.substr(0, 2), undefined),
|
|
365
|
-
minor: parseInt(hex.substr(2, 1), undefined),
|
|
366
|
-
sub: parseInt(hex.substr(3, 1), undefined),
|
|
367
|
-
};
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
private async getStringDescriptor(index: number): Promise<string> {
|
|
371
|
-
try {
|
|
372
|
-
const getStringDescriptor = promisify(this.device.getStringDescriptor).bind(this.device);
|
|
373
|
-
const buffer = await getStringDescriptor(index);
|
|
374
|
-
return buffer ? buffer.toString() : '';
|
|
375
|
-
} catch (error) {
|
|
376
|
-
return '';
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
private async getConfigurations(): Promise<USBConfiguration[]> {
|
|
381
|
-
const configs: USBConfiguration[] = [];
|
|
382
|
-
|
|
383
|
-
for (const config of this.device.allConfigDescriptors) {
|
|
384
|
-
const interfaces: USBInterface[] = [];
|
|
385
|
-
|
|
386
|
-
for (const iface of config.interfaces) {
|
|
387
|
-
const alternates: USBAlternateInterface[] = [];
|
|
388
|
-
|
|
389
|
-
for (const alternate of iface) {
|
|
390
|
-
const endpoints: USBEndpoint[] = [];
|
|
391
|
-
|
|
392
|
-
for (const endpoint of alternate.endpoints) {
|
|
393
|
-
endpoints.push({
|
|
394
|
-
endpointNumber: endpoint.bEndpointAddress & ENDPOINT_NUMBER_MASK,
|
|
395
|
-
direction: endpoint.bEndpointAddress & usb.LIBUSB_ENDPOINT_IN ? 'in' : 'out',
|
|
396
|
-
type: (endpoint.bmAttributes & LIBUSB_TRANSFER_TYPE_MASK) === usb.LIBUSB_TRANSFER_TYPE_BULK ? 'bulk'
|
|
397
|
-
: (endpoint.bmAttributes & LIBUSB_TRANSFER_TYPE_MASK) === usb.LIBUSB_TRANSFER_TYPE_INTERRUPT ? 'interrupt'
|
|
398
|
-
: 'isochronous',
|
|
399
|
-
packetSize: endpoint.wMaxPacketSize
|
|
400
|
-
});
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
alternates.push({
|
|
404
|
-
alternateSetting: alternate.bAlternateSetting,
|
|
405
|
-
interfaceClass: alternate.bInterfaceClass,
|
|
406
|
-
interfaceSubclass: alternate.bInterfaceSubClass,
|
|
407
|
-
interfaceProtocol: alternate.bInterfaceProtocol,
|
|
408
|
-
interfaceName: await this.getStringDescriptor(alternate.iInterface),
|
|
409
|
-
endpoints
|
|
410
|
-
});
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
const interfaceNumber = iface[0].bInterfaceNumber;
|
|
414
|
-
const alternate = alternates.find(alt => alt.alternateSetting === this.device.interface(interfaceNumber).altSetting);
|
|
415
|
-
|
|
416
|
-
if (alternate) {
|
|
417
|
-
interfaces.push({
|
|
418
|
-
interfaceNumber,
|
|
419
|
-
alternate,
|
|
420
|
-
alternates,
|
|
421
|
-
claimed: false
|
|
422
|
-
});
|
|
423
|
-
}
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
configs.push({
|
|
427
|
-
configurationValue: config.bConfigurationValue,
|
|
428
|
-
configurationName: await this.getStringDescriptor(config.iConfiguration),
|
|
429
|
-
interfaces
|
|
430
|
-
});
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
return configs;
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
private getEndpoint(address: number): Endpoint | undefined {
|
|
437
|
-
if (!this.device.interfaces) {
|
|
438
|
-
return undefined;
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
for (const iface of this.device.interfaces) {
|
|
442
|
-
const endpoint = iface.endpoint(address);
|
|
443
|
-
if (endpoint) {
|
|
444
|
-
return endpoint;
|
|
445
|
-
}
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
return undefined;
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
private controlTransferParamsToType(setup: USBControlTransferParameters, direction: number): number {
|
|
452
|
-
const recipient = setup.recipient === 'device' ? usb.LIBUSB_RECIPIENT_DEVICE
|
|
453
|
-
: setup.recipient === 'interface' ? usb.LIBUSB_RECIPIENT_INTERFACE
|
|
454
|
-
: setup.recipient === 'endpoint' ? usb.LIBUSB_RECIPIENT_ENDPOINT
|
|
455
|
-
: usb.LIBUSB_RECIPIENT_OTHER;
|
|
456
|
-
|
|
457
|
-
const requestType = setup.requestType === 'standard' ? usb.LIBUSB_REQUEST_TYPE_STANDARD
|
|
458
|
-
: setup.requestType === 'class' ? usb.LIBUSB_REQUEST_TYPE_CLASS
|
|
459
|
-
: usb.LIBUSB_REQUEST_TYPE_VENDOR;
|
|
460
|
-
|
|
461
|
-
return recipient | requestType | direction;
|
|
462
|
-
}
|
|
463
|
-
|
|
464
|
-
private async _releaseInterface(interfaceNumber: number): Promise<void> {
|
|
465
|
-
if (!this.opened) {
|
|
466
|
-
throw new Error('releaseInterface error: invalid state');
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
if (!this.configuration) {
|
|
470
|
-
throw new Error('releaseInterface error: interface not found');
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
const iface = this.configuration.interfaces.find(usbInterface => usbInterface.interfaceNumber === interfaceNumber);
|
|
474
|
-
if (!iface) {
|
|
475
|
-
throw new Error('releaseInterface error: interface not found');
|
|
476
|
-
}
|
|
477
|
-
|
|
478
|
-
if (!iface.claimed) {
|
|
479
|
-
return;
|
|
480
|
-
}
|
|
481
|
-
|
|
482
|
-
try {
|
|
483
|
-
const iface = this.device.interface(interfaceNumber);
|
|
484
|
-
const release = promisify(iface.release).bind(iface);
|
|
485
|
-
await release();
|
|
486
|
-
} catch (error) {
|
|
487
|
-
throw new Error(`releaseInterface error: ${error}`);
|
|
488
|
-
}
|
|
489
|
-
}
|
|
490
|
-
}
|
package/tsconfig.json
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "es5",
|
|
4
|
-
"strict": true,
|
|
5
|
-
"downlevelIteration": true,
|
|
6
|
-
"noImplicitReturns": true,
|
|
7
|
-
"noEmitOnError": true,
|
|
8
|
-
"noUnusedLocals": true,
|
|
9
|
-
"noUnusedParameters": true,
|
|
10
|
-
"sourceMap": true,
|
|
11
|
-
"declaration": true,
|
|
12
|
-
"outDir": "dist"
|
|
13
|
-
},
|
|
14
|
-
"include": [
|
|
15
|
-
"tsc"
|
|
16
|
-
]
|
|
17
|
-
}
|