@danidoble/webserial
Version:
WebSerial API wrapper
1,432 lines • 372 kB
JavaScript
var va = Object.defineProperty;
var $n = (r) => {
throw TypeError(r);
};
var Ea = (r, n, t) => n in r ? va(r, n, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[n] = t;
var lt = (r, n, t) => Ea(r, typeof n != "symbol" ? n + "" : n, t), Xe = (r, n, t) => n.has(r) || $n("Cannot " + t);
var I = (r, n, t) => (Xe(r, n, "read from private field"), t ? t.call(r) : n.get(r)), G = (r, n, t) => n.has(r) ? $n("Cannot add the same private member more than once") : n instanceof WeakSet ? n.add(r) : n.set(r, t), M = (r, n, t, e) => (Xe(r, n, "write to private field"), e ? e.call(r, t) : n.set(r, t), t), o = (r, n, t) => (Xe(r, n, "access private method"), t);
function Tt(r = 100) {
return new Promise((n) => setTimeout(() => n(), r));
}
function Pa() {
return "serial" in navigator;
}
function zn() {
return "geolocation" in navigator;
}
function Ta() {
return "crypto" in window;
}
function sn(r = 1) {
return r * 1e3;
}
function Ct(r) {
return r == null || r === "";
}
var at, ht, p, Ci, Si, T, on, B, N, we, P, cn, Yt;
const u = class u {
static status(n = null) {
var e, i;
if (!o(e = u, p, T).call(e, n)) return !1;
let t = [];
switch (I(u, at)) {
case "locker":
t = ["0", "8"];
break;
case "boardroid":
t = ["2", (5 + I(u, ht)).toString(16).toUpperCase()];
break;
case "jofemar":
t = ["6"];
break;
default:
return !1;
}
o(i = u, p, P).call(i, t);
}
static dispensed(n = null) {
var e, i;
if (!o(e = u, p, T).call(e, n)) return !1;
let t = [];
switch (I(u, at)) {
case "locker":
t = ["0", "7", "4", "4", "4"];
break;
case "boardroid":
t = ["2", "D7", "A", "0", "0", "0", "0", "0", "0", "0", "0", "0", "F2"];
break;
case "jofemar":
t = ["6", "30"];
break;
default:
return !1;
}
o(i = u, p, P).call(i, t);
}
static notDispensed(n = null) {
var e, i;
if (!o(e = u, p, T).call(e, n)) return !1;
let t = [];
switch (I(u, at)) {
case "locker":
t = ["0", "7", "5", "5", "5"];
break;
case "boardroid":
t = ["2", "D7", "A", "0", "0", "1", "0", "0", "0", "0", "0", "0", "F2"];
break;
case "jofemar":
t = ["6", "34"];
break;
default:
return !1;
}
o(i = u, p, P).call(i, t);
}
static gateInactive(n = null) {
var t;
if (!o(t = u, p, T).call(t, n) || !o(this, p, on).call(this)) return !1;
o(this, p, P).call(this, ["0", "7", "5", "5", "5"]);
}
static gateConfigured(n = null) {
var t;
if (!o(t = u, p, T).call(t, n) || !o(this, p, on).call(this)) return !1;
o(this, p, P).call(this, ["0", "6"]);
}
static keyPressed(n = null) {
var s, a, c;
if (!o(s = u, p, T).call(s, n) || !o(a = u, p, N).call(a)) return !1;
const t = ["30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "2A", "23", "41", "42", "43", "44"], e = (128 + I(u, ht)).toString(16), i = Math.floor(Math.random() * 15);
o(c = u, p, P).call(c, ["2", e, "54", t[i]]);
}
static doorOpened(n = null) {
var i, s;
if (!o(i = u, p, T).call(i, n) || !o(this, p, we).call(this)) return !1;
let t = [];
const e = (128 + I(u, ht)).toString(16);
switch (I(u, at)) {
case "boardroid":
t = ["2", "D8", "dc"];
break;
case "jofemar":
t = ["2", e, "50", "4F"];
break;
}
o(s = u, p, P).call(s, t);
}
static doorClosed(n = null) {
var i, s;
if (!o(i = u, p, T).call(i, n) || !o(this, p, we).call(this)) return !1;
let t = [];
const e = (128 + I(u, ht)).toString(16);
switch (I(u, at)) {
case "boardroid":
t = ["2", "D8", "db"];
break;
case "jofemar":
t = ["2", e, "50", "43"];
break;
}
o(s = u, p, P).call(s, t);
}
static channelDisconnected(n = null) {
var e, i, s;
if (!o(e = u, p, T).call(e, n) || !o(i = u, p, N).call(i)) return !1;
const t = (128 + I(u, ht)).toString(16);
o(s = u, p, P).call(s, ["2", t, "43", "43", "43", "FD"]);
}
static channelConnected(n = null) {
var e, i, s;
if (!o(e = u, p, T).call(e, n) || !o(i = u, p, N).call(i)) return !1;
const t = (128 + I(u, ht)).toString(16);
o(s = u, p, P).call(s, ["2", t, "43", "43", "43", "FC"]);
}
static channelEmpty(n = null) {
var e, i, s;
if (!o(e = u, p, T).call(e, n) || !o(i = u, p, N).call(i)) return !1;
const t = (128 + I(u, ht)).toString(16);
o(s = u, p, P).call(s, ["2", t, "43", "43", "43", "FF"]);
}
static workingTemperature(n = null) {
var e, i, s;
if (!o(e = u, p, T).call(e, n) || !o(i = u, p, N).call(i)) return !1;
const t = (128 + I(u, ht)).toString(16);
o(s = u, p, P).call(s, ["2", t, "43", "54", "16"]);
}
static currentTemperature(n = null) {
var i, s, a;
if (!o(i = u, p, T).call(i, n) || !o(s = u, p, we).call(s)) return !1;
let t = [];
const e = (128 + I(u, ht)).toString(16);
switch (I(u, at)) {
case "boardroid":
t = ["2", "D9", "44", "30"];
break;
case "jofemar":
t = ["2", e, "43", "74", "2B", "30", "39", "2E", "31", "7F", "43"];
break;
}
o(a = u, p, P).call(a, t);
}
static ready(n = null) {
var t, e, i;
if (!o(t = u, p, T).call(t, n) || !o(e = u, p, N).call(e)) return !1;
o(i = u, p, P).call(i, ["6", "30"]);
}
static busy(n = null) {
var t, e, i;
if (!o(t = u, p, T).call(t, n) || !o(e = u, p, N).call(e)) return !1;
o(i = u, p, P).call(i, ["6", "31"]);
}
static invalidTray(n = null) {
var t, e, i;
if (!o(t = u, p, T).call(t, n) || !o(e = u, p, N).call(e)) return !1;
o(i = u, p, P).call(i, ["6", "32"]);
}
static invalidChannel(n = null) {
var t, e, i;
if (!o(t = u, p, T).call(t, n) || !o(e = u, p, N).call(e)) return !1;
o(i = u, p, P).call(i, ["6", "33"]);
}
static emptyChannel(n = null) {
var t, e, i;
if (!o(t = u, p, T).call(t, n) || !o(e = u, p, N).call(e)) return !1;
o(i = u, p, P).call(i, ["6", "34"]);
}
static elevatorJam(n = null) {
var t, e, i;
if (!o(t = u, p, T).call(t, n) || !o(e = u, p, N).call(e)) return !1;
o(i = u, p, P).call(i, ["6", "35"]);
}
static elevatorMalfunction(n = null) {
var t, e, i;
if (!o(t = u, p, T).call(t, n) || !o(e = u, p, N).call(e)) return !1;
o(i = u, p, P).call(i, ["6", "36"]);
}
static phototransistorFailure(n = null) {
var t, e, i;
if (!o(t = u, p, T).call(t, n) || !o(e = u, p, N).call(e)) return !1;
o(i = u, p, P).call(i, ["6", "37"]);
}
static allChannelsEmpty(n = null) {
var t, e, i;
if (!o(t = u, p, T).call(t, n) || !o(e = u, p, N).call(e)) return !1;
o(i = u, p, P).call(i, ["6", "38"]);
}
static productDetectorFailure(n = null) {
var t, e, i;
if (!o(t = u, p, T).call(t, n) || !o(e = u, p, N).call(e)) return !1;
o(i = u, p, P).call(i, ["6", "39"]);
}
static displayDisconnected(n = null) {
var t, e, i;
if (!o(t = u, p, T).call(t, n) || !o(e = u, p, N).call(e)) return !1;
o(i = u, p, P).call(i, ["6", "41"]);
}
static productUnderElevator(n = null) {
var t, e, i;
if (!o(t = u, p, T).call(t, n) || !o(e = u, p, N).call(e)) return !1;
o(i = u, p, P).call(i, ["6", "42"]);
}
static elevatorSettingAlarm(n = null) {
var t, e, i;
if (!o(t = u, p, T).call(t, n) || !o(e = u, p, N).call(e)) return !1;
o(i = u, p, P).call(i, ["6", "43"]);
}
static buttonPanelFailure(n = null) {
var t, e, i;
if (!o(t = u, p, T).call(t, n) || !o(e = u, p, N).call(e)) return !1;
o(i = u, p, P).call(i, ["6", "44"]);
}
static errorWritingEeprom(n = null) {
var t, e, i;
if (!o(t = u, p, T).call(t, n) || !o(e = u, p, N).call(e)) return !1;
o(i = u, p, P).call(i, ["6", "45"]);
}
static errorControlTemperature(n = null) {
var t, e, i;
if (!o(t = u, p, T).call(t, n) || !o(e = u, p, N).call(e)) return !1;
o(i = u, p, P).call(i, ["6", "46"]);
}
static thermometerDisconnected(n = null) {
var t, e, i;
if (!o(t = u, p, T).call(t, n) || !o(e = u, p, N).call(e)) return !1;
o(i = u, p, P).call(i, ["6", "47"]);
}
static thermometerMisconfigured(n = null) {
var t, e, i;
if (!o(t = u, p, T).call(t, n) || !o(e = u, p, N).call(e)) return !1;
o(i = u, p, P).call(i, ["6", "48"]);
}
static thermometerFailure(n = null) {
var t, e, i;
if (!o(t = u, p, T).call(t, n) || !o(e = u, p, N).call(e)) return !1;
o(i = u, p, P).call(i, ["6", "49"]);
}
static errorExtractorConsumption(n = null) {
var t, e, i;
if (!o(t = u, p, T).call(t, n) || !o(e = u, p, N).call(e)) return !1;
o(i = u, p, P).call(i, ["6", "4A"]);
}
static channelSearchError(n = null) {
var t, e, i;
if (!o(t = u, p, T).call(t, n) || !o(e = u, p, N).call(e)) return !1;
o(i = u, p, P).call(i, ["6", "4B"]);
}
static productExitMouthSearchError(n = null) {
var t, e, i;
if (!o(t = u, p, T).call(t, n) || !o(e = u, p, N).call(e)) return !1;
o(i = u, p, P).call(i, ["6", "4C"]);
}
static elevatorInteriorLocked(n = null) {
var t, e, i;
if (!o(t = u, p, T).call(t, n) || !o(e = u, p, N).call(e)) return !1;
o(i = u, p, P).call(i, ["6", "4D"]);
}
static productDetectorVerifierError(n = null) {
var t, e, i;
if (!o(t = u, p, T).call(t, n) || !o(e = u, p, N).call(e)) return !1;
o(i = u, p, P).call(i, ["6", "4E"]);
}
static waitingForProductRecall(n = null) {
var t, e, i;
if (!o(t = u, p, T).call(t, n) || !o(e = u, p, N).call(e)) return !1;
o(i = u, p, P).call(i, ["6", "4F"]);
}
static productExpiredByTemperature(n = null) {
var t, e, i;
if (!o(t = u, p, T).call(t, n) || !o(e = u, p, N).call(e)) return !1;
o(i = u, p, P).call(i, ["6", "50"]);
}
static faultyAutomaticDoor(n = null) {
var t, e, i;
if (!o(t = u, p, T).call(t, n) || !o(e = u, p, N).call(e)) return !1;
o(i = u, p, P).call(i, ["6", "51"]);
}
static rejectLever(n = null) {
var t, e, i;
if (!o(t = u, p, T).call(t, n) || !o(e = u, p, B).call(e)) return !1;
o(i = u, p, P).call(i, ["2", "A0", "1"]);
}
static resetCoinPurse(n = null) {
var t, e, i;
if (!o(t = u, p, T).call(t, n) || !o(e = u, p, B).call(e)) return !1;
o(i = u, p, P).call(i, ["2", "A0", "2"]);
}
static coinInsertedBox(n = null, t = null) {
var s, a, c, l;
if (!o(s = u, p, T).call(s, n) || !o(a = u, p, B).call(a)) return !1;
const e = ["40", "41", "42", "43", "44", "45"], i = o(c = u, p, cn).call(c, e, t);
o(l = u, p, P).call(l, ["2", "A0", i]);
}
static coinInsertedTube(n = null, t = null) {
var s, a, c, l;
if (!o(s = u, p, T).call(s, n) || !o(a = u, p, B).call(a)) return !1;
const e = ["50", "51", "52", "53", "54", "55"], i = o(c = u, p, cn).call(c, e, t);
o(l = u, p, P).call(l, ["2", "A0", i]);
}
static banknoteInsertedStacker(n = null, t = null) {
var s, a, c, l;
if (!o(s = u, p, T).call(s, n) || !o(a = u, p, B).call(a)) return !1;
const e = ["80", "81", "82", "83", "84"], i = o(c = u, p, Yt).call(c, e, t);
o(l = u, p, P).call(l, ["2", "B0", i]);
}
static banknoteInsertedEscrow(n = null, t = null) {
var s, a, c, l;
if (!o(s = u, p, T).call(s, n) || !o(a = u, p, B).call(a)) return !1;
const e = ["90", "91", "92", "93", "94"], i = o(c = u, p, Yt).call(c, e, t);
o(l = u, p, P).call(l, ["2", "B0", i]);
}
static banknoteEjected(n = null, t = null) {
var s, a, c, l;
if (!o(s = u, p, T).call(s, n) || !o(a = u, p, B).call(a)) return !1;
const e = ["A0", "A1", "A2", "A3", "A4"], i = o(c = u, p, Yt).call(c, e, t);
o(l = u, p, P).call(l, ["2", "B0", i]);
}
static banknoteInsertedRecycler(n = null, t = null) {
var s, a, c, l;
if (!o(s = u, p, T).call(s, n) || !o(a = u, p, B).call(a)) return !1;
const e = ["B0", "B1", "B2", "B3", "B4"], i = o(c = u, p, Yt).call(c, e, t);
o(l = u, p, P).call(l, ["2", "B0", i]);
}
static banknoteTaken(n = null) {
var t, e, i;
if (!o(t = u, p, T).call(t, n) || !o(e = u, p, B).call(e)) return !1;
o(i = u, p, P).call(i, ["2", "B0", "2a"]);
}
static coinPurseEnabled(n = null) {
var t, e, i;
if (!o(t = u, p, T).call(t, n) || !o(e = u, p, B).call(e)) return !1;
o(i = u, p, P).call(i, ["2", "D0", "1"]);
}
static coinPurseDisabled(n = null) {
var t, e, i;
if (!o(t = u, p, T).call(t, n) || !o(e = u, p, B).call(e)) return !1;
o(i = u, p, P).call(i, ["2", "D0", "0"]);
}
static billPurseDisabled(n = null) {
var t, e, i;
if (!o(t = u, p, T).call(t, n) || !o(e = u, p, B).call(e)) return !1;
o(i = u, p, P).call(i, ["2", "D1", "0", "0"]);
}
static billPurseEnabled(n = null) {
var t, e, i;
if (!o(t = u, p, T).call(t, n) || !o(e = u, p, B).call(e)) return !1;
o(i = u, p, P).call(i, ["2", "D1", "1", "1"]);
}
static readTubes(n = null) {
var h, d, f;
if (!o(h = u, p, T).call(h, n) || !o(d = u, p, B).call(d)) return !1;
const t = [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
"a",
"b",
"c",
"d",
"e",
"f",
"10",
"11",
"12",
"13",
"14",
"15",
"16",
"17",
"18",
"19",
"1a",
"1b",
"1c",
"1d",
"1e",
"1f"
], [e, i, s, a, c, l] = [
t[Math.floor(Math.random() * 30)],
t[Math.floor(Math.random() * 30)],
t[Math.floor(Math.random() * 30)],
t[Math.floor(Math.random() * 30)],
t[Math.floor(Math.random() * 30)],
t[Math.floor(Math.random() * 30)]
];
o(f = u, p, P).call(f, ["2", "D2", e, i, s, a, c, l]);
}
static readBillPurse(n = null, t = null) {
var i, s, a, c;
if (!o(i = u, p, T).call(i, n) || !o(s = u, p, B).call(s)) return !1;
let e = [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
"a",
"b",
"c",
"d",
"e",
"f",
"10",
"11",
"12",
"13",
"14",
"15",
"16",
"17",
"18",
"19",
"1a",
"1b",
"1c"
];
if (n._recycler.ict) {
const l = e[Math.floor(Math.random() * 31)];
let h = "0", d = "0", f = "0", b = "0", E = "0";
if (t !== null && !isNaN(parseInt(t)))
switch (t.toString()) {
case "20":
h = l;
break;
case "50":
d = l;
break;
case "100":
f = l;
break;
case "200":
b = l;
break;
case "500":
E = l;
break;
}
else
switch (n._recycler.bill) {
case 0:
h = l;
break;
case 1:
d = l;
break;
case 2:
f = l;
break;
case 3:
b = l;
break;
case 4:
E = l;
break;
}
o(a = u, p, P).call(a, ["2", "D3", h, d, f, b, E, "0"]);
} else {
const [l, h, d, f, b, E] = [
e[Math.floor(Math.random() * 30)],
e[Math.floor(Math.random() * 30)],
e[Math.floor(Math.random() * 30)],
e[Math.floor(Math.random() * 2)],
e[Math.floor(Math.random())],
e[Math.floor(Math.random())]
];
o(c = u, p, P).call(c, ["2", "D3", l, h, d, f, b, E]);
}
}
static banknoteAccepted(n = null) {
var t, e, i;
if (!o(t = u, p, T).call(t, n) || !o(e = u, p, B).call(e)) return !1;
o(i = u, p, P).call(i, ["2", "D4", "1"]);
}
static banknoteRejected(n = null) {
var t, e, i;
if (!o(t = u, p, T).call(t, n) || !o(e = u, p, B).call(e)) return !1;
o(i = u, p, P).call(i, ["2", "D4", "0"]);
}
static banknotesDispensed(n = null) {
var e, i, s, a;
if (!o(e = u, p, T).call(e, n) || !o(i = u, p, B).call(i)) return !1;
let t = [
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
"a",
"b",
"c",
"d",
"e",
"f",
"10",
"11",
"12",
"13",
"14",
"15",
"16",
"17",
"18",
"19",
"1a",
"1b",
"1c"
];
if (n._recycler.ict) {
const c = t[Math.floor(Math.random() * 30)];
let l = "0", h = "0", d = "0", f = "0", b = "0";
switch (n._recycler.bill) {
case 0:
l = c;
break;
case 1:
h = c;
break;
case 2:
d = c;
break;
case 3:
f = c;
break;
case 4:
b = c;
break;
}
o(s = u, p, P).call(s, ["2", "D5", l, h, d, f, b, "0"]);
} else {
const [c, l, h, d, f, b] = [
t[Math.floor(Math.random() * 30)],
t[Math.floor(Math.random() * 30)],
t[Math.floor(Math.random() * 30)],
t[Math.floor(Math.random() * 2)],
t[Math.floor(Math.random())],
t[Math.floor(Math.random())]
];
o(a = u, p, P).call(a, ["2", "D5", c, l, h, d, f, b]);
}
}
static coinsDispensed(n = null) {
var t, e, i;
if (!o(t = u, p, T).call(t, n) || !o(e = u, p, B).call(e)) return !1;
o(i = u, p, P).call(i, ["2", "D6"]);
}
static relayOn(n = null) {
var t, e, i;
if (!o(t = u, p, T).call(t, n) || !o(e = u, p, B).call(e)) return !1;
o(i = u, p, P).call(i, ["2", "DA", "1"]);
}
static relayOff(n = null) {
var t, e, i;
if (!o(t = u, p, T).call(t, n) || !o(e = u, p, B).call(e)) return !1;
o(i = u, p, P).call(i, ["2", "DA", "0"]);
}
static nayaxEnabled(n = null) {
var t, e, i;
if (!o(t = u, p, T).call(t, n) || !o(e = u, p, B).call(e)) return !1;
o(i = u, p, P).call(i, ["2", "DD", "1"]);
}
static nayaxDisabled(n = null) {
var t, e, i;
if (!o(t = u, p, T).call(t, n) || !o(e = u, p, B).call(e)) return !1;
o(i = u, p, P).call(i, ["2", "DD", "0"]);
}
static nayaxPreCreditAuthorized(n = null) {
var t, e, i;
if (!o(t = u, p, T).call(t, n) || !o(e = u, p, B).call(e)) return !1;
o(i = u, p, P).call(i, ["2", "DD", "3"]);
}
static nayaxCancelRequest(n = null) {
var t, e, i;
if (!o(t = u, p, T).call(t, n) || !o(e = u, p, B).call(e)) return !1;
o(i = u, p, P).call(i, ["2", "DD", "4"]);
}
static nayaxSellApproved(n = null) {
var t, e, i;
if (!o(t = u, p, T).call(t, n) || !o(e = u, p, B).call(e)) return !1;
o(i = u, p, P).call(i, ["2", "DD", "5"]);
}
static nayaxSellDenied(n = null) {
var t, e, i;
if (!o(t = u, p, T).call(t, n) || !o(e = u, p, B).call(e)) return !1;
o(i = u, p, P).call(i, ["2", "DD", "6"]);
}
static nayaxEndSession(n = null) {
var t, e, i;
if (!o(t = u, p, T).call(t, n) || !o(e = u, p, B).call(e)) return !1;
o(i = u, p, P).call(i, ["2", "DD", "7"]);
}
static nayaxCancelled(n = null) {
var t, e, i;
if (!o(t = u, p, T).call(t, n) || !o(e = u, p, B).call(e)) return !1;
o(i = u, p, P).call(i, ["2", "DD", "8"]);
}
static nayaxDispensed(n = null) {
var t, e, i;
if (!o(t = u, p, T).call(t, n) || !o(e = u, p, B).call(e)) return !1;
o(i = u, p, P).call(i, ["2", "DD", "A", "0"]);
}
static nayaxNotDispensed(n = null) {
var t, e, i;
if (!o(t = u, p, T).call(t, n) || !o(e = u, p, B).call(e)) return !1;
o(i = u, p, P).call(i, ["2", "DD", "A", "1"]);
}
static fullTray(n = null) {
var t, e, i;
if (!o(t = u, p, T).call(t, n) || !o(e = u, p, N).call(e)) return !1;
o(i = u, p, P).call(i, ["6", "4F"]);
}
static setConnection(n = null) {
var t;
if (!o(t = u, p, T).call(t, n)) return !1;
n.__internal__.serial.connected = !0;
}
};
at = new WeakMap(), ht = new WeakMap(), p = new WeakSet(), Ci = function() {
if (u.enable === !1) throw new Error("Emulator is disabled");
return u.enable;
}, Si = function(n) {
if (typeof n != "object" || !(n instanceof Dt))
throw new Error(`Type ${n.typeDevice} is not supported`);
return u.instance = n, M(u, at, n.typeDevice), M(u, ht, n.deviceNumber), !0;
}, T = function(n = null) {
var t, e;
return !o(t = u, p, Ci).call(t) || n === null && u.instance === null ? !1 : (u.instance === null && o(e = u, p, Si).call(e, n), !0);
}, on = function() {
if (I(u, at) !== "locker") throw new Error("This function is only available for Locker devices");
return !0;
}, B = function() {
if (I(u, at) !== "boardroid")
throw new Error("This function is only available for Boardroid devices");
return !0;
}, N = function() {
if (I(u, at) !== "jofemar") throw new Error("This function is only available for Jofemar devices");
return !0;
}, we = function() {
if (I(u, at) === "locker") throw new Error("This function is not available for Locker devices");
return !0;
}, P = function(n) {
u.instance.__emulate({ code: n });
}, cn = function(n, t = null) {
let e = n[Math.floor(Math.random() * 5)];
if (t !== null && !isNaN(parseFloat(t)))
switch (t.toString()) {
case "0.5":
e = n[1];
break;
case "1":
e = n[2];
break;
case "2":
e = n[3];
break;
case "5":
e = n[4];
break;
case "10":
e = n[5];
break;
}
return e;
}, Yt = function(n, t = null) {
let e = n[Math.floor(Math.random() * 4)];
if (t !== null && !isNaN(parseFloat(t)))
switch (t.toString()) {
case "20":
e = n[0];
break;
case "50":
e = n[1];
break;
case "100":
e = n[2];
break;
case "200":
e = n[3];
break;
case "500":
e = n[4];
break;
}
return e;
}, G(u, p), lt(u, "enable", !1), lt(u, "instance", null), G(u, at, null), G(u, ht, 1);
let an = u;
var Ca = Object.defineProperty, ki = (r) => {
throw TypeError(r);
}, Sa = (r, n, t) => n in r ? Ca(r, n, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[n] = t, ce = (r, n, t) => Sa(r, typeof n != "symbol" ? n + "" : n, t), ka = (r, n, t) => n.has(r) || ki("Cannot " + t), xa = (r, n, t) => n.has(r) ? ki("Cannot add the same private member more than once") : n instanceof WeakSet ? n.add(r) : n.set(r, t), V = (r, n, t) => (ka(r, n, "access private method"), t);
const J = [];
for (let r = 0; r < 256; ++r)
J.push((r + 256).toString(16).slice(1));
function Aa(r, n = 0) {
return (J[r[n + 0]] + J[r[n + 1]] + J[r[n + 2]] + J[r[n + 3]] + "-" + J[r[n + 4]] + J[r[n + 5]] + "-" + J[r[n + 6]] + J[r[n + 7]] + "-" + J[r[n + 8]] + J[r[n + 9]] + "-" + J[r[n + 10]] + J[r[n + 11]] + J[r[n + 12]] + J[r[n + 13]] + J[r[n + 14]] + J[r[n + 15]]).toLowerCase();
}
let Je;
const Da = new Uint8Array(16);
function Ra() {
if (!Je) {
if (typeof crypto > "u" || !crypto.getRandomValues)
throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
Je = crypto.getRandomValues.bind(crypto);
}
return Je(Da);
}
const Ia = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), Gn = { randomUUID: Ia };
function Oa(r, n, t) {
var e;
if (Gn.randomUUID && !r)
return Gn.randomUUID();
r = r || {};
const i = r.random ?? ((e = r.rng) == null ? void 0 : e.call(r)) ?? Ra();
if (i.length < 16)
throw new Error("Random bytes length must be >= 16");
return i[6] = i[6] & 15 | 64, i[8] = i[8] & 63 | 128, Aa(i);
}
class Xn extends CustomEvent {
constructor(n, t) {
super(n, t);
}
}
class xi extends EventTarget {
constructor() {
super(...arguments), ce(this, "__listeners__", {
debug: !1
}), ce(this, "__debug__", !1);
}
dispatch(n, t = null) {
const e = new Xn(n, { detail: t });
this.dispatchEvent(e), this.__debug__ && this.dispatchEvent(new Xn("debug", { detail: { type: n, data: t } }));
}
dispatchAsync(n, t = null, e = 100) {
const i = this;
setTimeout(() => {
i.dispatch(n, t);
}, e);
}
on(n, t) {
typeof this.__listeners__[n] < "u" && !this.__listeners__[n] && (this.__listeners__[n] = !0), this.addEventListener(n, t);
}
off(n, t) {
this.removeEventListener(n, t);
}
serialRegisterAvailableListener(n) {
this.__listeners__[n] || (this.__listeners__[n] = !1);
}
get availableListeners() {
return Object.keys(this.__listeners__).sort().map((n) => ({
type: n,
listening: this.__listeners__[n]
}));
}
}
const ln = class L extends xi {
constructor() {
super(), ["change"].forEach((n) => {
this.serialRegisterAvailableListener(n);
});
}
static $dispatchChange(n = null) {
n && n.$checkAndDispatchConnection(), L.instance.dispatch("change", { devices: L.devices, dispatcher: n });
}
static typeError(n) {
const t = new Error();
throw t.message = `Type ${n} is not supported`, t.name = "DeviceTypeError", t;
}
static registerType(n) {
typeof L.devices[n] > "u" && (L.devices[n] = {});
}
static add(n) {
const t = n.typeDevice;
typeof L.devices[t] > "u" && (L.devices[t] = {});
const e = n.uuid;
if (typeof L.devices[t] > "u" && L.typeError(t), L.devices[t][e])
throw new Error(`Device with id ${e} already exists`);
return L.devices[t][e] = n, L.$dispatchChange(n), Object.keys(L.devices[t]).indexOf(e);
}
static get(n, t) {
return typeof L.devices[n] > "u" && (L.devices[n] = {}), typeof L.devices[n] > "u" && L.typeError(n), L.devices[n][t];
}
static getAll(n = null) {
return n === null ? L.devices : (typeof L.devices[n] > "u" && L.typeError(n), L.devices[n]);
}
static getList() {
return Object.values(L.devices).map((n) => Object.values(n)).flat();
}
static getByNumber(n, t) {
return typeof L.devices[n] > "u" && L.typeError(n), Object.values(L.devices[n]).find((e) => e.deviceNumber === t) ?? null;
}
static getCustom(n, t = 1) {
return typeof L.devices[n] > "u" && L.typeError(n), Object.values(L.devices[n]).find((e) => e.deviceNumber === t) ?? null;
}
};
ce(ln, "instance"), ce(ln, "devices", {});
let k = ln;
k.instance || (k.instance = new k());
function Jn(r = 100) {
return new Promise(
(n) => setTimeout(() => n(), r)
);
}
function Na() {
return "serial" in navigator;
}
const Qe = {
baudRate: 9600,
dataBits: 8,
stopBits: 1,
parity: "none",
bufferSize: 32768,
flowControl: "none"
};
var F, Kt, oe, hn, It, Ai, Qn, Zn, Yn, Di, Ri, Ii, Oi, ti, ei, Ni, Bi;
class Ba extends xi {
constructor({
filters: n = null,
config_port: t = Qe,
no_device: e = 1,
device_listen_on_channel: i = 1
} = {
filters: null,
config_port: Qe,
no_device: 1,
device_listen_on_channel: 1
}) {
if (super(), xa(this, F), ce(this, "__internal__", {
auto_response: !1,
device_number: 1,
aux_port_connector: 0,
last_error: {
message: null,
action: null,
code: null,
no_code: 0
},
serial: {
connected: !1,
port: null,
last_action: null,
response: {
length: null,
buffer: new Uint8Array([]),
as: "hex",
replacer: /[\n\r]+/g,
limiter: null
},
reader: null,
input_done: null,
output_done: null,
input_stream: null,
output_stream: null,
keep_reading: !0,
time_until_send_bytes: void 0,
delay_first_connection: 200,
bytes_connection: null,
filters: [],
config_port: Qe,
queue: [],
auto_response: ["DD", "DD"]
},
device: {
type: "unknown",
id: Oa(),
listen_on_port: null
},
time: {
response_connection: 500,
response_general: 2e3
},
timeout: {
until_response: 0
},
interval: {
reconnection: 0
}
}), !("serial" in navigator))
throw new Error("Web Serial not supported");
n && (this.serialFilters = n), t && (this.serialConfigPort = t), e && V(this, F, Ni).call(this, e), i && ["number", "string"].includes(typeof i) && (this.listenOnChannel = i), V(this, F, Ii).call(this), V(this, F, Oi).call(this);
}
set listenOnChannel(n) {
if (typeof n == "string" && (n = parseInt(n)), isNaN(n) || n < 1 || n > 255)
throw new Error("Invalid port number");
this.__internal__.device.listen_on_port = n, this.__internal__.serial.bytes_connection = this.serialSetConnectionConstant(n);
}
get lastAction() {
return this.__internal__.serial.last_action;
}
get listenOnChannel() {
return this.__internal__.device.listen_on_port ?? 1;
}
set serialFilters(n) {
this.__internal__.serial.filters = n;
}
get serialFilters() {
return this.__internal__.serial.filters;
}
set serialConfigPort(n) {
this.__internal__.serial.config_port = n;
}
get serialConfigPort() {
return this.__internal__.serial.config_port;
}
get isConnected() {
const n = this.__internal__.serial.connected, t = V(this, F, Kt).call(this, this.__internal__.serial.port);
return n && !t && V(this, F, oe).call(this, { error: "Port is closed, not readable or writable." }), this.__internal__.serial.connected = t, this.__internal__.serial.connected;
}
get isDisconnected() {
const n = this.__internal__.serial.connected, t = V(this, F, Kt).call(this, this.__internal__.serial.port);
return !n && t && (this.dispatch("serial:connected"), k.$dispatchChange(this)), this.__internal__.serial.connected = t, !this.__internal__.serial.connected;
}
get deviceNumber() {
return this.__internal__.device_number;
}
get uuid() {
return this.__internal__.device.id;
}
get typeDevice() {
return this.__internal__.device.type;
}
get queue() {
return this.__internal__.serial.queue;
}
async timeout(n, t) {
this.__internal__.last_error.message = "Operation response timed out.", this.__internal__.last_error.action = t, this.__internal__.last_error.code = n, this.__internal__.timeout.until_response && (clearTimeout(this.__internal__.timeout.until_response), this.__internal__.timeout.until_response = 0), t === "connect" ? (this.__internal__.serial.connected = !1, this.dispatch("serial:reconnect", {}), k.$dispatchChange(this)) : t === "connection:start" && (await this.serialDisconnect(), this.__internal__.serial.connected = !1, this.__internal__.aux_port_connector += 1, k.$dispatchChange(this), await this.serialConnect()), this.dispatch("serial:timeout", {
...this.__internal__.last_error,
bytes: n,
action: t
});
}
async disconnect(n = null) {
await this.serialDisconnect(), V(this, F, oe).call(this, n);
}
async connect() {
return new Promise((n, t) => {
Na() || t("Web Serial not supported"), setTimeout(async () => {
await Jn(499), await this.serialConnect(), this.isConnected ? n(`${this.typeDevice} device ${this.deviceNumber} connected`) : t(`${this.typeDevice} device ${this.deviceNumber} not connected`);
}, 1);
});
}
async serialDisconnect() {
try {
const n = this.__internal__.serial.reader, t = this.__internal__.serial.output_stream;
n && (await n.cancel().catch((e) => this.serialErrors(e)), 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();
} catch (n) {
this.serialErrors(n);
} finally {
this.__internal__.serial.reader = null, this.__internal__.serial.input_done = null, this.__internal__.serial.output_stream = null, this.__internal__.serial.output_done = null, this.__internal__.serial.connected = !1, this.__internal__.serial.port = null, k.$dispatchChange(this);
}
}
getResponseAsArrayBuffer() {
this.__internal__.serial.response.as = "arraybuffer";
}
getResponseAsArrayHex() {
this.__internal__.serial.response.as = "hex";
}
getResponseAsUint8Array() {
this.__internal__.serial.response.as = "uint8";
}
getResponseAsString() {
this.__internal__.serial.response.as = "string";
}
async serialPortsSaved(n) {
const t = this.serialFilters;
if (this.__internal__.aux_port_connector < n.length) {
const e = this.__internal__.aux_port_connector;
this.__internal__.serial.port = n[e];
} else
this.__internal__.aux_port_connector = 0, this.__internal__.serial.port = await navigator.serial.requestPort({
filters: t
});
if (!this.__internal__.serial.port)
throw new Error("Select another port please");
}
serialErrors(n) {
const t = n.toString().toLowerCase();
switch (!0) {
case t.includes("must be handling a user gesture to show a permission request"):
case t.includes("the port is closed."):
case t.includes("the port is closed or is not writable"):
case t.includes("the port is closed or is not readable"):
case t.includes("the port is closed or is not readable/writable"):
case t.includes("select another port please"):
case t.includes("no port selected by the user"):
case t.includes(
"this readable stream reader has been released and cannot be used to cancel its previous owner stream"
):
this.dispatch("serial:need-permission", {}), k.$dispatchChange(this);
break;
case t.includes("the port is already open."):
case t.includes("failed to open serial port"):
this.serialDisconnect().then(async () => {
this.__internal__.aux_port_connector += 1, await this.serialConnect();
});
break;
case t.includes("cannot read properties of undefined (reading 'writable')"):
case t.includes("cannot read properties of null (reading 'writable')"):
case t.includes("cannot read property 'writable' of null"):
case t.includes("cannot read property 'writable' of undefined"):
this.serialDisconnect().then(async () => {
await this.serialConnect();
});
break;
case t.includes("'close' on 'serialport': a call to close() is already in progress."):
break;
case t.includes("failed to execute 'open' on 'serialport': a call to open() is already in progress."):
break;
case t.includes("the port is already closed."):
break;
case t.includes("the device has been lost"):
this.dispatch("serial:lost", {}), k.$dispatchChange(this);
break;
case t.includes("navigator.serial is undefined"):
this.dispatch("serial:unsupported", {});
break;
default:
console.error(n);
break;
}
this.dispatch("serial:error", n);
}
async serialConnect() {
try {
this.dispatch("serial:connecting", {});
const n = await V(this, F, Ai).call(this);
if (n.length > 0)
await this.serialPortsSaved(n);
else {
const i = this.serialFilters;
this.__internal__.serial.port = await navigator.serial.requestPort({
filters: i
});
}
const t = this.__internal__.serial.port;
if (!t)
throw new Error("No port selected by the user");
await t.open(this.serialConfigPort);
const e = this;
t.onconnect = (i) => {
console.log(i), e.dispatch("serial:connected", i), k.$dispatchChange(this), e.__internal__.serial.queue.length > 0 && e.dispatch("internal:queue", {});
}, t.ondisconnect = async () => {
await e.disconnect();
}, await Jn(this.__internal__.serial.delay_first_connection), this.__internal__.timeout.until_response = setTimeout(async () => {
await e.timeout(e.__internal__.serial.bytes_connection ?? [], "connection:start");
}, this.__internal__.time.response_connection), this.__internal__.serial.last_action = "connect", await V(this, F, hn).call(this, this.__internal__.serial.bytes_connection ?? []), this.dispatch("serial:sent", {
action: "connect",
bytes: this.__internal__.serial.bytes_connection
}), this.__internal__.auto_response && V(this, F, It).call(this, this.__internal__.serial.auto_response, null), await V(this, F, Di).call(this);
} catch (n) {
this.serialErrors(n);
}
}
async serialForget() {
return await V(this, F, Ri).call(this);
}
decToHex(n) {
return typeof n == "string" && (n = parseInt(n, 10)), n.toString(16);
}
hexToDec(n) {
return parseInt(n, 16);
}
hexMaker(n = "00", t = 2) {
return n.toString().padStart(t, "0").toLowerCase();
}
add0x(n) {
const t = [];
return n.forEach((e, i) => {
t[i] = "0x" + e;
}), t;
}
bytesToHex(n) {
return this.add0x(Array.from(n, (t) => this.hexMaker(t)));
}
async appendToQueue(n, t) {
const e = this.bytesToHex(n);
if (["connect", "connection:start"].includes(t)) {
if (this.__internal__.serial.connected) return;
await this.serialConnect();
return;
}
this.__internal__.serial.queue.push({ bytes: e, action: t }), this.dispatch("internal:queue", {});
}
serialSetConnectionConstant(n = 1) {
throw new Error(`Method not implemented 'serialSetConnectionConstant' to listen on channel ${n}`);
}
serialMessage(n) {
throw console.log(n), new Error("Method not implemented 'serialMessage'");
}
serialCorruptMessage(n, t) {
throw console.log(n, t), new Error("Method not implemented 'serialCorruptMessage'");
}
clearSerialQueue() {
this.__internal__.serial.queue = [];
}
sumHex(n) {
let t = 0;
return n.forEach((e) => {
t += parseInt(e, 16);
}), t.toString(16);
}
toString() {
return JSON.stringify({
__class: this.typeDevice,
device_number: this.deviceNumber,
uuid: this.uuid,
connected: this.isConnected,
connection: this.__internal__.serial.bytes_connection
});
}
softReload() {
V(this, F, Bi).call(this), this.dispatch("serial:soft-reload", {});
}
async sendConnect() {
if (!this.__internal__.serial.bytes_connection)
throw new Error("No connection bytes defined");
await this.appendToQueue(this.__internal__.serial.bytes_connection, "connect");
}
// @ts-expect-error code is required but can be empty
async sendCustomCode({ code: n = [] } = { code: [] }) {
if (n === null || n.length === 0)
throw new Error("No data to send");
await this.appendToQueue(n, "custom");
}
stringToArrayHex(n) {
return Array.from(n).map((t) => t.charCodeAt(0).toString(16));
}
stringToArrayBuffer(n, t = `
`) {
return this.parseStringToTextEncoder(n, t).buffer;
}
parseStringToTextEncoder(n = "", t = `
`) {
const e = new TextEncoder();
return n += t, e.encode(n);
}
parseStringToBytes(n = "", t = `
`) {
const e = this.parseStringToTextEncoder(n, t);
return Array.from(e).map((i) => i.toString(16));
}
parseUint8ToHex(n) {
return Array.from(n).map((t) => t.toString(16));
}
parseHexToUint8(n) {
return new Uint8Array(n.map((t) => parseInt(t, 16)));
}
stringArrayToUint8Array(n) {
const t = [];
return n.forEach((e) => {
const i = e.replace("0x", "");
t.push(parseInt(i, 16));
}), new Uint8Array(t);
}
parseUint8ArrayToString(n) {
const t = this.stringArrayToUint8Array(n);
n = this.parseUint8ToHex(t);
const e = n.map((i) => parseInt(i, 16));
return this.__internal__.serial.response.replacer ? String.fromCharCode(...e).replace(this.__internal__.serial.response.replacer, "") : String.fromCharCode(...e);
}
hexToAscii(n) {
const t = n.toString();
let e = "";
for (let i = 0; i < t.length; i += 2)
e += String.fromCharCode(parseInt(t.substring(i, 2), 16));
return e;
}
asciiToHex(n) {
const t = [];
for (let e = 0, i = n.length; e < i; e++) {
const s = Number(n.charCodeAt(e)).toString(16);
t.push(s);
}
return t.join("");
}
$checkAndDispatchConnection() {
return this.isConnected;
}
}
F = /* @__PURE__ */ new WeakSet(), Kt = function(r) {
return !!(r && r.readable && r.writable);
}, oe = function(r = null) {
this.__internal__.serial.connected = !1, this.__internal__.aux_port_connector = 0, this.dispatch("serial:disconnected", r), k.$dispatchChange(this);
}, hn = async function(r) {
const n = this.__internal__.serial.port;
if (!n || n && (!n.readable || !n.writable))
throw V(this, F, oe).call(this, { error: "Port is closed, not readable or writable." }), new Error("The port is closed or is not readable/writable");
const t = this.stringArrayToUint8Array(r);
if (n.writable === null) return;
const e = n.writable.getWriter();
await e.write(t), e.releaseLock();
}, It = function(r = [], n = null) {
if (r && r.length > 0) {
const t = this.__internal__.serial.connected;
this.__internal__.serial.connected = V(this, F, Kt).call(this, this.__internal__.serial.port), k.$dispatchChange(this), !t && this.__internal__.serial.connected && this.dispatch("serial:connected"), 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);
const e = [];
for (const i in r)
e.push(r[i].toString().padStart(2, "0").toLowerCase());
if (this.__internal__.serial.response.as === "hex")
this.serialMessage(e);
else if (this.__internal__.serial.response.as === "uint8")
this.serialMessage(this.parseHexToUint8(this.add0x(e)));
else if (this.__internal__.serial.response.as === "string")
if (this.__internal__.serial.response.limiter !== null) {
const i = this.parseUint8ArrayToString(this.add0x(e)).split(this.__internal__.serial.response.limiter);
for (const s in i)
i[s] && this.serialMessage(i[s]);
} else
this.serialMessage(this.parseUint8ArrayToString(this.add0x(e)));
else {
const i = this.stringToArrayBuffer(
this.parseUint8ArrayToString(this.add0x(e))
);
this.serialMessage(i);
}
} else
this.serialCorruptMessage(r, n);
this.__internal__.serial.queue.length !== 0 && this.dispatch("internal:queue", {});
}, Ai = async function() {
const r = this.serialFilters, n = await navigator.serial.getPorts({ filters: r });
return r.length === 0 ? n : n.filter((t) => {
const e = t.getInfo();
return r.some((i) => e.usbProductId === i.usbProductId && e.usbVendorId === i.usbVendorId);
}).filter((t) => !V(this, F, Kt).call(this, t));
}, Qn = function(r) {
if (r) {
const n = this.__internal__.serial.response.buffer, t = new Uint8Array(n.length + r.byteLength);
t.set(n, 0), t.set(new Uint8Array(r), n.length), this.__internal__.serial.response.buffer = t;
}
}, Zn = async function() {
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(() => {
const r = [];
for (const n in this.__internal__.serial.response.buffer)
r.push(this.__internal__.serial.response.buffer[n].toString(16));
this.__internal__.serial.response.buffer && V(this, F, It).call(this, r), this.__internal__.serial.response.buffer = new Uint8Array(0);
}, 400);
}, Yn = async function() {
if (this.__internal__.serial.response.length !== null) {
if (this.__internal__.serial.response.length === this.__internal__.serial.response.buffer.length) {
const r = [];
for (const n in this.__internal__.serial.response.buffer)
r.push(this.__internal__.serial.response.buffer[n].toString(16));
V(this, F, It).call(this, r), this.__internal__.serial.response.buffer = new Uint8Array(0);
} else if (this.__internal__.serial.response.length < this.__internal__.serial.response.buffer.length) {
let r = new Uint8Array(0);
for (let t = 0; t < this.__internal__.serial.response.length; t++)
r[t] = this.__internal__.serial.response.buffer[t];
if (r.length === this.__internal__.serial.response.length) {
const t = [];
for (const e in r)
t.push(r[e].toString(16));
V(this, F, It).call(this, t), this.__internal__.serial.response.buffer = new Uint8Array(0);
return;
}
r = new Uint8Array(0);
const n = this.__internal__.serial.response.length * 2;
if (this.__internal__.serial.response.buffer.length === n) {
for (let t = 14; t < n; t++)
r[t - this.__internal__.serial.response.length] = this.__internal__.serial.response.buffer[t];
if (r.length === this.__internal__.serial.response.length) {
const t = [];
for (const e in r)
t.push(r[e].toString(16));
V(this, F, It).call(this, t), this.__internal__.serial.response.buffer = new Uint8Array(0);
}
}
}
}
}, Di = async function() {
const r = this.__internal__.serial.port;
if (!r || !r.readable) throw new Error("Port is not readable");
for (; r.readable && this.__internal__.serial.keep_reading; ) {
const n = r.readable.getReader();
this.__internal__.serial.reader = n;
try {
let t = !0;
for (; t; ) {
const { value: e, done: i } = await n.read();
if (i) {
n.releaseLock(), this.__internal__.serial.keep_reading = !1, t = !1;
break;
}
V(this, F, Qn).call(this, e), this.__internal__.serial.response.length === null ? await V(this, F, Zn).call(this) : await V(this, F, Yn).call(this);
}
} catch (t) {
this.serialErrors(t);
} finally {
n.releaseLock();
}
}
this.__internal__.serial.keep_reading = !0, this.__internal__.serial.port && await this.__internal__.serial.port.close();
}, Ri = async function() {
return typeof window > "u" ? !1 : "serial" in navigator && "forget" in SerialPort.prototype && this.__internal__.serial.port ? (await this.__internal__.serial.port.forget(), !0) : !1;
}, Ii = function() {
[
"serial:connected",
"serial:connecting",
"serial:reconnect",
"serial:timeout",
"serial:disconnected",
"serial:sent",
"serial:soft-reload",
"serial:message",
"unknown",
"serial:need-permission",
"serial:lost",
"serial:unsupported",
"serial:error",
"debug"
].forEach((r) => {
this.serialRegisterAvailableListener(r);
});
}, Oi = function() {
const r = this;
this.on("internal:queue", async () => {
var n;
await V(n = r, F, ei).call(n);
}), V(this, F, ti).call(this);
}, ti = function() {
const r = this;
navigator.serial.addEventListener("connect", async () => {
r.isDisconnected && await r.serialConnect().catch(() => {
});
});
}, ei = async function() {
if (!V(this, F, Kt).call(this, this.__internal__.serial.port)) {
V(this, F, oe).call(this, { error: "Port is closed, not readable or writable." }), await this.serialConnect();
return;
}
if (this.__internal__.timeout.until_response || this.__internal__.serial.queue.length === 0) return;
const r = this.__internal__.serial.queue[0];
let n = this.__internal__.time.response_general;
r.action === "connect" && (n = this.__internal__.time.response_connection), this.__internal__.timeout.until_response = setTimeout(async () => {
await this.timeout(r.bytes, r.action);
}, n), this.__internal__.serial.last_action = r.action ?? "unknown", await V(this, F, hn).call(this, r.bytes), this.dispatch("serial:sent", {
action: r.action,
bytes: r.bytes
}), this.__internal__.auto_response && V(this, F, It).call(this, this.__internal__.serial.auto_response, null);
const t = [...this.__internal__.serial.queue];
this.__internal__.serial.queue = t.splice(1);
}, Ni = function(r = 1) {
this.__internal__.device_number = r, this.__internal__.serial.bytes_connection = this.serialSetConnectionConstant(r);
}, Bi = function() {
this.__internal__.last_error = {
message: null,
action: null,
code: null,
no_code: 0
};
};
k.instance || (k.instance = new k());
const Ma = {
relay: [],
locker: [],
jofemar: [],
boardroid: [],
arduino: [],
pinpad: [],
pinpax: []
};
k.devices = { ...k.devices, ...Ma };
k.addCustom = (r, n) => {
k.registerType(r), k.add(n);
};
k.getCustomByUuid = (r, n) => k.get(r, n);
k.getJofemarByUuid = (r) => k.get("jofemar", r);
k.getLockerByUuid = (r) => k.get("locker", r);
k.getRelayByUuid = (r) => k.get("relay", r);
k.getBoardroidByUuid = (r) => k.get("boardroid", r);
k.getArduinoByUuid = (r) => k.get("arduino", r);
k.getPinPadByUuid = (r) => k.get("pinpad", r);
k.getPinPaxByUuid = (r) => k.get("pinpax", r);
k.getJofemar = (r = 1) => k.getByNumber("jofemar", r);
k.getBoardroid = (r = 1) => k.getByNumber("boardroid", r);
k.getLocker = (r = 1) => k.getByNumber("locker", r);
k.getRelay = (r = 1) => k.getByNumber("relay", r);
k.getArduino = (r = 1) => k.getByNumber("arduino", r);
k.getPinPad = (r = 1) => k.getByNumber("pinpad", r);
k.getPinPax = (r = 1) => k.getByNumber("pinpax", r);
class Dt extends Ba {
constructor(n) {
super(n), this.__internal__ = structuredClone(this.__internal__), this.getResponseAsArrayHex(), this.__internal__.device.door_open = !1, this.__internal__.time.response_engines = 2e3, this.__internal__.time.sense = 100, this.__internal__.interval.waiting_sense = 0, this.__internal__.dispense = {
must_response: !1,
dispensing: !1,
status: null,
counter: 0,
limit_counter: 20,
custom_limit_counter: null,
backup_dispense: {}
};
}
get isDoorOp