@danidoble/webserial 4.3.3 → 4.3.5
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/dist/boardroid.cjs +1 -1
- package/dist/boardroid.js +506 -478
- package/dist/hopper.cjs +2 -2
- package/dist/hopper.js +132 -121
- package/dist/jofemar.cjs +1 -1
- package/dist/jofemar.js +732 -705
- package/dist/kernel-D8A562gb.cjs +1 -0
- package/dist/kernel-DAtdBEi3.js +815 -0
- package/dist/kernel.cjs +2 -2
- package/dist/kernel.js +3 -3
- package/dist/locker.cjs +1 -1
- package/dist/locker.js +81 -83
- package/dist/pinpad.cjs +21 -21
- package/dist/pinpad.js +3386 -3278
- package/dist/pinpax.cjs +4 -4
- package/dist/pinpax.js +112 -116
- package/dist/relay.cjs +1 -1
- package/dist/relay.js +2 -2
- package/dist/{webserial-core-ByrJ7tlu.js → webserial-core-BjytHor1.js} +179 -182
- package/dist/webserial-core-N14HUamr.cjs +4 -0
- package/dist/webserial.cjs +2 -2
- package/dist/webserial.js +4 -4
- package/package.json +3 -3
- package/dist/kernel-BblykfpT.js +0 -875
- package/dist/kernel-CzkmE_OW.cjs +0 -1
- package/dist/webserial-core-5B5nYtyR.cjs +0 -4
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
var
|
|
2
|
-
throw TypeError(
|
|
3
|
-
},
|
|
4
|
-
class
|
|
1
|
+
var V = Object.defineProperty, R = (n) => {
|
|
2
|
+
throw TypeError(n);
|
|
3
|
+
}, z = (n, e, t) => e in n ? V(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t, y = (n, e, t) => z(n, typeof e != "symbol" ? e + "" : e, t), T = (n, e, t) => e.has(n) || R("Cannot " + t), b = (n, e, t) => (T(n, e, "read from private field"), e.get(n)), S = (n, e, t) => e.has(n) ? R("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(n) : e.set(n, t), J = (n, e, t, i) => (T(n, e, "write to private field"), e.set(n, t), t), l = (n, e, t) => (T(n, e, "access private method"), t);
|
|
4
|
+
class A extends CustomEvent {
|
|
5
5
|
constructor(e, t) {
|
|
6
6
|
super(e, t);
|
|
7
7
|
}
|
|
8
8
|
}
|
|
9
|
-
class
|
|
9
|
+
class I extends EventTarget {
|
|
10
10
|
constructor() {
|
|
11
|
-
super(...arguments),
|
|
11
|
+
super(...arguments), y(this, "__listeners__", {
|
|
12
12
|
debug: !1
|
|
13
|
-
}),
|
|
13
|
+
}), y(this, "__debug__", !1), y(this, "__listenersCallbacks__", []);
|
|
14
14
|
}
|
|
15
15
|
dispatch(e, t = null) {
|
|
16
|
-
const
|
|
17
|
-
this.dispatchEvent(
|
|
16
|
+
const i = new A(e, { detail: t });
|
|
17
|
+
this.dispatchEvent(i), this.__debug__ && this.dispatchEvent(new A("debug", { detail: { type: e, data: t } }));
|
|
18
18
|
}
|
|
19
|
-
dispatchAsync(e, t = null,
|
|
19
|
+
dispatchAsync(e, t = null, i = 100) {
|
|
20
20
|
const s = this;
|
|
21
21
|
setTimeout(() => {
|
|
22
22
|
s.dispatch(e, t);
|
|
23
|
-
},
|
|
23
|
+
}, i);
|
|
24
24
|
}
|
|
25
25
|
on(e, t) {
|
|
26
26
|
typeof this.__listeners__[e] < "u" && !this.__listeners__[e] && (this.__listeners__[e] = !0), this.__listenersCallbacks__.push({ key: e, callback: t }), this.addEventListener(e, t);
|
|
27
27
|
}
|
|
28
28
|
off(e, t) {
|
|
29
|
-
this.__listenersCallbacks__ = this.__listenersCallbacks__.filter((
|
|
29
|
+
this.__listenersCallbacks__ = this.__listenersCallbacks__.filter((i) => !(i.key === e && i.callback === t)), this.removeEventListener(e, t);
|
|
30
30
|
}
|
|
31
31
|
serialRegisterAvailableListener(e) {
|
|
32
32
|
this.__listeners__[e] || (this.__listeners__[e] = !1);
|
|
@@ -39,13 +39,12 @@ class P extends EventTarget {
|
|
|
39
39
|
}
|
|
40
40
|
removeAllListeners() {
|
|
41
41
|
for (const e of this.__listenersCallbacks__)
|
|
42
|
-
this.removeEventListener(e.key, e.callback);
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
};
|
|
42
|
+
["internal:queue"].includes(e.key) || (this.__listenersCallbacks__ = this.__listenersCallbacks__.filter((t) => !(t.key === e.key && t.callback === e.callback)), this.removeEventListener(e.key, e.callback));
|
|
43
|
+
for (const e of Object.keys(this.__listeners__))
|
|
44
|
+
this.__listeners__[e] = !1;
|
|
46
45
|
}
|
|
47
46
|
}
|
|
48
|
-
const
|
|
47
|
+
const C = class a extends I {
|
|
49
48
|
constructor() {
|
|
50
49
|
super(), ["change"].forEach((e) => {
|
|
51
50
|
this.serialRegisterAvailableListener(e);
|
|
@@ -64,10 +63,10 @@ const w = class a extends P {
|
|
|
64
63
|
static add(e) {
|
|
65
64
|
const t = e.typeDevice;
|
|
66
65
|
typeof a.devices[t] > "u" && a.registerType(t);
|
|
67
|
-
const
|
|
68
|
-
if (typeof a.devices[t] > "u" && a.typeError(t), a.devices[t][
|
|
69
|
-
throw new Error(`Device with id ${
|
|
70
|
-
return a.devices[t][
|
|
66
|
+
const i = e.uuid;
|
|
67
|
+
if (typeof a.devices[t] > "u" && a.typeError(t), a.devices[t][i])
|
|
68
|
+
throw new Error(`Device with id ${i} already exists`);
|
|
69
|
+
return a.devices[t][i] = e, a.$dispatchChange(e), Object.keys(a.devices[t]).indexOf(i);
|
|
71
70
|
}
|
|
72
71
|
static get(e, t) {
|
|
73
72
|
return typeof a.devices[e] > "u" && a.registerType(e), typeof a.devices[e] > "u" && a.typeError(e), a.devices[e][t];
|
|
@@ -79,10 +78,10 @@ const w = class a extends P {
|
|
|
79
78
|
return Object.values(a.devices).map((e) => Object.values(e)).flat();
|
|
80
79
|
}
|
|
81
80
|
static getByNumber(e, t) {
|
|
82
|
-
return typeof a.devices[e] > "u" && a.typeError(e), Object.values(a.devices[e]).find((
|
|
81
|
+
return typeof a.devices[e] > "u" && a.typeError(e), Object.values(a.devices[e]).find((i) => i.deviceNumber === t) ?? null;
|
|
83
82
|
}
|
|
84
83
|
static getCustom(e, t = 1) {
|
|
85
|
-
return typeof a.devices[e] > "u" && a.typeError(e), Object.values(a.devices[e]).find((
|
|
84
|
+
return typeof a.devices[e] > "u" && a.typeError(e), Object.values(a.devices[e]).find((i) => i.deviceNumber === t) ?? null;
|
|
86
85
|
}
|
|
87
86
|
static async connectToAll() {
|
|
88
87
|
const e = a.getList();
|
|
@@ -117,18 +116,18 @@ const w = class a extends P {
|
|
|
117
116
|
return Promise.resolve(e.filter((t) => t.isDisconnected));
|
|
118
117
|
}
|
|
119
118
|
};
|
|
120
|
-
|
|
121
|
-
let c =
|
|
119
|
+
y(C, "instance"), y(C, "devices", {});
|
|
120
|
+
let c = C;
|
|
122
121
|
c.instance || (c.instance = new c());
|
|
123
|
-
function
|
|
122
|
+
function M(n = 100) {
|
|
124
123
|
return new Promise(
|
|
125
|
-
(e) => setTimeout(() => e(),
|
|
124
|
+
(e) => setTimeout(() => e(), n)
|
|
126
125
|
);
|
|
127
126
|
}
|
|
128
|
-
function
|
|
127
|
+
function G() {
|
|
129
128
|
return "serial" in navigator;
|
|
130
129
|
}
|
|
131
|
-
const
|
|
130
|
+
const v = {
|
|
132
131
|
baudRate: 9600,
|
|
133
132
|
dataBits: 8,
|
|
134
133
|
stopBits: 1,
|
|
@@ -136,22 +135,22 @@ const b = {
|
|
|
136
135
|
bufferSize: 32768,
|
|
137
136
|
flowControl: "none"
|
|
138
137
|
};
|
|
139
|
-
var r,
|
|
140
|
-
class
|
|
138
|
+
var p, r, f, m, q, x, k, u, N, L, D, B, P, O, g, H, j, F, U, $, W, Q;
|
|
139
|
+
class K extends I {
|
|
141
140
|
constructor({
|
|
142
141
|
filters: e = null,
|
|
143
|
-
config_port: t =
|
|
144
|
-
no_device:
|
|
142
|
+
config_port: t = v,
|
|
143
|
+
no_device: i = 1,
|
|
145
144
|
device_listen_on_channel: s = 1,
|
|
146
145
|
bypassSerialBytesConnection: o = !1
|
|
147
146
|
} = {
|
|
148
147
|
filters: null,
|
|
149
|
-
config_port:
|
|
148
|
+
config_port: v,
|
|
150
149
|
no_device: 1,
|
|
151
150
|
device_listen_on_channel: 1,
|
|
152
151
|
bypassSerialBytesConnection: !1
|
|
153
152
|
}) {
|
|
154
|
-
if (super(),
|
|
153
|
+
if (super(), S(this, r), y(this, "__internal__", {
|
|
155
154
|
bypassSerialBytesConnection: !1,
|
|
156
155
|
auto_response: !1,
|
|
157
156
|
device_number: 1,
|
|
@@ -188,7 +187,7 @@ class z extends P {
|
|
|
188
187
|
delay_first_connection: 200,
|
|
189
188
|
bytes_connection: null,
|
|
190
189
|
filters: [],
|
|
191
|
-
config_port:
|
|
190
|
+
config_port: v,
|
|
192
191
|
queue: [],
|
|
193
192
|
auto_response: ["DD", "DD"],
|
|
194
193
|
free_timeout_ms: 50,
|
|
@@ -211,9 +210,9 @@ class z extends P {
|
|
|
211
210
|
interval: {
|
|
212
211
|
reconnection: 0
|
|
213
212
|
}
|
|
214
|
-
}), !("serial" in navigator))
|
|
213
|
+
}), S(this, p, null), !("serial" in navigator))
|
|
215
214
|
throw new Error("Web Serial not supported");
|
|
216
|
-
e && (this.serialFilters = e), t && (this.serialConfigPort = t), o && (this.__internal__.bypassSerialBytesConnection = o),
|
|
215
|
+
e && (this.serialFilters = e), t && (this.serialConfigPort = t), o && (this.__internal__.bypassSerialBytesConnection = o), i && l(this, r, W).call(this, i), s && ["number", "string"].includes(typeof s) && (this.listenOnChannel = s), l(this, r, j).call(this), l(this, r, F).call(this);
|
|
217
216
|
}
|
|
218
217
|
set listenOnChannel(e) {
|
|
219
218
|
if (typeof e == "string" && (e = parseInt(e)), isNaN(e) || e < 1 || e > 255)
|
|
@@ -247,15 +246,15 @@ class z extends P {
|
|
|
247
246
|
this.__internal__.serial.useRTSCTS = e;
|
|
248
247
|
}
|
|
249
248
|
get isConnected() {
|
|
250
|
-
const e = this.__internal__.serial.connected, t = l(this, r,
|
|
251
|
-
return e && !t && l(this, r,
|
|
249
|
+
const e = this.__internal__.serial.connected, t = l(this, r, f).call(this, this.__internal__.serial.port);
|
|
250
|
+
return e && !t && l(this, r, m).call(this, { error: "Port is closed, not readable or writable." }), this.__internal__.serial.connected = t, this.__internal__.serial.connected;
|
|
252
251
|
}
|
|
253
252
|
get isConnecting() {
|
|
254
253
|
return this.__internal__.serial.connecting;
|
|
255
254
|
}
|
|
256
255
|
get isDisconnected() {
|
|
257
|
-
const e = this.__internal__.serial.connected, t = l(this, r,
|
|
258
|
-
return !e && t && (this.dispatch("serial:connected"), l(this, r,
|
|
256
|
+
const e = this.__internal__.serial.connected, t = l(this, r, f).call(this, this.__internal__.serial.port);
|
|
257
|
+
return !e && t && (this.dispatch("serial:connected"), l(this, r, g).call(this, !1), c.$dispatchChange(this)), this.__internal__.serial.connected = t, !this.__internal__.serial.connected;
|
|
259
258
|
}
|
|
260
259
|
get deviceNumber() {
|
|
261
260
|
return this.__internal__.device_number;
|
|
@@ -333,15 +332,13 @@ class z extends P {
|
|
|
333
332
|
});
|
|
334
333
|
}
|
|
335
334
|
async disconnect(e = null) {
|
|
336
|
-
await this.serialDisconnect(), l(this, r,
|
|
335
|
+
await this.serialDisconnect(), l(this, r, m).call(this, e);
|
|
337
336
|
}
|
|
338
337
|
async connect() {
|
|
339
338
|
return this.isConnected ? !0 : (this.__internal__.serial.aux_connecting = "idle", new Promise((e, t) => {
|
|
340
|
-
|
|
341
|
-
const
|
|
342
|
-
|
|
343
|
-
const s = setInterval(() => {
|
|
344
|
-
this.__internal__.serial.aux_connecting === "finished" ? (clearInterval(s), this.__internal__.serial.aux_connecting = "idle", this.off("serial:connecting", n), this.isConnected ? e(!0) : t(`${this.typeDevice} device ${this.deviceNumber} not connected`)) : this.__internal__.serial.aux_connecting === "connecting" && (this.__internal__.serial.aux_connecting = "idle", this.dispatch("serial:connecting", { active: !0 }));
|
|
339
|
+
G() || t("Web Serial not supported"), b(this, p) || J(this, p, l(this, r, q).bind(this)), this.on("internal:connecting", b(this, p));
|
|
340
|
+
const i = setInterval(() => {
|
|
341
|
+
this.__internal__.serial.aux_connecting === "finished" ? (clearInterval(i), this.__internal__.serial.aux_connecting = "idle", b(this, p) !== null && this.off("internal:connecting", b(this, p)), this.isConnected ? e(!0) : t(`${this.typeDevice} device ${this.deviceNumber} not connected`)) : this.__internal__.serial.aux_connecting === "connecting" && (this.__internal__.serial.aux_connecting = "idle", this.dispatch("internal:connecting", { active: !0 }), this.dispatch("serial:connecting", { active: !0 }));
|
|
345
342
|
}, 100);
|
|
346
343
|
this.serialConnect();
|
|
347
344
|
}));
|
|
@@ -349,7 +346,7 @@ class z extends P {
|
|
|
349
346
|
async serialDisconnect() {
|
|
350
347
|
try {
|
|
351
348
|
const e = this.__internal__.serial.reader, t = this.__internal__.serial.output_stream;
|
|
352
|
-
e && (await e.cancel().catch((
|
|
349
|
+
e && (await e.cancel().catch((i) => this.serialErrors(i)), await this.__internal__.serial.input_done), t && (await t.getWriter().close(), await this.__internal__.serial.output_done), this.__internal__.serial.connected && this.__internal__.serial && this.__internal__.serial.port && await this.__internal__.serial.port.close();
|
|
353
350
|
} catch (e) {
|
|
354
351
|
this.serialErrors(e);
|
|
355
352
|
} finally {
|
|
@@ -371,8 +368,8 @@ class z extends P {
|
|
|
371
368
|
async serialPortsSaved(e) {
|
|
372
369
|
const t = this.serialFilters;
|
|
373
370
|
if (this.__internal__.aux_port_connector < e.length) {
|
|
374
|
-
const
|
|
375
|
-
this.__internal__.serial.port = e[
|
|
371
|
+
const i = this.__internal__.aux_port_connector;
|
|
372
|
+
this.__internal__.serial.port = e[i];
|
|
376
373
|
} else
|
|
377
374
|
this.__internal__.aux_port_connector = 0, this.__internal__.serial.port = await navigator.serial.requestPort({
|
|
378
375
|
filters: t
|
|
@@ -429,8 +426,8 @@ class z extends P {
|
|
|
429
426
|
}
|
|
430
427
|
async serialConnect() {
|
|
431
428
|
try {
|
|
432
|
-
l(this, r,
|
|
433
|
-
const e = await l(this, r,
|
|
429
|
+
l(this, r, g).call(this, !0);
|
|
430
|
+
const e = await l(this, r, N).call(this);
|
|
434
431
|
if (e.length > 0)
|
|
435
432
|
await this.serialPortsSaved(e);
|
|
436
433
|
else {
|
|
@@ -443,24 +440,24 @@ class z extends P {
|
|
|
443
440
|
if (!t)
|
|
444
441
|
throw new Error("No port selected by the user");
|
|
445
442
|
await t.open(this.serialConfigPort);
|
|
446
|
-
const
|
|
443
|
+
const i = this;
|
|
447
444
|
t.onconnect = (s) => {
|
|
448
445
|
var o;
|
|
449
|
-
|
|
446
|
+
i.dispatch("serial:connected", s), l(o = i, r, g).call(o, !1), c.$dispatchChange(this), i.__internal__.serial.queue.length > 0 && i.dispatch("internal:queue", {});
|
|
450
447
|
}, t.ondisconnect = async () => {
|
|
451
|
-
await
|
|
452
|
-
}, await
|
|
453
|
-
await
|
|
454
|
-
}, this.__internal__.time.response_connection), this.__internal__.serial.last_action = "connect", await l(this, r,
|
|
448
|
+
await i.disconnect();
|
|
449
|
+
}, await M(this.__internal__.serial.delay_first_connection), this.__internal__.timeout.until_response = setTimeout(async () => {
|
|
450
|
+
await i.timeout(i.__internal__.serial.bytes_connection ?? [], "connection:start");
|
|
451
|
+
}, this.__internal__.time.response_connection), this.__internal__.serial.last_action = "connect", await l(this, r, x).call(this, this.__internal__.serial.bytes_connection ?? []), this.dispatch("serial:sent", {
|
|
455
452
|
action: "connect",
|
|
456
453
|
bytes: this.__internal__.serial.bytes_connection
|
|
457
|
-
}), this.__internal__.auto_response && l(this, r, u).call(this, this.__internal__.serial.auto_response), await l(this, r,
|
|
454
|
+
}), this.__internal__.auto_response && l(this, r, u).call(this, this.__internal__.serial.auto_response), await l(this, r, O).call(this);
|
|
458
455
|
} catch (e) {
|
|
459
|
-
l(this, r,
|
|
456
|
+
l(this, r, g).call(this, !1), this.serialErrors(e);
|
|
460
457
|
}
|
|
461
458
|
}
|
|
462
459
|
async serialForget() {
|
|
463
|
-
return await l(this, r,
|
|
460
|
+
return await l(this, r, H).call(this);
|
|
464
461
|
}
|
|
465
462
|
decToHex(e) {
|
|
466
463
|
return typeof e == "string" && (e = parseInt(e, 10)), e.toString(16);
|
|
@@ -473,8 +470,8 @@ class z extends P {
|
|
|
473
470
|
}
|
|
474
471
|
add0x(e) {
|
|
475
472
|
const t = [];
|
|
476
|
-
return e.forEach((
|
|
477
|
-
t[s] = "0x" +
|
|
473
|
+
return e.forEach((i, s) => {
|
|
474
|
+
t[s] = "0x" + i;
|
|
478
475
|
}), t;
|
|
479
476
|
}
|
|
480
477
|
bytesToHex(e) {
|
|
@@ -495,13 +492,13 @@ class z extends P {
|
|
|
495
492
|
return t;
|
|
496
493
|
}
|
|
497
494
|
async appendToQueue(e, t) {
|
|
498
|
-
const
|
|
495
|
+
const i = this.validateBytes(e);
|
|
499
496
|
if (["connect", "connection:start"].includes(t)) {
|
|
500
497
|
if (this.__internal__.serial.connected) return;
|
|
501
498
|
await this.serialConnect();
|
|
502
499
|
return;
|
|
503
500
|
}
|
|
504
|
-
this.__internal__.serial.queue.push({ bytes:
|
|
501
|
+
this.__internal__.serial.queue.push({ bytes: i, action: t }), this.dispatch("internal:queue", {});
|
|
505
502
|
}
|
|
506
503
|
serialSetConnectionConstant(e = 1) {
|
|
507
504
|
if (this.__internal__.bypassSerialBytesConnection) return this.__internal__.serial.bytes_connection;
|
|
@@ -518,8 +515,8 @@ class z extends P {
|
|
|
518
515
|
}
|
|
519
516
|
sumHex(e) {
|
|
520
517
|
let t = 0;
|
|
521
|
-
return e.forEach((
|
|
522
|
-
t += parseInt(
|
|
518
|
+
return e.forEach((i) => {
|
|
519
|
+
t += parseInt(i, 16);
|
|
523
520
|
}), t.toString(16);
|
|
524
521
|
}
|
|
525
522
|
toString() {
|
|
@@ -532,7 +529,7 @@ class z extends P {
|
|
|
532
529
|
});
|
|
533
530
|
}
|
|
534
531
|
softReload() {
|
|
535
|
-
l(this, r,
|
|
532
|
+
l(this, r, Q).call(this), this.dispatch("serial:soft-reload", {});
|
|
536
533
|
}
|
|
537
534
|
async sendConnect() {
|
|
538
535
|
if (!this.__internal__.serial.bytes_connection)
|
|
@@ -553,13 +550,13 @@ class z extends P {
|
|
|
553
550
|
}
|
|
554
551
|
parseStringToTextEncoder(e = "", t = `
|
|
555
552
|
`) {
|
|
556
|
-
const
|
|
557
|
-
return e += t,
|
|
553
|
+
const i = new TextEncoder();
|
|
554
|
+
return e += t, i.encode(e);
|
|
558
555
|
}
|
|
559
556
|
parseStringToBytes(e = "", t = `
|
|
560
557
|
`) {
|
|
561
|
-
const
|
|
562
|
-
return Array.from(
|
|
558
|
+
const i = this.parseStringToTextEncoder(e, t);
|
|
559
|
+
return Array.from(i).map((s) => s.toString(16));
|
|
563
560
|
}
|
|
564
561
|
parseUint8ToHex(e) {
|
|
565
562
|
return Array.from(e).map((t) => t.toString(16));
|
|
@@ -569,28 +566,28 @@ class z extends P {
|
|
|
569
566
|
}
|
|
570
567
|
stringArrayToUint8Array(e) {
|
|
571
568
|
const t = [];
|
|
572
|
-
return typeof e == "string" ? this.parseStringToTextEncoder(e).buffer : (e.forEach((
|
|
573
|
-
const s =
|
|
569
|
+
return typeof e == "string" ? this.parseStringToTextEncoder(e).buffer : (e.forEach((i) => {
|
|
570
|
+
const s = i.replace("0x", "");
|
|
574
571
|
t.push(parseInt(s, 16));
|
|
575
572
|
}), new Uint8Array(t));
|
|
576
573
|
}
|
|
577
574
|
parseUint8ArrayToString(e) {
|
|
578
575
|
let t = new Uint8Array(0);
|
|
579
576
|
e instanceof Uint8Array ? t = e : t = this.stringArrayToUint8Array(e), e = this.parseUint8ToHex(t);
|
|
580
|
-
const
|
|
581
|
-
return this.__internal__.serial.response.replacer ? String.fromCharCode(...
|
|
577
|
+
const i = e.map((s) => parseInt(s, 16));
|
|
578
|
+
return this.__internal__.serial.response.replacer ? String.fromCharCode(...i).replace(this.__internal__.serial.response.replacer, "") : String.fromCharCode(...i);
|
|
582
579
|
}
|
|
583
580
|
hexToAscii(e) {
|
|
584
581
|
const t = e.toString();
|
|
585
|
-
let
|
|
582
|
+
let i = "";
|
|
586
583
|
for (let s = 0; s < t.length; s += 2)
|
|
587
|
-
|
|
588
|
-
return
|
|
584
|
+
i += String.fromCharCode(parseInt(t.substring(s, 2), 16));
|
|
585
|
+
return i;
|
|
589
586
|
}
|
|
590
587
|
asciiToHex(e) {
|
|
591
588
|
const t = [];
|
|
592
|
-
for (let
|
|
593
|
-
const o = Number(e.charCodeAt(
|
|
589
|
+
for (let i = 0, s = e.length; i < s; i++) {
|
|
590
|
+
const o = Number(e.charCodeAt(i)).toString(16);
|
|
594
591
|
t.push(o);
|
|
595
592
|
}
|
|
596
593
|
return t.join("");
|
|
@@ -599,151 +596,151 @@ class z extends P {
|
|
|
599
596
|
return this.isConnected;
|
|
600
597
|
}
|
|
601
598
|
}
|
|
602
|
-
r = /* @__PURE__ */ new WeakSet(),
|
|
603
|
-
return !!(
|
|
604
|
-
},
|
|
605
|
-
this.__internal__.serial.connected = !1, this.__internal__.aux_port_connector = 0, this.dispatch("serial:disconnected",
|
|
606
|
-
},
|
|
607
|
-
this.__internal__.serial.aux_connecting =
|
|
608
|
-
},
|
|
599
|
+
p = /* @__PURE__ */ new WeakMap(), r = /* @__PURE__ */ new WeakSet(), f = function(n) {
|
|
600
|
+
return !!(n && n.readable && n.writable);
|
|
601
|
+
}, m = function(n = null) {
|
|
602
|
+
this.__internal__.serial.connected = !1, this.__internal__.aux_port_connector = 0, this.dispatch("serial:disconnected", n), c.$dispatchChange(this);
|
|
603
|
+
}, q = function(n) {
|
|
604
|
+
this.__internal__.serial.aux_connecting = n.detail.active ? "connecting" : "finished";
|
|
605
|
+
}, x = async function(n) {
|
|
609
606
|
const e = this.__internal__.serial.port;
|
|
610
607
|
if (!e || e && (!e.readable || !e.writable))
|
|
611
|
-
throw l(this, r,
|
|
612
|
-
const t = this.validateBytes(
|
|
613
|
-
if (this.useRTSCTS && await l(this, r,
|
|
614
|
-
const
|
|
615
|
-
await
|
|
616
|
-
},
|
|
608
|
+
throw l(this, r, m).call(this, { error: "Port is closed, not readable or writable." }), new Error("The port is closed or is not readable/writable");
|
|
609
|
+
const t = this.validateBytes(n);
|
|
610
|
+
if (this.useRTSCTS && await l(this, r, k).call(this, e, 5e3), e.writable === null) return;
|
|
611
|
+
const i = e.writable.getWriter();
|
|
612
|
+
await i.write(t), i.releaseLock();
|
|
613
|
+
}, k = async function(n, e = 5e3) {
|
|
617
614
|
const t = Date.now();
|
|
618
615
|
for (; ; ) {
|
|
619
616
|
if (Date.now() - t > e)
|
|
620
617
|
throw new Error("Timeout waiting for clearToSend signal");
|
|
621
|
-
const { clearToSend:
|
|
622
|
-
if (
|
|
623
|
-
await
|
|
618
|
+
const { clearToSend: i } = await n.getSignals();
|
|
619
|
+
if (i) return;
|
|
620
|
+
await M(100);
|
|
624
621
|
}
|
|
625
|
-
}, u = function(
|
|
626
|
-
if (
|
|
622
|
+
}, u = function(n = new Uint8Array([]), e = !1) {
|
|
623
|
+
if (n && n.length > 0) {
|
|
627
624
|
const t = this.__internal__.serial.connected;
|
|
628
|
-
if (this.__internal__.serial.connected = l(this, r,
|
|
629
|
-
e ? this.serialCorruptMessage(this.parseUint8ToHex(
|
|
625
|
+
if (this.__internal__.serial.connected = l(this, r, f).call(this, this.__internal__.serial.port), c.$dispatchChange(this), !t && this.__internal__.serial.connected && (this.dispatch("serial:connected"), l(this, r, g).call(this, !1)), this.__internal__.interval.reconnection && (clearInterval(this.__internal__.interval.reconnection), this.__internal__.interval.reconnection = 0), this.__internal__.timeout.until_response && (clearTimeout(this.__internal__.timeout.until_response), this.__internal__.timeout.until_response = 0), this.__internal__.serial.response.as === "hex")
|
|
626
|
+
e ? this.serialCorruptMessage(this.parseUint8ToHex(n)) : this.serialMessage(this.parseUint8ToHex(n));
|
|
630
627
|
else if (this.__internal__.serial.response.as === "uint8")
|
|
631
|
-
e ? this.serialCorruptMessage(
|
|
628
|
+
e ? this.serialCorruptMessage(n) : this.serialMessage(n);
|
|
632
629
|
else if (this.__internal__.serial.response.as === "string") {
|
|
633
|
-
const
|
|
630
|
+
const i = this.parseUint8ArrayToString(n);
|
|
634
631
|
if (this.__internal__.serial.response.limiter !== null) {
|
|
635
|
-
const s =
|
|
632
|
+
const s = i.split(this.__internal__.serial.response.limiter);
|
|
636
633
|
for (const o in s)
|
|
637
634
|
s[o] && (e ? this.serialCorruptMessage(s[o]) : this.serialMessage(s[o]));
|
|
638
635
|
} else
|
|
639
|
-
e ? this.serialCorruptMessage(
|
|
636
|
+
e ? this.serialCorruptMessage(i) : this.serialMessage(i);
|
|
640
637
|
} else {
|
|
641
|
-
const
|
|
642
|
-
e ? this.serialCorruptMessage(
|
|
638
|
+
const i = this.stringToArrayBuffer(this.parseUint8ArrayToString(n));
|
|
639
|
+
e ? this.serialCorruptMessage(i) : this.serialMessage(i);
|
|
643
640
|
}
|
|
644
641
|
}
|
|
645
642
|
this.__internal__.serial.queue.length !== 0 && this.dispatch("internal:queue", {});
|
|
646
|
-
},
|
|
647
|
-
const
|
|
648
|
-
return
|
|
649
|
-
const
|
|
650
|
-
return
|
|
651
|
-
}).filter((t) => !l(this, r,
|
|
652
|
-
},
|
|
653
|
-
if (
|
|
654
|
-
const e = this.__internal__.serial.response.buffer, t = new Uint8Array(e.length +
|
|
655
|
-
t.set(e, 0), t.set(new Uint8Array(
|
|
656
|
-
}
|
|
657
|
-
},
|
|
643
|
+
}, N = async function() {
|
|
644
|
+
const n = this.serialFilters, e = await navigator.serial.getPorts({ filters: n });
|
|
645
|
+
return n.length === 0 ? e : e.filter((t) => {
|
|
646
|
+
const i = t.getInfo();
|
|
647
|
+
return n.some((s) => i.usbProductId === s.usbProductId && i.usbVendorId === s.usbVendorId);
|
|
648
|
+
}).filter((t) => !l(this, r, f).call(this, t));
|
|
649
|
+
}, L = function(n) {
|
|
650
|
+
if (n) {
|
|
651
|
+
const e = this.__internal__.serial.response.buffer, t = new Uint8Array(e.length + n.byteLength);
|
|
652
|
+
t.set(e, 0), t.set(new Uint8Array(n), e.length), this.__internal__.serial.response.buffer = t;
|
|
653
|
+
}
|
|
654
|
+
}, D = async function() {
|
|
658
655
|
this.__internal__.serial.time_until_send_bytes && (clearTimeout(this.__internal__.serial.time_until_send_bytes), this.__internal__.serial.time_until_send_bytes = 0), this.__internal__.serial.time_until_send_bytes = setTimeout(() => {
|
|
659
656
|
this.__internal__.serial.response.buffer && l(this, r, u).call(this, this.__internal__.serial.response.buffer), this.__internal__.serial.response.buffer = new Uint8Array(0);
|
|
660
657
|
}, this.__internal__.serial.free_timeout_ms || 50);
|
|
661
|
-
},
|
|
662
|
-
const
|
|
658
|
+
}, B = async function() {
|
|
659
|
+
const n = this.__internal__.serial.response.length;
|
|
663
660
|
let e = this.__internal__.serial.response.buffer;
|
|
664
|
-
if (this.__internal__.serial.time_until_send_bytes && (clearTimeout(this.__internal__.serial.time_until_send_bytes), this.__internal__.serial.time_until_send_bytes = 0), !(
|
|
665
|
-
for (; e.length >=
|
|
666
|
-
const t = e.slice(0,
|
|
667
|
-
l(this, r, u).call(this, t), e = e.slice(
|
|
661
|
+
if (this.__internal__.serial.time_until_send_bytes && (clearTimeout(this.__internal__.serial.time_until_send_bytes), this.__internal__.serial.time_until_send_bytes = 0), !(n === null || !e || e.length === 0)) {
|
|
662
|
+
for (; e.length >= n; ) {
|
|
663
|
+
const t = e.slice(0, n);
|
|
664
|
+
l(this, r, u).call(this, t), e = e.slice(n);
|
|
668
665
|
}
|
|
669
666
|
this.__internal__.serial.response.buffer = e, e.length > 0 && (this.__internal__.serial.time_until_send_bytes = setTimeout(() => {
|
|
670
667
|
l(this, r, u).call(this, this.__internal__.serial.response.buffer, !0);
|
|
671
668
|
}, this.__internal__.serial.free_timeout_ms || 50));
|
|
672
669
|
}
|
|
673
|
-
},
|
|
670
|
+
}, P = async function() {
|
|
674
671
|
const {
|
|
675
|
-
limiter:
|
|
672
|
+
limiter: n,
|
|
676
673
|
prefixLimiter: e = !1,
|
|
677
674
|
sufixLimiter: t = !0
|
|
678
675
|
} = this.__internal__.serial.response;
|
|
679
|
-
if (!
|
|
676
|
+
if (!n)
|
|
680
677
|
throw new Error("No limiter defined for delimited serial response");
|
|
681
|
-
const
|
|
682
|
-
if (!
|
|
678
|
+
const i = this.__internal__.serial.response.buffer;
|
|
679
|
+
if (!n || !i || i.length === 0) return;
|
|
683
680
|
this.__internal__.serial.time_until_send_bytes && (clearTimeout(this.__internal__.serial.time_until_send_bytes), this.__internal__.serial.time_until_send_bytes = 0);
|
|
684
|
-
let s = new TextDecoder().decode(
|
|
681
|
+
let s = new TextDecoder().decode(i);
|
|
685
682
|
const o = [];
|
|
686
|
-
if (typeof
|
|
683
|
+
if (typeof n == "string") {
|
|
687
684
|
let _;
|
|
688
685
|
if (e && t)
|
|
689
|
-
_ = new RegExp(`${
|
|
686
|
+
_ = new RegExp(`${n}([^${n}]+)${n}`, "g");
|
|
690
687
|
else if (e)
|
|
691
|
-
_ = new RegExp(`${
|
|
688
|
+
_ = new RegExp(`${n}([^${n}]*)`, "g");
|
|
692
689
|
else if (t)
|
|
693
|
-
_ = new RegExp(`([^${
|
|
690
|
+
_ = new RegExp(`([^${n}]+)${n}`, "g");
|
|
694
691
|
else
|
|
695
692
|
return;
|
|
696
693
|
let d, h = 0;
|
|
697
694
|
for (; (d = _.exec(s)) !== null; )
|
|
698
695
|
o.push(new TextEncoder().encode(d[1])), h = _.lastIndex;
|
|
699
696
|
s = s.slice(h);
|
|
700
|
-
} else if (
|
|
697
|
+
} else if (n instanceof RegExp) {
|
|
701
698
|
let _, d = 0;
|
|
702
699
|
if (e && t) {
|
|
703
|
-
const h = new RegExp(`${
|
|
700
|
+
const h = new RegExp(`${n.source}(.*?)${n.source}`, "g");
|
|
704
701
|
for (; (_ = h.exec(s)) !== null; )
|
|
705
702
|
o.push(new TextEncoder().encode(_[1])), d = h.lastIndex;
|
|
706
703
|
} else if (t)
|
|
707
|
-
for (; (_ =
|
|
708
|
-
const h = _.index,
|
|
709
|
-
o.push(new TextEncoder().encode(
|
|
704
|
+
for (; (_ = n.exec(s)) !== null; ) {
|
|
705
|
+
const h = _.index, w = s.slice(d, h);
|
|
706
|
+
o.push(new TextEncoder().encode(w)), d = n.lastIndex;
|
|
710
707
|
}
|
|
711
708
|
else if (e) {
|
|
712
|
-
const h = s.split(
|
|
709
|
+
const h = s.split(n);
|
|
713
710
|
h.shift();
|
|
714
|
-
for (const
|
|
715
|
-
o.push(new TextEncoder().encode(
|
|
711
|
+
for (const w of h)
|
|
712
|
+
o.push(new TextEncoder().encode(w));
|
|
716
713
|
s = "";
|
|
717
714
|
}
|
|
718
715
|
s = s.slice(d);
|
|
719
716
|
}
|
|
720
717
|
for (const _ of o)
|
|
721
718
|
l(this, r, u).call(this, _);
|
|
722
|
-
const
|
|
723
|
-
this.__internal__.serial.response.buffer =
|
|
719
|
+
const E = new TextEncoder().encode(s);
|
|
720
|
+
this.__internal__.serial.response.buffer = E, E.length > 0 && (this.__internal__.serial.time_until_send_bytes = setTimeout(() => {
|
|
724
721
|
l(this, r, u).call(this, this.__internal__.serial.response.buffer, !0), this.__internal__.serial.response.buffer = new Uint8Array(0);
|
|
725
722
|
}, this.__internal__.serial.free_timeout_ms ?? 50));
|
|
726
|
-
},
|
|
727
|
-
const
|
|
728
|
-
if (!
|
|
729
|
-
const e =
|
|
723
|
+
}, O = async function() {
|
|
724
|
+
const n = this.__internal__.serial.port;
|
|
725
|
+
if (!n || !n.readable) throw new Error("Port is not readable");
|
|
726
|
+
const e = n.readable.getReader();
|
|
730
727
|
this.__internal__.serial.reader = e;
|
|
731
728
|
try {
|
|
732
729
|
for (; this.__internal__.serial.keep_reading; ) {
|
|
733
|
-
const { value: t, done:
|
|
734
|
-
if (
|
|
735
|
-
l(this, r,
|
|
730
|
+
const { value: t, done: i } = await e.read();
|
|
731
|
+
if (i) break;
|
|
732
|
+
l(this, r, L).call(this, t), this.__internal__.serial.response.delimited ? await l(this, r, P).call(this) : this.__internal__.serial.response.length === null ? await l(this, r, D).call(this) : await l(this, r, B).call(this);
|
|
736
733
|
}
|
|
737
734
|
} catch (t) {
|
|
738
735
|
this.serialErrors(t);
|
|
739
736
|
} finally {
|
|
740
737
|
e.releaseLock(), this.__internal__.serial.keep_reading = !0, this.__internal__.serial.port && await this.__internal__.serial.port.close();
|
|
741
738
|
}
|
|
742
|
-
},
|
|
743
|
-
|
|
744
|
-
},
|
|
739
|
+
}, g = function(n) {
|
|
740
|
+
n !== this.__internal__.serial.connecting && (this.__internal__.serial.connecting = n, this.dispatch("serial:connecting", { active: n }), this.dispatch("internal:connecting", { active: n }));
|
|
741
|
+
}, H = async function() {
|
|
745
742
|
return typeof window > "u" ? !1 : "serial" in navigator && "forget" in SerialPort.prototype && this.__internal__.serial.port ? (await this.__internal__.serial.port.forget(), !0) : !1;
|
|
746
|
-
},
|
|
743
|
+
}, j = function() {
|
|
747
744
|
[
|
|
748
745
|
"serial:connected",
|
|
749
746
|
"serial:connecting",
|
|
@@ -760,48 +757,48 @@ r = /* @__PURE__ */ new WeakSet(), p = function(i) {
|
|
|
760
757
|
"serial:unsupported",
|
|
761
758
|
"serial:error",
|
|
762
759
|
"debug"
|
|
763
|
-
].forEach((
|
|
764
|
-
this.serialRegisterAvailableListener(
|
|
760
|
+
].forEach((n) => {
|
|
761
|
+
this.serialRegisterAvailableListener(n);
|
|
765
762
|
});
|
|
766
|
-
},
|
|
767
|
-
const
|
|
763
|
+
}, F = function() {
|
|
764
|
+
const n = this;
|
|
768
765
|
this.on("internal:queue", async () => {
|
|
769
766
|
var e;
|
|
770
|
-
await l(e =
|
|
771
|
-
}), l(this, r,
|
|
772
|
-
},
|
|
773
|
-
const
|
|
767
|
+
await l(e = n, r, $).call(e);
|
|
768
|
+
}), l(this, r, U).call(this);
|
|
769
|
+
}, U = function() {
|
|
770
|
+
const n = this;
|
|
774
771
|
navigator.serial.addEventListener("connect", async () => {
|
|
775
|
-
|
|
772
|
+
n.isDisconnected && await n.serialConnect().catch(() => {
|
|
776
773
|
});
|
|
777
774
|
});
|
|
778
|
-
},
|
|
779
|
-
if (!l(this, r,
|
|
780
|
-
l(this, r,
|
|
775
|
+
}, $ = async function() {
|
|
776
|
+
if (!l(this, r, f).call(this, this.__internal__.serial.port)) {
|
|
777
|
+
l(this, r, m).call(this, { error: "Port is closed, not readable or writable." }), await this.serialConnect();
|
|
781
778
|
return;
|
|
782
779
|
}
|
|
783
780
|
if (this.__internal__.timeout.until_response || this.__internal__.serial.queue.length === 0) return;
|
|
784
|
-
const
|
|
781
|
+
const n = this.__internal__.serial.queue[0];
|
|
785
782
|
let e = this.__internal__.time.response_general;
|
|
786
|
-
if (
|
|
787
|
-
await this.timeout(
|
|
788
|
-
}, e), this.__internal__.serial.last_action =
|
|
789
|
-
action:
|
|
790
|
-
bytes:
|
|
783
|
+
if (n.action === "connect" && (e = this.__internal__.time.response_connection), this.__internal__.timeout.until_response = setTimeout(async () => {
|
|
784
|
+
await this.timeout(n.bytes, n.action);
|
|
785
|
+
}, e), this.__internal__.serial.last_action = n.action ?? "unknown", await l(this, r, x).call(this, n.bytes), this.dispatch("serial:sent", {
|
|
786
|
+
action: n.action,
|
|
787
|
+
bytes: n.bytes
|
|
791
788
|
}), this.__internal__.auto_response) {
|
|
792
|
-
let
|
|
789
|
+
let i = new Uint8Array(0);
|
|
793
790
|
try {
|
|
794
|
-
|
|
791
|
+
i = this.validateBytes(this.__internal__.serial.auto_response);
|
|
795
792
|
} catch (s) {
|
|
796
793
|
this.serialErrors(s);
|
|
797
794
|
}
|
|
798
|
-
l(this, r, u).call(this,
|
|
795
|
+
l(this, r, u).call(this, i);
|
|
799
796
|
}
|
|
800
797
|
const t = [...this.__internal__.serial.queue];
|
|
801
798
|
this.__internal__.serial.queue = t.splice(1);
|
|
802
|
-
},
|
|
803
|
-
this.__internal__.device_number =
|
|
804
|
-
},
|
|
799
|
+
}, W = function(n = 1) {
|
|
800
|
+
this.__internal__.device_number = n, !this.__internal__.bypassSerialBytesConnection && (this.__internal__.serial.bytes_connection = this.serialSetConnectionConstant(n));
|
|
801
|
+
}, Q = function() {
|
|
805
802
|
this.__internal__.last_error = {
|
|
806
803
|
message: null,
|
|
807
804
|
action: null,
|
|
@@ -810,6 +807,6 @@ r = /* @__PURE__ */ new WeakSet(), p = function(i) {
|
|
|
810
807
|
};
|
|
811
808
|
};
|
|
812
809
|
export {
|
|
813
|
-
|
|
810
|
+
K as Z,
|
|
814
811
|
c as h
|
|
815
812
|
};
|