usb 2.9.0 → 2.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/CHANGELOG.md +5 -0
  2. package/README.md +6 -0
  3. package/binding.gyp +1 -1
  4. package/dist/index.js +35 -113
  5. package/dist/index.js.map +1 -1
  6. package/dist/usb/bindings.js +2 -2
  7. package/dist/usb/bindings.js.map +1 -1
  8. package/dist/usb/capability.js +3 -4
  9. package/dist/usb/capability.js.map +1 -1
  10. package/dist/usb/device.js +101 -123
  11. package/dist/usb/device.js.map +1 -1
  12. package/dist/usb/endpoint.d.ts +2 -1
  13. package/dist/usb/endpoint.js +74 -98
  14. package/dist/usb/endpoint.js.map +1 -1
  15. package/dist/usb/index.js +26 -59
  16. package/dist/usb/index.js.map +1 -1
  17. package/dist/usb/interface.js +41 -44
  18. package/dist/usb/interface.js.map +1 -1
  19. package/dist/webusb/index.js +169 -355
  20. package/dist/webusb/index.js.map +1 -1
  21. package/dist/webusb/webusb-device.js +367 -751
  22. package/dist/webusb/webusb-device.js.map +1 -1
  23. package/package.json +5 -5
  24. package/prebuilds/android-arm/node.napi.armv7.node +0 -0
  25. package/prebuilds/android-arm64/node.napi.armv8.node +0 -0
  26. package/prebuilds/darwin-x64+arm64/node.napi.node +0 -0
  27. package/prebuilds/linux-arm/node.napi.armv6.node +0 -0
  28. package/prebuilds/linux-arm/node.napi.armv7.node +0 -0
  29. package/prebuilds/linux-arm64/node.napi.armv8.node +0 -0
  30. package/prebuilds/linux-ia32/node.napi.node +0 -0
  31. package/prebuilds/linux-x64/node.napi.glibc.node +0 -0
  32. package/prebuilds/linux-x64/node.napi.musl.node +0 -0
  33. package/prebuilds/win32-ia32/node.napi.node +0 -0
  34. package/prebuilds/win32-x64/node.napi.node +0 -0
  35. package/test/usb.coffee +25 -4
  36. package/test/worker.cjs +5 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## [2.10.0] - 2023-08-22
