@danidoble/webserial
Version:
WebSerial API wrapper
4 lines • 280 kB
JavaScript
(function(D,N){typeof exports=="object"&&typeof module<"u"?N(exports):typeof define=="function"&&define.amd?define(["exports"],N):(D=typeof globalThis<"u"?globalThis:D||self,N(D.WebSerial={}))})(this,function(D){"use strict";var Lc=Object.defineProperty;var or=D=>{throw TypeError(D)};var Vc=(D,N,G)=>N in D?Lc(D,N,{enumerable:!0,configurable:!0,writable:!0,value:G}):D[N]=G;var _t=(D,N,G)=>Vc(D,typeof N!="symbol"?N+"":N,G),Pn=(D,N,G)=>N.has(D)||or("Cannot "+G);var O=(D,N,G)=>(Pn(D,N,"read from private field"),G?G.call(D):N.get(D)),Q=(D,N,G)=>N.has(D)?or("Cannot add the same private member more than once"):N instanceof WeakSet?N.add(D):N.set(D,G),L=(D,N,G,te)=>(Pn(D,N,"write to private field"),te?te.call(D,G):N.set(D,G),G),o=(D,N,G)=>(Pn(D,N,"access private method"),G);var ot,dt,d,cr,lr,T,Tn,F,M,Le,P,Cn,le,ce,Fe,hr,it,X,Tt,I,ur,dr,pr,_r,Sn,fr,Lt,Vt,Ve,qe,He,p,yr,br,mr,kn,wr,vr,Er,Pr,Tr,Cr,Sr,kr,xr,Ar,he,ue,Dr,de,Rr,qt,Ir,J,Or,Nr,xn,Br,Mr,Fr,An,Dn,pe,Rn,Ur,wt,vt,je,In,_e,On,Nn,Lr,Bn,Mn,Vr,qr,Yt,Fn,Hr,jr,Kr,Ke,Wr,$r,Un,zr,Gr,Xr,Jr,Qr,Zr,Yr,ts,es,Ln,Vn,ns,is,rs,st,ss,as,os,cs,qn,ls,g,hs,us,ds,lt,We,ps,_s,fs,gs,ys,bs,ms,ws,vs,Es,Ps,Ts,Cs,Ss,ks,xs,As,Ds,Rs,Is,Os,Ns,Bs,Ms,Fs,Us,gt,tt,$e,et,Et,Ls,Vs,qs,Hs,fe,Hn,jn,ze,Ge,js,Jt,Ut,Qt,w,Ks,Ws,Xe,$s,zs,Gs,Xs,Js,Qs,Zs,Ys,Kn,ta,ea,na,ia,ra,sa,aa,oa,ca,la,ha,ua,da,pa,ht,Je,_a,fa,ga,ya,Wn,Qe,ba,ma,$n,zn,Gn,Zt,wa,va;function N(r=100){return new Promise(n=>setTimeout(()=>n(),r))}function G(){return"serial"in navigator}function te(){return"geolocation"in navigator}function Ea(){return"crypto"in window}function Ze(r=1){return r*1e3}function kt(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,ot)){case"locker":t=["0","8"];break;case"boardroid":t=["2",(5+O(u,dt)).toString(16).toUpperCase()];break;case"jofemar":t=["6"];break;default:return!1}o(i=u,d,P).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,ot)){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,P).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,ot)){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,P).call(i,t)}static gateInactive(n=null){var t;if(!o(t=u,d,T).call(t,n)||!o(this,d,Tn).call(this))return!1;o(this,d,P).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,Tn).call(this))return!1;o(this,d,P).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,M).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,dt)).toString(16),i=Math.floor(Math.random()*15);o(c=u,d,P).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,Le).call(this))return!1;let t=[];const e=(128+O(u,dt)).toString(16);switch(O(u,ot)){case"boardroid":t=["2","D8","dc"];break;case"jofemar":t=["2",e,"50","4F"];break}o(s=u,d,P).call(s,t)}static doorClosed(n=null){var i,s;if(!o(i=u,d,T).call(i,n)||!o(this,d,Le).call(this))return!1;let t=[];const e=(128+O(u,dt)).toString(16);switch(O(u,ot)){case"boardroid":t=["2","D8","db"];break;case"jofemar":t=["2",e,"50","43"];break}o(s=u,d,P).call(s,t)}static channelDisconnected(n=null){var e,i,s;if(!o(e=u,d,T).call(e,n)||!o(i=u,d,M).call(i))return!1;const t=(128+O(u,dt)).toString(16);o(s=u,d,P).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,M).call(i))return!1;const t=(128+O(u,dt)).toString(16);o(s=u,d,P).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,M).call(i))return!1;const t=(128+O(u,dt)).toString(16);o(s=u,d,P).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,M).call(i))return!1;const t=(128+O(u,dt)).toString(16);o(s=u,d,P).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,Le).call(s))return!1;let t=[];const e=(128+O(u,dt)).toString(16);switch(O(u,ot)){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,P).call(a,t)}static ready(n=null){var t,e,i;if(!o(t=u,d,T).call(t,n)||!o(e=u,d,M).call(e))return!1;o(i=u,d,P).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,M).call(e))return!1;o(i=u,d,P).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,M).call(e))return!1;o(i=u,d,P).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,M).call(e))return!1;o(i=u,d,P).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,M).call(e))return!1;o(i=u,d,P).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,M).call(e))return!1;o(i=u,d,P).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,M).call(e))return!1;o(i=u,d,P).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,M).call(e))return!1;o(i=u,d,P).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,M).call(e))return!1;o(i=u,d,P).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,M).call(e))return!1;o(i=u,d,P).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,M).call(e))return!1;o(i=u,d,P).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,M).call(e))return!1;o(i=u,d,P).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,M).call(e))return!1;o(i=u,d,P).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,M).call(e))return!1;o(i=u,d,P).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,M).call(e))return!1;o(i=u,d,P).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,M).call(e))return!1;o(i=u,d,P).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,M).call(e))return!1;o(i=u,d,P).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,M).call(e))return!1;o(i=u,d,P).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,M).call(e))return!1;o(i=u,d,P).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,M).call(e))return!1;o(i=u,d,P).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,M).call(e))return!1;o(i=u,d,P).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,M).call(e))return!1;o(i=u,d,P).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,M).call(e))return!1;o(i=u,d,P).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,M).call(e))return!1;o(i=u,d,P).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,M).call(e))return!1;o(i=u,d,P).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,M).call(e))return!1;o(i=u,d,P).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,M).call(e))return!1;o(i=u,d,P).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,F).call(e))return!1;o(i=u,d,P).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,F).call(e))return!1;o(i=u,d,P).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,F).call(a))return!1;const e=["40","41","42","43","44","45"],i=o(c=u,d,Cn).call(c,e,t);o(l=u,d,P).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,F).call(a))return!1;const e=["50","51","52","53","54","55"],i=o(c=u,d,Cn).call(c,e,t);o(l=u,d,P).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,F).call(a))return!1;const e=["80","81","82","83","84"],i=o(c=u,d,le).call(c,e,t);o(l=u,d,P).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,F).call(a))return!1;const e=["90","91","92","93","94"],i=o(c=u,d,le).call(c,e,t);o(l=u,d,P).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,F).call(a))return!1;const e=["A0","A1","A2","A3","A4"],i=o(c=u,d,le).call(c,e,t);o(l=u,d,P).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,F).call(a))return!1;const e=["B0","B1","B2","B3","B4"],i=o(c=u,d,le).call(c,e,t);o(l=u,d,P).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,F).call(e))return!1;o(i=u,d,P).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,F).call(e))return!1;o(i=u,d,P).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,F).call(e))return!1;o(i=u,d,P).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,F).call(e))return!1;o(i=u,d,P).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,F).call(e))return!1;o(i=u,d,P).call(i,["2","D1","1","1"])}static readTubes(n=null){var h,_,f;if(!o(h=u,d,T).call(h,n)||!o(_=u,d,F).call(_))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,d,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,d,T).call(i,n)||!o(s=u,d,F).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",_="0",f="0",b="0",E="0";if(t!==null&&!isNaN(parseInt(t)))switch(t.toString()){case"20":h=l;break;case"50":_=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:_=l;break;case 2:f=l;break;case 3:b=l;break;case 4:E=l;break}o(a=u,d,P).call(a,["2","D3",h,_,f,b,E,"0"])}else{const[l,h,_,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,d,P).call(c,["2","D3",l,h,_,f,b,E])}}static banknoteAccepted(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,P).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,F).call(e))return!1;o(i=u,d,P).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,F).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",_="0",f="0",b="0";switch(n._recycler.bill){case 0:l=c;break;case 1:h=c;break;case 2:_=c;break;case 3:f=c;break;case 4:b=c;break}o(s=u,d,P).call(s,["2","D5",l,h,_,f,b,"0"])}else{const[c,l,h,_,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,d,P).call(a,["2","D5",c,l,h,_,f,b])}}static coinsDispensed(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,P).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,F).call(e))return!1;o(i=u,d,P).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,F).call(e))return!1;o(i=u,d,P).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,F).call(e))return!1;o(i=u,d,P).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,F).call(e))return!1;o(i=u,d,P).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,F).call(e))return!1;o(i=u,d,P).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,F).call(e))return!1;o(i=u,d,P).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,F).call(e))return!1;o(i=u,d,P).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,F).call(e))return!1;o(i=u,d,P).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,F).call(e))return!1;o(i=u,d,P).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,F).call(e))return!1;o(i=u,d,P).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,F).call(e))return!1;o(i=u,d,P).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,F).call(e))return!1;o(i=u,d,P).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,M).call(e))return!1;o(i=u,d,P).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}};ot=new WeakMap,dt=new WeakMap,d=new WeakSet,cr=function(){if(u.enable===!1)throw new Error("Emulator is disabled");return u.enable},lr=function(n){if(typeof n!="object"||!(n instanceof xt))throw new Error(`Type ${n.typeDevice} is not supported`);return u.instance=n,L(u,ot,n.typeDevice),L(u,dt,n.deviceNumber),!0},T=function(n=null){var t,e;return!o(t=u,d,cr).call(t)||n===null&&u.instance===null?!1:(u.instance===null&&o(e=u,d,lr).call(e,n),!0)},Tn=function(){if(O(u,ot)!=="locker")throw new Error("This function is only available for Locker devices");return!0},F=function(){if(O(u,ot)!=="boardroid")throw new Error("This function is only available for Boardroid devices");return!0},M=function(){if(O(u,ot)!=="jofemar")throw new Error("This function is only available for Jofemar devices");return!0},Le=function(){if(O(u,ot)==="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},le=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},Q(u,d),_t(u,"enable",!1),_t(u,"instance",null),Q(u,ot,null),Q(u,dt,1);let ge=u;var Pa=Object.defineProperty,Xn=r=>{throw TypeError(r)},Ta=(r,n,t)=>n in r?Pa(r,n,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[n]=t,ee=(r,n,t)=>Ta(r,typeof n!="symbol"?n+"":n,t),Ca=(r,n,t)=>n.has(r)||Xn("Cannot "+t),Sa=(r,n,t)=>n.has(r)?Xn("Cannot add the same private member more than once"):n instanceof WeakSet?n.add(r):n.set(r,t),q=(r,n,t)=>(Ca(r,n,"access private method"),t);const Z=[];for(let r=0;r<256;++r)Z.push((r+256).toString(16).slice(1));function ka(r,n=0){return(Z[r[n+0]]+Z[r[n+1]]+Z[r[n+2]]+Z[r[n+3]]+"-"+Z[r[n+4]]+Z[r[n+5]]+"-"+Z[r[n+6]]+Z[r[n+7]]+"-"+Z[r[n+8]]+Z[r[n+9]]+"-"+Z[r[n+10]]+Z[r[n+11]]+Z[r[n+12]]+Z[r[n+13]]+Z[r[n+14]]+Z[r[n+15]]).toLowerCase()}let Ye;const xa=new Uint8Array(16);function Aa(){if(!Ye){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");Ye=crypto.getRandomValues.bind(crypto)}return Ye(xa)}const Da=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),Jn={randomUUID:Da};function Ra(r,n,t){var e;if(Jn.randomUUID&&!r)return Jn.randomUUID();r=r||{};const i=r.random??((e=r.rng)==null?void 0:e.call(r))??Aa();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,ka(i)}class Qn extends CustomEvent{constructor(n,t){super(n,t)}}class Zn extends EventTarget{constructor(){super(...arguments),ee(this,"__listeners__",{debug:!1}),ee(this,"__debug__",!1)}dispatch(n,t=null){const e=new Qn(n,{detail:t});this.dispatchEvent(e),this.__debug__&&this.dispatchEvent(new Qn("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 tn=class H extends Zn{constructor(){super(),["change"].forEach(n=>{this.serialRegisterAvailableListener(n)})}static $dispatchChange(n=null){n&&n.$checkAndDispatchConnection(),H.instance.dispatch("change",{devices:H.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 H.devices[n]>"u"&&(H.devices[n]={})}static add(n){const t=n.typeDevice;typeof H.devices[t]>"u"&&(H.devices[t]={});const e=n.uuid;if(typeof H.devices[t]>"u"&&H.typeError(t),H.devices[t][e])throw new Error(`Device with id ${e} already exists`);return H.devices[t][e]=n,H.$dispatchChange(n),Object.keys(H.devices[t]).indexOf(e)}static get(n,t){return typeof H.devices[n]>"u"&&(H.devices[n]={}),typeof H.devices[n]>"u"&&H.typeError(n),H.devices[n][t]}static getAll(n=null){return n===null?H.devices:(typeof H.devices[n]>"u"&&H.typeError(n),H.devices[n])}static getList(){return Object.values(H.devices).map(n=>Object.values(n)).flat()}static getByNumber(n,t){return typeof H.devices[n]>"u"&&H.typeError(n),Object.values(H.devices[n]).find(e=>e.deviceNumber===t)??null}static getCustom(n,t=1){return typeof H.devices[n]>"u"&&H.typeError(n),Object.values(H.devices[n]).find(e=>e.deviceNumber===t)??null}};ee(tn,"instance"),ee(tn,"devices",{});let k=tn;k.instance||(k.instance=new k);function Yn(r=100){return new Promise(n=>setTimeout(()=>n(),r))}function Ia(){return"serial"in navigator}const en={baudRate:9600,dataBits:8,stopBits:1,parity:"none",bufferSize:32768,flowControl:"none"};var U,Ht,ne,nn,Ot,ti,ei,ni,ii,ri,si,ai,oi,ci,li,hi,ui;class Oa extends Zn{constructor({filters:n=null,config_port:t=en,no_device:e=1,device_listen_on_channel:i=1}={filters:null,config_port:en,no_device:1,device_listen_on_channel:1}){if(super(),Sa(this,U),ee(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:en,queue:[],auto_response:["DD","DD"]},device:{type:"unknown",id:Ra(),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&&q(this,U,hi).call(this,e),i&&["number","string"].includes(typeof i)&&(this.listenOnChannel=i),q(this,U,ai).call(this),q(this,U,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=q(this,U,Ht).call(this,this.__internal__.serial.port);return n&&!t&&q(this,U,ne).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=q(this,U,Ht).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(),q(this,U,ne).call(this,n)}async connect(){return new Promise((n,t)=>{Ia()||t("Web Serial not supported"),setTimeout(async()=>{await Yn(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 q(this,U,ti).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 Yn(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 q(this,U,nn).call(this,this.__internal__.serial.bytes_connection??[]),this.dispatch("serial:sent",{action:"connect",bytes:this.__internal__.serial.bytes_connection}),this.__internal__.auto_response&&q(this,U,Ot).call(this,this.__internal__.serial.auto_response,null),await q(this,U,ri).call(this)}catch(n){this.serialErrors(n)}}async serialForget(){return await q(this,U,si).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(){q(this,U,ui).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")}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}}U=new WeakSet,Ht=function(r){return!!(r&&r.readable&&r.writable)},ne=function(r=null){this.__internal__.serial.connected=!1,this.__internal__.aux_port_connector=0,this.dispatch("serial:disconnected",r),k.$dispatchChange(this)},nn=async function(r){const n=this.__internal__.serial.port;if(!n||n&&(!n.readable||!n.writable))throw q(this,U,ne).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()},Ot=function(r=[],n=null){if(r&&r.length>0){const t=this.__internal__.serial.connected;this.__internal__.serial.connected=q(this,U,Ht).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",{})},ti=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=>!q(this,U,Ht).call(this,t))},ei=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}},ni=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&&q(this,U,Ot).call(this,r),this.__internal__.serial.response.buffer=new Uint8Array(0)},400)},ii=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));q(this,U,Ot).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));q(this,U,Ot).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));q(this,U,Ot).call(this,t),this.__internal__.serial.response.buffer=new Uint8Array(0)}}}}},ri=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}q(this,U,ei).call(this,e),this.__internal__.serial.response.length===null?await q(this,U,ni).call(this):await q(this,U,ii).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()},si=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},ai=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 q(n=r,U,li).call(n)}),q(this,U,ci).call(this)},ci=function(){const r=this;navigator.serial.addEventListener("connect",async()=>{r.isDisconnected&&await r.serialConnect().catch(()=>{})})},li=async function(){if(!q(this,U,Ht).call(this,this.__internal__.serial.port)){q(this,U,ne).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 q(this,U,nn).call(this,r.bytes),this.dispatch("serial:sent",{action:r.action,bytes:r.bytes}),this.__internal__.auto_response&&q(this,U,Ot).call(this,this.__internal__.serial.auto_response,null);const t=[...this.__internal__.serial.queue];this.__internal__.serial.queue=t.splice(1)},hi=function(r=1){this.__internal__.device_number=r,this.__internal__.serial.bytes_connection=this.serialSetConnectionConstant(r)},ui=function(){this.__internal__.last_error={message:null,action:null,code:null,no_code:0}},k.instance||(k.instance=new k);const Na={relay:[],locker:[],jofemar:[],boardroid:[],arduino:[],pinpad:[],pinpax:[]};k.devices={...k.devices,...Na},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 xt extends Oa{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 isDoorOpen(){return this.__internal__.device.door_open}get isDispensing(){return this.__internal__.interval.waiting_sense||this.__internal__.dispense.dispensing}async timeout(n,t){await super.timeout(n,t),t==="dispense"&&(this.__internal__.dispense.status="no-response")}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")}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 n=this.__internal__.dispense.limit_counter;return this.__internal__.dispense.custom_limit_counter&&(n=this.__internal__.dispense.custom_limit_counter),n+=Math.ceil(n*.6),this.__internal__.dispense.counter>=n?(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:n}),null)}async internalDispenseStatus(){if(this.__internal__.dispense.must_response&&(await N(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 n=this;return new Promise(t=>{this.__internal__.interval.waiting_sense=setInterval(()=>{switch(n.__internal__.dispense.status){case null:n.internalDispensingProcess()===!1&&(n.internalClearSensing(),n.dispatch("not-dispensed",{reason:"timeout"}),t({status:!1,error:"timeout"}));break;case!0:n.internalClearSensing(),n.__internal__.dispense.status=!0,n.dispatch("dispensed",{}),t({status:!0,error:null});break;case!1:n.internalClearSensing(),n.__internal__.dispense.status=!1,n.dispatch("not-dispensed",{reason:"no-stock"}),t({status:!1,error:null});break;case"elevator-locked":n.internalClearSensing(),n.__internal__.dispense.status=!1,n.dispatch("not-dispensed",{reason:"elevator-locked"}),t({status:!1,error:"elevator-locked"});break;case"no-response":n.internalClearSensing(),n.__internal__.dispense.status=!1,n.dispatch("not-dispensed",{reason:"no-response"}),t({status:!1,error:"no-response"});break}},this.__internal__.time.sense)})}async internalDispense(n){if(this.isDispensing)throw new Error("Another dispensing process is running");if(!ge.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(n,"dispense"),await this.internalDispenseStatus()):new Promise(t=>{const e=setInterval(async()=>{if(this.__internal__.serial.queue.length>0)return;clearInterval(e),await this.appendToQueue(n,"dispense");const i=await this.internalDispenseStatus();t(i)},100)})}__emulate(n){if(typeof n.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 t=[];for(const e in n.code)t.push(n.code[e].toString().padStart(2,"0").toLowerCase());this.serialMessage(t)}set listenOnPort(n){this.listenOnChannel=n}get listenOnPort(){return this.__internal__.device.listen_on_port??1}}class Ba extends xt{constructor({filters:t=null,config_port:e=null,no_device:i=1}={}){super({filters:t,config_port:e,no_device:i});Q(this,Fe);Q(this,ce,{activate:["A0","01","01","A2"],deactivate:["A0","01","00","A1"]});if(this.__internal__.device.type="relay",this.__internal__.auto_response=!0,k.getCustom(this.typeDevice,i))throw new Error(`Device ${this.typeDevice} ${i} already exists`);o(this,Fe,hr).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,ce).activate;t[3]=this.serialRelaySumHex(t),await this.appendToQueue(t,"relay:turn-on")}async turnOff(){const t=O(this,ce).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 N(e),await i.turnOn()):(await i.turnOn(),await N(e),await i.turnOff())}}ce=new WeakMap,Fe=new WeakSet,hr=function(){k.add(this)};class Ma extends xt{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});Q(this,I);Q(this,it,!1);Q(this,X,0);Q(this,Tt,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,I,dr).call(this),o(this,I,ur).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,it)&&O(this,X)>=89?(e.finished_test=!0,L(this,it,!1),L(this,X,0)):O(this,it)&&(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,it)&&O(this,X)>=89?(e.finished_test=!0,L(this,it,!1),L(this,X,0)):O(this,it)&&(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,it)&&O(this,X)>=89?(e.finished_test=!0,L(this,it,!1),L(this,X,0)):O(this,it)&&(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,I,Lt).call(this,t);const e=o(this,I,fr).call(this,t);return await this.internalDispense(e)}async status({cell:t=1}={}){t=o(this,I,Lt).call(this,t);const e=o(this,I,pr).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,I,_r).call(this,t,e);return await this.appendToQueue(i,"light-scan")}async enable({cell:t=1}={}){t=o(this,I,Lt).call(this,t);const[e,i]=this.parseCellToColumnRow(t),s=o(this,I,Sn).call(this,{enable:!0,column:e,row:i});await this.appendToQueue(s,"activate")}async disable({cell:t=1}={}){t=o(this,I,Lt).call(this,t);const[e,i]=this.parseCellToColumnRow(t),s=o(this,I,Sn).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,I,Vt).call(this),L(this,it,!0),o(this,I,Ve).call(this);const t=[];for(let e=1;e<=90;e++){const i=await this.dispense(e);t.push(i),L(this,X,e),o(this,I,Ve).call(this)}L(this,X,90),o(this,I,Ve).call(this,t),o(this,I,Vt).call(this)}async enableAll(){o(this,I,Vt).call(this),L(this,it,!0),o(this,I,qe).call(this);for(let t=1;t<=90;t++)await this.enable(t),L(this,X,t),o(this,I,qe).call(this);L(this,X,90),o(this,I,qe).call(this),o(this,I,Vt).call(this)}async disableAll(){o(this,I,Vt).call(this),L(this,it,!0),o(this,I,He).call(this);for(let t=1;t<=90;t++)await this.enable(t),L(this,X,t),o(this,I,He).call(this);L(this,X,90),o(this,I,He).call(this),o(this,I,Vt).call(this)}}it=new WeakMap,X=new WeakMap,Tt=new WeakMap,I=new WeakSet,ur=function(){const t=["percentage:disable","percentage:enable","percentage:open"];for(const e of t)this.serialRegisterAvailableListener(e)},dr=function(){k.add(this)},pr=function(t=1){return t=o(this,I,Lt).call(this,t),this.serialLockerHexCmd(new Uint8Array([16,this.__internal__.device.listen_on_port,t]))},_r=function(t=0,e=10){return this.serialLockerHexCmd(new Uint8Array([32,this.__internal__.device.listen_on_port,t,e]))},Sn=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]))},fr=function(