@danidoble/webserial 4.1.0 → 4.1.1
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 +148 -1
- package/dist/webserial.js +5 -2
- package/dist/webserial.umd.cjs +2 -2
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -1 +1,148 @@
|
|
|
1
|
-
# Webserial API
|
|
1
|
+
# Webserial API (Wrapper)
|
|
2
|
+
|
|
3
|
+
Opensource wrapper to simplify connect to serial devices over [Webserial API](https://wicg.github.io/serial/)
|
|
4
|
+
|
|
5
|
+
# Install
|
|
6
|
+
|
|
7
|
+
Using npm
|
|
8
|
+
|
|
9
|
+
```shell
|
|
10
|
+
npm install @danidoble/webserial
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Using pnpm
|
|
14
|
+
|
|
15
|
+
```shell
|
|
16
|
+
pnpm install @danidoble/webserial
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Using bun
|
|
20
|
+
|
|
21
|
+
```shell
|
|
22
|
+
bun install @danidoble/webserial
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
# Docs
|
|
26
|
+
|
|
27
|
+
If you want to use a custom or device or the other inside this package a good starter point would be [Here](https://webserial-docs.danidoble.com)
|
|
28
|
+
|
|
29
|
+
# Example
|
|
30
|
+
|
|
31
|
+
In this example we'll use Arduino interface
|
|
32
|
+
|
|
33
|
+
```html
|
|
34
|
+
<!-- index.html -->
|
|
35
|
+
|
|
36
|
+
<!doctype html>
|
|
37
|
+
<html lang="es">
|
|
38
|
+
<head>
|
|
39
|
+
<meta charset="UTF-8" />
|
|
40
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
41
|
+
<title>Webserial</title>
|
|
42
|
+
<script src="arduino.js" type="module"></script>
|
|
43
|
+
</head>
|
|
44
|
+
<body class="bg-neutral-950 text-white p-4 w-full">
|
|
45
|
+
<div class="webserial w-full max-w-xl mx-auto grid grid-cols-1 gap-y-4">
|
|
46
|
+
<div class="my-6"></div>
|
|
47
|
+
<button id="connect" class="hidden px-4 py-3 bg-gray-800 rounded-lg">Connect to serial</button>
|
|
48
|
+
|
|
49
|
+
<div id="need-permission" class="hidden p-4 bg-rose-900 rounded-lg">
|
|
50
|
+
Woooah! It seems that you need to give permission to access the serial port. Please, click the button 'Connect
|
|
51
|
+
to serial' to try again.
|
|
52
|
+
</div>
|
|
53
|
+
|
|
54
|
+
<div id="disconnected" class="hidden p-4 bg-neutral-900 w-full">
|
|
55
|
+
The arduino is disconnected. Please, check the connection.
|
|
56
|
+
</div>
|
|
57
|
+
|
|
58
|
+
<div id="unsupported" class="hidden p-4 bg-orange-700 w-full absolute bottom-0 left-0">
|
|
59
|
+
This browser does not support the WebSerial API. Please, use a compatible browser.
|
|
60
|
+
</div>
|
|
61
|
+
|
|
62
|
+
<div id="log" class="bg-neutral-800 p-4 rounded-lg">Log: <br /></div>
|
|
63
|
+
</div>
|
|
64
|
+
|
|
65
|
+
<script src="https://cdn.tailwindcss.com?plugins=forms,typography,aspect-ratio,container-queries"></script>
|
|
66
|
+
</body>
|
|
67
|
+
</html>
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
```js
|
|
71
|
+
// arduino.js
|
|
72
|
+
|
|
73
|
+
import { Arduino } from '@danidoble/webserial';
|
|
74
|
+
|
|
75
|
+
const arduino = new Arduino();
|
|
76
|
+
arduino.on('serial:message', (data) => {
|
|
77
|
+
console.log(data.detail);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
arduino.on('serial:timeout', (data) => {
|
|
81
|
+
console.log('serial:timeout', data.detail);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
// arduino.on('serial:sent', data => {
|
|
85
|
+
// console.log('serial:sent',data.detail);
|
|
86
|
+
// });
|
|
87
|
+
|
|
88
|
+
arduino.on('serial:error', (event) => {
|
|
89
|
+
document.getElementById('log').innerText += event.detail.message + '\n\n';
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
// eslint-disable-next-line no-unused-vars
|
|
93
|
+
arduino.on('serial:disconnected', (event) => {
|
|
94
|
+
document.getElementById('log').innerText += 'Disconnected\n\n';
|
|
95
|
+
|
|
96
|
+
document.getElementById('disconnected').classList.remove('hidden');
|
|
97
|
+
document.getElementById('connect').classList.remove('hidden');
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
// eslint-disable-next-line no-unused-vars
|
|
101
|
+
arduino.on('serial:connecting', (event) => {
|
|
102
|
+
document.getElementById('log').innerText += 'Connecting\n\n';
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
// eslint-disable-next-line no-unused-vars
|
|
106
|
+
arduino.on('serial:connected', (event) => {
|
|
107
|
+
document.getElementById('log').innerText += 'Connected\n\n';
|
|
108
|
+
|
|
109
|
+
document.getElementById('disconnected').classList.add('hidden');
|
|
110
|
+
document.getElementById('need-permission').classList.add('hidden');
|
|
111
|
+
document.getElementById('connect').classList.add('hidden');
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
// eslint-disable-next-line no-unused-vars
|
|
115
|
+
arduino.on('serial:need-permission', (event) => {
|
|
116
|
+
document.getElementById('disconnected').classList.remove('hidden');
|
|
117
|
+
document.getElementById('need-permission').classList.remove('hidden');
|
|
118
|
+
document.getElementById('connect').classList.remove('hidden');
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
// eslint-disable-next-line no-unused-vars
|
|
122
|
+
arduino.on('serial:soft-reload', (event) => {
|
|
123
|
+
// reset your variables
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
// eslint-disable-next-line no-unused-vars
|
|
127
|
+
arduino.on('serial:unsupported', (event) => {
|
|
128
|
+
document.getElementById('unsupported').classList.remove('hidden');
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
function tryConnect() {
|
|
132
|
+
arduino
|
|
133
|
+
.connect()
|
|
134
|
+
.then(() => {})
|
|
135
|
+
.catch(console.error);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
document.addEventListener('DOMContentLoaded', () => {
|
|
139
|
+
tryConnect();
|
|
140
|
+
document.getElementById('connect').addEventListener('click', tryConnect);
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
// get device instance after
|
|
144
|
+
// import {Devices} from '@danidoble/webserial'
|
|
145
|
+
// const myDevice = Devices.getArduino(1);
|
|
146
|
+
|
|
147
|
+
// window.arduino = arduino;
|
|
148
|
+
```
|
package/dist/webserial.js
CHANGED
|
@@ -23,10 +23,13 @@ function _a() {
|
|
|
23
23
|
}
|
|
24
24
|
const ga = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), qn = { randomUUID: ga };
|
|
25
25
|
function ba(r, n, t) {
|
|
26
|
+
var i;
|
|
26
27
|
if (qn.randomUUID && !n && !r)
|
|
27
28
|
return qn.randomUUID();
|
|
28
29
|
r = r || {};
|
|
29
|
-
const e = r.random
|
|
30
|
+
const e = r.random ?? ((i = r.rng) == null ? void 0 : i.call(r)) ?? _a();
|
|
31
|
+
if (e.length < 16)
|
|
32
|
+
throw new Error("Random bytes length must be >= 16");
|
|
30
33
|
return e[6] = e[6] & 15 | 64, e[8] = e[8] & 63 | 128, pa(e);
|
|
31
34
|
}
|
|
32
35
|
class fi extends EventTarget {
|
|
@@ -8552,7 +8555,7 @@ const Sc = {
|
|
|
8552
8555
|
wait: ut,
|
|
8553
8556
|
getSeconds: tn,
|
|
8554
8557
|
supportWebSerial: _i
|
|
8555
|
-
}, kc = "4.1.
|
|
8558
|
+
}, kc = "4.1.1";
|
|
8556
8559
|
export {
|
|
8557
8560
|
Cc as Arduino,
|
|
8558
8561
|
Tc as Boardroid,
|
package/dist/webserial.umd.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(I,x){typeof exports=="object"&&typeof module<"u"?x(exports):typeof define=="function"&&define.amd?define(["exports"],x):(I=typeof globalThis<"u"?globalThis:I||self,x(I.WebSerial={}))})(this,function(I){"use strict";var yc=Object.defineProperty;var Ki=I=>{throw TypeError(I)};var wc=(I,x,X)=>x in I?yc(I,x,{enumerable:!0,configurable:!0,writable:!0,value:X}):I[x]=X;var Z=(I,x,X)=>wc(I,typeof x!="symbol"?x+"":x,X),gn=(I,x,X)=>x.has(I)||Ki("Cannot "+X);var O=(I,x,X)=>(gn(I,x,"read from private field"),X?X.call(I):x.get(I)),$=(I,x,X)=>x.has(I)?Ki("Cannot add the same private member more than once"):x instanceof WeakSet?x.add(I):x.set(I,X),L=(I,x,X,Vt)=>(gn(I,x,"write to private field"),Vt?Vt.call(I,X):x.set(I,X),X),o=(I,x,X)=>(gn(I,x,"access private method"),X);var st,ht,d,Wi,zi,T,bn,U,F,Be,E,mn,se,B,Xi,yn,Mt,Gi,Ji,$i,Qi,Zi,Yi,tr,er,nr,ir,rr,sr,re,Ie,ar,nt,G,Pt,R,or,cr,lr,hr,wn,ur,Ft,Ut,Ne,Me,Fe,p,dr,pr,fr,vn,_r,gr,br,mr,yr,wr,vr,Pr,Er,Tr,ae,oe,Cr,ce,Sr,Lt,kr,J,xr,Ar,Pn,Dr,Rr,Ir,En,Tn,le,Cn,Or,mt,yt,Ue,Sn,he,kn,xn,Br,An,Dn,Nr,Mr,Qt,Rn,Fr,Ur,Lr,Le,Vr,qr,In,jr,Hr,Kr,Wr,zr,Xr,Gr,Jr,$r,On,Bn,Qr,Zr,Yr,g,ts,es,ns,ot,Ve,is,rs,ss,as,os,cs,ls,hs,us,ds,ps,fs,_s,gs,bs,ms,ys,ws,vs,Ps,Es,Ts,Cs,Ss,ks,xs,ft,Y,qe,tt,wt,As,Ds,Rs,Is,ue,Nn,Mn,je,He,Os,Gt,Nt,Jt,w,Bs,Ns,Ke,Ms,Fs,Us,Ls,Vs,qs,js,Hs,Fn,Ks,Ws,zs,Xs,Gs,Js,$s,Qs,Zs,Ys,ta,ea,na,ia,ct,We,ra,sa,aa,oa,Un,ze,ca,la,Ln,Vn,qn,$t,ha,ua;const x=[];for(let r=0;r<256;++r)x.push((r+256).toString(16).slice(1));function X(r,n=0){return(x[r[n+0]]+x[r[n+1]]+x[r[n+2]]+x[r[n+3]]+"-"+x[r[n+4]]+x[r[n+5]]+"-"+x[r[n+6]]+x[r[n+7]]+"-"+x[r[n+8]]+x[r[n+9]]+"-"+x[r[n+10]]+x[r[n+11]]+x[r[n+12]]+x[r[n+13]]+x[r[n+14]]+x[r[n+15]]).toLowerCase()}let Vt;const da=new Uint8Array(16);function pa(){if(!Vt){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");Vt=crypto.getRandomValues.bind(crypto)}return Vt(da)}const jn={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function fa(r,n,t){if(jn.randomUUID&&!n&&!r)return jn.randomUUID();r=r||{};const e=r.random||(r.rng||pa)();return e[6]=e[6]&15|64,e[8]=e[8]&63|128,X(e)}class Hn extends EventTarget{constructor(){super(...arguments);Z(this,"__listeners__",{});Z(this,"__debug__",!1)}dispatch(t,e=null){const i=new Kn(t,{detail:e});this.dispatchEvent(i),this.__debug__&&this.dispatchEvent(new Kn("debug",{detail:{type:t,data:e}}))}dispatchAsync(t,e=null,i=100){const s=this;setTimeout(()=>{s.dispatch(t,e)},i)}on(t,e){typeof this.__listeners__[t]<"u"&&this.__listeners__[t]===!1&&(this.__listeners__[t]=!0),this.addEventListener(t,e)}off(t,e){this.removeEventListener(t,e)}serialRegisterAvailableListener(t){this.__listeners__[t]||(this.__listeners__[t]=!1)}get availableListeners(){return Object.keys(this.__listeners__).sort().map(e=>({type:e,listening:this.__listeners__[e]}))}}class Kn extends CustomEvent{constructor(n,t){super(n,t)}}function dt(r=100){return new Promise(n=>setTimeout(()=>n(),r))}function Wn(){return"serial"in navigator}function zn(){return"geolocation"in navigator}function _a(){return"crypto"in window}function Xe(r=1){return r*1e3}function Ct(r){return r==null||r===""}const u=class u{static status(n=null){var e,i;if(!o(e=u,d,T).call(e,n))return!1;let t=[];switch(O(u,st)){case"locker":t=["0","8"];break;case"boardroid":t=["2",(5+O(u,ht)).toString(16).toUpperCase()];break;case"jofemar":t=["6"];break;default:return!1}o(i=u,d,E).call(i,t)}static dispensed(n=null){var e,i;if(!o(e=u,d,T).call(e,n))return!1;let t=[];switch(O(u,st)){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,d,E).call(i,t)}static notDispensed(n=null){var e,i;if(!o(e=u,d,T).call(e,n))return!1;let t=[];switch(O(u,st)){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,d,E).call(i,t)}static gateInactive(n=null){var t;if(!o(t=u,d,T).call(t,n)||!o(this,d,bn).call(this))return!1;o(this,d,E).call(this,["0","7","5","5","5"])}static gateConfigured(n=null){var t;if(!o(t=u,d,T).call(t,n)||!o(this,d,bn).call(this))return!1;o(this,d,E).call(this,["0","6"])}static keyPressed(n=null){var s,a,c;if(!o(s=u,d,T).call(s,n)||!o(a=u,d,F).call(a))return!1;const t=["30","31","32","33","34","35","36","37","38","39","2A","23","41","42","43","44"],e=(128+O(u,ht)).toString(16),i=Math.floor(Math.random()*15);o(c=u,d,E).call(c,["2",e,"54",t[i]])}static doorOpened(n=null){var i,s;if(!o(i=u,d,T).call(i,n)||!o(this,d,Be).call(this))return!1;let t=[];const e=(128+O(u,ht)).toString(16);switch(O(u,st)){case"boardroid":t=["2","D8","dc"];break;case"jofemar":t=["2",e,"50","4F"];break}o(s=u,d,E).call(s,t)}static doorClosed(n=null){var i,s;if(!o(i=u,d,T).call(i,n)||!o(this,d,Be).call(this))return!1;let t=[];const e=(128+O(u,ht)).toString(16);switch(O(u,st)){case"boardroid":t=["2","D8","db"];break;case"jofemar":t=["2",e,"50","43"];break}o(s=u,d,E).call(s,t)}static channelDisconnected(n=null){var e,i,s;if(!o(e=u,d,T).call(e,n)||!o(i=u,d,F).call(i))return!1;const t=(128+O(u,ht)).toString(16);o(s=u,d,E).call(s,["2",t,"43","43","43","FD"])}static channelConnected(n=null){var e,i,s;if(!o(e=u,d,T).call(e,n)||!o(i=u,d,F).call(i))return!1;const t=(128+O(u,ht)).toString(16);o(s=u,d,E).call(s,["2",t,"43","43","43","FC"])}static channelEmpty(n=null){var e,i,s;if(!o(e=u,d,T).call(e,n)||!o(i=u,d,F).call(i))return!1;const t=(128+O(u,ht)).toString(16);o(s=u,d,E).call(s,["2",t,"43","43","43","FF"])}static workingTemperature(n=null){var e,i,s;if(!o(e=u,d,T).call(e,n)||!o(i=u,d,F).call(i))return!1;const t=(128+O(u,ht)).toString(16);o(s=u,d,E).call(s,["2",t,"43","54","16"])}static currentTemperature(n=null){var i,s,a;if(!o(i=u,d,T).call(i,n)||!o(s=u,d,Be).call(s))return!1;let t=[];const e=(128+O(u,ht)).toString(16);switch(O(u,st)){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,d,E).call(a,t)}static ready(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,F).call(e))return!1;o(i=u,d,E).call(i,["6","30"])}static busy(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,F).call(e))return!1;o(i=u,d,E).call(i,["6","31"])}static invalidTray(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,F).call(e))return!1;o(i=u,d,E).call(i,["6","32"])}static invalidChannel(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,F).call(e))return!1;o(i=u,d,E).call(i,["6","33"])}static emptyChannel(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,F).call(e))return!1;o(i=u,d,E).call(i,["6","34"])}static elevatorJam(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,F).call(e))return!1;o(i=u,d,E).call(i,["6","35"])}static elevatorMalfunction(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,F).call(e))return!1;o(i=u,d,E).call(i,["6","36"])}static phototransistorFailure(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,F).call(e))return!1;o(i=u,d,E).call(i,["6","37"])}static allChannelsEmpty(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,F).call(e))return!1;o(i=u,d,E).call(i,["6","38"])}static productDetectorFailure(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,F).call(e))return!1;o(i=u,d,E).call(i,["6","39"])}static displayDisconnected(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,F).call(e))return!1;o(i=u,d,E).call(i,["6","41"])}static productUnderElevator(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,F).call(e))return!1;o(i=u,d,E).call(i,["6","42"])}static elevatorSettingAlarm(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,F).call(e))return!1;o(i=u,d,E).call(i,["6","43"])}static buttonPanelFailure(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,F).call(e))return!1;o(i=u,d,E).call(i,["6","44"])}static errorWritingEeprom(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,F).call(e))return!1;o(i=u,d,E).call(i,["6","45"])}static errorControlTemperature(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,F).call(e))return!1;o(i=u,d,E).call(i,["6","46"])}static thermometerDisconnected(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,F).call(e))return!1;o(i=u,d,E).call(i,["6","47"])}static thermometerMisconfigured(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,F).call(e))return!1;o(i=u,d,E).call(i,["6","48"])}static thermometerFailure(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,F).call(e))return!1;o(i=u,d,E).call(i,["6","49"])}static errorExtractorConsumption(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,F).call(e))return!1;o(i=u,d,E).call(i,["6","4A"])}static channelSearchError(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,F).call(e))return!1;o(i=u,d,E).call(i,["6","4B"])}static productExitMouthSearchError(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,F).call(e))return!1;o(i=u,d,E).call(i,["6","4C"])}static elevatorInteriorLocked(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,F).call(e))return!1;o(i=u,d,E).call(i,["6","4D"])}static productDetectorVerifierError(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,F).call(e))return!1;o(i=u,d,E).call(i,["6","4E"])}static waitingForProductRecall(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,F).call(e))return!1;o(i=u,d,E).call(i,["6","4F"])}static productExpiredByTemperature(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,F).call(e))return!1;o(i=u,d,E).call(i,["6","50"])}static faultyAutomaticDoor(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,F).call(e))return!1;o(i=u,d,E).call(i,["6","51"])}static rejectLever(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,U).call(e))return!1;o(i=u,d,E).call(i,["2","A0","1"])}static resetCoinPurse(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,U).call(e))return!1;o(i=u,d,E).call(i,["2","A0","2"])}static coinInsertedBox(n=null,t=null){var s,a,c,l;if(!o(s=u,d,T).call(s,n)||!o(a=u,d,U).call(a))return!1;const e=["40","41","42","43","44","45"],i=o(c=u,d,mn).call(c,e,t);o(l=u,d,E).call(l,["2","A0",i])}static coinInsertedTube(n=null,t=null){var s,a,c,l;if(!o(s=u,d,T).call(s,n)||!o(a=u,d,U).call(a))return!1;const e=["50","51","52","53","54","55"],i=o(c=u,d,mn).call(c,e,t);o(l=u,d,E).call(l,["2","A0",i])}static banknoteInsertedStacker(n=null,t=null){var s,a,c,l;if(!o(s=u,d,T).call(s,n)||!o(a=u,d,U).call(a))return!1;const e=["80","81","82","83","84"],i=o(c=u,d,se).call(c,e,t);o(l=u,d,E).call(l,["2","B0",i])}static banknoteInsertedEscrow(n=null,t=null){var s,a,c,l;if(!o(s=u,d,T).call(s,n)||!o(a=u,d,U).call(a))return!1;const e=["90","91","92","93","94"],i=o(c=u,d,se).call(c,e,t);o(l=u,d,E).call(l,["2","B0",i])}static banknoteEjected(n=null,t=null){var s,a,c,l;if(!o(s=u,d,T).call(s,n)||!o(a=u,d,U).call(a))return!1;const e=["A0","A1","A2","A3","A4"],i=o(c=u,d,se).call(c,e,t);o(l=u,d,E).call(l,["2","B0",i])}static banknoteInsertedRecycler(n=null,t=null){var s,a,c,l;if(!o(s=u,d,T).call(s,n)||!o(a=u,d,U).call(a))return!1;const e=["B0","B1","B2","B3","B4"],i=o(c=u,d,se).call(c,e,t);o(l=u,d,E).call(l,["2","B0",i])}static banknoteTaken(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,U).call(e))return!1;o(i=u,d,E).call(i,["2","B0","2a"])}static coinPurseEnabled(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,U).call(e))return!1;o(i=u,d,E).call(i,["2","D0","1"])}static coinPurseDisabled(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,U).call(e))return!1;o(i=u,d,E).call(i,["2","D0","0"])}static billPurseDisabled(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,U).call(e))return!1;o(i=u,d,E).call(i,["2","D1","0","0"])}static billPurseEnabled(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,U).call(e))return!1;o(i=u,d,E).call(i,["2","D1","1","1"])}static readTubes(n=null){var h,f,_;if(!o(h=u,d,T).call(h,n)||!o(f=u,d,U).call(f))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(_=u,d,E).call(_,["2","D2",e,i,s,a,c,l])}static readBillPurse(n=null,t=null){var i,s,a,c;if(!o(i=u,d,T).call(i,n)||!o(s=u,d,U).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",f="0",_="0",m="0",P="0";if(t!==null&&!isNaN(parseInt(t)))switch(t.toString()){case"20":h=l;break;case"50":f=l;break;case"100":_=l;break;case"200":m=l;break;case"500":P=l;break}else switch(n._recycler.bill){case 0:h=l;break;case 1:f=l;break;case 2:_=l;break;case 3:m=l;break;case 4:P=l;break}o(a=u,d,E).call(a,["2","D3",h,f,_,m,P,"0"])}else{const[l,h,f,_,m,P]=[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,d,E).call(c,["2","D3",l,h,f,_,m,P])}}static banknoteAccepted(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,U).call(e))return!1;o(i=u,d,E).call(i,["2","D4","1"])}static banknoteRejected(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,U).call(e))return!1;o(i=u,d,E).call(i,["2","D4","0"])}static banknotesDispensed(n=null){var e,i,s,a;if(!o(e=u,d,T).call(e,n)||!o(i=u,d,U).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",f="0",_="0",m="0";switch(n._recycler.bill){case 0:l=c;break;case 1:h=c;break;case 2:f=c;break;case 3:_=c;break;case 4:m=c;break}o(s=u,d,E).call(s,["2","D5",l,h,f,_,m,"0"])}else{const[c,l,h,f,_,m]=[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,d,E).call(a,["2","D5",c,l,h,f,_,m])}}static coinsDispensed(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,U).call(e))return!1;o(i=u,d,E).call(i,["2","D6"])}static relayOn(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,U).call(e))return!1;o(i=u,d,E).call(i,["2","DA","1"])}static relayOff(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,U).call(e))return!1;o(i=u,d,E).call(i,["2","DA","0"])}static nayaxEnabled(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,U).call(e))return!1;o(i=u,d,E).call(i,["2","DD","1"])}static nayaxDisabled(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,U).call(e))return!1;o(i=u,d,E).call(i,["2","DD","0"])}static nayaxPreCreditAuthorized(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,U).call(e))return!1;o(i=u,d,E).call(i,["2","DD","3"])}static nayaxCancelRequest(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,U).call(e))return!1;o(i=u,d,E).call(i,["2","DD","4"])}static nayaxSellApproved(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,U).call(e))return!1;o(i=u,d,E).call(i,["2","DD","5"])}static nayaxSellDenied(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,U).call(e))return!1;o(i=u,d,E).call(i,["2","DD","6"])}static nayaxEndSession(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,U).call(e))return!1;o(i=u,d,E).call(i,["2","DD","7"])}static nayaxCancelled(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,U).call(e))return!1;o(i=u,d,E).call(i,["2","DD","8"])}static nayaxDispensed(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,U).call(e))return!1;o(i=u,d,E).call(i,["2","DD","A","0"])}static nayaxNotDispensed(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,U).call(e))return!1;o(i=u,d,E).call(i,["2","DD","A","1"])}static fullTray(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,F).call(e))return!1;o(i=u,d,E).call(i,["6","4F"])}static setConnection(n=null){var t;if(!o(t=u,d,T).call(t,n))return!1;n.__internal__.serial.connected=!0}};st=new WeakMap,ht=new WeakMap,d=new WeakSet,Wi=function(){if(u.enable===!1)throw new Error("Emulator is disabled");return u.enable},zi=function(n){if(typeof n!="object"||!(n instanceof kt))throw new Error(`Type ${n.typeDevice} is not supported`);return u.instance=n,L(u,st,n.typeDevice),L(u,ht,n.deviceNumber),!0},T=function(n=null){var t,e;return!o(t=u,d,Wi).call(t)||n===null&&u.instance===null?!1:(u.instance===null&&o(e=u,d,zi).call(e,n),!0)},bn=function(){if(O(u,st)!=="locker")throw new Error("This function is only available for Locker devices");return!0},U=function(){if(O(u,st)!=="boardroid")throw new Error("This function is only available for Boardroid devices");return!0},F=function(){if(O(u,st)!=="jofemar")throw new Error("This function is only available for Jofemar devices");return!0},Be=function(){if(O(u,st)==="locker")throw new Error("This function is not available for Locker devices");return!0},E=function(n){u.instance.__emulate({code:n})},mn=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},se=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},$(u,d),Z(u,"enable",!1),Z(u,"instance",null),$(u,st,null),$(u,ht,1);let Zt=u;const M=class M extends Hn{static typeError(n){const t=new Error;throw t.message=`Type ${n} is not supported`,t.name="DeviceTypeError",t}static addCustom(n,t){typeof M.devices[n]>"u"&&(M.devices[n]=[]),M.add(t)}static add(n){const t=n.typeDevice,e=n.uuid;if(typeof M.devices[t]>"u")return M.typeError(t);if(this.instance.dispatch("change",M.devices),!M.devices[t][e])return M.devices[t][e]=n,this.instance.dispatch("change",M.devices),M.devices[t].indexOf(n)}static get(n,t){return typeof M.devices[n]>"u"?M.typeError(n):M.devices[n][t]}static getJofemarByUuid(n){return M.get("jofemar",n)}static getLockerByUuid(n){return M.get("locker",n)}static getRelayByUuid(n){return M.get("relay",n)}static getBoardroidByUuid(n){return M.get("boardroid",n)}static getArduinoByUuid(n){return M.get("arduino",n)}static getPinPadByUuid(n){return M.get("pinpad",n)}static getAll(n=null){return n===null?M.devices:typeof M.devices[n]>"u"?M.typeError(n):M.devices[n]}static getList(){return Object.values(M.devices).map(t=>Object.values(t)).flat()}static getJofemar(n=1){return Object.values(M.devices.jofemar).find(e=>e.deviceNumber===n)??null}static getBoardroid(n=1){return Object.values(M.devices.boardroid).find(e=>e.deviceNumber===n)??null}static getLocker(n=1){return Object.values(M.devices.locker).find(e=>e.deviceNumber===n)??null}static getRelay(n=1){return Object.values(M.devices.relay).find(e=>e.deviceNumber===n)??null}static getArduino(n=1){return Object.values(M.devices.arduino).find(e=>e.deviceNumber===n)??null}static getPinPad(n=1){return Object.values(M.devices.pinpad).find(e=>e.deviceNumber===n)??null}static getCustom(n,t=1){return typeof M.devices[n]>"u"?M.typeError(n):Object.values(M.devices[n]).find(i=>i.deviceNumber===t)??null}};Z(M,"instance",null),Z(M,"devices",{relay:[],locker:[],jofemar:[],boardroid:[],arduino:[],pinpad:[]});let K=M;K.instance||(K.instance=new K);class kt extends Hn{constructor({filters:t=null,config_port:e=null,no_device:i=1,device_listen_on_port:s=1}={}){super();$(this,B);Z(this,"__internal__",{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([])},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:{baudRate:9600,dataBits:8,stopBits:1,parity:"none",bufferSize:32768,flowControl:"none"},queue:[]},device:{type:"unknown",id:fa(),listen_on_port:null,door_open:!1},time:{response_connection:500,response_general:2e3,response_engines:2e3,sense:100},timeout:{until_response:0},interval:{reconnection:0,waiting_sense:0},dispense:{must_response:!1,dispensing:!1,status:null,counter:0,limit_counter:20,custom_limit_counter:null,backup_dispense:{}}});t&&(this.serialFilters=t),e&&(this.serialConfigPort=e),i&&o(this,B,rr).call(this,i),s&&(typeof s=="number"||typeof s=="string")&&(this.listenOnPort=s),o(this,B,tr).call(this),o(this,B,er).call(this)}set listenOnPort(t){if(t=parseInt(t),isNaN(t)||t<1||t>255)throw new Error("Invalid port number");this.__internal__.device.listen_on_port=t,this.__internal__.serial.bytes_connection=this.serialSetConnectionConstant(t)}get isDoorOpen(){return this.__internal__.device.door_open}get lastAction(){return this.__internal__.serial.last_action}get listenOnPort(){return this.__internal__.device.listen_on_port??1}set serialFilters(t){this.__internal__.serial.filters=t}get serialFilters(){return this.__internal__.serial.filters}set serialConfigPort(t){this.__internal__.serial.config_port=t}get serialConfigPort(){return this.__internal__.serial.config_port}get isConnected(){return this.__internal__.serial.connected}get isDisconnected(){return!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}get isDispensing(){return this.__internal__.interval.waiting_sense||this.__internal__.dispense.dispensing}async timeout(t,e){this.__internal__.last_error.message="Operation response timed out.",this.__internal__.last_error.action=e,this.__internal__.last_error.code=t,this.__internal__.timeout.until_response&&(clearTimeout(this.__internal__.timeout.until_response),this.__internal__.timeout.until_response=0),e==="connect"?(this.__internal__.serial.connected=!1,this.dispatch("serial:reconnect",{})):e==="connection:start"?(await this.serialDisconnect(),this.__internal__.serial.connected=!1,this.__internal__.aux_port_connector+=1,await this.serialConnect()):e==="dispense"&&(this.__internal__.dispense.status="no-response"),this.dispatch("serial:timeout",{...this.__internal__.last_error,bytes:t,action:e})}async disconnect(t=null){await this.serialDisconnect(),this.__internal__.serial.connected=!1,this.__internal__.aux_port_connector=0,this.dispatch("serial:disconnected",t),K.instance.dispatch("change")}async connect(){return new Promise((t,e)=>{Wn()||e("Web Serial not supported"),setTimeout(async()=>{await dt(499),await this.serialConnect(),this.isConnected?t(`${this.typeDevice} device ${this.deviceNumber} connected`):e(`${this.typeDevice} device ${this.deviceNumber} not connected`)},1)})}async serialDisconnect(){try{const t=this.__internal__.serial.reader,e=this.__internal__.serial.output_stream;t&&(await t.cancel().catch(s=>this.serialErrors(s)),await this.__internal__.serial.input_done),e&&(await e.getWriter().close(),await this.__internal__.serial.output_done),this.__internal__.serial.connected&&this.__internal__.serial&&await this.__internal__.serial.port.close()}catch(t){this.serialErrors(t)}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}}async serialPortsSaved(t){const e=this.serialFilters;if(this.__internal__.aux_port_connector<t.length){const i=this.__internal__.aux_port_connector;this.__internal__.serial.port=t[i]}else this.__internal__.aux_port_connector=0,this.__internal__.serial.port=await navigator.serial.requestPort({filters:e});if(!this.__internal__.serial.port)throw new Error("Select another port please")}serialErrors(t){const e=t.toString().toLowerCase();switch(!0){case e.includes("must be handling a user gesture to show a permission request"):case e.includes("the port is closed."):case e.includes("select another port please"):case e.includes("no port selected by the user"):case e.includes("this readable stream reader has been released and cannot be used to cancel its previous owner stream"):this.dispatch("serial:need-permission",{}),K.instance.dispatch("change");break;case e.includes("the port is already open."):case e.includes("failed to open serial port"):this.serialDisconnect().then(async()=>{this.__internal__.aux_port_connector+=1,await this.serialConnect()});break;case e.includes("cannot read properties of undefined (reading 'writable')"):case e.includes("cannot read properties of null (reading 'writable')"):case e.includes("cannot read property 'writable' of null"):case e.includes("cannot read property 'writable' of undefined"):this.serialDisconnect().then(async()=>{await this.serialConnect()});break;case e.includes("'close' on 'serialport': a call to close() is already in progress."):break;case e.includes("failed to execute 'open' on 'serialport': a call to open() is already in progress."):break;case e.includes("the port is already closed."):break;case e.includes("the device has been lost"):this.dispatch("serial:lost",{}),K.instance.dispatch("change");break;case e.includes("navigator.serial is undefined"):this.dispatch("serial:unsupported",{});break;default:console.error(t);break}this.dispatch("serial:error",t)}async serialConnect(){try{this.dispatch("serial:connecting",{});const t=await o(this,B,Gi).call(this);if(t.length>0)await this.serialPortsSaved(t);else{const s=this.serialFilters;this.__internal__.serial.port=await navigator.serial.requestPort({filters:s})}const e=this.__internal__.serial.port;await e.open(this.serialConfigPort);const i=this;e.onconnect=s=>{i.dispatch("serial:connected",s.detail),K.instance.dispatch("change"),i.__internal__.serial.queue.length>0&&i.dispatch("internal:queue",{})},e.ondisconnect=async s=>{await i.disconnect(s.detail??null)},await dt(this.__internal__.serial.delay_first_connection),this.__internal__.timeout.until_response=setTimeout(async()=>{await i.timeout(i.__internal__.serial.bytes_connection,"connection:start")},this.__internal__.time.response_connection),this.__internal__.serial.last_action="connect",await o(this,B,yn).call(this,this.__internal__.serial.bytes_connection),this.dispatch("serial:sent",{action:"connect",bytes:this.__internal__.serial.bytes_connection}),this.typeDevice==="relay"&&o(this,B,Mt).call(this,["DD","DD"],null),await o(this,B,Zi).call(this)}catch(t){this.serialErrors(t)}}async serialForget(){return await o(this,B,Yi).call(this)}decToHex(t){return parseInt(t,10).toString(16)}hexToDec(t){return parseInt(t,16)}hexMaker(t="00",e=2){return t.toString().padStart(e,"0").toLowerCase()}add0x(t){let e=[];return t.forEach((i,s)=>{e[s]="0x"+i}),e}bytesToHex(t){return this.add0x(Array.from(t,e=>this.hexMaker(e)))}async appendToQueue(t,e){const i=this.bytesToHex(t);if(["connect","connection:start"].includes(e)){if(this.__internal__.serial.connected)return;await this.serialConnect();return}this.__internal__.serial.queue.push({bytes:i,action:e}),this.dispatch("internal:queue",{})}serialSetConnectionConstant(t=1){throw new Error("Method not implemented")}serialMessage(t){throw new Error("Method not implemented")}serialCorruptMessage(t,e){throw new Error("Method not implemented")}clearSerialQueue(){this.__internal__.serial.queue=[]}sumHex(t){let e=0;return t.forEach(i=>{e+=parseInt(i,16)}),e.toString(16)}internalClearSensing(){this.__internal__.interval.waiting_sense&&clearInterval(this.__internal__.interval.waiting_sense),this.__internal__.interval.waiting_sense=0,this.__internal__.dispense.status=null,this.__internal__.dispense.counter=0,this.__internal__.dispense.dispensing=!1}internalDispensingProcess(){let t=this.__internal__.dispense.limit_counter;return this.__internal__.dispense.custom_limit_counter&&(t=this.__internal__.dispense.custom_limit_counter),t+=Math.ceil(t*.6),this.__internal__.dispense.counter>=t?(this.internalClearSensing(),this.__internal__.dispense.status=!1,this.__internal__.dispense.dispensing=!1,!1):(this.__internal__.dispense.counter=parseFloat((.1+this.__internal__.dispense.counter).toFixed(1)),this.__internal__.dispense.counter%1===0&&this.dispatch("dispensing",{status:this.__internal__.dispense.status,counter:this.__internal__.dispense.counter,limit:t}),null)}async internalDispenseStatus(){if(this.__internal__.dispense.must_response&&(await dt(this.__internal__.time.response_engines+10),this.__internal__.dispense.status==="no-response"))return this.internalClearSensing(),this.__internal__.dispense.status=!1,this.dispatch("not-dispensed",{reason:"no-response"}),{status:!1,error:"no-response"};this.__internal__.dispense.status=null,this.__internal__.dispense.dispensing=!0,this.dispatch("internal:dispense:running",{});const t=this;return new Promise(e=>{this.__internal__.interval.waiting_sense=setInterval(()=>{switch(t.__internal__.dispense.status){case null:t.internalDispensingProcess()===!1&&(t.internalClearSensing(),t.dispatch("not-dispensed",{reason:"timeout"}),e({status:!1,error:"timeout"}));break;case!0:t.internalClearSensing(),t.__internal__.dispense.status=!0,t.dispatch("dispensed",{}),e({status:!0,error:null});break;case!1:t.internalClearSensing(),t.__internal__.dispense.status=!1,t.dispatch("not-dispensed",{reason:"no-stock"}),e({status:!1,error:null});break;case"elevator-locked":t.internalClearSensing(),t.__internal__.dispense.status=!1,t.dispatch("not-dispensed",{reason:"elevator-locked"}),e({status:!1,error:"elevator-locked"});break;case"no-response":t.internalClearSensing(),t.__internal__.dispense.status=!1,t.dispatch("not-dispensed",{reason:"no-response"}),e({status:!1,error:"no-response"});break}},this.__internal__.time.sense)})}async internalDispense(t){if(this.isDispensing)throw new Error("Another dispensing process is running");if(!Zt.enable&&!this.__internal__.serial.connected&&(await this.serialConnect(),!this.__internal__.serial.connected))throw new Error("Serial device not connected");return this.__internal__.serial.queue.length===0?(await this.appendToQueue(t,"dispense"),await this.internalDispenseStatus()):new Promise(e=>{const i=setInterval(async()=>{if(this.__internal__.serial.queue.length>0)return;clearInterval(i),await this.appendToQueue(t,"dispense");const s=await this.internalDispenseStatus();e(s)},100)})}__emulate(t){if(typeof t.code!="object"){console.error("Invalid data to make an emulation");return}this.__internal__.serial.connected||(this.__internal__.serial.connected=!0,this.dispatch("serial:connected"),K.instance.dispatch("change"),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 t.code)e.push(t.code[i].toString().padStart(2,"0").toLowerCase());this.serialMessage(e)}toString(){return JSON.stringify({__class:this.typeDevice,device_number:this.deviceNumber,uuid:this.uuid,connected:this.isConnected,connection:this.__internal__.serial.bytes_connection})}softReload(){o(this,B,sr).call(this),this.dispatch("serial:soft-reload",{})}async sendConnect(){await this.appendToQueue(this.__internal__.serial.bytes_connection,"connect")}async sendCustomCode({code:t=[]}={}){await this.appendToQueue(t,"custom")}stringToArrayBuffer(t,e=`
|
|
1
|
+
(function(I,x){typeof exports=="object"&&typeof module<"u"?x(exports):typeof define=="function"&&define.amd?define(["exports"],x):(I=typeof globalThis<"u"?globalThis:I||self,x(I.WebSerial={}))})(this,function(I){"use strict";var yc=Object.defineProperty;var Ki=I=>{throw TypeError(I)};var wc=(I,x,X)=>x in I?yc(I,x,{enumerable:!0,configurable:!0,writable:!0,value:X}):I[x]=X;var Z=(I,x,X)=>wc(I,typeof x!="symbol"?x+"":x,X),gn=(I,x,X)=>x.has(I)||Ki("Cannot "+X);var O=(I,x,X)=>(gn(I,x,"read from private field"),X?X.call(I):x.get(I)),$=(I,x,X)=>x.has(I)?Ki("Cannot add the same private member more than once"):x instanceof WeakSet?x.add(I):x.set(I,X),L=(I,x,X,Vt)=>(gn(I,x,"write to private field"),Vt?Vt.call(I,X):x.set(I,X),X),o=(I,x,X)=>(gn(I,x,"access private method"),X);var st,ht,d,Wi,zi,T,bn,U,F,Be,E,mn,se,B,Xi,yn,Mt,Gi,Ji,$i,Qi,Zi,Yi,tr,er,nr,ir,rr,sr,re,Ie,ar,nt,G,Pt,R,or,cr,lr,hr,wn,ur,Ft,Ut,Ne,Me,Fe,p,dr,pr,fr,vn,_r,gr,br,mr,yr,wr,vr,Pr,Er,Tr,ae,oe,Cr,ce,Sr,Lt,kr,J,xr,Ar,Pn,Dr,Rr,Ir,En,Tn,le,Cn,Or,mt,yt,Ue,Sn,he,kn,xn,Br,An,Dn,Nr,Mr,Qt,Rn,Fr,Ur,Lr,Le,Vr,qr,In,jr,Hr,Kr,Wr,zr,Xr,Gr,Jr,$r,On,Bn,Qr,Zr,Yr,g,ts,es,ns,ot,Ve,is,rs,ss,as,os,cs,ls,hs,us,ds,ps,fs,_s,gs,bs,ms,ys,ws,vs,Ps,Es,Ts,Cs,Ss,ks,xs,ft,Y,qe,tt,wt,As,Ds,Rs,Is,ue,Nn,Mn,je,He,Os,Gt,Nt,Jt,w,Bs,Ns,Ke,Ms,Fs,Us,Ls,Vs,qs,js,Hs,Fn,Ks,Ws,zs,Xs,Gs,Js,$s,Qs,Zs,Ys,ta,ea,na,ia,ct,We,ra,sa,aa,oa,Un,ze,ca,la,Ln,Vn,qn,$t,ha,ua;const x=[];for(let r=0;r<256;++r)x.push((r+256).toString(16).slice(1));function X(r,n=0){return(x[r[n+0]]+x[r[n+1]]+x[r[n+2]]+x[r[n+3]]+"-"+x[r[n+4]]+x[r[n+5]]+"-"+x[r[n+6]]+x[r[n+7]]+"-"+x[r[n+8]]+x[r[n+9]]+"-"+x[r[n+10]]+x[r[n+11]]+x[r[n+12]]+x[r[n+13]]+x[r[n+14]]+x[r[n+15]]).toLowerCase()}let Vt;const da=new Uint8Array(16);function pa(){if(!Vt){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");Vt=crypto.getRandomValues.bind(crypto)}return Vt(da)}const jn={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function fa(r,n,t){var i;if(jn.randomUUID&&!n&&!r)return jn.randomUUID();r=r||{};const e=r.random??((i=r.rng)==null?void 0:i.call(r))??pa();if(e.length<16)throw new Error("Random bytes length must be >= 16");return e[6]=e[6]&15|64,e[8]=e[8]&63|128,X(e)}class Hn extends EventTarget{constructor(){super(...arguments);Z(this,"__listeners__",{});Z(this,"__debug__",!1)}dispatch(t,e=null){const i=new Kn(t,{detail:e});this.dispatchEvent(i),this.__debug__&&this.dispatchEvent(new Kn("debug",{detail:{type:t,data:e}}))}dispatchAsync(t,e=null,i=100){const s=this;setTimeout(()=>{s.dispatch(t,e)},i)}on(t,e){typeof this.__listeners__[t]<"u"&&this.__listeners__[t]===!1&&(this.__listeners__[t]=!0),this.addEventListener(t,e)}off(t,e){this.removeEventListener(t,e)}serialRegisterAvailableListener(t){this.__listeners__[t]||(this.__listeners__[t]=!1)}get availableListeners(){return Object.keys(this.__listeners__).sort().map(e=>({type:e,listening:this.__listeners__[e]}))}}class Kn extends CustomEvent{constructor(n,t){super(n,t)}}function dt(r=100){return new Promise(n=>setTimeout(()=>n(),r))}function Wn(){return"serial"in navigator}function zn(){return"geolocation"in navigator}function _a(){return"crypto"in window}function Xe(r=1){return r*1e3}function Ct(r){return r==null||r===""}const u=class u{static status(n=null){var e,i;if(!o(e=u,d,T).call(e,n))return!1;let t=[];switch(O(u,st)){case"locker":t=["0","8"];break;case"boardroid":t=["2",(5+O(u,ht)).toString(16).toUpperCase()];break;case"jofemar":t=["6"];break;default:return!1}o(i=u,d,E).call(i,t)}static dispensed(n=null){var e,i;if(!o(e=u,d,T).call(e,n))return!1;let t=[];switch(O(u,st)){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,d,E).call(i,t)}static notDispensed(n=null){var e,i;if(!o(e=u,d,T).call(e,n))return!1;let t=[];switch(O(u,st)){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,d,E).call(i,t)}static gateInactive(n=null){var t;if(!o(t=u,d,T).call(t,n)||!o(this,d,bn).call(this))return!1;o(this,d,E).call(this,["0","7","5","5","5"])}static gateConfigured(n=null){var t;if(!o(t=u,d,T).call(t,n)||!o(this,d,bn).call(this))return!1;o(this,d,E).call(this,["0","6"])}static keyPressed(n=null){var s,a,c;if(!o(s=u,d,T).call(s,n)||!o(a=u,d,F).call(a))return!1;const t=["30","31","32","33","34","35","36","37","38","39","2A","23","41","42","43","44"],e=(128+O(u,ht)).toString(16),i=Math.floor(Math.random()*15);o(c=u,d,E).call(c,["2",e,"54",t[i]])}static doorOpened(n=null){var i,s;if(!o(i=u,d,T).call(i,n)||!o(this,d,Be).call(this))return!1;let t=[];const e=(128+O(u,ht)).toString(16);switch(O(u,st)){case"boardroid":t=["2","D8","dc"];break;case"jofemar":t=["2",e,"50","4F"];break}o(s=u,d,E).call(s,t)}static doorClosed(n=null){var i,s;if(!o(i=u,d,T).call(i,n)||!o(this,d,Be).call(this))return!1;let t=[];const e=(128+O(u,ht)).toString(16);switch(O(u,st)){case"boardroid":t=["2","D8","db"];break;case"jofemar":t=["2",e,"50","43"];break}o(s=u,d,E).call(s,t)}static channelDisconnected(n=null){var e,i,s;if(!o(e=u,d,T).call(e,n)||!o(i=u,d,F).call(i))return!1;const t=(128+O(u,ht)).toString(16);o(s=u,d,E).call(s,["2",t,"43","43","43","FD"])}static channelConnected(n=null){var e,i,s;if(!o(e=u,d,T).call(e,n)||!o(i=u,d,F).call(i))return!1;const t=(128+O(u,ht)).toString(16);o(s=u,d,E).call(s,["2",t,"43","43","43","FC"])}static channelEmpty(n=null){var e,i,s;if(!o(e=u,d,T).call(e,n)||!o(i=u,d,F).call(i))return!1;const t=(128+O(u,ht)).toString(16);o(s=u,d,E).call(s,["2",t,"43","43","43","FF"])}static workingTemperature(n=null){var e,i,s;if(!o(e=u,d,T).call(e,n)||!o(i=u,d,F).call(i))return!1;const t=(128+O(u,ht)).toString(16);o(s=u,d,E).call(s,["2",t,"43","54","16"])}static currentTemperature(n=null){var i,s,a;if(!o(i=u,d,T).call(i,n)||!o(s=u,d,Be).call(s))return!1;let t=[];const e=(128+O(u,ht)).toString(16);switch(O(u,st)){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,d,E).call(a,t)}static ready(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,F).call(e))return!1;o(i=u,d,E).call(i,["6","30"])}static busy(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,F).call(e))return!1;o(i=u,d,E).call(i,["6","31"])}static invalidTray(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,F).call(e))return!1;o(i=u,d,E).call(i,["6","32"])}static invalidChannel(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,F).call(e))return!1;o(i=u,d,E).call(i,["6","33"])}static emptyChannel(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,F).call(e))return!1;o(i=u,d,E).call(i,["6","34"])}static elevatorJam(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,F).call(e))return!1;o(i=u,d,E).call(i,["6","35"])}static elevatorMalfunction(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,F).call(e))return!1;o(i=u,d,E).call(i,["6","36"])}static phototransistorFailure(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,F).call(e))return!1;o(i=u,d,E).call(i,["6","37"])}static allChannelsEmpty(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,F).call(e))return!1;o(i=u,d,E).call(i,["6","38"])}static productDetectorFailure(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,F).call(e))return!1;o(i=u,d,E).call(i,["6","39"])}static displayDisconnected(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,F).call(e))return!1;o(i=u,d,E).call(i,["6","41"])}static productUnderElevator(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,F).call(e))return!1;o(i=u,d,E).call(i,["6","42"])}static elevatorSettingAlarm(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,F).call(e))return!1;o(i=u,d,E).call(i,["6","43"])}static buttonPanelFailure(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,F).call(e))return!1;o(i=u,d,E).call(i,["6","44"])}static errorWritingEeprom(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,F).call(e))return!1;o(i=u,d,E).call(i,["6","45"])}static errorControlTemperature(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,F).call(e))return!1;o(i=u,d,E).call(i,["6","46"])}static thermometerDisconnected(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,F).call(e))return!1;o(i=u,d,E).call(i,["6","47"])}static thermometerMisconfigured(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,F).call(e))return!1;o(i=u,d,E).call(i,["6","48"])}static thermometerFailure(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,F).call(e))return!1;o(i=u,d,E).call(i,["6","49"])}static errorExtractorConsumption(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,F).call(e))return!1;o(i=u,d,E).call(i,["6","4A"])}static channelSearchError(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,F).call(e))return!1;o(i=u,d,E).call(i,["6","4B"])}static productExitMouthSearchError(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,F).call(e))return!1;o(i=u,d,E).call(i,["6","4C"])}static elevatorInteriorLocked(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,F).call(e))return!1;o(i=u,d,E).call(i,["6","4D"])}static productDetectorVerifierError(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,F).call(e))return!1;o(i=u,d,E).call(i,["6","4E"])}static waitingForProductRecall(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,F).call(e))return!1;o(i=u,d,E).call(i,["6","4F"])}static productExpiredByTemperature(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,F).call(e))return!1;o(i=u,d,E).call(i,["6","50"])}static faultyAutomaticDoor(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,F).call(e))return!1;o(i=u,d,E).call(i,["6","51"])}static rejectLever(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,U).call(e))return!1;o(i=u,d,E).call(i,["2","A0","1"])}static resetCoinPurse(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,U).call(e))return!1;o(i=u,d,E).call(i,["2","A0","2"])}static coinInsertedBox(n=null,t=null){var s,a,c,l;if(!o(s=u,d,T).call(s,n)||!o(a=u,d,U).call(a))return!1;const e=["40","41","42","43","44","45"],i=o(c=u,d,mn).call(c,e,t);o(l=u,d,E).call(l,["2","A0",i])}static coinInsertedTube(n=null,t=null){var s,a,c,l;if(!o(s=u,d,T).call(s,n)||!o(a=u,d,U).call(a))return!1;const e=["50","51","52","53","54","55"],i=o(c=u,d,mn).call(c,e,t);o(l=u,d,E).call(l,["2","A0",i])}static banknoteInsertedStacker(n=null,t=null){var s,a,c,l;if(!o(s=u,d,T).call(s,n)||!o(a=u,d,U).call(a))return!1;const e=["80","81","82","83","84"],i=o(c=u,d,se).call(c,e,t);o(l=u,d,E).call(l,["2","B0",i])}static banknoteInsertedEscrow(n=null,t=null){var s,a,c,l;if(!o(s=u,d,T).call(s,n)||!o(a=u,d,U).call(a))return!1;const e=["90","91","92","93","94"],i=o(c=u,d,se).call(c,e,t);o(l=u,d,E).call(l,["2","B0",i])}static banknoteEjected(n=null,t=null){var s,a,c,l;if(!o(s=u,d,T).call(s,n)||!o(a=u,d,U).call(a))return!1;const e=["A0","A1","A2","A3","A4"],i=o(c=u,d,se).call(c,e,t);o(l=u,d,E).call(l,["2","B0",i])}static banknoteInsertedRecycler(n=null,t=null){var s,a,c,l;if(!o(s=u,d,T).call(s,n)||!o(a=u,d,U).call(a))return!1;const e=["B0","B1","B2","B3","B4"],i=o(c=u,d,se).call(c,e,t);o(l=u,d,E).call(l,["2","B0",i])}static banknoteTaken(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,U).call(e))return!1;o(i=u,d,E).call(i,["2","B0","2a"])}static coinPurseEnabled(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,U).call(e))return!1;o(i=u,d,E).call(i,["2","D0","1"])}static coinPurseDisabled(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,U).call(e))return!1;o(i=u,d,E).call(i,["2","D0","0"])}static billPurseDisabled(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,U).call(e))return!1;o(i=u,d,E).call(i,["2","D1","0","0"])}static billPurseEnabled(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,U).call(e))return!1;o(i=u,d,E).call(i,["2","D1","1","1"])}static readTubes(n=null){var h,f,_;if(!o(h=u,d,T).call(h,n)||!o(f=u,d,U).call(f))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(_=u,d,E).call(_,["2","D2",e,i,s,a,c,l])}static readBillPurse(n=null,t=null){var i,s,a,c;if(!o(i=u,d,T).call(i,n)||!o(s=u,d,U).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",f="0",_="0",m="0",P="0";if(t!==null&&!isNaN(parseInt(t)))switch(t.toString()){case"20":h=l;break;case"50":f=l;break;case"100":_=l;break;case"200":m=l;break;case"500":P=l;break}else switch(n._recycler.bill){case 0:h=l;break;case 1:f=l;break;case 2:_=l;break;case 3:m=l;break;case 4:P=l;break}o(a=u,d,E).call(a,["2","D3",h,f,_,m,P,"0"])}else{const[l,h,f,_,m,P]=[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,d,E).call(c,["2","D3",l,h,f,_,m,P])}}static banknoteAccepted(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,U).call(e))return!1;o(i=u,d,E).call(i,["2","D4","1"])}static banknoteRejected(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,U).call(e))return!1;o(i=u,d,E).call(i,["2","D4","0"])}static banknotesDispensed(n=null){var e,i,s,a;if(!o(e=u,d,T).call(e,n)||!o(i=u,d,U).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",f="0",_="0",m="0";switch(n._recycler.bill){case 0:l=c;break;case 1:h=c;break;case 2:f=c;break;case 3:_=c;break;case 4:m=c;break}o(s=u,d,E).call(s,["2","D5",l,h,f,_,m,"0"])}else{const[c,l,h,f,_,m]=[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,d,E).call(a,["2","D5",c,l,h,f,_,m])}}static coinsDispensed(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,U).call(e))return!1;o(i=u,d,E).call(i,["2","D6"])}static relayOn(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,U).call(e))return!1;o(i=u,d,E).call(i,["2","DA","1"])}static relayOff(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,U).call(e))return!1;o(i=u,d,E).call(i,["2","DA","0"])}static nayaxEnabled(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,U).call(e))return!1;o(i=u,d,E).call(i,["2","DD","1"])}static nayaxDisabled(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,U).call(e))return!1;o(i=u,d,E).call(i,["2","DD","0"])}static nayaxPreCreditAuthorized(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,U).call(e))return!1;o(i=u,d,E).call(i,["2","DD","3"])}static nayaxCancelRequest(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,U).call(e))return!1;o(i=u,d,E).call(i,["2","DD","4"])}static nayaxSellApproved(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,U).call(e))return!1;o(i=u,d,E).call(i,["2","DD","5"])}static nayaxSellDenied(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,U).call(e))return!1;o(i=u,d,E).call(i,["2","DD","6"])}static nayaxEndSession(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,U).call(e))return!1;o(i=u,d,E).call(i,["2","DD","7"])}static nayaxCancelled(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,U).call(e))return!1;o(i=u,d,E).call(i,["2","DD","8"])}static nayaxDispensed(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,U).call(e))return!1;o(i=u,d,E).call(i,["2","DD","A","0"])}static nayaxNotDispensed(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,U).call(e))return!1;o(i=u,d,E).call(i,["2","DD","A","1"])}static fullTray(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,F).call(e))return!1;o(i=u,d,E).call(i,["6","4F"])}static setConnection(n=null){var t;if(!o(t=u,d,T).call(t,n))return!1;n.__internal__.serial.connected=!0}};st=new WeakMap,ht=new WeakMap,d=new WeakSet,Wi=function(){if(u.enable===!1)throw new Error("Emulator is disabled");return u.enable},zi=function(n){if(typeof n!="object"||!(n instanceof kt))throw new Error(`Type ${n.typeDevice} is not supported`);return u.instance=n,L(u,st,n.typeDevice),L(u,ht,n.deviceNumber),!0},T=function(n=null){var t,e;return!o(t=u,d,Wi).call(t)||n===null&&u.instance===null?!1:(u.instance===null&&o(e=u,d,zi).call(e,n),!0)},bn=function(){if(O(u,st)!=="locker")throw new Error("This function is only available for Locker devices");return!0},U=function(){if(O(u,st)!=="boardroid")throw new Error("This function is only available for Boardroid devices");return!0},F=function(){if(O(u,st)!=="jofemar")throw new Error("This function is only available for Jofemar devices");return!0},Be=function(){if(O(u,st)==="locker")throw new Error("This function is not available for Locker devices");return!0},E=function(n){u.instance.__emulate({code:n})},mn=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},se=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},$(u,d),Z(u,"enable",!1),Z(u,"instance",null),$(u,st,null),$(u,ht,1);let Zt=u;const M=class M extends Hn{static typeError(n){const t=new Error;throw t.message=`Type ${n} is not supported`,t.name="DeviceTypeError",t}static addCustom(n,t){typeof M.devices[n]>"u"&&(M.devices[n]=[]),M.add(t)}static add(n){const t=n.typeDevice,e=n.uuid;if(typeof M.devices[t]>"u")return M.typeError(t);if(this.instance.dispatch("change",M.devices),!M.devices[t][e])return M.devices[t][e]=n,this.instance.dispatch("change",M.devices),M.devices[t].indexOf(n)}static get(n,t){return typeof M.devices[n]>"u"?M.typeError(n):M.devices[n][t]}static getJofemarByUuid(n){return M.get("jofemar",n)}static getLockerByUuid(n){return M.get("locker",n)}static getRelayByUuid(n){return M.get("relay",n)}static getBoardroidByUuid(n){return M.get("boardroid",n)}static getArduinoByUuid(n){return M.get("arduino",n)}static getPinPadByUuid(n){return M.get("pinpad",n)}static getAll(n=null){return n===null?M.devices:typeof M.devices[n]>"u"?M.typeError(n):M.devices[n]}static getList(){return Object.values(M.devices).map(t=>Object.values(t)).flat()}static getJofemar(n=1){return Object.values(M.devices.jofemar).find(e=>e.deviceNumber===n)??null}static getBoardroid(n=1){return Object.values(M.devices.boardroid).find(e=>e.deviceNumber===n)??null}static getLocker(n=1){return Object.values(M.devices.locker).find(e=>e.deviceNumber===n)??null}static getRelay(n=1){return Object.values(M.devices.relay).find(e=>e.deviceNumber===n)??null}static getArduino(n=1){return Object.values(M.devices.arduino).find(e=>e.deviceNumber===n)??null}static getPinPad(n=1){return Object.values(M.devices.pinpad).find(e=>e.deviceNumber===n)??null}static getCustom(n,t=1){return typeof M.devices[n]>"u"?M.typeError(n):Object.values(M.devices[n]).find(i=>i.deviceNumber===t)??null}};Z(M,"instance",null),Z(M,"devices",{relay:[],locker:[],jofemar:[],boardroid:[],arduino:[],pinpad:[]});let K=M;K.instance||(K.instance=new K);class kt extends Hn{constructor({filters:t=null,config_port:e=null,no_device:i=1,device_listen_on_port:s=1}={}){super();$(this,B);Z(this,"__internal__",{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([])},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:{baudRate:9600,dataBits:8,stopBits:1,parity:"none",bufferSize:32768,flowControl:"none"},queue:[]},device:{type:"unknown",id:fa(),listen_on_port:null,door_open:!1},time:{response_connection:500,response_general:2e3,response_engines:2e3,sense:100},timeout:{until_response:0},interval:{reconnection:0,waiting_sense:0},dispense:{must_response:!1,dispensing:!1,status:null,counter:0,limit_counter:20,custom_limit_counter:null,backup_dispense:{}}});t&&(this.serialFilters=t),e&&(this.serialConfigPort=e),i&&o(this,B,rr).call(this,i),s&&(typeof s=="number"||typeof s=="string")&&(this.listenOnPort=s),o(this,B,tr).call(this),o(this,B,er).call(this)}set listenOnPort(t){if(t=parseInt(t),isNaN(t)||t<1||t>255)throw new Error("Invalid port number");this.__internal__.device.listen_on_port=t,this.__internal__.serial.bytes_connection=this.serialSetConnectionConstant(t)}get isDoorOpen(){return this.__internal__.device.door_open}get lastAction(){return this.__internal__.serial.last_action}get listenOnPort(){return this.__internal__.device.listen_on_port??1}set serialFilters(t){this.__internal__.serial.filters=t}get serialFilters(){return this.__internal__.serial.filters}set serialConfigPort(t){this.__internal__.serial.config_port=t}get serialConfigPort(){return this.__internal__.serial.config_port}get isConnected(){return this.__internal__.serial.connected}get isDisconnected(){return!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}get isDispensing(){return this.__internal__.interval.waiting_sense||this.__internal__.dispense.dispensing}async timeout(t,e){this.__internal__.last_error.message="Operation response timed out.",this.__internal__.last_error.action=e,this.__internal__.last_error.code=t,this.__internal__.timeout.until_response&&(clearTimeout(this.__internal__.timeout.until_response),this.__internal__.timeout.until_response=0),e==="connect"?(this.__internal__.serial.connected=!1,this.dispatch("serial:reconnect",{})):e==="connection:start"?(await this.serialDisconnect(),this.__internal__.serial.connected=!1,this.__internal__.aux_port_connector+=1,await this.serialConnect()):e==="dispense"&&(this.__internal__.dispense.status="no-response"),this.dispatch("serial:timeout",{...this.__internal__.last_error,bytes:t,action:e})}async disconnect(t=null){await this.serialDisconnect(),this.__internal__.serial.connected=!1,this.__internal__.aux_port_connector=0,this.dispatch("serial:disconnected",t),K.instance.dispatch("change")}async connect(){return new Promise((t,e)=>{Wn()||e("Web Serial not supported"),setTimeout(async()=>{await dt(499),await this.serialConnect(),this.isConnected?t(`${this.typeDevice} device ${this.deviceNumber} connected`):e(`${this.typeDevice} device ${this.deviceNumber} not connected`)},1)})}async serialDisconnect(){try{const t=this.__internal__.serial.reader,e=this.__internal__.serial.output_stream;t&&(await t.cancel().catch(s=>this.serialErrors(s)),await this.__internal__.serial.input_done),e&&(await e.getWriter().close(),await this.__internal__.serial.output_done),this.__internal__.serial.connected&&this.__internal__.serial&&await this.__internal__.serial.port.close()}catch(t){this.serialErrors(t)}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}}async serialPortsSaved(t){const e=this.serialFilters;if(this.__internal__.aux_port_connector<t.length){const i=this.__internal__.aux_port_connector;this.__internal__.serial.port=t[i]}else this.__internal__.aux_port_connector=0,this.__internal__.serial.port=await navigator.serial.requestPort({filters:e});if(!this.__internal__.serial.port)throw new Error("Select another port please")}serialErrors(t){const e=t.toString().toLowerCase();switch(!0){case e.includes("must be handling a user gesture to show a permission request"):case e.includes("the port is closed."):case e.includes("select another port please"):case e.includes("no port selected by the user"):case e.includes("this readable stream reader has been released and cannot be used to cancel its previous owner stream"):this.dispatch("serial:need-permission",{}),K.instance.dispatch("change");break;case e.includes("the port is already open."):case e.includes("failed to open serial port"):this.serialDisconnect().then(async()=>{this.__internal__.aux_port_connector+=1,await this.serialConnect()});break;case e.includes("cannot read properties of undefined (reading 'writable')"):case e.includes("cannot read properties of null (reading 'writable')"):case e.includes("cannot read property 'writable' of null"):case e.includes("cannot read property 'writable' of undefined"):this.serialDisconnect().then(async()=>{await this.serialConnect()});break;case e.includes("'close' on 'serialport': a call to close() is already in progress."):break;case e.includes("failed to execute 'open' on 'serialport': a call to open() is already in progress."):break;case e.includes("the port is already closed."):break;case e.includes("the device has been lost"):this.dispatch("serial:lost",{}),K.instance.dispatch("change");break;case e.includes("navigator.serial is undefined"):this.dispatch("serial:unsupported",{});break;default:console.error(t);break}this.dispatch("serial:error",t)}async serialConnect(){try{this.dispatch("serial:connecting",{});const t=await o(this,B,Gi).call(this);if(t.length>0)await this.serialPortsSaved(t);else{const s=this.serialFilters;this.__internal__.serial.port=await navigator.serial.requestPort({filters:s})}const e=this.__internal__.serial.port;await e.open(this.serialConfigPort);const i=this;e.onconnect=s=>{i.dispatch("serial:connected",s.detail),K.instance.dispatch("change"),i.__internal__.serial.queue.length>0&&i.dispatch("internal:queue",{})},e.ondisconnect=async s=>{await i.disconnect(s.detail??null)},await dt(this.__internal__.serial.delay_first_connection),this.__internal__.timeout.until_response=setTimeout(async()=>{await i.timeout(i.__internal__.serial.bytes_connection,"connection:start")},this.__internal__.time.response_connection),this.__internal__.serial.last_action="connect",await o(this,B,yn).call(this,this.__internal__.serial.bytes_connection),this.dispatch("serial:sent",{action:"connect",bytes:this.__internal__.serial.bytes_connection}),this.typeDevice==="relay"&&o(this,B,Mt).call(this,["DD","DD"],null),await o(this,B,Zi).call(this)}catch(t){this.serialErrors(t)}}async serialForget(){return await o(this,B,Yi).call(this)}decToHex(t){return parseInt(t,10).toString(16)}hexToDec(t){return parseInt(t,16)}hexMaker(t="00",e=2){return t.toString().padStart(e,"0").toLowerCase()}add0x(t){let e=[];return t.forEach((i,s)=>{e[s]="0x"+i}),e}bytesToHex(t){return this.add0x(Array.from(t,e=>this.hexMaker(e)))}async appendToQueue(t,e){const i=this.bytesToHex(t);if(["connect","connection:start"].includes(e)){if(this.__internal__.serial.connected)return;await this.serialConnect();return}this.__internal__.serial.queue.push({bytes:i,action:e}),this.dispatch("internal:queue",{})}serialSetConnectionConstant(t=1){throw new Error("Method not implemented")}serialMessage(t){throw new Error("Method not implemented")}serialCorruptMessage(t,e){throw new Error("Method not implemented")}clearSerialQueue(){this.__internal__.serial.queue=[]}sumHex(t){let e=0;return t.forEach(i=>{e+=parseInt(i,16)}),e.toString(16)}internalClearSensing(){this.__internal__.interval.waiting_sense&&clearInterval(this.__internal__.interval.waiting_sense),this.__internal__.interval.waiting_sense=0,this.__internal__.dispense.status=null,this.__internal__.dispense.counter=0,this.__internal__.dispense.dispensing=!1}internalDispensingProcess(){let t=this.__internal__.dispense.limit_counter;return this.__internal__.dispense.custom_limit_counter&&(t=this.__internal__.dispense.custom_limit_counter),t+=Math.ceil(t*.6),this.__internal__.dispense.counter>=t?(this.internalClearSensing(),this.__internal__.dispense.status=!1,this.__internal__.dispense.dispensing=!1,!1):(this.__internal__.dispense.counter=parseFloat((.1+this.__internal__.dispense.counter).toFixed(1)),this.__internal__.dispense.counter%1===0&&this.dispatch("dispensing",{status:this.__internal__.dispense.status,counter:this.__internal__.dispense.counter,limit:t}),null)}async internalDispenseStatus(){if(this.__internal__.dispense.must_response&&(await dt(this.__internal__.time.response_engines+10),this.__internal__.dispense.status==="no-response"))return this.internalClearSensing(),this.__internal__.dispense.status=!1,this.dispatch("not-dispensed",{reason:"no-response"}),{status:!1,error:"no-response"};this.__internal__.dispense.status=null,this.__internal__.dispense.dispensing=!0,this.dispatch("internal:dispense:running",{});const t=this;return new Promise(e=>{this.__internal__.interval.waiting_sense=setInterval(()=>{switch(t.__internal__.dispense.status){case null:t.internalDispensingProcess()===!1&&(t.internalClearSensing(),t.dispatch("not-dispensed",{reason:"timeout"}),e({status:!1,error:"timeout"}));break;case!0:t.internalClearSensing(),t.__internal__.dispense.status=!0,t.dispatch("dispensed",{}),e({status:!0,error:null});break;case!1:t.internalClearSensing(),t.__internal__.dispense.status=!1,t.dispatch("not-dispensed",{reason:"no-stock"}),e({status:!1,error:null});break;case"elevator-locked":t.internalClearSensing(),t.__internal__.dispense.status=!1,t.dispatch("not-dispensed",{reason:"elevator-locked"}),e({status:!1,error:"elevator-locked"});break;case"no-response":t.internalClearSensing(),t.__internal__.dispense.status=!1,t.dispatch("not-dispensed",{reason:"no-response"}),e({status:!1,error:"no-response"});break}},this.__internal__.time.sense)})}async internalDispense(t){if(this.isDispensing)throw new Error("Another dispensing process is running");if(!Zt.enable&&!this.__internal__.serial.connected&&(await this.serialConnect(),!this.__internal__.serial.connected))throw new Error("Serial device not connected");return this.__internal__.serial.queue.length===0?(await this.appendToQueue(t,"dispense"),await this.internalDispenseStatus()):new Promise(e=>{const i=setInterval(async()=>{if(this.__internal__.serial.queue.length>0)return;clearInterval(i),await this.appendToQueue(t,"dispense");const s=await this.internalDispenseStatus();e(s)},100)})}__emulate(t){if(typeof t.code!="object"){console.error("Invalid data to make an emulation");return}this.__internal__.serial.connected||(this.__internal__.serial.connected=!0,this.dispatch("serial:connected"),K.instance.dispatch("change"),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 t.code)e.push(t.code[i].toString().padStart(2,"0").toLowerCase());this.serialMessage(e)}toString(){return JSON.stringify({__class:this.typeDevice,device_number:this.deviceNumber,uuid:this.uuid,connected:this.isConnected,connection:this.__internal__.serial.bytes_connection})}softReload(){o(this,B,sr).call(this),this.dispatch("serial:soft-reload",{})}async sendConnect(){await this.appendToQueue(this.__internal__.serial.bytes_connection,"connect")}async sendCustomCode({code:t=[]}={}){await this.appendToQueue(t,"custom")}stringToArrayBuffer(t,e=`
|
|
2
2
|
`){return this.parseStringToTextEncoder(t,e).buffer}parseStringToTextEncoder(t="",e=`
|
|
3
3
|
`){const i=new TextEncoder;return t+=e,i.encode(t)}parseStringToBytes(t="",e=`
|
|
4
4
|
`){const i=this.parseStringToTextEncoder(t,e);return Array.from(i).map(s=>s.toString(16))}parseUint8ToHex(t){return Array.from(t).map(e=>e.toString(16))}parseHexToUint8(t){return new Uint8Array(t.map(e=>parseInt(e,16)))}parseUint8ArrayToString(t){t=new Uint8Array(t),t=this.parseUint8ToHex(t);const e=t.map(i=>parseInt(i,16));return String.fromCharCode(...e).replace(/[\n\r]+/g,"")}hexToAscii(t){let e=t.toString(),i="";for(let s=0;s<e.length;s+=2)i+=String.fromCharCode(parseInt(e.substring(s,2),16));return i}asciiToHex(t){const e=[];for(let i=0,s=t.length;i<s;i++){const a=Number(t.charCodeAt(i)).toString(16);e.push(a)}return e.join("")}}B=new WeakSet,Xi=function(t){return!!(t.readable&&t.writable)},yn=async function(t){const e=this.__internal__.serial.port;if(!e){if(Zt.enable)return;throw new Error("The port is closed.")}const i=new Uint8Array(t),s=e.writable.getWriter();await s.write(i),s.releaseLock()},Mt=function(t=[],e=null){if(t&&t.length>0){this.__internal__.serial.connected||(this.dispatch("serial:connected"),K.instance.dispatch("change")),this.__internal__.serial.connected=!0,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 i=[];for(const s in t)i.push(t[s].toString().padStart(2,"0").toLowerCase());this.serialMessage(i)}else this.serialCorruptMessage(t,e);this.__internal__.serial.queue.length!==0&&this.dispatch("internal:queue",{})},Gi=async function(){const t=this.serialFilters,e=await navigator.serial.getPorts({filters:t});return t.length===0?e:e.filter(s=>{const a=s.getInfo();return t.some(c=>a.usbProductId===c.usbProductId&&a.usbVendorId===c.usbVendorId)}).filter(s=>!o(this,B,Xi).call(this,s))},Ji=function(t){if(t){const e=this.__internal__.serial.response.buffer;let i=new Uint8Array(e.length+t.byteLength);i.set(e,0),i.set(new Uint8Array(t),e.length),this.__internal__.serial.response.buffer=i}},$i=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(()=>{let t=[];for(const e in this.__internal__.serial.response.buffer)t.push(this.__internal__.serial.response.buffer[e].toString(16));this.__internal__.serial.response.buffer&&o(this,B,Mt).call(this,t),this.__internal__.serial.response.buffer=new Uint8Array(0)},400)},Qi=async function(){if(this.__internal__.serial.response.length===this.__internal__.serial.response.buffer.length){const t=[];for(const e in this.__internal__.serial.response.buffer)t.push(this.__internal__.serial.response.buffer[e].toString(16));await o(this,B,Mt).call(this,t),this.__internal__.serial.response.buffer=new Uint8Array(0)}else if(this.__internal__.serial.response.length<this.__internal__.serial.response.buffer.length){let t=[];for(let i=0;i<this.__internal__.serial.response.length;i++)t[i]=this.__internal__.serial.response.buffer[i];if(t.length===this.__internal__.serial.response.length){const i=[];for(const s in t)i.push(t[s].toString(16));await o(this,B,Mt).call(this,i),this.__internal__.serial.response.buffer=new Uint8Array(0);return}t=[];const e=this.__internal__.serial.response.length*2;if(this.__internal__.serial.response.buffer.length===e){for(let i=14;i<e;i++)t[i-this.__internal__.serial.response.length]=this.__internal__.serial.response.buffer[i];if(t.length===this.__internal__.serial.response.length){const i=[];for(const s in t)i.push(t[s].toString(16));await o(this,B,Mt).call(this,i),this.__internal__.serial.response.buffer=new Uint8Array(0)}}}},Zi=async function(){const t=this.__internal__.serial.port;for(;t.readable&&this.__internal__.serial.keep_reading;){const e=t.readable.getReader();this.__internal__.serial.reader=e;try{let i=!0;for(;i;){const{value:s,done:a}=await e.read();if(a){e.releaseLock(),this.__internal__.serial.keep_reading=!1,i=!1;break}o(this,B,Ji).call(this,s),this.__internal__.serial.response.length===null?await o(this,B,$i).call(this):await o(this,B,Qi).call(this)}}catch(i){this.serialErrors(i)}finally{e.releaseLock()}}this.__internal__.serial.keep_reading=!0,await this.__internal__.serial.port.close()},Yi=async function(){return typeof window>"u"?!1:"serial"in navigator&&"forget"in window.SerialPort.prototype?(await this.__internal__.serial.port.forget(),!0):!1},tr=function(){["serial:connected","serial:connecting","serial:reconnect","serial:timeout","serial:disconnected","serial:sent","serial:soft-reload","serial:message","dispensed","not-dispensed","dispensing","unknown","serial:need-permission","serial:lost","serial:unsupported","serial:error","debug"].forEach(e=>{this.serialRegisterAvailableListener(e)})},er=function(){const t=this;this.on("internal:queue",async()=>{var e;await o(e=t,B,ir).call(e)}),o(this,B,nr).call(this)},nr=function(){const t=this;navigator.serial.addEventListener("connect",async()=>{t.isDisconnected&&await t.serialConnect().catch(()=>{})})},ir=async function(){if(!this.__internal__.serial.connected){await this.serialConnect();return}if(this.__internal__.timeout.until_response||this.__internal__.serial.queue.length===0)return;const t=this.__internal__.serial.queue[0];let e=this.__internal__.time.response_general;t.action==="connect"?e=this.__internal__.time.response_connection:t.action==="dispense"&&(e=this.__internal__.time.response_engines),this.__internal__.timeout.until_response=setTimeout(async()=>{await this.timeout(t.bytes,t.action)},e),this.__internal__.serial.last_action=t.action??"unknown",await o(this,B,yn).call(this,t.bytes),this.dispatch("serial:sent",{action:t.action,bytes:t.bytes}),this.typeDevice==="relay"&&o(this,B,Mt).call(this,["DD","DD"],null);const i=[...this.__internal__.serial.queue];this.__internal__.serial.queue=i.splice(1)},rr=function(t=1){this.__internal__.device_number=t,this.__internal__.serial.bytes_connection=this.serialSetConnectionConstant(t)},sr=function(){this.__internal__.last_error={message:null,action:null,code:null,no_code:0}};class ga extends kt{constructor({filters:t=null,config_port:e=null,no_device:i=1}={}){super({filters:t,config_port:e,no_device:i});$(this,Ie);$(this,re,{activate:["A0","01","01","A2"],deactivate:["A0","01","00","A1"]});if(this.__internal__.device.type="relay",K.getCustom(this.typeDevice,i))throw new Error(`Device ${this.typeDevice} ${i} already exists`);o(this,Ie,ar).call(this)}serialMessage(t){const e={code:t,name:null,description:null,request:null,no_code:0};switch(t[1].toString()){case"dd":e.name="Connection with the serial device completed.",e.description="Your connection with the serial device was successfully completed.",e.request="connect",e.no_code=100;break;case"de":break;default:e.name="Unrecognized response",e.description="The response of application was received, but dont identify with any of current parameters",e.request="undefined",e.no_code=400;break}this.dispatch("serial:message",e)}serialRelaySumHex(t){let e=0;return t.forEach((i,s)=>{s!==3&&(e+=parseInt(i,16))}),e.toString(16).toUpperCase()}serialSetConnectionConstant(t=1){const e=["A0","01","00","A1"];return e[1]=this.hexMaker(this.decToHex(t.toString())),e[3]=this.serialRelaySumHex(e),this.add0x(e)}async turnOn(){const t=O(this,re).activate;t[3]=this.serialRelaySumHex(t),await this.appendToQueue(t,"relay:turn-on")}async turnOff(){const t=O(this,re).deactivate;t[3]=this.serialRelaySumHex(t),await this.appendToQueue(t,"relay:turn-off")}async toggle({inverse:t=!1,ms:e=300}={}){const i=this;t?(await i.turnOff(),await dt(e),await i.turnOn()):(await i.turnOn(),await dt(e),await i.turnOff())}}re=new WeakMap,Ie=new WeakSet,ar=function(){K.add(this)};class ba extends kt{constructor({filters:t=null,config_port:e=null,no_device:i=1,device_listen_on_port:s=3}={}){super({filters:t,config_port:e,no_device:i,device_listen_on_port:s});$(this,R);$(this,nt,!1);$(this,G,0);$(this,Pt,0);if(this.__internal__.device.type="locker",K.getCustom(this.typeDevice,i))throw new Error(`Device ${this.typeDevice} ${i} already exists`);this.__internal__.device.milliseconds=666,this.__internal__.dispense.limit_counter=1,o(this,R,cr).call(this),o(this,R,or).call(this)}serialMessage(t){const e={code:t,name:null,description:null,request:null,no_code:0};switch(t[1]){case"08":e.name="Connection with the serial device completed.",e.description="Your connection with the serial device was successfully completed.",e.request="connect",e.no_code=100;break;case"07":switch(t[4]){case"00":e.name="Cell closed.",e.description="The selected cell is closed.",e.request="dispense",e.no_code=1102,this.__internal__.dispense.status=!1,this.dispatch("dispensed",{}),O(this,nt)&&O(this,G)>=89?(e.finished_test=!0,L(this,nt,!1),L(this,G,0)):O(this,nt)&&(e.finished_test=!1);break;case"01":case"04":e.name="Cell open.",e.description="The selected cell was open successfully.",e.request="dispense",e.no_code=102,this.__internal__.dispense.status=!0,this.dispatch("dispensed",{}),O(this,nt)&&O(this,G)>=89?(e.finished_test=!0,L(this,nt,!1),L(this,G,0)):O(this,nt)&&(e.finished_test=!1);break;case"05":e.name="Cell inactive.",e.description="The selected cell is inactive or doesn't exist.",e.request="dispense",e.no_code=101,this.__internal__.dispense.status=!1,this.dispatch("not-dispensed",{}),O(this,nt)&&O(this,G)>=89?(e.finished_test=!0,L(this,nt,!1),L(this,G,0)):O(this,nt)&&(e.finished_test=!1);break}break;case"06":e.name="Configuration applied.",e.description="The configuration was successfully applied.",e.request="configure cell",e.no_code=103;break;default:e.request="undefined",e.name="Response unrecognized",e.description="The response of application was received, but dont identify with any of current parameters",e.no_code=400;break}this.dispatch("serial:message",e)}serialSetConnectionConstant(t=3){return this.add0x(this.serialLockerGetConnectionCmd(t))}serialLockerCmdMaker(t){const e=this.__internal__.device.milliseconds;let i=null;try{i=new Uint8Array(t.length+8),i.set(t,2),i[0]=2,i[1]=t.length+4,i[i.length-2]=3;let s=0;for(let l=1;l<t.length;l++)s+=t[l],s*=parseInt(Math.pow(2,l-1).toString());i[t.length+2]=s%256,i[t.length+3]=e*3%256,i[t.length+4]=e*8%256;let a=0;for(let l=3;l<t.length+5;l++)a+=i[l];i[t.length+5]=a%256;let c=0;for(let l=0;l<i.length-1;l++)c^=i[l];i[i.length-1]=c}catch(s){this.serialErrors(`Error generating command: ${s.message}`),i=null}return i}serialLockerHexCmd(t){const e=this.serialLockerCmdMaker(t),i=[];for(let s=0;s<e.length;s++)i.push(this.decToHex(e[s]));return i}serialLockerGetConnectionCmd(t=3){if(t<1||t>255)throw new Error("Invalid port number");return this.serialLockerHexCmd(new Uint8Array([0,t]))}parseCellToColumnRow(t){const e=Math.floor((t-1)/10)+1;let i=t%8;return i===0&&(i=8),[e,i]}async dispense({cell:t=1}={}){t=o(this,R,Ft).call(this,t);const e=o(this,R,ur).call(this,t);return await this.internalDispense(e)}async status({cell:t=1}={}){t=o(this,R,Ft).call(this,t);const e=o(this,R,lr).call(this,t);return await this.appendToQueue(e,"status")}async lightScan({since:t=0,until:e=10}={}){if(t<0||t>10)throw new Error("Invalid since number");if(e<0||e>10)throw new Error("Invalid until number");const i=o(this,R,hr).call(this,t,e);return await this.appendToQueue(i,"light-scan")}async enable({cell:t=1}={}){t=o(this,R,Ft).call(this,t);const[e,i]=this.parseCellToColumnRow(t),s=o(this,R,wn).call(this,{enable:!0,column:e,row:i});await this.appendToQueue(s,"activate")}async disable({cell:t=1}={}){t=o(this,R,Ft).call(this,t);const[e,i]=this.parseCellToColumnRow(t),s=o(this,R,wn).call(this,{enable:!1,column:e,row:i});await this.appendToQueue(s,"disable")}async openAll(){if(this.isDispensing)throw new Error("Another dispensing process is running");o(this,R,Ut).call(this),L(this,nt,!0),o(this,R,Ne).call(this);const t=[];for(let e=1;e<=90;e++){const i=await this.dispense(e);t.push(i),L(this,G,e),o(this,R,Ne).call(this)}L(this,G,90),o(this,R,Ne).call(this,t),o(this,R,Ut).call(this)}async enableAll(){o(this,R,Ut).call(this),L(this,nt,!0),o(this,R,Me).call(this);for(let t=1;t<=90;t++)await this.enable(t),L(this,G,t),o(this,R,Me).call(this);L(this,G,90),o(this,R,Me).call(this),o(this,R,Ut).call(this)}async disableAll(){o(this,R,Ut).call(this),L(this,nt,!0),o(this,R,Fe).call(this);for(let t=1;t<=90;t++)await this.enable(t),L(this,G,t),o(this,R,Fe).call(this);L(this,G,90),o(this,R,Fe).call(this),o(this,R,Ut).call(this)}}nt=new WeakMap,G=new WeakMap,Pt=new WeakMap,R=new WeakSet,or=function(){const t=["percentage:disable","percentage:enable","percentage:open"];for(const e of t)this.serialRegisterAvailableListener(e)},cr=function(){K.add(this)},lr=function(t=1){return t=o(this,R,Ft).call(this,t),this.serialLockerHexCmd(new Uint8Array([16,this.__internal__.device.listen_on_port,t]))},hr=function(t=0,e=10){return this.serialLockerHexCmd(new Uint8Array([32,this.__internal__.device.listen_on_port,t,e]))},wn=function({enable:t=!0,column:e=0,row:i=10}={}){if(e<0||e>8)throw new Error("Invalid column number");if(i<0||i>10)throw new Error("Invalid row number");let s=1;return t||(s=0),this.serialLockerHexCmd(new Uint8Array([48,this.__internal__.device.listen_on_port,e,i,s]))},ur=function(t=1){t=o(this,R,Ft).call(this,t);const e=this.__internal__.device.milliseconds,i=e%256,s=Math.floor(e/3)%256;return this.serialLockerHexCmd(new Uint8Array([64,this.__internal__.device.listen_on_port,t,i,s]))},Ft=function(t){const e=parseInt(t);if(isNaN(e)||e<1||e>90)throw new Error("Invalid cell number");return e},Ut=function(){L(this,nt,!1),L(this,G,0),L(this,Pt,0)},Ne=function(t=null){L(this,Pt,Math.round(O(this,G)*100/90)),this.dispatch("percentage:open",{percentage:O(this,Pt),dispensed:t})},Me=function(){L(this,Pt,Math.round(O(this,G)*100/90)),this.dispatch("percentage:enable",{percentage:O(this,Pt)})},Fe=function(){L(this,Pt,Math.round(O(this,G)*100/90)),this.dispatch("percentage:disable",{percentage:O(this,Pt)})};var ma="0123456789abcdefghijklmnopqrstuvwxyz";function St(r){return ma.charAt(r)}function ya(r,n){return r&n}function de(r,n){return r|n}function Xn(r,n){return r^n}function Gn(r,n){return r&~n}function wa(r){if(r==0)return-1;var n=0;return r&65535||(r>>=16,n+=16),r&255||(r>>=8,n+=8),r&15||(r>>=4,n+=4),r&3||(r>>=2,n+=2),r&1||++n,n}function va(r){for(var n=0;r!=0;)r&=r-1,++n;return n}var qt="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",Jn="=";function pe(r){var n,t,e="";for(n=0;n+3<=r.length;n+=3)t=parseInt(r.substring(n,n+3),16),e+=qt.charAt(t>>6)+qt.charAt(t&63);for(n+1==r.length?(t=parseInt(r.substring(n,n+1),16),e+=qt.charAt(t<<2)):n+2==r.length&&(t=parseInt(r.substring(n,n+2),16),e+=qt.charAt(t>>2)+qt.charAt((t&3)<<4));(e.length&3)>0;)e+=Jn;return e}function $n(r){var n="",t,e=0,i=0;for(t=0;t<r.length&&r.charAt(t)!=Jn;++t){var s=qt.indexOf(r.charAt(t));s<0||(e==0?(n+=St(s>>2),i=s&3,e=1):e==1?(n+=St(i<<2|s>>4),i=s&15,e=2):e==2?(n+=St(i),n+=St(s>>2),i=s&3,e=3):(n+=St(i<<2|s>>4),n+=St(s&15),e=0))}return e==1&&(n+=St(i<<2)),n}var jt,Pa={decode:function(r){var n;if(jt===void 0){var t="0123456789ABCDEF",e=` \f
|
|
@@ -39,4 +39,4 @@ version: 2.9.0
|
|
|
39
39
|
*
|
|
40
40
|
* This source code is licensed under the MIT license found in the
|
|
41
41
|
* LICENSE file in the root directory of this source tree.
|
|
42
|
-
*/const gc={wait:dt,getSeconds:Xe,supportWebSerial:Wn},bc="4.1.
|
|
42
|
+
*/const gc={wait:dt,getSeconds:Xe,supportWebSerial:Wn},bc="4.1.1";I.Arduino=_c,I.Boardroid=fc,I.Devices=K,I.Emulator=Zt,I.Jofemar=pc,I.Kernel=kt,I.Locker=ba,I.PinPad=dc,I.Relay=ga,I.utils=gc,I.version=bc,Object.defineProperty(I,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@danidoble/webserial",
|
|
3
3
|
"description": "WebSerial API wrapper",
|
|
4
|
-
"version": "4.1.
|
|
4
|
+
"version": "4.1.1",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"author": "danidoble",
|
|
@@ -39,16 +39,16 @@
|
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@eslint/eslintrc": "^3.2.0",
|
|
42
|
-
"@eslint/js": "^9.
|
|
42
|
+
"@eslint/js": "^9.18.0",
|
|
43
43
|
"@vitejs/plugin-basic-ssl": "^1.2.0",
|
|
44
44
|
"autoprefixer": "^10.4.20",
|
|
45
45
|
"axios": "^1.7.9",
|
|
46
|
-
"eslint": "^9.
|
|
46
|
+
"eslint": "^9.18.0",
|
|
47
47
|
"globals": "^15.14.0",
|
|
48
48
|
"jsencrypt": "^3.3.2",
|
|
49
|
-
"postcss": "^8.
|
|
49
|
+
"postcss": "^8.5.1",
|
|
50
50
|
"prettier": "^3.4.2",
|
|
51
|
-
"uuid": "^11.0.
|
|
52
|
-
"vite": "^6.0.
|
|
51
|
+
"uuid": "^11.0.5",
|
|
52
|
+
"vite": "^6.0.7"
|
|
53
53
|
}
|
|
54
54
|
}
|