@psdk/device-webusb 0.5.16 → 0.5.18
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/README.md +19 -0
- package/build/index.js +18 -8
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/README.md
ADDED
package/build/index.js
CHANGED
|
@@ -3,17 +3,25 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.DeviceFilter = exports.WebusbReadOptions = exports.Webusb = void 0;
|
|
4
4
|
const frame_father_1 = require("@psdk/frame-father");
|
|
5
5
|
class Webusb {
|
|
6
|
+
filters;
|
|
7
|
+
configuration;
|
|
8
|
+
interface;
|
|
9
|
+
readEndpoint;
|
|
10
|
+
writeEndpoint;
|
|
11
|
+
inputReadEndpoint;
|
|
12
|
+
inputWriteEndpoint;
|
|
13
|
+
state;
|
|
14
|
+
device;
|
|
6
15
|
constructor(options) {
|
|
7
|
-
var _a, _b, _c, _d;
|
|
8
16
|
if (options.filters.length == 0) {
|
|
9
17
|
throw new Error('Missing filters');
|
|
10
18
|
}
|
|
11
19
|
this.filters = options.filters;
|
|
12
|
-
this.configuration =
|
|
13
|
-
this.interface =
|
|
20
|
+
this.configuration = options.configuration ?? 1;
|
|
21
|
+
this.interface = options.interface ?? 0;
|
|
14
22
|
this.state = frame_father_1.ConnectionState.DISCONNECTED;
|
|
15
|
-
this.inputReadEndpoint =
|
|
16
|
-
this.inputWriteEndpoint =
|
|
23
|
+
this.inputReadEndpoint = options.readEndpoint ?? 2;
|
|
24
|
+
this.inputWriteEndpoint = options.writeEndpoint ?? 2;
|
|
17
25
|
}
|
|
18
26
|
static withFilter(filter) {
|
|
19
27
|
return this.withFilters([filter]);
|
|
@@ -80,7 +88,7 @@ class Webusb {
|
|
|
80
88
|
}
|
|
81
89
|
async read(options) {
|
|
82
90
|
const device = _device();
|
|
83
|
-
const _options = options
|
|
91
|
+
const _options = options ?? WebusbReadOptions.def();
|
|
84
92
|
const result = await device.transferIn(_readEndpoint(), _options.readLength);
|
|
85
93
|
const { status, data } = result;
|
|
86
94
|
if (status != 'ok') {
|
|
@@ -104,10 +112,10 @@ class Webusb {
|
|
|
104
112
|
}
|
|
105
113
|
exports.Webusb = Webusb;
|
|
106
114
|
class WebusbReadOptions extends frame_father_1.ReadOptions {
|
|
115
|
+
_length;
|
|
107
116
|
constructor(options) {
|
|
108
|
-
var _a;
|
|
109
117
|
super(options);
|
|
110
|
-
this._length =
|
|
118
|
+
this._length = options?.length ?? 1024;
|
|
111
119
|
}
|
|
112
120
|
static def() {
|
|
113
121
|
return new WebusbReadOptions();
|
|
@@ -118,6 +126,8 @@ class WebusbReadOptions extends frame_father_1.ReadOptions {
|
|
|
118
126
|
}
|
|
119
127
|
exports.WebusbReadOptions = WebusbReadOptions;
|
|
120
128
|
class DeviceFilter {
|
|
129
|
+
vendorId;
|
|
130
|
+
productId;
|
|
121
131
|
constructor(options) {
|
|
122
132
|
this.vendorId = options.vendorId;
|
|
123
133
|
this.productId = options.productId;
|