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.
Files changed (60) hide show
  1. package/.eslintignore +4 -0
  2. package/.eslintrc.json +87 -0
  3. package/.gitattributes +1 -0
  4. package/.vscode/launch.json +15 -0
  5. package/.vscode/tasks.json +23 -0
  6. package/CHANGELOG.md +13 -0
  7. package/README.md +400 -175
  8. package/dist/index.d.ts +17 -0
  9. package/dist/index.js +138 -0
  10. package/dist/index.js.map +1 -0
  11. package/dist/usb/bindings.d.ts +253 -0
  12. package/dist/usb/bindings.js +10 -0
  13. package/dist/usb/bindings.js.map +1 -0
  14. package/dist/usb/capability.d.ts +14 -0
  15. package/dist/usb/capability.js +18 -0
  16. package/dist/usb/capability.js.map +1 -0
  17. package/dist/usb/descriptors.d.ts +129 -0
  18. package/dist/usb/descriptors.js +3 -0
  19. package/dist/usb/descriptors.js.map +1 -0
  20. package/dist/usb/device.d.ts +94 -0
  21. package/dist/usb/device.js +300 -0
  22. package/dist/usb/device.js.map +1 -0
  23. package/dist/usb/endpoint.d.ts +91 -0
  24. package/dist/usb/endpoint.js +236 -0
  25. package/dist/usb/endpoint.js.map +1 -0
  26. package/dist/usb/index.d.ts +25 -0
  27. package/dist/usb/index.js +116 -0
  28. package/dist/usb/index.js.map +1 -0
  29. package/dist/usb/interface.d.ts +78 -0
  30. package/dist/usb/interface.js +137 -0
  31. package/dist/usb/interface.js.map +1 -0
  32. package/dist/webusb/index.d.ts +56 -0
  33. package/dist/webusb/index.js +412 -0
  34. package/dist/webusb/index.js.map +1 -0
  35. package/dist/webusb/mutex.d.ts +22 -0
  36. package/dist/webusb/mutex.js +89 -0
  37. package/dist/webusb/mutex.js.map +1 -0
  38. package/dist/webusb/webusb-device.d.ts +49 -0
  39. package/dist/webusb/webusb-device.js +892 -0
  40. package/dist/webusb/webusb-device.js.map +1 -0
  41. package/package.json +28 -15
  42. package/prebuilds/win32-ia32/node.napi.node +0 -0
  43. package/prebuilds/win32-x64/node.napi.node +0 -0
  44. package/src/device.cc +2 -2
  45. package/test/usb.coffee +13 -7
  46. package/test/webusb.coffee +189 -0
  47. package/tsc/index.ts +72 -0
  48. package/tsc/usb/bindings.ts +304 -0
  49. package/tsc/usb/capability.ts +22 -0
  50. package/tsc/usb/descriptors.ts +180 -0
  51. package/tsc/usb/device.ts +325 -0
  52. package/tsc/usb/endpoint.ts +228 -0
  53. package/tsc/usb/index.ts +111 -0
  54. package/tsc/usb/interface.ts +172 -0
  55. package/tsc/webusb/index.ts +363 -0
  56. package/tsc/webusb/mutex.ts +38 -0
  57. package/tsc/webusb/webusb-device.ts +541 -0
  58. package/tsconfig.json +17 -0
  59. package/typedoc.json +9 -0
  60. package/usb.js +0 -573