4
+
5
+ ### Fixed
6
+ - Fixed using callbacks in startPolling - [`631`](https://github.com/node-usb/node-usb/pull/631) ([Tim Strazzere](https://github.com/strazzere))
7
+
3
8
  ## [2.9.0] - 2023-03-16
4
9
 
5
10
  ### Changed
package/README.md CHANGED
@@ -20,6 +20,8 @@ You can install one using [Zadig](http://zadig.akeo.ie/) or another approach is
20
20
 
21
21
  Note that you cannot use multiple drivers on Windows as they get exclusive access to the device. So if you want to switch between drivers (e.g. using a printer with this software or the system), you will need to uninstall/install drivers as required.
22
22
 
23
+ For further info, check [How to use libusb on Windows](https://github.com/libusb/libusb/wiki/Windows#user-content-How_to_use_libusb_on_Windows) in the libusb's wiki.
24
+
23
25
  ## Linux
24
26
 
25
27
  On Linux, you'll need libudev to build libusb if a prebuild is not available. On Ubuntu/Debian:
@@ -28,6 +30,10 @@ On Linux, you'll need libudev to build libusb if a prebuild is not available. On
28
30
  sudo apt-get install build-essential libudev-dev
29
31
  ```
30
32
 
33
+ # Troubleshooting
34
+
35
+ For libusb issues, please refer to the FAQ at https://github.com/libusb/libusb/wiki/FAQ
36
+
31
37
  # Installation
32
38
 
33
39
  Native modules are bundled using `prebuildify`, so installation should be as simple as installing the package.
package/binding.gyp CHANGED
@@ -34,7 +34,7 @@
34
34
  'defines': [
35
35
  '_FILE_OFFSET_BITS=64',
36
36
  '_LARGEFILE_SOURCE',
37
- 'NAPI_VERSION=6'
37
+ 'NAPI_VERSION=8'
38
38
  ],
39
39
  'include_dirs+': [
40
40
  'src/',
package/dist/index.js CHANGED
@@ -9,136 +9,58 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
9
9
  var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
10
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
11
  };
12
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
14
- return new (P || (P = Promise))(function (resolve, reject) {
15
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
17
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
18
- step((generator = generator.apply(thisArg, _arguments || [])).next());
19
- });
20
- };
21
- var __generator = (this && this.__generator) || function (thisArg, body) {
22
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
23
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
24
- function verb(n) { return function (v) { return step([n, v]); }; }
25
- function step(op) {
26
- if (f) throw new TypeError("Generator is already executing.");
27
- while (_) try {
28
- 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;
29
- if (y = 0, t) op = [op[0] & 2, t.value];
30
- switch (op[0]) {
31
- case 0: case 1: t = op; break;
32
- case 4: _.label++; return { value: op[1], done: false };
33
- case 5: _.label++; y = op[1]; op = [0]; continue;
34
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
35
- default:
36
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
37
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
38
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
39
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
40
- if (t[2]) _.ops.pop();
41
- _.trys.pop(); continue;
42
- }
43
- op = body.call(thisArg, _);
44
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
45
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
46
- }
47
- };
48
- var __values = (this && this.__values) || function(o) {
49
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
50
- if (m) return m.call(o);
51
- if (o && typeof o.length === "number") return {
52
- next: function () {
53
- if (o && i >= o.length) o = void 0;
54
- return { value: o && o[i++], done: !o };
55
- }
56
- };
57
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
58
- };
59
12
  Object.defineProperty(exports, "__esModule", { value: true });
60
13
  exports.LibUSBException = exports.useUsbDkBackend = exports.getDeviceList = exports.Transfer = exports.Device = exports.webusb = exports.findBySerialNumber = exports.findByIds = exports.usb = void 0;
61
- var util_1 = require("util");
62
- var webusb_1 = require("./webusb");
63
- var usb = require("./usb");
14
+ const util_1 = require("util");
15
+ const webusb_1 = require("./webusb");
16
+ const usb = require("./usb");
64
17
  exports.usb = usb;
65
18
  /**
66
19
  * Convenience method to get the first device with the specified VID and PID, or `undefined` if no such device is present.
67
20
  * @param vid
68
21
  * @param pid
69
22
  */
70
- var findByIds = function (vid, pid) {
71
- var devices = usb.getDeviceList();
72
- return devices.find(function (item) { return item.deviceDescriptor.idVendor === vid && item.deviceDescriptor.idProduct === pid; });
23
+ const findByIds = (vid, pid) => {
24
+ const devices = usb.getDeviceList();
25
+ return devices.find(item => item.deviceDescriptor.idVendor === vid && item.deviceDescriptor.idProduct === pid);
73
26
  };
74
27
  exports.findByIds = findByIds;
75
28
  /**
76
29
  * Convenience method to get the device with the specified serial number, or `undefined` if no such device is present.
77
30
  * @param serialNumber
78
31
  */
79
- var findBySerialNumber = function (serialNumber) { return __awaiter(void 0, void 0, void 0, function () {
80
- var devices, opened, devices_1, devices_1_1, device, getStringDescriptor, buffer, _a, e_1_1;
81
- var e_1, _b;
82
- return __generator(this, function (_c) {
83
- switch (_c.label) {
84
- case 0:
85
- devices = usb.getDeviceList();
86
- opened = function (device) { return !!device.interfaces; };
87
- _c.label = 1;
88
- case 1:
89
- _c.trys.push([1, 9, 10, 11]);
90
- devices_1 = __values(devices), devices_1_1 = devices_1.next();
91
- _c.label = 2;
92
- case 2:
93
- if (!!devices_1_1.done) return [3 /*break*/, 8];
94
- device = devices_1_1.value;
95
- _c.label = 3;
96
- case 3:
97
- _c.trys.push([3, 5, 6, 7]);
98
- if (!opened(device)) {
99
- device.open();
100
- }
101
- getStringDescriptor = util_1.promisify(device.getStringDescriptor).bind(device);
102
- return [4 /*yield*/, getStringDescriptor(device.deviceDescriptor.iSerialNumber)];
103
- case 4:
104
- buffer = _c.sent();
105
- if (buffer && buffer.toString() === serialNumber) {
106
- return [2 /*return*/, device];
107
- }
108
- return [3 /*break*/, 7];
109
- case 5:
110
- _a = _c.sent();
111
- return [3 /*break*/, 7];
112
- case 6:
113
- try {
114
- if (opened(device)) {
115
- device.close();
116
- }
117
- }
118
- catch (_d) {
119
- // Ignore any errors, device may be a system device or inaccessible
120
- }
121
- return [7 /*endfinally*/];
122
- case 7:
123
- devices_1_1 = devices_1.next();
124
- return [3 /*break*/, 2];
125
- case 8: return [3 /*break*/, 11];
126
- case 9:
127
- e_1_1 = _c.sent();
128
- e_1 = { error: e_1_1 };
129
- return [3 /*break*/, 11];
130
- case 10:
131
- try {
132
- if (devices_1_1 && !devices_1_1.done && (_b = devices_1.return)) _b.call(devices_1);
32
+ const findBySerialNumber = async (serialNumber) => {
33
+ const devices = usb.getDeviceList();
34
+ const opened = (device) => !!device.interfaces;
35
+ for (const device of devices) {
36
+ try {
37
+ if (!opened(device)) {
38
+ device.open();
39
+ }
40
+ const getStringDescriptor = util_1.promisify(device.getStringDescriptor).bind(device);
41
+ const buffer = await getStringDescriptor(device.deviceDescriptor.iSerialNumber);
42
+ if (buffer && buffer.toString() === serialNumber) {
43
+ return device;
44
+ }
45
+ }
46
+ catch {
47
+ // Ignore any errors, device may be a system device or inaccessible
48
+ }
49
+ finally {
50
+ try {
51
+ if (opened(device)) {
52
+ device.close();
133
53
  }
134
- finally { if (e_1) throw e_1.error; }
135
- return [7 /*endfinally*/];
136
- case 11: return [2 /*return*/, undefined];
54
+ }
55
+ catch {
56
+ // Ignore any errors, device may be a system device or inaccessible
57
+ }
137
58
  }
138
- });
139
- }); };
59
+ }
60
+ return undefined;
61
+ };
140
62
  exports.findBySerialNumber = findBySerialNumber;
141
- var webusb = new webusb_1.WebUSB();
63
+ const webusb = new webusb_1.WebUSB();
142
64
  exports.webusb = webusb;
143
65
  // Usb types
144
66
  var usb_1 = require("./usb");
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../tsc/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6BAAiC;AACjC,mCAAkC;AAClC,2BAA6B;AAoDzB,kBAAG;AAlDP;;;;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;AA6CE,8BAAS;AA3Cb;;;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,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AEhC,eAAe;AACf,2CAAyB;AACzB,yDAAuC"}
@@ -3,8 +3,8 @@
3
3
  // Eric Brody <https://github.com/underscorebrody>
4
4
  // Rob Moran <https://github.com/thegecko>
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- var path_1 = require("path");
6
+ const path_1 = require("path");
7
7
  /* eslint-disable @typescript-eslint/no-var-requires */
8
- var usb = require('node-gyp-build')(path_1.join(__dirname, '..', '..'));
8
+ const usb = require('node-gyp-build')(path_1.join(__dirname, '..', '..'));
9
9
  module.exports = usb;
10
10
  //# sourceMappingURL=bindings.js.map
@@ -1 +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"}
1
+ {"version":3,"file":"bindings.js","sourceRoot":"","sources":["../../tsc/usb/bindings.ts"],"names":[],"mappings":";AAAA,+CAA+C;AAC/C,mDAAmD;AACnD,2CAA2C;;AAE3C,+BAA4B;AAG5B,uDAAuD;AACvD,MAAM,GAAG,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC,WAAI,CAAC,SAAS,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;AACnE,MAAM,CAAC,OAAO,GAAG,GAAG,CAAC"}
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Capability = void 0;
4
- var Capability = /** @class */ (function () {
5
- function Capability(device, id) {
4
+ class Capability {
5
+ constructor(device, id) {
6
6
  this.device = device;
7
7
  this.id = id;
8
8
  if (!device._bosDescriptor) {
@@ -12,7 +12,6 @@ var Capability = /** @class */ (function () {
12
12
  this.type = this.descriptor.bDevCapabilityType;
13
13
  this.data = this.descriptor.dev_capability_data;
14
14
  }
15
- return Capability;
16
- }());
15
+ }
17
16
  exports.Capability = Capability;
18
17
  //# sourceMappingURL=capability.js.map
@@ -1 +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"}
1
+ {"version":3,"file":"capability.js","sourceRoot":"","sources":["../../tsc/usb/capability.ts"],"names":[],"mappings":";;;AAGA,MAAa,UAAU;IAUnB,YAAsB,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;CACJ;AAlBD,gCAkBC"}
@@ -1,101 +1,84 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
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() {
4
+ const usb = require("./bindings");
5
+ const interface_1 = require("./interface");
6
+ const capability_1 = require("./capability");
7
+ const isBuffer = (obj) => !!obj && obj instanceof Uint8Array;
8
+ const DEFAULT_TIMEOUT = 1000;
9
+ class ExtendedDevice {
10
+ constructor() {
11
11
  this._timeout = DEFAULT_TIMEOUT;
12
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();
13
+ /**
14
+ * Timeout in milliseconds to use for control transfers.
15
+ */
16
+ get timeout() {
17
+ return this._timeout || DEFAULT_TIMEOUT;
18
+ }
19
+ set timeout(value) {
20
+ this._timeout = value;
21
+ }
22
+ /**
23
+ * Object with properties for the fields of the active configuration descriptor.
24
+ */
25
+ get configDescriptor() {
26
+ try {
27
+ return this.__getConfigDescriptor();
28
+ }
29
+ catch (e) {
30
+ // Check descriptor exists
31
+ if (e.errno === usb.LIBUSB_ERROR_NOT_FOUND) {
32
+ return undefined;
52
33
  }
53
- catch (e) {
54
- // Check descriptors exist
55
- if (e.errno === usb.LIBUSB_ERROR_NOT_FOUND) {
56
- return [];
57
- }
58
- throw e;
34
+ throw e;
35
+ }
36
+ }
37
+ /**
38
+ * Contains all config descriptors of the device (same structure as .configDescriptor above)
39
+ */
40
+ get allConfigDescriptors() {
41
+ try {
42
+ return this.__getAllConfigDescriptors();
43
+ }
44
+ catch (e) {
45
+ // Check descriptors exist
46
+ if (e.errno === usb.LIBUSB_ERROR_NOT_FOUND) {
47
+ return [];
59
48
  }
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
- });
49
+ throw e;
50
+ }
51
+ }
52
+ /**
53
+ * Contains the parent of the device, such as a hub. If there is no parent this property is set to `null`.
54
+ */
55
+ get parent() {
56
+ return this.__getParent();
57
+ }
74
58
  /**
75
59
  * Open the device.
76
60
  * @param defaultConfig
77
61
  */
78
- ExtendedDevice.prototype.open = function (defaultConfig) {
79
- if (defaultConfig === void 0) { defaultConfig = true; }
62
+ open(defaultConfig = true) {
80
63
  this.__open();
81
64
  if (defaultConfig === false) {
82
65
  return;
83
66
  }
84
67
  this.interfaces = [];
85
- var len = this.configDescriptor ? this.configDescriptor.interfaces.length : 0;
86
- for (var i = 0; i < len; i++) {
68
+ const len = this.configDescriptor ? this.configDescriptor.interfaces.length : 0;
69
+ for (let i = 0; i < len; i++) {
87
70
  this.interfaces[i] = new interface_1.Interface(this, i);
88
71
  }
89
- };
72
+ }
90
73
  /**
91
74
  * Close the device.
92
75
  *
93
76
  * The device must be open to use this method.
94
77
  */
95
- ExtendedDevice.prototype.close = function () {
78
+ close() {
96
79
  this.__close();
97
80
  this.interfaces = undefined;
98
- };
81
+ }
99
82
  /**
100
83
  * 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
84
  * then before claiming an interface, call this method.
@@ -104,21 +87,20 @@ var ExtendedDevice = /** @class */ (function () {
104
87
  * @param desired
105
88
  * @param callback
106
89
  */
107
- ExtendedDevice.prototype.setConfiguration = function (desired, callback) {
108
- var _this = this;
109
- this.__setConfiguration(desired, function (error) {
90
+ setConfiguration(desired, callback) {
91
+ this.__setConfiguration(desired, error => {
110
92
  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);
93
+ this.interfaces = [];
94
+ const len = this.configDescriptor ? this.configDescriptor.interfaces.length : 0;
95
+ for (let i = 0; i < len; i++) {
96
+ this.interfaces[i] = new interface_1.Interface(this, i);
115
97
  }
116
98
  }
117
99
  if (callback) {
118
- callback.call(_this, error);
100
+ callback.call(this, error);
119
101
  }
120
102
  });
121
- };
103
+ }
122
104
  /**
123
105
  * Perform a control transfer with `libusb_control_transfer`.
124
106
  *
@@ -134,12 +116,11 @@ var ExtendedDevice = /** @class */ (function () {
134
116
  * @param data_or_length
135
117
  * @param callback
136
118
  */
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;
119
+ controlTransfer(bmRequestType, bRequest, wValue, wIndex, data_or_length, callback) {
120
+ const isIn = !!(bmRequestType & usb.LIBUSB_ENDPOINT_IN);
121
+ const wLength = isIn ? data_or_length : data_or_length.length;
141
122
  if (isIn) {
142
- if (!(data_or_length >= 0)) {
123
+ if (wLength < 0) {
143
124
  throw new TypeError('Expected size number for IN transfer (based on bmRequestType)');
144
125
  }
145
126
  }
@@ -150,7 +131,7 @@ var ExtendedDevice = /** @class */ (function () {
150
131
  }
151
132
  // Buffer for the setup packet
152
133
  // http://libusbx.sourceforge.net/api-1.0/structlibusb__control__setup.html
153
- var buf = Buffer.alloc(wLength + usb.LIBUSB_CONTROL_SETUP_SIZE);
134
+ const buf = Buffer.alloc(wLength + usb.LIBUSB_CONTROL_SETUP_SIZE);
154
135
  buf.writeUInt8(bmRequestType, 0);
155
136
  buf.writeUInt8(bRequest, 1);
156
137
  buf.writeUInt16LE(wValue, 2);
@@ -159,13 +140,13 @@ var ExtendedDevice = /** @class */ (function () {
159
140
  if (!isIn) {
160
141
  buf.set(data_or_length, usb.LIBUSB_CONTROL_SETUP_SIZE);
161
142
  }
162
- var transfer = new usb.Transfer(this, 0, usb.LIBUSB_TRANSFER_TYPE_CONTROL, this.timeout, function (error, buf, actual) {
143
+ const transfer = new usb.Transfer(this, 0, usb.LIBUSB_TRANSFER_TYPE_CONTROL, this.timeout, (error, buf, actual) => {
163
144
  if (callback) {
164
145
  if (isIn) {
165
- callback.call(_this, error, buf.slice(usb.LIBUSB_CONTROL_SETUP_SIZE, usb.LIBUSB_CONTROL_SETUP_SIZE + actual));
146
+ callback.call(this, error, buf.slice(usb.LIBUSB_CONTROL_SETUP_SIZE, usb.LIBUSB_CONTROL_SETUP_SIZE + actual));
166
147
  }
167
148
  else {
168
- callback.call(_this, error, actual);
149
+ callback.call(this, error, actual);
169
150
  }
170
151
  }
171
152
  });
@@ -174,29 +155,29 @@ var ExtendedDevice = /** @class */ (function () {
174
155
  }
175
156
  catch (e) {
176
157
  if (callback) {
177
- process.nextTick(function () { return callback.call(_this, e, undefined); });
158
+ process.nextTick(() => callback.call(this, e, undefined));
178
159
  }
179
160
  }
180
161
  return this;
181
- };
162
+ }
182
163
  /**
183
164
  * Return the interface with the specified interface number.
184
165
  *
185
166
  * The device must be open to use this method.
186
167
  * @param addr
187
168
  */
188
- ExtendedDevice.prototype.interface = function (addr) {
169
+ interface(addr) {
189
170
  if (!this.interfaces) {
190
171
  throw new Error('Device must be open before searching for interfaces');
191
172
  }
192
173
  addr = addr || 0;
193
- for (var i = 0; i < this.interfaces.length; i++) {
174
+ for (let i = 0; i < this.interfaces.length; i++) {
194
175
  if (this.interfaces[i].interfaceNumber === addr) {
195
176
  return this.interfaces[i];
196
177
  }
197
178
  }
198
- throw new Error("Interface not found for address: " + addr);
199
- };
179
+ throw new Error(`Interface not found for address: ${addr}`);
180
+ }
200
181
  /**
201
182
  * Perform a control transfer to retrieve a string descriptor
202
183
  *
@@ -204,29 +185,28 @@ var ExtendedDevice = /** @class */ (function () {
204
185
  * @param desc_index
205
186
  * @param callback
206
187
  */
207
- ExtendedDevice.prototype.getStringDescriptor = function (desc_index, callback) {
188
+ getStringDescriptor(desc_index, callback) {
208
189
  // Index 0 indicates null
209
190
  if (desc_index === 0) {
210
191
  callback();
211
192
  return;
212
193
  }
213
- var langid = 0x0409;
214
- var length = 255;
215
- this.controlTransfer(usb.LIBUSB_ENDPOINT_IN, usb.LIBUSB_REQUEST_GET_DESCRIPTOR, ((usb.LIBUSB_DT_STRING << 8) | desc_index), langid, length, function (error, buffer) {
194
+ const langid = 0x0409;
195
+ const length = 255;
196
+ this.controlTransfer(usb.LIBUSB_ENDPOINT_IN, usb.LIBUSB_REQUEST_GET_DESCRIPTOR, ((usb.LIBUSB_DT_STRING << 8) | desc_index), langid, length, (error, buffer) => {
216
197
  if (error) {
217
198
  return callback(error);
218
199
  }
219
200
  callback(undefined, isBuffer(buffer) ? buffer.toString('utf16le', 2) : undefined);
220
201
  });
221
- };
202
+ }
222
203
  /**
223
204
  * Perform a control transfer to retrieve an object with properties for the fields of the Binary Object Store descriptor.
224
205
  *
225
206
  * The device must be open to use this method.
226
207
  * @param callback
227
208
  */
228
- ExtendedDevice.prototype.getBosDescriptor = function (callback) {
229
- var _this = this;
209
+ getBosDescriptor(callback) {
230
210
  if (this._bosDescriptor) {
231
211
  // Cached descriptor
232
212
  return callback(undefined, this._bosDescriptor);
@@ -235,7 +215,7 @@ var ExtendedDevice = /** @class */ (function () {
235
215
  // BOS is only supported from USB 2.0.1
236
216
  return callback(undefined, undefined);
237
217
  }
238
- 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) {
218
+ this.controlTransfer(usb.LIBUSB_ENDPOINT_IN, usb.LIBUSB_REQUEST_GET_DESCRIPTOR, (usb.LIBUSB_DT_BOS << 8), 0, usb.LIBUSB_DT_BOS_SIZE, (error, buffer) => {
239
219
  if (error) {
240
220
  // Check BOS descriptor exists
241
221
  if (error.errno === usb.LIBUSB_TRANSFER_STALL)
@@ -245,8 +225,8 @@ var ExtendedDevice = /** @class */ (function () {
245
225
  if (!isBuffer(buffer)) {
246
226
  return callback(undefined, undefined);
247
227
  }
248
- var totalLength = buffer.readUInt16LE(2);
249
- _this.controlTransfer(usb.LIBUSB_ENDPOINT_IN, usb.LIBUSB_REQUEST_GET_DESCRIPTOR, (usb.LIBUSB_DT_BOS << 8), 0, totalLength, function (error, buffer) {
228
+ const totalLength = buffer.readUInt16LE(2);
229
+ this.controlTransfer(usb.LIBUSB_ENDPOINT_IN, usb.LIBUSB_REQUEST_GET_DESCRIPTOR, (usb.LIBUSB_DT_BOS << 8), 0, totalLength, (error, buffer) => {
250
230
  if (error) {
251
231
  // Check BOS descriptor exists
252
232
  if (error.errno === usb.LIBUSB_TRANSFER_STALL)
@@ -256,16 +236,16 @@ var ExtendedDevice = /** @class */ (function () {
256
236
  if (!isBuffer(buffer)) {
257
237
  return callback(undefined, undefined);
258
238
  }
259
- var descriptor = {
239
+ const descriptor = {
260
240
  bLength: buffer.readUInt8(0),
261
241
  bDescriptorType: buffer.readUInt8(1),
262
242
  wTotalLength: buffer.readUInt16LE(2),
263
243
  bNumDeviceCaps: buffer.readUInt8(4),
264
244
  capabilities: []
265
245
  };
266
- var i = usb.LIBUSB_DT_BOS_SIZE;
246
+ let i = usb.LIBUSB_DT_BOS_SIZE;
267
247
  while (i < descriptor.wTotalLength) {
268
- var capability = {
248
+ const capability = {
269
249
  bLength: buffer.readUInt8(i + 0),
270
250
  bDescriptorType: buffer.readUInt8(i + 1),
271
251
  bDevCapabilityType: buffer.readUInt8(i + 2),
@@ -275,31 +255,29 @@ var ExtendedDevice = /** @class */ (function () {
275
255
  i += capability.bLength;
276
256
  }
277
257
  // Cache descriptor
278
- _this._bosDescriptor = descriptor;
279
- callback(undefined, _this._bosDescriptor);
258
+ this._bosDescriptor = descriptor;
259
+ callback(undefined, this._bosDescriptor);
280
260
  });
281
261
  });
282
- };
262
+ }
283
263
  /**
284
264
  * Retrieve a list of Capability objects for the Binary Object Store capabilities of the device.
285
265
  *
286
266
  * The device must be open to use this method.
287
267
  * @param callback
288
268
  */
289
- ExtendedDevice.prototype.getCapabilities = function (callback) {
290
- var _this = this;
291
- var capabilities = [];
292
- this.getBosDescriptor(function (error, descriptor) {
269
+ getCapabilities(callback) {
270
+ const capabilities = [];
271
+ this.getBosDescriptor((error, descriptor) => {
293
272
  if (error)
294
273
  return callback(error, undefined);
295
- var len = descriptor ? descriptor.capabilities.length : 0;
296
- for (var i = 0; i < len; i++) {
297
- capabilities.push(new capability_1.Capability(_this, i));
274
+ const len = descriptor ? descriptor.capabilities.length : 0;
275
+ for (let i = 0; i < len; i++) {
276
+ capabilities.push(new capability_1.Capability(this, i));
298
277
  }
299
278
  callback(undefined, capabilities);
300
279
  });
301
- };
302
- return ExtendedDevice;
303
- }());
280
+ }
281
+ }
304
282
  exports.ExtendedDevice = ExtendedDevice;
305
283
  //# sourceMappingURL=device.js.map