usb 1.9.2 → 2.0.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/.eslintignore +4 -0
- package/.eslintrc.json +87 -0
- package/.gitattributes +1 -0
- package/.vscode/launch.json +15 -0
- package/.vscode/tasks.json +23 -0
- package/CHANGELOG.md +13 -0
- package/README.md +400 -175
- package/dist/index.d.ts +17 -0
- package/dist/index.js +138 -0
- package/dist/index.js.map +1 -0
- package/dist/usb/bindings.d.ts +253 -0
- package/dist/usb/bindings.js +10 -0
- package/dist/usb/bindings.js.map +1 -0
- package/dist/usb/capability.d.ts +14 -0
- package/dist/usb/capability.js +18 -0
- package/dist/usb/capability.js.map +1 -0
- package/dist/usb/descriptors.d.ts +129 -0
- package/dist/usb/descriptors.js +3 -0
- package/dist/usb/descriptors.js.map +1 -0
- package/dist/usb/device.d.ts +94 -0
- package/dist/usb/device.js +300 -0
- package/dist/usb/device.js.map +1 -0
- package/dist/usb/endpoint.d.ts +91 -0
- package/dist/usb/endpoint.js +236 -0
- package/dist/usb/endpoint.js.map +1 -0
- package/dist/usb/index.d.ts +25 -0
- package/dist/usb/index.js +116 -0
- package/dist/usb/index.js.map +1 -0
- package/dist/usb/interface.d.ts +78 -0
- package/dist/usb/interface.js +137 -0
- package/dist/usb/interface.js.map +1 -0
- package/dist/webusb/index.d.ts +56 -0
- package/dist/webusb/index.js +412 -0
- package/dist/webusb/index.js.map +1 -0
- package/dist/webusb/mutex.d.ts +22 -0
- package/dist/webusb/mutex.js +89 -0
- package/dist/webusb/mutex.js.map +1 -0
- package/dist/webusb/webusb-device.d.ts +49 -0
- package/dist/webusb/webusb-device.js +892 -0
- package/dist/webusb/webusb-device.js.map +1 -0
- package/package.json +28 -15
- package/prebuilds/win32-ia32/node.napi.node +0 -0
- package/prebuilds/win32-x64/node.napi.node +0 -0
- package/src/device.cc +2 -2
- package/test/usb.coffee +13 -7
- package/test/webusb.coffee +189 -0
- package/tsc/index.ts +72 -0
- package/tsc/usb/bindings.ts +304 -0
- package/tsc/usb/capability.ts +22 -0
- package/tsc/usb/descriptors.ts +180 -0
- package/tsc/usb/device.ts +325 -0
- package/tsc/usb/endpoint.ts +228 -0
- package/tsc/usb/index.ts +111 -0
- package/tsc/usb/interface.ts +172 -0
- package/tsc/webusb/index.ts +363 -0
- package/tsc/webusb/mutex.ts +38 -0
- package/tsc/webusb/webusb-device.ts +541 -0
- package/tsconfig.json +17 -0
- package/typedoc.json +9 -0
- package/usb.js +0 -573
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import * as usb from './bindings';
|
|
3
|
+
import { Interface } from './interface';
|
|
4
|
+
import { Capability } from './capability';
|
|
5
|
+
import { BosDescriptor, ConfigDescriptor } from './descriptors';
|
|
6
|
+
export declare class ExtendedDevice {
|
|
7
|
+
/**
|
|
8
|
+
* List of Interface objects for the interfaces of the default configuration of the device.
|
|
9
|
+
*/
|
|
10
|
+
interfaces: Interface[] | undefined;
|
|
11
|
+
private _timeout;
|
|
12
|
+
/**
|
|
13
|
+
* Timeout in milliseconds to use for control transfers.
|
|
14
|
+
*/
|
|
15
|
+
get timeout(): number;
|
|
16
|
+
set timeout(value: number);
|
|
17
|
+
/**
|
|
18
|
+
* Object with properties for the fields of the active configuration descriptor.
|
|
19
|
+
*/
|
|
20
|
+
get configDescriptor(): ConfigDescriptor | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* Contains all config descriptors of the device (same structure as .configDescriptor above)
|
|
23
|
+
*/
|
|
24
|
+
get allConfigDescriptors(): ConfigDescriptor[];
|
|
25
|
+
/**
|
|
26
|
+
* Contains the parent of the device, such as a hub. If there is no parent this property is set to `null`.
|
|
27
|
+
*/
|
|
28
|
+
get parent(): usb.Device;
|
|
29
|
+
/**
|
|
30
|
+
* Open the device.
|
|
31
|
+
* @param defaultConfig
|
|
32
|
+
*/
|
|
33
|
+
open(this: usb.Device, defaultConfig?: boolean): void;
|
|
34
|
+
/**
|
|
35
|
+
* Close the device.
|
|
36
|
+
*
|
|
37
|
+
* The device must be open to use this method.
|
|
38
|
+
*/
|
|
39
|
+
close(this: usb.Device): void;
|
|
40
|
+
/**
|
|
41
|
+
* Set the device configuration to something other than the default (0). To use this, first call `.open(false)` (which tells it not to auto configure),
|
|
42
|
+
* then before claiming an interface, call this method.
|
|
43
|
+
*
|
|
44
|
+
* The device must be open to use this method.
|
|
45
|
+
* @param desired
|
|
46
|
+
* @param callback
|
|
47
|
+
*/
|
|
48
|
+
setConfiguration(this: usb.Device, desired: number, callback?: (error: usb.LibUSBException | undefined) => void): void;
|
|
49
|
+
/**
|
|
50
|
+
* Perform a control transfer with `libusb_control_transfer`.
|
|
51
|
+
*
|
|
52
|
+
* Parameter `data_or_length` can be an integer length for an IN transfer, or a `Buffer` for an OUT transfer. The type must match the direction specified in the MSB of bmRequestType.
|
|
53
|
+
*
|
|
54
|
+
* The `data` parameter of the callback is actual transferred for OUT transfers, or will be passed a Buffer for IN transfers.
|
|
55
|
+
*
|
|
56
|
+
* The device must be open to use this method.
|
|
57
|
+
* @param bmRequestType
|
|
58
|
+
* @param bRequest
|
|
59
|
+
* @param wValue
|
|
60
|
+
* @param wIndex
|
|
61
|
+
* @param data_or_length
|
|
62
|
+
* @param callback
|
|
63
|
+
*/
|
|
64
|
+
controlTransfer(this: usb.Device, bmRequestType: number, bRequest: number, wValue: number, wIndex: number, data_or_length: number | Buffer, callback?: (error: usb.LibUSBException | undefined, buffer: Buffer | number | undefined) => void): usb.Device;
|
|
65
|
+
/**
|
|
66
|
+
* Return the interface with the specified interface number.
|
|
67
|
+
*
|
|
68
|
+
* The device must be open to use this method.
|
|
69
|
+
* @param addr
|
|
70
|
+
*/
|
|
71
|
+
interface(this: usb.Device, addr: number): Interface;
|
|
72
|
+
/**
|
|
73
|
+
* Perform a control transfer to retrieve a string descriptor
|
|
74
|
+
*
|
|
75
|
+
* The device must be open to use this method.
|
|
76
|
+
* @param desc_index
|
|
77
|
+
* @param callback
|
|
78
|
+
*/
|
|
79
|
+
getStringDescriptor(this: usb.Device, desc_index: number, callback: (error?: usb.LibUSBException, value?: string) => void): void;
|
|
80
|
+
/**
|
|
81
|
+
* Perform a control transfer to retrieve an object with properties for the fields of the Binary Object Store descriptor.
|
|
82
|
+
*
|
|
83
|
+
* The device must be open to use this method.
|
|
84
|
+
* @param callback
|
|
85
|
+
*/
|
|
86
|
+
getBosDescriptor(this: usb.Device, callback: (error?: usb.LibUSBException, descriptor?: BosDescriptor) => void): void;
|
|
87
|
+
/**
|
|
88
|
+
* Retrieve a list of Capability objects for the Binary Object Store capabilities of the device.
|
|
89
|
+
*
|
|
90
|
+
* The device must be open to use this method.
|
|
91
|
+
* @param callback
|
|
92
|
+
*/
|
|
93
|
+
getCapabilities(this: usb.Device, callback: (error: usb.LibUSBException | undefined, capabilities?: Capability[]) => void): void;
|
|
94
|
+
}
|
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ExtendedDevice = void 0;
|
|
4
|
+
var usb = require("./bindings");
|
|
5
|
+
var interface_1 = require("./interface");
|
|
6
|
+
var capability_1 = require("./capability");
|
|
7
|
+
var isBuffer = function (obj) { return !!obj && obj instanceof Uint8Array; };
|
|
8
|
+
var DEFAULT_TIMEOUT = 1000;
|
|
9
|
+
var ExtendedDevice = /** @class */ (function () {
|
|
10
|
+
function ExtendedDevice() {
|
|
11
|
+
this._timeout = DEFAULT_TIMEOUT;
|
|
12
|
+
}
|
|
13
|
+
Object.defineProperty(ExtendedDevice.prototype, "timeout", {
|
|
14
|
+
/**
|
|
15
|
+
* Timeout in milliseconds to use for control transfers.
|
|
16
|
+
*/
|
|
17
|
+
get: function () {
|
|
18
|
+
return this._timeout || DEFAULT_TIMEOUT;
|
|
19
|
+
},
|
|
20
|
+
set: function (value) {
|
|
21
|
+
this._timeout = value;
|
|
22
|
+
},
|
|
23
|
+
enumerable: false,
|
|
24
|
+
configurable: true
|
|
25
|
+
});
|
|
26
|
+
Object.defineProperty(ExtendedDevice.prototype, "configDescriptor", {
|
|
27
|
+
/**
|
|
28
|
+
* Object with properties for the fields of the active configuration descriptor.
|
|
29
|
+
*/
|
|
30
|
+
get: function () {
|
|
31
|
+
try {
|
|
32
|
+
return this.__getConfigDescriptor();
|
|
33
|
+
}
|
|
34
|
+
catch (e) {
|
|
35
|
+
// Check descriptor exists
|
|
36
|
+
if (e.errno === usb.LIBUSB_ERROR_NOT_FOUND) {
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
throw e;
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
enumerable: false,
|
|
43
|
+
configurable: true
|
|
44
|
+
});
|
|
45
|
+
Object.defineProperty(ExtendedDevice.prototype, "allConfigDescriptors", {
|
|
46
|
+
/**
|
|
47
|
+
* Contains all config descriptors of the device (same structure as .configDescriptor above)
|
|
48
|
+
*/
|
|
49
|
+
get: function () {
|
|
50
|
+
try {
|
|
51
|
+
return this.__getAllConfigDescriptors();
|
|
52
|
+
}
|
|
53
|
+
catch (e) {
|
|
54
|
+
// Check descriptors exist
|
|
55
|
+
if (e.errno === usb.LIBUSB_ERROR_NOT_FOUND) {
|
|
56
|
+
return [];
|
|
57
|
+
}
|
|
58
|
+
throw e;
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
enumerable: false,
|
|
62
|
+
configurable: true
|
|
63
|
+
});
|
|
64
|
+
Object.defineProperty(ExtendedDevice.prototype, "parent", {
|
|
65
|
+
/**
|
|
66
|
+
* Contains the parent of the device, such as a hub. If there is no parent this property is set to `null`.
|
|
67
|
+
*/
|
|
68
|
+
get: function () {
|
|
69
|
+
return this.__getParent();
|
|
70
|
+
},
|
|
71
|
+
enumerable: false,
|
|
72
|
+
configurable: true
|
|
73
|
+
});
|
|
74
|
+
/**
|
|
75
|
+
* Open the device.
|
|
76
|
+
* @param defaultConfig
|
|
77
|
+
*/
|
|
78
|
+
ExtendedDevice.prototype.open = function (defaultConfig) {
|
|
79
|
+
if (defaultConfig === void 0) { defaultConfig = true; }
|
|
80
|
+
this.__open();
|
|
81
|
+
if (defaultConfig === false) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
this.interfaces = [];
|
|
85
|
+
var len = this.configDescriptor ? this.configDescriptor.interfaces.length : 0;
|
|
86
|
+
for (var i = 0; i < len; i++) {
|
|
87
|
+
this.interfaces[i] = new interface_1.Interface(this, i);
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
/**
|
|
91
|
+
* Close the device.
|
|
92
|
+
*
|
|
93
|
+
* The device must be open to use this method.
|
|
94
|
+
*/
|
|
95
|
+
ExtendedDevice.prototype.close = function () {
|
|
96
|
+
this.__close();
|
|
97
|
+
this.interfaces = undefined;
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* Set the device configuration to something other than the default (0). To use this, first call `.open(false)` (which tells it not to auto configure),
|
|
101
|
+
* then before claiming an interface, call this method.
|
|
102
|
+
*
|
|
103
|
+
* The device must be open to use this method.
|
|
104
|
+
* @param desired
|
|
105
|
+
* @param callback
|
|
106
|
+
*/
|
|
107
|
+
ExtendedDevice.prototype.setConfiguration = function (desired, callback) {
|
|
108
|
+
var _this = this;
|
|
109
|
+
this.__setConfiguration(desired, function (error) {
|
|
110
|
+
if (!error) {
|
|
111
|
+
_this.interfaces = [];
|
|
112
|
+
var len = _this.configDescriptor ? _this.configDescriptor.interfaces.length : 0;
|
|
113
|
+
for (var i = 0; i < len; i++) {
|
|
114
|
+
_this.interfaces[i] = new interface_1.Interface(_this, i);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
if (callback) {
|
|
118
|
+
callback.call(_this, error);
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
};
|
|
122
|
+
/**
|
|
123
|
+
* Perform a control transfer with `libusb_control_transfer`.
|
|
124
|
+
*
|
|
125
|
+
* Parameter `data_or_length` can be an integer length for an IN transfer, or a `Buffer` for an OUT transfer. The type must match the direction specified in the MSB of bmRequestType.
|
|
126
|
+
*
|
|
127
|
+
* The `data` parameter of the callback is actual transferred for OUT transfers, or will be passed a Buffer for IN transfers.
|
|
128
|
+
*
|
|
129
|
+
* The device must be open to use this method.
|
|
130
|
+
* @param bmRequestType
|
|
131
|
+
* @param bRequest
|
|
132
|
+
* @param wValue
|
|
133
|
+
* @param wIndex
|
|
134
|
+
* @param data_or_length
|
|
135
|
+
* @param callback
|
|
136
|
+
*/
|
|
137
|
+
ExtendedDevice.prototype.controlTransfer = function (bmRequestType, bRequest, wValue, wIndex, data_or_length, callback) {
|
|
138
|
+
var _this = this;
|
|
139
|
+
var isIn = !!(bmRequestType & usb.LIBUSB_ENDPOINT_IN);
|
|
140
|
+
var wLength = isIn ? data_or_length : data_or_length.length;
|
|
141
|
+
if (isIn) {
|
|
142
|
+
if (!(data_or_length >= 0)) {
|
|
143
|
+
throw new TypeError('Expected size number for IN transfer (based on bmRequestType)');
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
if (!isBuffer(data_or_length)) {
|
|
148
|
+
throw new TypeError('Expected buffer for OUT transfer (based on bmRequestType)');
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
// Buffer for the setup packet
|
|
152
|
+
// http://libusbx.sourceforge.net/api-1.0/structlibusb__control__setup.html
|
|
153
|
+
var buf = Buffer.alloc(wLength + usb.LIBUSB_CONTROL_SETUP_SIZE);
|
|
154
|
+
buf.writeUInt8(bmRequestType, 0);
|
|
155
|
+
buf.writeUInt8(bRequest, 1);
|
|
156
|
+
buf.writeUInt16LE(wValue, 2);
|
|
157
|
+
buf.writeUInt16LE(wIndex, 4);
|
|
158
|
+
buf.writeUInt16LE(wLength, 6);
|
|
159
|
+
if (!isIn) {
|
|
160
|
+
buf.set(data_or_length, usb.LIBUSB_CONTROL_SETUP_SIZE);
|
|
161
|
+
}
|
|
162
|
+
var transfer = new usb.Transfer(this, 0, usb.LIBUSB_TRANSFER_TYPE_CONTROL, this.timeout, function (error, buf, actual) {
|
|
163
|
+
if (callback) {
|
|
164
|
+
if (isIn) {
|
|
165
|
+
callback.call(_this, error, buf.slice(usb.LIBUSB_CONTROL_SETUP_SIZE, usb.LIBUSB_CONTROL_SETUP_SIZE + actual));
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
callback.call(_this, error, actual);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
try {
|
|
173
|
+
transfer.submit(buf);
|
|
174
|
+
}
|
|
175
|
+
catch (e) {
|
|
176
|
+
if (callback) {
|
|
177
|
+
process.nextTick(function () { return callback.call(_this, e, undefined); });
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
return this;
|
|
181
|
+
};
|
|
182
|
+
/**
|
|
183
|
+
* Return the interface with the specified interface number.
|
|
184
|
+
*
|
|
185
|
+
* The device must be open to use this method.
|
|
186
|
+
* @param addr
|
|
187
|
+
*/
|
|
188
|
+
ExtendedDevice.prototype.interface = function (addr) {
|
|
189
|
+
if (!this.interfaces) {
|
|
190
|
+
throw new Error('Device must be open before searching for interfaces');
|
|
191
|
+
}
|
|
192
|
+
addr = addr || 0;
|
|
193
|
+
for (var i = 0; i < this.interfaces.length; i++) {
|
|
194
|
+
if (this.interfaces[i].interfaceNumber === addr) {
|
|
195
|
+
return this.interfaces[i];
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
throw new Error("Interface not found for address: " + addr);
|
|
199
|
+
};
|
|
200
|
+
/**
|
|
201
|
+
* Perform a control transfer to retrieve a string descriptor
|
|
202
|
+
*
|
|
203
|
+
* The device must be open to use this method.
|
|
204
|
+
* @param desc_index
|
|
205
|
+
* @param callback
|
|
206
|
+
*/
|
|
207
|
+
ExtendedDevice.prototype.getStringDescriptor = function (desc_index, callback) {
|
|
208
|
+
var langid = 0x0409;
|
|
209
|
+
var length = 255;
|
|
210
|
+
this.controlTransfer(usb.LIBUSB_ENDPOINT_IN, usb.LIBUSB_REQUEST_GET_DESCRIPTOR, ((usb.LIBUSB_DT_STRING << 8) | desc_index), langid, length, function (error, buffer) {
|
|
211
|
+
if (error) {
|
|
212
|
+
return callback(error);
|
|
213
|
+
}
|
|
214
|
+
callback(undefined, isBuffer(buffer) ? buffer.toString('utf16le', 2) : undefined);
|
|
215
|
+
});
|
|
216
|
+
};
|
|
217
|
+
/**
|
|
218
|
+
* Perform a control transfer to retrieve an object with properties for the fields of the Binary Object Store descriptor.
|
|
219
|
+
*
|
|
220
|
+
* The device must be open to use this method.
|
|
221
|
+
* @param callback
|
|
222
|
+
*/
|
|
223
|
+
ExtendedDevice.prototype.getBosDescriptor = function (callback) {
|
|
224
|
+
var _this = this;
|
|
225
|
+
if (this._bosDescriptor) {
|
|
226
|
+
// Cached descriptor
|
|
227
|
+
return callback(undefined, this._bosDescriptor);
|
|
228
|
+
}
|
|
229
|
+
if (this.deviceDescriptor.bcdUSB < 0x201) {
|
|
230
|
+
// BOS is only supported from USB 2.0.1
|
|
231
|
+
return callback(undefined, undefined);
|
|
232
|
+
}
|
|
233
|
+
this.controlTransfer(usb.LIBUSB_ENDPOINT_IN, usb.LIBUSB_REQUEST_GET_DESCRIPTOR, (usb.LIBUSB_DT_BOS << 8), 0, usb.LIBUSB_DT_BOS_SIZE, function (error, buffer) {
|
|
234
|
+
if (error) {
|
|
235
|
+
// Check BOS descriptor exists
|
|
236
|
+
if (error.errno === usb.LIBUSB_TRANSFER_STALL)
|
|
237
|
+
return callback(undefined, undefined);
|
|
238
|
+
return callback(error, undefined);
|
|
239
|
+
}
|
|
240
|
+
if (!isBuffer(buffer)) {
|
|
241
|
+
return callback(undefined, undefined);
|
|
242
|
+
}
|
|
243
|
+
var totalLength = buffer.readUInt16LE(2);
|
|
244
|
+
_this.controlTransfer(usb.LIBUSB_ENDPOINT_IN, usb.LIBUSB_REQUEST_GET_DESCRIPTOR, (usb.LIBUSB_DT_BOS << 8), 0, totalLength, function (error, buffer) {
|
|
245
|
+
if (error) {
|
|
246
|
+
// Check BOS descriptor exists
|
|
247
|
+
if (error.errno === usb.LIBUSB_TRANSFER_STALL)
|
|
248
|
+
return callback(undefined, undefined);
|
|
249
|
+
return callback(error, undefined);
|
|
250
|
+
}
|
|
251
|
+
if (!isBuffer(buffer)) {
|
|
252
|
+
return callback(undefined, undefined);
|
|
253
|
+
}
|
|
254
|
+
var descriptor = {
|
|
255
|
+
bLength: buffer.readUInt8(0),
|
|
256
|
+
bDescriptorType: buffer.readUInt8(1),
|
|
257
|
+
wTotalLength: buffer.readUInt16LE(2),
|
|
258
|
+
bNumDeviceCaps: buffer.readUInt8(4),
|
|
259
|
+
capabilities: []
|
|
260
|
+
};
|
|
261
|
+
var i = usb.LIBUSB_DT_BOS_SIZE;
|
|
262
|
+
while (i < descriptor.wTotalLength) {
|
|
263
|
+
var capability = {
|
|
264
|
+
bLength: buffer.readUInt8(i + 0),
|
|
265
|
+
bDescriptorType: buffer.readUInt8(i + 1),
|
|
266
|
+
bDevCapabilityType: buffer.readUInt8(i + 2),
|
|
267
|
+
dev_capability_data: buffer.slice(i + 3, i + buffer.readUInt8(i + 0))
|
|
268
|
+
};
|
|
269
|
+
descriptor.capabilities.push(capability);
|
|
270
|
+
i += capability.bLength;
|
|
271
|
+
}
|
|
272
|
+
// Cache descriptor
|
|
273
|
+
_this._bosDescriptor = descriptor;
|
|
274
|
+
callback(undefined, _this._bosDescriptor);
|
|
275
|
+
});
|
|
276
|
+
});
|
|
277
|
+
};
|
|
278
|
+
/**
|
|
279
|
+
* Retrieve a list of Capability objects for the Binary Object Store capabilities of the device.
|
|
280
|
+
*
|
|
281
|
+
* The device must be open to use this method.
|
|
282
|
+
* @param callback
|
|
283
|
+
*/
|
|
284
|
+
ExtendedDevice.prototype.getCapabilities = function (callback) {
|
|
285
|
+
var _this = this;
|
|
286
|
+
var capabilities = [];
|
|
287
|
+
this.getBosDescriptor(function (error, descriptor) {
|
|
288
|
+
if (error)
|
|
289
|
+
return callback(error, undefined);
|
|
290
|
+
var len = descriptor ? descriptor.capabilities.length : 0;
|
|
291
|
+
for (var i = 0; i < len; i++) {
|
|
292
|
+
capabilities.push(new capability_1.Capability(_this, i));
|
|
293
|
+
}
|
|
294
|
+
callback(undefined, capabilities);
|
|
295
|
+
});
|
|
296
|
+
};
|
|
297
|
+
return ExtendedDevice;
|
|
298
|
+
}());
|
|
299
|
+
exports.ExtendedDevice = ExtendedDevice;
|
|
300
|
+
//# sourceMappingURL=device.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"device.js","sourceRoot":"","sources":["../../tsc/usb/device.ts"],"names":[],"mappings":";;;AAAA,gCAAkC;AAClC,yCAAwC;AACxC,2CAA0C;AAG1C,IAAM,QAAQ,GAAG,UAAC,GAAoC,IAAwB,OAAA,CAAC,CAAC,GAAG,IAAI,GAAG,YAAY,UAAU,EAAlC,CAAkC,CAAC;AACjH,IAAM,eAAe,GAAG,IAAI,CAAC;AAE7B;IAAA;QAMY,aAAQ,GAAG,eAAe,CAAC;IAsTvC,CAAC;IAlTG,sBAAW,mCAAO;QAHlB;;WAEG;aACH;YACI,OAAO,IAAI,CAAC,QAAQ,IAAI,eAAe,CAAC;QAC5C,CAAC;aACD,UAAmB,KAAa;YAC5B,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC;QAC1B,CAAC;;;OAHA;IAQD,sBAAW,4CAAgB;QAH3B;;WAEG;aACH;YACI,IAAI;gBACA,OAAQ,IAA8B,CAAC,qBAAqB,EAAE,CAAC;aAClE;YAAC,OAAO,CAAC,EAAE;gBACR,0BAA0B;gBAC1B,IAAI,CAAC,CAAC,KAAK,KAAK,GAAG,CAAC,sBAAsB,EAAE;oBACxC,OAAO,SAAS,CAAC;iBACpB;gBACD,MAAM,CAAC,CAAC;aACX;QACL,CAAC;;;OAAA;IAKD,sBAAW,gDAAoB;QAH/B;;WAEG;aACH;YACI,IAAI;gBACA,OAAQ,IAA8B,CAAC,y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C,CAAC;YAE7C,IAAM,GAAG,GAAG,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;YAC5D,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,EAAE,CAAC,EAAE,EAAE;gBAC1B,YAAY,CAAC,IAAI,CAAC,IAAI,uBAAU,CAAC,KAAI,EAAE,CAAC,CAAC,CAAC,CAAC;aAC9C;YAED,QAAQ,CAAC,SAAS,EAAE,YAAY,CAAC,CAAC;QACtC,CAAC,CAAC,CAAC;IACP,CAAC;IACL,qBAAC;AAAD,CAAC,AA5TD,IA4TC;AA5TY,wCAAc"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { EventEmitter } from 'events';
|
|
3
|
+
import { LibUSBException, Transfer, Device } from './bindings';
|
|
4
|
+
import { EndpointDescriptor } from './descriptors';
|
|
5
|
+
/** Common base for InEndpoint and OutEndpoint. */
|
|
6
|
+
export declare abstract class Endpoint extends EventEmitter {
|
|
7
|
+
protected device: Device;
|
|
8
|
+
address: number;
|
|
9
|
+
/** Endpoint direction: `"in"` or `"out"`. */
|
|
10
|
+
abstract direction: 'in' | 'out';
|
|
11
|
+
/** Endpoint type: `usb.LIBUSB_TRANSFER_TYPE_BULK`, `usb.LIBUSB_TRANSFER_TYPE_INTERRUPT`, or `usb.LIBUSB_TRANSFER_TYPE_ISOCHRONOUS`. */
|
|
12
|
+
transferType: number;
|
|
13
|
+
/** Sets the timeout in milliseconds for transfers on this endpoint. The default, `0`, is infinite timeout. */
|
|
14
|
+
timeout: number;
|
|
15
|
+
/** Object with fields from the endpoint descriptor -- see libusb documentation or USB spec. */
|
|
16
|
+
descriptor: EndpointDescriptor;
|
|
17
|
+
constructor(device: Device, descriptor: EndpointDescriptor);
|
|
18
|
+
/** Clear the halt/stall condition for this endpoint. */
|
|
19
|
+
clearHalt(callback: (error: LibUSBException | undefined) => void): void;
|
|
20
|
+
/**
|
|
21
|
+
* Create a new `Transfer` object for this endpoint.
|
|
22
|
+
*
|
|
23
|
+
* The passed callback will be called when the transfer is submitted and finishes. Its arguments are the error (if any), the submitted buffer, and the amount of data actually written (for
|
|
24
|
+
* OUT transfers) or read (for IN transfers).
|
|
25
|
+
*
|
|
26
|
+
* @param timeout Timeout for the transfer (0 means unlimited).
|
|
27
|
+
* @param callback Transfer completion callback.
|
|
28
|
+
*/
|
|
29
|
+
makeTransfer(timeout: number, callback: (error: LibUSBException | undefined, buffer: Buffer, actualLength: number) => void): Transfer;
|
|
30
|
+
}
|
|
31
|
+
/** Endpoints in the IN direction (device->PC) have this type. */
|
|
32
|
+
export declare class InEndpoint extends Endpoint {
|
|
33
|
+
/** Endpoint direction. */
|
|
34
|
+
direction: 'in' | 'out';
|
|
35
|
+
protected pollTransfers: Transfer[] | undefined;
|
|
36
|
+
protected pollTransferSize: number;
|
|
37
|
+
protected pollPending: number;
|
|
38
|
+
pollActive: boolean;
|
|
39
|
+
constructor(device: Device, descriptor: EndpointDescriptor);
|
|
40
|
+
/**
|
|
41
|
+
* Perform a transfer to read data from the endpoint.
|
|
42
|
+
*
|
|
43
|
+
* If length is greater than maxPacketSize, libusb will automatically split the transfer in multiple packets, and you will receive one callback with all data once all packets are complete.
|
|
44
|
+
*
|
|
45
|
+
* `this` in the callback is the InEndpoint object.
|
|
46
|
+
*
|
|
47
|
+
* The device must be open to use this method.
|
|
48
|
+
* @param length
|
|
49
|
+
* @param callback
|
|
50
|
+
*/
|
|
51
|
+
transfer(length: number, callback: (error: LibUSBException | undefined, data?: Buffer) => void): InEndpoint;
|
|
52
|
+
/**
|
|
53
|
+
* Start polling the endpoint.
|
|
54
|
+
*
|
|
55
|
+
* The library will keep `nTransfers` transfers of size `transferSize` pending in the kernel at all times to ensure continuous data flow.
|
|
56
|
+
* This is handled by the libusb event thread, so it continues even if the Node v8 thread is busy. The `data` and `error` events are emitted as transfers complete.
|
|
57
|
+
*
|
|
58
|
+
* The device must be open to use this method.
|
|
59
|
+
* @param nTransfers
|
|
60
|
+
* @param transferSize
|
|
61
|
+
*/
|
|
62
|
+
startPoll(nTransfers?: number, transferSize?: number, _callback?: (error: LibUSBException | undefined, buffer: Buffer, actualLength: number) => void): Transfer[];
|
|
63
|
+
protected startPollTransfers(nTransfers: number | undefined, transferSize: number | undefined, callback: (error: LibUSBException | undefined, buffer: Buffer, actualLength: number) => void): Transfer[];
|
|
64
|
+
/**
|
|
65
|
+
* Stop polling.
|
|
66
|
+
*
|
|
67
|
+
* Further data may still be received. The `end` event is emitted and the callback is called once all transfers have completed or canceled.
|
|
68
|
+
*
|
|
69
|
+
* The device must be open to use this method.
|
|
70
|
+
* @param callback
|
|
71
|
+
*/
|
|
72
|
+
stopPoll(callback?: () => void): void;
|
|
73
|
+
}
|
|
74
|
+
/** Endpoints in the OUT direction (PC->device) have this type. */
|
|
75
|
+
export declare class OutEndpoint extends Endpoint {
|
|
76
|
+
/** Endpoint direction. */
|
|
77
|
+
direction: 'in' | 'out';
|
|
78
|
+
/**
|
|
79
|
+
* Perform a transfer to write `data` to the endpoint.
|
|
80
|
+
*
|
|
81
|
+
* If length is greater than maxPacketSize, libusb will automatically split the transfer in multiple packets, and you will receive one callback once all packets are complete.
|
|
82
|
+
*
|
|
83
|
+
* `this` in the callback is the OutEndpoint object.
|
|
84
|
+
*
|
|
85
|
+
* The device must be open to use this method.
|
|
86
|
+
* @param buffer
|
|
87
|
+
* @param callback
|
|
88
|
+
*/
|
|
89
|
+
transfer(buffer: Buffer, callback?: (error: LibUSBException | undefined, actual: number) => void): OutEndpoint;
|
|
90
|
+
transferWithZLP(buffer: Buffer, callback: (error: LibUSBException | undefined) => void): void;
|
|
91
|
+
}
|