@@ -0,0 +1,17 @@
1
+ import { WebUSB } from './webusb';
2
+ import { WebUSBDevice } from './webusb/webusb-device';
3
+ import * as usb from './usb';
4
+ /**
5
+ * Convenience method to get the first device with the specified VID and PID, or `undefined` if no such device is present.
6
+ * @param vid
7
+ * @param pid
8
+ */
9
+ declare const findByIds: (vid: number, pid: number) => usb.Device | undefined;
10
+ /**
11
+ * Convenience method to get the device with the specified serial number, or `undefined` if no such device is present.
12
+ * @param serialNumber
13
+ */
14
+ declare const findBySerialNumber: (serialNumber: string) => Promise<usb.Device | undefined>;
15
+ declare const webusb: WebUSB;
16
+ declare const getDeviceList: typeof usb.getDeviceList;
17
+ export { usb, getDeviceList, findByIds, findBySerialNumber, webusb, WebUSB, WebUSBDevice };
package/dist/index.js ADDED
@@ -0,0 +1,138 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ var __values = (this && this.__values) || function(o) {
39
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
40
+ if (m) return m.call(o);
41
+ if (o && typeof o.length === "number") return {
42
+ next: function () {
43
+ if (o && i >= o.length) o = void 0;
44
+ return { value: o && o[i++], done: !o };
45
+ }
46
+ };
47
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
48
+ };
49
+ Object.defineProperty(exports, "__esModule", { value: true });
50
+ exports.WebUSBDevice = exports.WebUSB = exports.webusb = exports.findBySerialNumber = exports.findByIds = exports.getDeviceList = exports.usb = void 0;
51
+ var util_1 = require("util");
52
+ var webusb_1 = require("./webusb");
53
+ Object.defineProperty(exports, "WebUSB", { enumerable: true, get: function () { return webusb_1.WebUSB; } });
54
+ var webusb_device_1 = require("./webusb/webusb-device");
55
+ Object.defineProperty(exports, "WebUSBDevice", { enumerable: true, get: function () { return webusb_device_1.WebUSBDevice; } });
56
+ var usb = require("./usb");
57
+ exports.usb = usb;
58
+ /**
59
+ * Convenience method to get the first device with the specified VID and PID, or `undefined` if no such device is present.
60
+ * @param vid
61
+ * @param pid
62
+ */
63
+ var findByIds = function (vid, pid) {
64
+ var devices = usb.getDeviceList();
65
+ return devices.find(function (item) { return item.deviceDescriptor.idVendor === vid && item.deviceDescriptor.idProduct === pid; });
66
+ };
67
+ exports.findByIds = findByIds;
68
+ /**
69
+ * Convenience method to get the device with the specified serial number, or `undefined` if no such device is present.
70
+ * @param serialNumber
71
+ */
72
+ var findBySerialNumber = function (serialNumber) { return __awaiter(void 0, void 0, void 0, function () {
73
+ var devices, opened, devices_1, devices_1_1, device, getStringDescriptor, buffer, _a, e_1_1;
74
+ var e_1, _b;
75
+ return __generator(this, function (_c) {
76
+ switch (_c.label) {
77
+ case 0:
78
+ devices = usb.getDeviceList();
79
+ opened = function (device) { return !!device.interfaces; };
80
+ _c.label = 1;
81
+ case 1:
82
+ _c.trys.push([1, 9, 10, 11]);
83
+ devices_1 = __values(devices), devices_1_1 = devices_1.next();
84
+ _c.label = 2;
85
+ case 2:
86
+ if (!!devices_1_1.done) return [3 /*break*/, 8];
87
+ device = devices_1_1.value;
88
+ _c.label = 3;
89
+ case 3:
90
+ _c.trys.push([3, 5, 6, 7]);
91
+ if (!opened(device)) {
92
+ device.open();
93
+ }
94
+ getStringDescriptor = util_1.promisify(device.getStringDescriptor).bind(device);
95
+ return [4 /*yield*/, getStringDescriptor(device.deviceDescriptor.iSerialNumber)];
96
+ case 4:
97
+ buffer = _c.sent();
98
+ if (buffer && buffer.toString() === serialNumber) {
99
+ return [2 /*return*/, device];
100
+ }
101
+ return [3 /*break*/, 7];
102
+ case 5:
103
+ _a = _c.sent();
104
+ return [3 /*break*/, 7];
105
+ case 6:
106
+ try {
107
+ if (opened(device)) {
108
+ device.close();
109
+ }
110
+ }
111
+ catch (_d) {
112
+ // Ignore any errors, device may be a system device or inaccessible
113
+ }
114
+ return [7 /*endfinally*/];
115
+ case 7:
116
+ devices_1_1 = devices_1.next();
117
+ return [3 /*break*/, 2];
118
+ case 8: return [3 /*break*/, 11];
119
+ case 9:
120
+ e_1_1 = _c.sent();
121
+ e_1 = { error: e_1_1 };
122
+ return [3 /*break*/, 11];
123
+ case 10:
124
+ try {
125
+ if (devices_1_1 && !devices_1_1.done && (_b = devices_1.return)) _b.call(devices_1);
126
+ }
127
+ finally { if (e_1) throw e_1.error; }
128
+ return [7 /*endfinally*/];
129
+ case 11: return [2 /*return*/, undefined];
130
+ }
131
+ });
132
+ }); };
133
+ exports.findBySerialNumber = findBySerialNumber;
134
+ var webusb = new webusb_1.WebUSB();
135
+ exports.webusb = webusb;
136
+ var getDeviceList = usb.getDeviceList;
137
+ exports.getDeviceList = getDeviceList;
138
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../tsc/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6BAAiC;AACjC,mCAAkC;AAkE9B,uFAlEK,eAAM,OAkEL;AAjEV,wDAAsD;AAoElD,6FApEK,4BAAY,OAoEL;AAnEhB,2BAA6B;AAqDzB,kBAAG;AAnDP;;;;GAIG;AACH,IAAM,SAAS,GAAG,UAAC,GAAW,EAAE,GAAW;IACvC,IAAM,OAAO,GAAG,GAAG,CAAC,aAAa,EAAE,CAAC;IACpC,OAAO,OAAO,CAAC,IAAI,CAAC,UAAA,IAAI,IAAI,OAAA,IAAI,CAAC,gBAAgB,CAAC,QAAQ,KAAK,GAAG,IAAI,IAAI,CAAC,gBAAgB,CAAC,SAAS,KAAK,GAAG,EAAjF,CAAiF,CAAC,CAAC;AACnH,CAAC,CAAC;AA+CE,8BAAS;AA7Cb;;;GAGG;AACH,IAAM,kBAAkB,GAAG,UAAO,YAAoB;;;;;;gBAC5C,OAAO,GAAG,GAAG,CAAC,aAAa,EAAE,CAAC;gBAC9B,MAAM,GAAG,UAAC,MAAkB,IAAc,OAAA,CAAC,CAAC,MAAM,CAAC,UAAU,EAAnB,CAAmB,CAAC;;;;gBAE/C,YAAA,SAAA,OAAO,CAAA;;;;gBAAjB,MAAM;;;;gBAET,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE;oBACjB,MAAM,CAAC,IAAI,EAAE,CAAC;iBACjB;gBAEK,mBAAmB,GAAG,gBAAS,CAAC,MAAM,CAAC,mBAAmB,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;gBAChE,qBAAM,mBAAmB,CAAC,MAAM,CAAC,gBAAgB,CAAC,aAAa,CAAC,EAAA;;gBAAzE,MAAM,GAAG,SAAgE;gBAE/E,IAAI,MAAM,IAAI,MAAM,CAAC,QAAQ,EAAE,KAAK,YAAY,EAAE;oBAC9C,sBAAO,MAAM,EAAC;iBACjB;;;;;;gBAID,IAAI;oBACA,IAAI,MAAM,CAAC,MAAM,CAAC,EAAE;wBAChB,MAAM,CAAC,KAAK,EAAE,CAAC;qBAClB;iBACJ;gBAAC,WAAM;oBACJ,mEAAmE;iBACtE;;;;;;;;;;;;;;;;qBAIT,sBAAO,SAAS,EAAC;;;KACpB,CAAC;AAYE,gDAAkB;AAVtB,IAAM,MAAM,GAAG,IAAI,eAAM,EAAE,CAAC;AAaxB,wBAAM;AAZV,IAAM,aAAa,GAAG,GAAG,CAAC,aAAa,CAAC;AAOpC,sCAAa"}
@@ -0,0 +1,253 @@
1
+ /// <reference types="node" />
2
+ import type { DeviceDescriptor, ConfigDescriptor, BosDescriptor } from './descriptors';
3
+ /**
4
+ * Return a list of `Device` objects for the USB devices attached to the system.
5
+ */
6
+ export declare function getDeviceList(): Device[];
7
+ export declare const INIT_ERROR: number;
8
+ export declare class LibUSBException extends Error {
9
+ errno: number;
10
+ }
11
+ /**
12
+ * Set the libusb debug level (between 0 and 4)
13
+ * @param level libusb debug level (between 0 and 4)
14
+ */
15
+ export declare function setDebugLevel(level: number): void;
16
+ export declare function _enableHotplugEvents(): void;
17
+ export declare function _disableHotplugEvents(): void;
18
+ export declare function _getLibusbCapability(capability: number): number;
19
+ /**
20
+ * Restore (re-reference) the hotplug events unreferenced by `unrefHotplugEvents()`
21
+ */
22
+ export declare function refHotplugEvents(): void;
23
+ /**
24
+ * Unreference the hotplug events from the event loop, allowing the process to exit even when listening for the `attach` and `detach` events
25
+ */
26
+ export declare function unrefHotplugEvents(): void;
27
+ /** Represents a USB transfer */
28
+ export declare class Transfer {
29
+ constructor(device: Device, endpointAddr: number, type: number, timeout: number, callback: (error: LibUSBException, buf: Buffer, actual: number) => void);
30
+ /**
31
+ * (Re-)submit the transfer.
32
+ *
33
+ * @param buffer Buffer where data will be written (for IN transfers) or read from (for OUT transfers).
34
+ */
35
+ submit(buffer: Buffer, callback?: (error: LibUSBException | undefined, buffer: Buffer, actualLength: number) => void): Transfer;
36
+ /**
37
+ * Cancel the transfer.
38
+ *
39
+ * Returns `true` if the transfer was canceled, `false` if it wasn't in pending state.
40
+ */
41
+ cancel(): boolean;
42
+ }
43
+ /** Represents a USB device. */
44
+ export declare class Device {
45
+ /** Integer USB device number */
46
+ busNumber: number;
47
+ /** Integer USB device address */
48
+ deviceAddress: number;
49
+ /** Array containing the USB device port numbers, or `undefined` if not supported on this platform. */
50
+ portNumbers: number[];
51
+ /** Object with properties for the fields of the device descriptor. */
52
+ deviceDescriptor: DeviceDescriptor;
53
+ _bosDescriptor?: BosDescriptor;
54
+ __open(): void;
55
+ __close(): void;
56
+ __getParent(): Device;
57
+ __getConfigDescriptor(): ConfigDescriptor;
58
+ __getAllConfigDescriptors(): ConfigDescriptor[];
59
+ __setConfiguration(desired: number, callback: (error?: LibUSBException) => void): void;
60
+ __clearHalt(addr: number, callback: (error?: LibUSBException) => void): void;
61
+ __setInterface(addr: number, altSetting: number, callback: (error?: LibUSBException) => void): void;
62
+ __claimInterface(addr: number): void;
63
+ __releaseInterface(addr: number, callback: (error?: LibUSBException) => void): void;
64
+ __detachKernelDriver(addr: number): void;
65
+ __attachKernelDriver(addr: number): void;
66
+ __isKernelDriverActive(addr: number): boolean;
67
+ /**
68
+ * Performs a reset of the device. Callback is called when complete.
69
+ *
70
+ * The device must be open to use this method.
71
+ * @param callback
72
+ */
73
+ reset(callback: (error?: LibUSBException) => void): void;
74
+ }
75
+ /**
76
+ * In the context of a \ref libusb_device_descriptor "device descriptor",
77
+ * this bDeviceClass value indicates that each interface specifies its
78
+ * own class information and all interfaces operate independently.
79
+ */
80
+ export declare const LIBUSB_CLASS_PER_INTERFACE: number;
81
+ /** Audio class */
82
+ export declare const LIBUSB_CLASS_AUDIO: number;
83
+ /** Communications class */
84
+ export declare const LIBUSB_CLASS_COMM: number;
85
+ /** Human Interface Device class */
86
+ export declare const LIBUSB_CLASS_HID: number;
87
+ /** Printer class */
88
+ export declare const LIBUSB_CLASS_PRINTER: number;
89
+ /** Image class */
90
+ export declare const LIBUSB_CLASS_PTP: number;
91
+ /** Mass storage class */
92
+ export declare const LIBUSB_CLASS_MASS_STORAGE: number;
93
+ /** Hub class */
94
+ export declare const LIBUSB_CLASS_HUB: number;
95
+ /** Data class */
96
+ export declare const LIBUSB_CLASS_DATA: number;
97
+ /** Wireless class */
98
+ export declare const LIBUSB_CLASS_WIRELESS: number;
99
+ /** Application class */
100
+ export declare const LIBUSB_CLASS_APPLICATION: number;
101
+ /** Class is vendor-specific */
102
+ export declare const LIBUSB_CLASS_VENDOR_SPEC: number;
103
+ /** Request status of the specific recipient */
104
+ export declare const LIBUSB_REQUEST_GET_STATUS: number;
105
+ /** Clear or disable a specific feature */
106
+ export declare const LIBUSB_REQUEST_CLEAR_FEATURE: number;
107
+ /** Set or enable a specific feature */
108
+ export declare const LIBUSB_REQUEST_SET_FEATURE: number;
109
+ /** Set device address for all future accesses */
110
+ export declare const LIBUSB_REQUEST_SET_ADDRESS: number;
111
+ /** Get the specified descriptor */
112
+ export declare const LIBUSB_REQUEST_GET_DESCRIPTOR: number;
113
+ /** Used to update existing descriptors or add new descriptors */
114
+ export declare const LIBUSB_REQUEST_SET_DESCRIPTOR: number;
115
+ /** Get the current device configuration value */
116
+ export declare const LIBUSB_REQUEST_GET_CONFIGURATION: number;
117
+ /** Set device configuration */
118
+ export declare const LIBUSB_REQUEST_SET_CONFIGURATION: number;
119
+ /** Return the selected alternate setting for the specified interface */
120
+ export declare const LIBUSB_REQUEST_GET_INTERFACE: number;
121
+ /** Select an alternate interface for the specified interface */
122
+ export declare const LIBUSB_REQUEST_SET_INTERFACE: number;
123
+ /** Set then report an endpoint's synchronization frame */
124
+ export declare const LIBUSB_REQUEST_SYNCH_FRAME: number;
125
+ /** Device descriptor. See libusb_device_descriptor. */
126
+ export declare const LIBUSB_DT_DEVICE: number;
127
+ /** Configuration descriptor. See libusb_config_descriptor. */
128
+ export declare const LIBUSB_DT_CONFIG: number;
129
+ /** String descriptor */
130
+ export declare const LIBUSB_DT_STRING: number;
131
+ export declare const LIBUSB_DT_BOS: number;
132
+ /** Interface descriptor. See libusb_interface_descriptor. */
133
+ export declare const LIBUSB_DT_INTERFACE: number;
134
+ /** Endpoint descriptor. See libusb_endpoint_descriptor. */
135
+ export declare const LIBUSB_DT_ENDPOINT: number;
136
+ /** HID descriptor */
137
+ export declare const LIBUSB_DT_HID: number;
138
+ /** HID report descriptor */
139
+ export declare const LIBUSB_DT_REPORT: number;
140
+ /** Physical descriptor */
141
+ export declare const LIBUSB_DT_PHYSICAL: number;
142
+ /** Hub descriptor */
143
+ export declare const LIBUSB_DT_HUB: number;
144
+ /** In: device-to-host */
145
+ export declare const LIBUSB_ENDPOINT_IN: number;
146
+ /** Out: host-to-device */
147
+ export declare const LIBUSB_ENDPOINT_OUT: number;
148
+ /** Control endpoint */
149
+ export declare const LIBUSB_TRANSFER_TYPE_CONTROL: number;
150
+ /** Isochronous endpoint */
151
+ export declare const LIBUSB_TRANSFER_TYPE_ISOCHRONOUS: number;
152
+ /** Bulk endpoint */
153
+ export declare const LIBUSB_TRANSFER_TYPE_BULK: number;
154
+ /** Interrupt endpoint */
155
+ export declare const LIBUSB_TRANSFER_TYPE_INTERRUPT: number;
156
+ /** No synchronization */
157
+ export declare const LIBUSB_ISO_SYNC_TYPE_NONE: number;
158
+ /** Asynchronous */
159
+ export declare const LIBUSB_ISO_SYNC_TYPE_ASYNC: number;
160
+ /** Adaptive */
161
+ export declare const LIBUSB_ISO_SYNC_TYPE_ADAPTIVE: number;
162
+ /** Synchronous */
163
+ export declare const LIBUSB_ISO_SYNC_TYPE_SYNC: number;
164
+ /** Data endpoint */
165
+ export declare const LIBUSB_ISO_USAGE_TYPE_DATA: number;
166
+ /** Feedback endpoint */
167
+ export declare const LIBUSB_ISO_USAGE_TYPE_FEEDBACK: number;
168
+ /** Implicit feedback Data endpoint */
169
+ export declare const LIBUSB_ISO_USAGE_TYPE_IMPLICIT: number;
170
+ /**
171
+ * Transfer completed without error. Note that this does not indicate
172
+ * that the entire amount of requested data was transferred.
173
+ */
174
+ export declare const LIBUSB_TRANSFER_COMPLETED: number;
175
+ /** Transfer failed */
176
+ export declare const LIBUSB_TRANSFER_ERROR: number;
177
+ /** Transfer timed out */
178
+ export declare const LIBUSB_TRANSFER_TIMED_OUT: number;
179
+ /** Transfer was cancelled */
180
+ export declare const LIBUSB_TRANSFER_CANCELLED: number;
181
+ /**
182
+ * For bulk/interrupt endpoints: halt condition detected (endpoint
183
+ * stalled). For control endpoints: control request not supported.
184
+ */
185
+ export declare const LIBUSB_TRANSFER_STALL: number;
186
+ /** Device was disconnected */
187
+ export declare const LIBUSB_TRANSFER_NO_DEVICE: number;
188
+ /** Device sent more data than requested */
189
+ export declare const LIBUSB_TRANSFER_OVERFLOW: number;
190
+ /** Report short frames as errors */
191
+ export declare const LIBUSB_TRANSFER_SHORT_NOT_OK: number;
192
+ /**
193
+ * Automatically free() transfer buffer during libusb_free_transfer().
194
+ * Note that buffers allocated with libusb_dev_mem_alloc() should not
195
+ * be attempted freed in this way, since free() is not an appropriate
196
+ * way to release such memory.
197
+ */
198
+ export declare const LIBUSB_TRANSFER_FREE_BUFFER: number;
199
+ /**
200
+ * Automatically call libusb_free_transfer() after callback returns.
201
+ * If this flag is set, it is illegal to call libusb_free_transfer()
202
+ * from your transfer callback, as this will result in a double-free
203
+ * when this flag is acted upon.
204
+ */
205
+ export declare const LIBUSB_TRANSFER_FREE_TRANSFER: number;
206
+ /** Standard */
207
+ export declare const LIBUSB_REQUEST_TYPE_STANDARD: number;
208
+ /** Class */
209
+ export declare const LIBUSB_REQUEST_TYPE_CLASS: number;
210
+ /** Vendor */
211
+ export declare const LIBUSB_REQUEST_TYPE_VENDOR: number;
212
+ /** Reserved */
213
+ export declare const LIBUSB_REQUEST_TYPE_RESERVED: number;
214
+ /** Device */
215
+ export declare const LIBUSB_RECIPIENT_DEVICE: number;
216
+ /** Interface */
217
+ export declare const LIBUSB_RECIPIENT_INTERFACE: number;
218
+ /** Endpoint */
219
+ export declare const LIBUSB_RECIPIENT_ENDPOINT: number;
220
+ /** Other */
221
+ export declare const LIBUSB_RECIPIENT_OTHER: number;
222
+ export declare const LIBUSB_CONTROL_SETUP_SIZE: number;
223
+ export declare const LIBUSB_DT_BOS_SIZE: number;
224
+ export declare const LIBUSB_CAP_HAS_CAPABILITY: number;
225
+ export declare const LIBUSB_CAP_HAS_HOTPLUG: number;
226
+ export declare const LIBUSB_CAP_HAS_HID_ACCESS: number;
227
+ export declare const LIBUSB_CAP_SUPPORTS_DETACH_KERNEL_DRIVER: number;
228
+ /** Input/output error */
229
+ export declare const LIBUSB_ERROR_IO: number;
230
+ /** Invalid parameter */
231
+ export declare const LIBUSB_ERROR_INVALID_PARAM: number;
232
+ /** Access denied (insufficient permissions) */
233
+ export declare const LIBUSB_ERROR_ACCESS: number;
234
+ /** No such device (it may have been disconnected) */
235
+ export declare const LIBUSB_ERROR_NO_DEVICE: number;
236
+ /** Entity not found */
237
+ export declare const LIBUSB_ERROR_NOT_FOUND: number;
238
+ /** Resource busy */
239
+ export declare const LIBUSB_ERROR_BUSY: number;
240
+ /** Operation timed out */
241
+ export declare const LIBUSB_ERROR_TIMEOUT: number;
242
+ /** Overflow */
243
+ export declare const LIBUSB_ERROR_OVERFLOW: number;
244
+ /** Pipe error */
245
+ export declare const LIBUSB_ERROR_PIPE: number;
246
+ /** System call interrupted (perhaps due to signal) */
247
+ export declare const LIBUSB_ERROR_INTERRUPTED: number;
248
+ /** Insufficient memory */
249
+ export declare const LIBUSB_ERROR_NO_MEM: number;
250
+ /** Operation not supported or unimplemented on this platform */
251
+ export declare const LIBUSB_ERROR_NOT_SUPPORTED: number;
252
+ /** Other error */
253
+ export declare const LIBUSB_ERROR_OTHER: number;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ // Definitions from DefinitelyTyped, thanks to:
3
+ // Eric Brody <https://github.com/underscorebrody>
4
+ // Rob Moran <https://github.com/thegecko>
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ var path_1 = require("path");
7
+ /* eslint-disable @typescript-eslint/no-var-requires */
8
+ var usb = require('node-gyp-build')(path_1.join(__dirname, '..', '..'));
9
+ module.exports = usb;
10
+ //# sourceMappingURL=bindings.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bindings.js","sourceRoot":"","sources":["../../tsc/usb/bindings.ts"],"names":[],"mappings":";AAAA,+CAA+C;AAC/C,mDAAmD;AACnD,2CAA2C;;AAE3C,6BAA4B;AAG5B,uDAAuD;AACvD,IAAM,GAAG,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC,WAAI,CAAC,SAAS,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;AACnE,MAAM,CAAC,OAAO,GAAG,GAAG,CAAC"}
@@ -0,0 +1,14 @@
1
+ /// <reference types="node" />
2
+ import type { Device } from './bindings';
3
+ import { CapabilityDescriptor } from './descriptors';
4
+ export declare class Capability {
5
+ protected device: Device;
6
+ protected id: number;
7
+ /** Object with fields from the capability descriptor -- see libusb documentation or USB spec. */
8
+ descriptor: CapabilityDescriptor;
9
+ /** Integer capability type. */
10
+ type: number;
11
+ /** Buffer capability data. */
12
+ data: Buffer;
13
+ constructor(device: Device, id: number);
14
+ }
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Capability = void 0;
4
+ var Capability = /** @class */ (function () {
5
+ function Capability(device, id) {
6
+ this.device = device;
7
+ this.id = id;
8
+ if (!device._bosDescriptor) {
9
+ throw new Error('bosDescriptor not found');
10
+ }
11
+ this.descriptor = device._bosDescriptor.capabilities[this.id];
12
+ this.type = this.descriptor.bDevCapabilityType;
13
+ this.data = this.descriptor.dev_capability_data;
14
+ }
15
+ return Capability;
16
+ }());
17
+ exports.Capability = Capability;
18
+ //# sourceMappingURL=capability.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"capability.js","sourceRoot":"","sources":["../../tsc/usb/capability.ts"],"names":[],"mappings":";;;AAGA;IAUI,oBAAsB,MAAc,EAAY,EAAU;QAApC,WAAM,GAAN,MAAM,CAAQ;QAAY,OAAE,GAAF,EAAE,CAAQ;QACtD,IAAI,CAAC,MAAM,CAAC,cAAc,EAAE;YACxB,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;SAC9C;QACD,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,cAAc,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAC9D,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,UAAU,CAAC,kBAAkB,CAAC;QAC/C,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,UAAU,CAAC,mBAAmB,CAAC;IACpD,CAAC;IACL,iBAAC;AAAD,CAAC,AAlBD,IAkBC;AAlBY,gCAAU"}
@@ -0,0 +1,129 @@
1
+ /// <reference types="node" />
2
+ /** A structure representing the standard USB device descriptor */
3
+ export interface DeviceDescriptor {
4
+ /** Size of this descriptor (in bytes) */
5
+ bLength: number;
6
+ /** Descriptor type. */
7
+ bDescriptorType: number;
8
+ /** USB specification release number in binary-coded decimal. */
9
+ bcdUSB: number;
10
+ /** USB-IF class code for the device. */
11
+ bDeviceClass: number;
12
+ /** USB-IF subclass code for the device, qualified by the bDeviceClass value. */
13
+ bDeviceSubClass: number;
14
+ /** USB-IF protocol code for the device, qualified by the bDeviceClass and bDeviceSubClass values. */
15
+ bDeviceProtocol: number;
16
+ /** Maximum packet size for endpoint 0. */
17
+ bMaxPacketSize0: number;
18
+ /** USB-IF vendor ID. */
19
+ idVendor: number;
20
+ /** USB-IF product ID. */
21
+ idProduct: number;
22
+ /** Device release number in binary-coded decimal. */
23
+ bcdDevice: number;
24
+ /** Index of string descriptor describing manufacturer. */
25
+ iManufacturer: number;
26
+ /** Index of string descriptor describing product. */
27
+ iProduct: number;
28
+ /** Index of string descriptor containing device serial number. */
29
+ iSerialNumber: number;
30
+ /** Number of possible configurations. */
31
+ bNumConfigurations: number;
32
+ }
33
+ /** A structure representing the standard USB configuration descriptor */
34
+ export interface ConfigDescriptor {
35
+ /** Size of this descriptor (in bytes) */
36
+ bLength: number;
37
+ /** Descriptor type. */
38
+ bDescriptorType: number;
39
+ /** Total length of data returned for this configuration. */
40
+ wTotalLength: number;
41
+ /** Number of interfaces supported by this configuration. */
42
+ bNumInterfaces: number;
43
+ /** Identifier value for this configuration. */
44
+ bConfigurationValue: number;
45
+ /** Index of string descriptor describing this configuration. */
46
+ iConfiguration: number;
47
+ /** Configuration characteristics. */
48
+ bmAttributes: number;
49
+ /** Maximum power consumption of the USB device from this bus in this configuration when the device is fully operation. */
50
+ bMaxPower: number;
51
+ /** Extra descriptors. */
52
+ extra: Buffer;
53
+ /** Array of interfaces supported by this configuration. */
54
+ interfaces: InterfaceDescriptor[][];
55
+ }
56
+ /** A structure representing the standard USB interface descriptor */
57
+ export interface InterfaceDescriptor {
58
+ /** Size of this descriptor (in bytes) */
59
+ bLength: number;
60
+ /** Descriptor type. */
61
+ bDescriptorType: number;
62
+ /** Number of this interface. */
63
+ bInterfaceNumber: number;
64
+ /** Value used to select this alternate setting for this interface. */
65
+ bAlternateSetting: number;
66
+ /** Number of endpoints used by this interface (excluding the control endpoint). */
67
+ bNumEndpoints: number;
68
+ /** USB-IF class code for this interface. */
69
+ bInterfaceClass: number;
70
+ /** USB-IF subclass code for this interface, qualified by the bInterfaceClass value. */
71
+ bInterfaceSubClass: number;
72
+ /** USB-IF protocol code for this interface, qualified by the bInterfaceClass and bInterfaceSubClass values. */
73
+ bInterfaceProtocol: number;
74
+ /** Index of string descriptor describing this interface. */
75
+ iInterface: number;
76
+ /** Extra descriptors. */
77
+ extra: Buffer;
78
+ /** Array of endpoint descriptors. */
79
+ endpoints: EndpointDescriptor[];
80
+ }
81
+ /** A structure representing the standard USB endpoint descriptor */
82
+ export interface EndpointDescriptor {
83
+ /** Size of this descriptor (in bytes) */
84
+ bLength: number;
85
+ /** Descriptor type. */
86
+ bDescriptorType: number;
87
+ /** The address of the endpoint described by this descriptor. */
88
+ bEndpointAddress: number;
89
+ /** Attributes which apply to the endpoint when it is configured using the bConfigurationValue. */
90
+ bmAttributes: number;
91
+ /** Maximum packet size this endpoint is capable of sending/receiving. */
92
+ wMaxPacketSize: number;
93
+ /** Interval for polling endpoint for data transfers. */
94
+ bInterval: number;
95
+ /** For audio devices only: the rate at which synchronization feedback is provided. */
96
+ bRefresh: number;
97
+ /** For audio devices only: the address if the synch endpoint. */
98
+ bSynchAddress: number;
99
+ /**
100
+ * Extra descriptors.
101
+ *
102
+ * If libusb encounters unknown endpoint descriptors, it will store them here, should you wish to parse them.
103
+ */
104
+ extra: Buffer;
105
+ }
106
+ /** A generic representation of a BOS Device Capability descriptor */
107
+ export interface CapabilityDescriptor {
108
+ /** Size of this descriptor (in bytes) */
109
+ bLength: number;
110
+ /** Descriptor type. */
111
+ bDescriptorType: number;
112
+ /** Device Capability type. */
113
+ bDevCapabilityType: number;
114
+ /** Device Capability data (bLength - 3 bytes) */
115
+ dev_capability_data: Buffer;
116
+ }
117
+ /** A structure representing the Binary Device Object Store (BOS) descriptor */
118
+ export interface BosDescriptor {
119
+ /** Size of this descriptor (in bytes) */
120
+ bLength: number;
121
+ /** Descriptor type. */
122
+ bDescriptorType: number;
123
+ /** Length of this descriptor and all of its sub descriptors. */
124
+ wTotalLength: number;
125
+ /** The number of separate device capability descriptors in the BOS. */
126
+ bNumDeviceCaps: number;
127
+ /** Device Capability Descriptors */
128
+ capabilities: CapabilityDescriptor[];
129
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=descriptors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"descriptors.js","sourceRoot":"","sources":["../../tsc/usb/descriptors.ts"],"names":[],"mappings":""}