@danidoble/webserial 4.2.3 → 4.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/arduino.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var d=s=>{throw TypeError(s)};var p=(s,n,e)=>n.has(s)||d("Cannot "+e);var h=(s,n,e)=>n.has(s)?d("Cannot add the same private member more than once"):n instanceof WeakSet?n.add(s):n.set(s,e);var o=(s,n,e)=>(p(s,n,"access private method"),e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("./kernel-CtyQRsMI.cjs");var r,l,u;class y extends c.Kernel{constructor({filters:e=null,config_port:a=null,no_device:i=1}={}){super({filters:e,config_port:a,no_device:i});h(this,r);if(this.__internal__.device.type="arduino",c.c.getCustom(this.typeDevice,i))throw new Error(`Device ${this.typeDevice} ${i} already exists`);this.__internal__.time.response_connection=2e3,this.__internal__.time.response_general=2e3,this.__internal__.serial.delay_first_connection=1e3,o(this,r,u).call(this),o(this,r,l).call(this),this.getResponseAsString()}serialMessage(e){const a=this.stringToArrayHex(e),i=this.stringToArrayBuffer(e),t={original_code:a,arrayBuffer:i,code:null,name:null,description:null,request:null,no_code:0};switch(t.code=e,e){case"connected":t.name="connected",t.description="Connection established",t.request="connect",t.no_code=100;break;case"created by danidoble":t.name="thanks",t.description="thanks for using this software",t.request="credits",t.no_code=101;break;case"hello there":t.name="hello there",t.description="hi human",t.request="hi",t.no_code=102;break;case"ara ara":t.name="ara ara",t.description="troll",t.request="ara ara",t.no_code=404;break;default:t.name="unknown",t.description="Unknown command",t.request="unknown",t.no_code=400;break}this.dispatch("serial:message",t)}serialSetConnectionConstant(e=1){return this.add0x(this.parseStringToBytes("CONNECT"))}async sayCredits(){const e=this.parseStringToBytes("CREDITS");await this.appendToQueue(e,"credits")}async sayHi(){const e=this.parseStringToBytes("HI");await this.appendToQueue(e,"hi")}async sayAra(){const e=this.parseStringToBytes("OTHER");await this.appendToQueue(e,"ara")}async sendCustomCode({code:e=""}={}){if(typeof e!="string")throw new Error("Invalid string");const a=this.parseStringToBytes(e);await this.appendToQueue(a,"custom")}async doSomething(){await this.sayCredits(),await this.sayAra(),await this.sayHi()}}r=new WeakSet,l=function(){c.c.add(this)},u=function(){};exports.Arduino=y;
1
+ "use strict";var d=s=>{throw TypeError(s)};var p=(s,n,e)=>n.has(s)||d("Cannot "+e);var h=(s,n,e)=>n.has(s)?d("Cannot add the same private member more than once"):n instanceof WeakSet?n.add(s):n.set(s,e);var o=(s,n,e)=>(p(s,n,"access private method"),e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("./kernel-C0epz_jB.cjs");var r,l,u;class _ extends c.Kernel{constructor({filters:e=null,config_port:a=null,no_device:i=1}={}){super({filters:e,config_port:a,no_device:i});h(this,r);if(this.__internal__.device.type="arduino",c._.getCustom(this.typeDevice,i))throw new Error(`Device ${this.typeDevice} ${i} already exists`);this.__internal__.time.response_connection=2e3,this.__internal__.time.response_general=2e3,this.__internal__.serial.delay_first_connection=1e3,o(this,r,u).call(this),o(this,r,l).call(this),this.getResponseAsString()}serialMessage(e){const a=this.stringToArrayHex(e),i=this.stringToArrayBuffer(e),t={original_code:a,arrayBuffer:i,code:null,name:null,description:null,request:null,no_code:0};switch(t.code=e,e){case"connected":t.name="connected",t.description="Connection established",t.request="connect",t.no_code=100;break;case"created by danidoble":t.name="thanks",t.description="thanks for using this software",t.request="credits",t.no_code=101;break;case"hello there":t.name="hello there",t.description="hi human",t.request="hi",t.no_code=102;break;case"ara ara":t.name="ara ara",t.description="troll",t.request="ara ara",t.no_code=404;break;default:t.name="unknown",t.description="Unknown command",t.request="unknown",t.no_code=400;break}this.dispatch("serial:message",t)}serialSetConnectionConstant(e=1){return this.add0x(this.parseStringToBytes("CONNECT"))}async sayCredits(){const e=this.parseStringToBytes("CREDITS");await this.appendToQueue(e,"credits")}async sayHi(){const e=this.parseStringToBytes("HI");await this.appendToQueue(e,"hi")}async sayAra(){const e=this.parseStringToBytes("OTHER");await this.appendToQueue(e,"ara")}async sendCustomCode({code:e=""}={}){if(typeof e!="string")throw new Error("Invalid string");const a=this.parseStringToBytes(e);await this.appendToQueue(a,"custom")}async doSomething(){await this.sayCredits(),await this.sayAra(),await this.sayHi()}}r=new WeakSet,l=function(){c._.add(this)},u=function(){};exports.Arduino=_;
package/dist/arduino.js CHANGED
@@ -4,7 +4,7 @@ var c = (s) => {
4
4
  var p = (s, n, e) => n.has(s) || c("Cannot " + e);
5
5
  var h = (s, n, e) => n.has(s) ? c("Cannot add the same private member more than once") : n instanceof WeakSet ? n.add(s) : n.set(s, e);
6
6
  var o = (s, n, e) => (p(s, n, "access private method"), e);
7
- import { K as _, c as d } from "./kernel-B15wfB2x.js";
7
+ import { K as _, _ as d } from "./kernel-BFXQSiNz.js";
8
8
  var a, l, u;
9
9
  class m extends _ {
10
10
  constructor({ filters: e = null, config_port: r = null, no_device: i = 1 } = {}) {
@@ -1 +1 @@
1
- "use strict";var de=Object.defineProperty;var M=d=>{throw TypeError(d)};var ue=(d,u,t)=>u in d?de(d,u,{enumerable:!0,configurable:!0,writable:!0,value:t}):d[u]=t;var b=(d,u,t)=>ue(d,typeof u!="symbol"?u+"":u,t),F=(d,u,t)=>u.has(d)||M("Cannot "+t);var v=(d,u,t)=>(F(d,u,"read from private field"),t?t.call(d):u.get(d)),C=(d,u,t)=>u.has(d)?M("Cannot add the same private member more than once"):u instanceof WeakSet?u.add(d):u.set(d,t),_=(d,u,t,e)=>(F(d,u,"write to private field"),e?e.call(d,t):u.set(d,t),t),a=(d,u,t)=>(F(d,u,"access private method"),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const R=require("./kernel-CtyQRsMI.cjs");var w,f,y,s,D,H,x,N,O,j,U,A,L,Q,z,B,W,m,V,Y,G,J,K,X,Z,g,$,ee,te,ne,p,T,se,ie,re,ae,S,I,oe,ce,P,E,q;class pe extends R.Kernel{constructor({filters:t=null,config_port:e=null,no_device:n=1}={}){super({filters:t,config_port:e,no_device:n});C(this,s);b(this,"__coin_purse",{available:!0});b(this,"__banknote_purse",{available:!0,isRecycler:!0,recycler:{ict:!0,banknote:1}});b(this,"__sale",{price:0,change:0,change_verified:0,dispense_all:!0,last_change:0,clear(){this.price=0,this.change=0,this.change_verified=0,this.dispense_all=!0,this.last_change=0}});b(this,"__money_session",{inserted:0,retired:0,clear(){this.inserted=0,this.retired=0}});b(this,"coins",{tubes:{g50:0,c50:0,p1:0,p2:0,p5:0,p10:0},box:{g50:0,c50:0,p1:0,p2:0,p5:0,p10:0},totals:{g50:0,c50:0,p1:0,p2:0,p5:0,p10:0},total:0});b(this,"banknotes",{stacker:{p20:0,p50:0,p100:0,p200:0,p500:0,p1000:0},recycler:{p20:0,p50:0,p100:0,p200:0,p500:0,p1000:0},out:{p20:0,p50:0,p100:0,p200:0,p500:0,p1000:0},totals:{p20:0,p50:0,p100:0,p200:0,p500:0,p1000:0},total:0});b(this,"card_reader",{available:!1,max_pre_credit:0});C(this,w,!1);C(this,f,0);C(this,y,0);if(this.__internal__.device.type="boardroid",R.c.getCustom(this.typeDevice,n))throw new Error(`Device ${this.typeDevice} ${n} already exists`);this.__internal__.serial.config_port.baudRate=115200,this.__internal__.serial.response.length=14,this.__internal__.time.response_connection=600,this.__internal__.time.response_general=4e3,this.__internal__.time.response_engines=15e3,this.__internal__.dispense.limit_counter=15,this.__internal__.dispense.custom_limit_counter=null,this.__internal__.dispense.backup_dispense={channel:1,second_channel:null,sensor:!0,seconds:null},a(this,s,D).call(this),a(this,s,H).call(this)}get totalInTubes(){return this.coins.tubes.g50*.5+this.coins.tubes.c50*.5+this.coins.tubes.p1+this.coins.tubes.p2*2+this.coins.tubes.p5*5+this.coins.tubes.p10*10}get totalInRecycler(){return this.banknotes.recycler.p20*20+this.banknotes.recycler.p50*50+this.banknotes.recycler.p100*100+this.banknotes.recycler.p200*200+this.banknotes.recycler.p500*500+this.banknotes.recycler.p1000*1e3}get hasRecycler(){return this.__banknote_purse.available&&this.__banknote_purse.isRecycler}set hasRecycler(t){this.__banknote_purse.isRecycler=t}get hasICT(){return this.hasRecycler&&this.__banknote_purse.recycler.ict}set hasICT(t){this.__banknote_purse.recycler.ict=t}set banknoteICT(t){if(![20,50,100,200,500].includes(t))throw new Error(`Invalid banknote value: ${t}`);t=[20,50,100,200,500].indexOf(t),this.__banknote_purse.recycler.banknote=t}get banknoteICT(){return[20,50,100,200,500][this.__banknote_purse.recycler.banknote]}get hasCoinPurse(){return this.__coin_purse.available}set hasCoinPurse(t){if(typeof t!="boolean")throw new Error(`Invalid value: ${t}`);this.__coin_purse.available=t}set price(t){let e=parseFloat(t);(isNaN(e)||e<0)&&(e=0),this.__sale.price=e}get price(){return this.__sale.price}get change(){return this.__sale.price<=0||this.__money_session.inserted<=this.__sale.price?0:this.__money_session.inserted-this.__sale.price}softReload(){super.softReload(),this.__sale.clear(),this.__money_session.clear()}serialBoardroidSumHex(t){let e=0;return t.forEach((n,i)=>{i!==0&&i!==11&&(e+=parseInt(n,16))}),e.toString(16).toUpperCase()}serialMessage(t){let e={code:t,name:null,description:null,request:null,no_code:0};const n=(5+this.deviceNumber).toString(16).padStart(2,"0").toLowerCase();switch(t[1]){case n:e.request="connect",e=a(this,s,O).call(this,e);break;case"a0":e.request="--automatic",e=a(this,s,W).call(this,t,e);break;case"b0":e.request="--automatic",e=a(this,s,m).call(this,t,e);break;case"d0":e.request="coin-purse:config",e=a(this,s,V).call(this,t[2],e);break;case"d1":e.request="banknote-purse:config",e.additional={scrow:null},e=a(this,s,Y).call(this,t,e);break;case"d2":e.request="coin-purse:read-tubes",e=a(this,s,G).call(this,t,e);break;case"d3":e.request="banknote-purse:read-recycler",e=a(this,s,J).call(this,t,e);break;case"d4":e.request="banknote-purse:banknote-scrow-status",e=a(this,s,K).call(this,t[2],e);break;case"d5":e.request="banknote-purse:dispense",e=a(this,s,X).call(this,t,e);break;case"d6":e.request="coin-purse:dispense",e=a(this,s,Z).call(this,t,e);break;case"d7":e.request="dispense",e=a(this,s,g).call(this,t[5],e);break;case"d8":e.request="--automatic",e=a(this,s,$).call(this,t[13],e);break;case"d9":e.request="status:temperature",e=a(this,s,ee).call(this,t,e);break;case"da":e.request="status:relay",e=a(this,s,te).call(this,t[2],e);break;case"db":e.request="banknote-purse:save-memory",e.no_code=18,e.name="Bill purse memory saved?",e.description="The memory of bill purse was saved successfully?",this.dispatch("banknote-purse:save-memory",{message:e});break;case"dc":e.request="coin-purse:read-memory",e.no_code=19,e.name="Coin purse memory read?",e.description="The memory of coin purse was read successfully?",this.dispatch("banknote-purse:read-memory",{message:e});break;case"dd":e.request="card-reader",a(this,s,ne).call(this,t,e);break;default:e.request="--unknown",e.name="Response unrecognized",e.description="The response of application was received, but dont identify with any of current parameters",e.no_code=400,this.dispatch("unknown",e);break}this.dispatch("serial:message",e)}serialSetConnectionConstant(t=1){let e=["F1","06","00","00","00","00","00","00","00","00","F2","F8"];return e[1]=this.hexMaker(this.decToHex((5+t).toString())),e[11]=this.serialBoardroidSumHex(e),this.add0x(e)}async coinPurseConfigure({enable:t=!1,high:e="FF",low:n="FF"}={}){if(!this.__coin_purse.available)throw new Error("Coin purse not available");const r=["F1","C1",t?"01":"00",e,n,"00","00","00","00","00","F2","00"];await a(this,s,p).call(this,r,"coin-purse:config")}async coinPurseEnable(){await this.coinPurseConfigure({enable:!0})}async coinPurseDisable(){await this.coinPurseConfigure({enable:!1})}async coinPurseDispense({$_50c:t=0,$_1:e=0,$_2:n=0,$_5:i=0,$_10:r=0}={}){if(!this.__coin_purse.available)throw new Error("Coin purse not available");if([t,e,n,i,r].some(o=>isNaN(o)||typeof o=="string"))throw new Error("One of the values is not a number");if(t<1&&e<1&&n<1&&i<1&&r<1)throw new Error("No coins to dispense");[t,e,n,i,r]=[this.decToHex(t),this.decToHex(e),this.decToHex(n),this.decToHex(i),this.decToHex(r)];let c=["F1","C6",t,e,n,i,r,"00","00","00","F2","00"];await a(this,s,p).call(this,c,"coin-purse:dispense")}async coinPurseReadTubes(){const t=["F1","C2","00","00","00","00","00","00","00","00","F2","00"];await a(this,s,p).call(this,t,"coin-purse:read-tubes")}async banknotePurseConfigure({enable:t=!1,scrow:e=!1}={}){if(!this.__banknote_purse.available)throw new Error("Banknote purse not available");let n;return a(this,s,x).call(this)?n=a(this,s,se).call(this,{enable:t,scrow:e}):n=a(this,s,ie).call(this,{enable:t,scrow:e}),await a(this,s,p).call(this,n,"banknote-purse:config")}async banknotePurseDispense({$_20:t=0,$_50:e=0,$_100:n=0,$_200:i=0,$_500:r=0,$_1000:c=0}={}){if(!this.__banknote_purse.available)throw new Error("Banknote purse not available");if(!this.__banknote_purse.isRecycler)throw new Error("Banknote purse is not recycler");let o;if(a(this,s,x).call(this)){const l=[t,e,n,i,r];o=a(this,s,re).call(this,l[this.__banknote_purse.recycler.banknote])}else o=a(this,s,ae).call(this,{$_20:t,$_50:e,$_100:n,$_200:i,$_500:r,$_1000:c});await a(this,s,p).call(this,o,"banknote-purse:dispense")}async banknotePurseEnable({scrow:t=!1}){return await this.banknotePurseConfigure({enable:!0,scrow:t})}async banknotePurseDisable(){return await this.banknotePurseConfigure({enable:!1})}async banknotePurseAcceptInScrow(){if(!this.__banknote_purse.available)throw new Error("Banknote purse not available");const t=["F1","C4","01","00","00","00","00","00","00","00","F2","00"];await a(this,s,p).call(this,t,"banknote-purse:banknote-scrow-status")}async banknotePurseRejectInScrow(){if(!this.__banknote_purse.available)throw new Error("Banknote purse not available");const t=["F1","C4","00","00","00","00","00","00","00","00","F2","00"];await a(this,s,p).call(this,t,"banknote-purse:banknote-scrow-status")}async banknotePurseSaveMemory({channel:t=null,$_20:e=null,$_50:n=null,$_100:i=null,$_200:r=null,$_500:c=null,$_1000:o=null}={}){if(!this.__banknote_purse.available)throw new Error("Banknote purse not available");if(t===null||e===null||n===null||i===null||r===null||c===null||o===null)throw new Error("One of the values is not defined");const l=["F1","C8",this.decToHex(t),"00",this.decToHex(e),this.decToHex(n),this.decToHex(i),this.decToHex(r),this.decToHex(c),this.decToHex(o),"F2","00"];await a(this,s,p).call(this,l,"banknote-purse:save-memory")}async banknotePurseReadRecycler(){if(!this.__banknote_purse.available)throw new Error("Banknote purse not available");if(!this.__banknote_purse.isRecycler)throw new Error("Banknote purse is not recycler");const t=["F1","C3","00","00","00","00","00","00","00","00","F2","B5"];return await a(this,s,p).call(this,t,"banknote-purse:read-recycler")}async cardReaderDisable(){if(!this.card_reader.available)throw new Error("Card reader not available");const t=["F1","CD","00","00","00","00","00","00","00","00","F2","00"];return await a(this,s,p).call(this,t,"card-reader:disable")}async cardReaderDispense({channel:t=1,second_channel:e=null,sensor:n=!0,seconds:i=null,price:r=0}={}){if(!this.card_reader.available)throw new Error("Card reader not available");if(isNaN(this.card_reader.max_pre_credit)||this.card_reader.max_pre_credit===0)throw new Error("Card reader pre-credit not configured");if(isNaN(r)||r<=0)throw new Error("Price must be greater than 0");if(r>this.card_reader.max_pre_credit)throw new Error("Price is greater than pre-credit configured");if(!n&&(i===null||i<=0||i>40))throw new Error("Invalid time to dispense without sensor, must be between 0.1 and 40.0 seconds");const c=this.decToHex(r/256),o=this.decToHex(r%256),l=this.decToHex(t+9);let h="00";e&&(h=this.decToHex(e+9));let k="00";n||(k=this.decToHex(i*10));const le=["F1","CD","01",l,h,k,c,o,"00","00","F2","00"];await a(this,s,p).call(this,le,"card-reader:dispense")}async paymentPursesDisable({coin:t=!0,banknote:e=!0,cardReader:n=!1}={}){t&&await this.coinPurseDisable(),e&&await this.banknotePurseDisable(),n&&await this.cardReaderDisable()}async paymentPursesEnable({coin:t=!0,banknote:e=!0,scrowBanknote:n=!1}={}){t&&await this.coinPurseEnable(),e&&await this.banknotePurseEnable({scrow:n})}async coolingRelayConfigure({enable:t=!1}={}){const n=["F1","CC",t?"01":"00","00","00","00","00","00","00","00","F2","00"];return await a(this,s,p).call(this,n,"status:relay")}async coolingRelayEnable(){return await this.coolingRelayConfigure({enable:!0})}async coolingRelayDisable(){return await this.coolingRelayConfigure({enable:!1})}async readTemperature(){const t=["F1","CB","00","00","00","00","00","00","00","00","F2","00"];return await a(this,s,p).call(this,t,"status:temperature")}async dispense({selection:t=1,second_selection:e=null,sensor:n=!0,seconds:i=null,retry:r=!0}={}){if(t=parseInt(t),isNaN(t)||t<1||t>80)throw new Error("Invalid channel number");if(e!==null&&(e<1||e>80||e===t))throw new Error("Invalid second channel number");if(!n&&(i===null||i<=0||i>40))throw new Error("Invalid time to dispense without sensor, must be between 0.1 and 40.0 seconds");r&&(this.__internal__.dispense.backup_dispense={selection:t,second_selection:e,sensor:n,seconds:i}),t+=9;const c=this.decToHex(t);let o="00";e&&(e+=9,o=this.decToHex(e));let l="00";n||(l=this.decToHex(Math.round(i*6.2)),this.__internal__.dispense.custom_limit_counter=i);const h=a(this,s,T).call(this,["F1","C7",c,o,l,"00","00","00","00","00","F2","00"]);let k=await this.internalDispense(h);return!k.dispensed&&r&&(k=await this.internalDispense(h)),this.__internal__.dispense.custom_limit_counter=null,k}async testEngines({singleEngine:t=!1}={}){if(this.isDispensing)throw new Error("Another dispensing process is running");if(v(this,w))throw new Error("Another test is running");a(this,s,S).call(this),_(this,w,!0);const e=[];a(this,s,I).call(this);for(let n=1;n<=80;n++){const i=await this.dispense({selection:n,second_selection:t?null:n+1,sensor:!1,seconds:.4,retry:!1});e.push(i),_(this,f,n),a(this,s,I).call(this),t||n++}_(this,f,80),a(this,s,I).call(this,{dispensed:e}),a(this,s,S).call(this)}async sendCustomCode({code:t=[]}={}){if(t.length===0)throw new Error("Invalid code");const e=a(this,s,T).call(this,t);await this.appendToQueue(e,"custom")}hasToReturnChange(t=0){let e=t;return e<=0?!0:(e=a(this,s,P).call(this,e).pending,e=a(this,s,E).call(this,e).pending,!(e>0))}async returnChange(){return await a(this,s,q).call(this)}async returnInsertedMoney(){return this.__money_session.inserted<=0?!1:await a(this,s,q).call(this,this.__money_session.inserted)}async serialCorruptMessage(t,e){this.dispatch("corrupt:message",{data:t,message:e})}}w=new WeakMap,f=new WeakMap,y=new WeakMap,s=new WeakSet,D=function(){const t=["banknote-purse:banknote-scrow-status","banknote-purse:config","banknote-purse:event-banknote","banknote-purse:read-memory","banknote-purse:recycler","banknote-purse:save-memory","card-reader:event","change:pending","change:dispense","coin-purse:coin-event","coin-purse:config","coin-purse:reject-lever","coin-purse:reset","coin-purse:tubes","percentage:test","run:default-load","session:money-dispensed","session:money-request","event:door","door:event","status:relay","status:temperature"];for(const e of t)this.serialRegisterAvailableListener(e)},H=function(){R.c.add(this)},x=function(){return this.__banknote_purse.isRecycler&&this.__banknote_purse.recycler.ict},N=function(){return this.hasCoinPurse||this.hasRecycler},O=function(t){return t.name="Connection with the serial device completed.",t.description="Your connection with the serial device was successfully completed.",t.no_code=1,this.dispatch("run:default-load",{}),t},j=function(t){const e={g50:["40","50","60","70","90"],c50:["41","51","61","71","91"],p1:["42","52","62","72","92"],p2:["43","53","63","73","93"],p5:["44","54","64","74","94"],p10:["45","55","65","75","95"],p20:["47","57","67","77","97"]};let n=null;for(let r in e)if(e[r].includes(t)){n=r;break}return n?[{g50:"50 pennies (the big one)",c0:"50 pennies (the little one)",p1:"1 peso",p2:"2 pesos",p5:"5 pesos",p10:"10 pesos",p20:"20 pesos"}[n],n]:[`Undefined value: ¿${t}?`,null]},U=function(t){return["g50","c50","p1","p2","p5","p10","p20"].includes(t)},A=function(t){const e={p20:["80","90","a0","b0"],p50:["81","91","a1","b1"],p100:["82","92","a2","b2"],p200:["83","93","a3","b3"],p500:["84","94","a4","b4"],p1000:["85","95","a5","b5"]};let n=null;for(let r in e)if(e[r].includes(t)){n=r;break}return n?[{p20:"20 pesos",p50:"50 pesos",p100:"100 pesos",p200:"200 pesos",p500:"500 pesos",p1000:"1000 pesos"}[n],n]:[`Undefined value: ¿${t}?`,null]},L=function(t){return["p20","p50","p100","p200","p500","p1000"].includes(t)},Q=function(t){return["r20","r50","r100"].includes(t)},z=function(){return["r20","r50","r100","r200","r500"][this.__banknote_purse.recycler.banknote]},B=function(t,e,n){if(!t)return;let i=!0;if(a(this,s,U).call(this,t)&&n==="coin"){if(typeof this.coins.tubes[t]>"u")return;e==="tube"?this.coins.tubes[t]+=1:e==="box"&&(this.coins.box[t]+=1);let r=0;["g50","c50"].includes(t)?r=.5:r+=parseInt(t.slice(1)),this.coins.totals[t]+=r,this.__money_session.inserted+=r,this.coins.total+=r}else if(a(this,s,L).call(this,t)&&n==="banknote"){if(typeof this.banknotes.recycler[t]>"u")return;e==="recycler"?this.banknotes.recycler[t]+=1:e==="stacker"&&(this.banknotes.stacker[t]+=1);let r=parseInt(t.slice(1));this.banknotes.totals[t]+=r,this.__money_session.inserted+=r,this.banknotes.total+=r}else if(a(this,s,Q).call(this,t)&&e==="out"&&n==="banknote"){if(typeof this.banknotes.out[t.replace("r","p")]>"u")return;this.banknotes.out[t.replace("r","p")]+=1;let r=parseInt(t.slice(1));this.__money_session.retired+=r,this.banknotes.recycler[t.replace("r","p")]-=1,this.banknotes.total-=r,i=!1,this.dispatch("session:money-dispensed",{type_money:t,retired:r,finish:!1,type:"banknotes"})}i&&this.dispatch("session:money-request",{})},W=function(t,e){const n=parseInt(t[2],16);return e.name="Coin Inserted",e.no_code=2,e.additional={where:null,coin:null},n===1?(e.name="Lever pressed",e.description="Reject lever",e.no_code=100,this.dispatch("coin-purse:reject-lever",{})):n===2?(e.name="Reset coin purse",e.description="The configuration of coin purse was reset",e.no_code=101,this.dispatch("coin-purse:reset",{})):n>=64&&n<=79?(e.name="Coin inserted in profit box",e.additional.where="box"):n>=80&&n<=95?(e.name="Coin inserted in tube",e.additional.where="tube"):n>=96&&n<=111?(e.name="Unused coin",e.description="Something come from coin changer but in MDB Docs is unused",e.additional.where="unused"):n>=112&&n<=127?(e.name="Coin rejected",e.additional.where="rejected"):n>=144&&n<=159?(e.name="Coin dispensed",e.additional.where="out",e.description=`Undefined value: ¿${t[2]}?`):(e.name="Coin inserted",e.description="Undefined status. Without information of this",e.no_code=400),n===1||n===2||n>=160||n>=128&&n<=143||([e.description,e.additional.coin]=a(this,s,j).call(this,t[2]),e.no_code=38+n,a(this,s,B).call(this,e.additional.coin,e.additional.where,"coin"),["tube","out"].includes(e.additional.where)&&this.dispatch("coin-purse:tubes",this.coins.tubes),this.dispatch("coin-purse:coin-event",this.coins)),e},m=function(t,e){const n=parseInt(t[2],16);return e.name="Banknote Inserted",e.no_code=2,e.additional={where:null,banknote:null},n===42?(e.name="Banknote dispensed",e.description="Banknote dispensed by request.",e.additional.banknote=a(this,s,z).call(this),e.additional.where="out",e.no_code=200):n>=128&&n<=143?(e.name="Banknote inserted",e.additional.where="stacker"):n>=144&&n<=159?(e.name="Banknote inserted in pre stacker",e.additional.where="tmp"):n>=160&&n<=175?(e.name="Banknote rejected",e.additional.where="nothing"):n>=176&&n<=191&&(e.name="Banknote inserted",e.additional.where="recycler"),n>=128&&n<=191&&([e.description,e.additional.banknote]=a(this,s,A).call(this,t[2]),e.no_code=74+n),a(this,s,B).call(this,e.additional.banknote,e.additional.where,"banknote"),this.dispatch("banknote-purse:event-banknote",this.banknotes),e},V=function(t,e){const n=parseInt(t,16);return n===1?(e.name="Coin purse enabled",e.description="Configuration complete, enabled",e.no_code=3):n===0?(e.name="Coin purse disabled",e.description="Disabled by system request",e.no_code=4):(e.name="Status unknown",e.description="The response of coin purse doesn't identify successfully",e.no_code=400),this.dispatch("coin-purse:config",{enabled:n===1}),e},Y=function(t,e){const n=parseInt(t[2],16),i=parseInt(t[3],16);return n===0?(e.name="Bill purse disabled",e.description="Configuration complete, disabled"):n===1&&(e.name="Bill purse enabled",e.description="Configuration complete, enabled"),i===0?e.additional.scrow="Scrow disabled, banknote received automatic":i===1&&(e.additional.scrow="Scrow enabled, require manual action"),e.no_code=5,this.dispatch("banknote-purse:config",{enabled:n===1,scrow:i===1}),e},G=function(t,e){e.no_code=6;const[n,i,r,c,o,l]=[parseInt(t[2],16),parseInt(t[3],16),parseInt(t[4],16),parseInt(t[5],16),parseInt(t[6],16),parseInt(t[7],16)];return e.additional={coins:{g50:n,c50:i,p1:r,p2:c,p5:o,p10:l}},this.coins.tubes.g50=n,this.coins.tubes.c50=i,this.coins.tubes.p1=r,this.coins.tubes.p2=c,this.coins.tubes.p5=o,this.coins.tubes.p10=l,this.coins.totals.g50=(this.coins.box.g50+n)*.5,this.coins.totals.c50=(this.coins.box.c50+i)*.5,this.coins.totals.p1=this.coins.box.p1+r,this.coins.totals.p2=(this.coins.box.p2+c)*2,this.coins.totals.p5=(this.coins.box.p5+o)*5,this.coins.totals.p10=(this.coins.box.p10+l)*10,this.coins.total=this.coins.totals.g50+this.coins.totals.c50+this.coins.totals.p1+this.coins.totals.p2+this.coins.totals.p5+this.coins.totals.p10,e.name="Read tubes",e.description="Quantity of coins approximated",this.dispatch("coin-purse:tubes",this.coins.tubes),e},J=function(t,e){e.no_code=7;const[n,i,r,c,o,l]=[parseInt(t[2],16),parseInt(t[3],16),parseInt(t[4],16),parseInt(t[5],16),parseInt(t[6],16),parseInt(t[7],16)];return e.additional={banknotes:{b20:n,b50:i,b100:r,b200:c,b500:o,b1000:l}},this.banknotes.recycler.p20=n,this.banknotes.recycler.p50=i,this.banknotes.recycler.p100=r,this.banknotes.recycler.p200=c,this.banknotes.recycler.p500=o,this.banknotes.recycler.p1000=l,this.banknotes.totals.p20=(this.banknotes.stacker.p20+n)*20,this.banknotes.totals.p50=(this.banknotes.stacker.p50+i)*50,this.banknotes.totals.p100=(this.banknotes.stacker.p100+r)*100,this.banknotes.totals.p200=(this.banknotes.stacker.p200+c)*200,this.banknotes.totals.p500=(this.banknotes.stacker.p500+o)*500,this.banknotes.totals.p1000=(this.banknotes.stacker.p1000+l)*1e3,this.banknotes.total=this.banknotes.totals.p20+this.banknotes.totals.p50+this.banknotes.totals.p100+this.banknotes.totals.p200+this.banknotes.totals.p500+this.banknotes.totals.p1000,e.name="Read recycler",e.description="Quantity of banknotes approximated",this.dispatch("banknote-purse:recycler",this.banknotes.recycler),e},K=function(t,e){const n=parseInt(t,16);return n===1?e.name="Banknote accepted":n===0?e.name="Banknote rejected":e.name="Unknown status banknote",e.no_code=8,this.dispatch("banknote-purse:banknote-scrow-status",{status:n===1}),e},X=function(t,e){const[n,i,r,c,o,l]=[parseInt(t[2],16),parseInt(t[3],16),parseInt(t[4],16),parseInt(t[5],16),parseInt(t[6],16),parseInt(t[7],16)],h=n*20+i*50+r*100+c*200+o*500+l*1e3;return e.name="Banknotes dispensed",e.description=h>0?"Banknotes dispensed by request":"No banknotes dispensed, recycler empty",e.no_code=9,e.additional={banknotes:{b20:n,b50:i,b100:r,b200:c,b500:o,b1000:l},total_dispensed:h},this.dispatch("session:money-dispensed",{type_money:null,retired:null,finish:!1,type:"banknotes",data:e}),e},Z=function(t,e){return e.name="Coins dispensed",e.no_code=10,e.description="Coins dispensed by request",isNaN(this.__sale.last_change)&&(this.__sale.last_change=0),this.__money_session.retired+=this.__sale.last_change,this.dispatchAsync("session:money-dispensed",{type_money:null,retired:null,finish:!1,type:"coins"},500),e},g=function(t,e){const n=parseInt(t,16);return n===1?(e.name="Product not delivered",e.description="The product requested wasn't delivered",e.no_code=11,this.__internal__.dispense.status=!1):n===0?(e.name="Product delivered",e.description="The product requested was delivered",e.no_code=12,this.__internal__.dispense.status=!0):(e.name="Unknown status product",e.description="The response of product doesn't identify successfully",e.no_code=400,this.__internal__.dispense.status=!1),this.dispatch("dispensed",{}),e},$=function(t,e){let n="closed";return t==="db"?(e.name="Door closed",e.no_code=13):t==="dc"?(e.name="Door open",e.no_code=14,n="open"):(e.name="Unknown status door",e.description="The response of door doesn't identify successfully",e.no_code=400,n="unknown"),this.__internal__.device.door_open=n==="open",this.dispatch("event:door",{open:n==="open"}),this.dispatch("door:event",{open:n==="open"}),e},ee=function(t,e){const n=parseInt(t[2],16)*255,i=parseInt(t[3],16),r=(n+i)*.1;return e.no_code=15,e.name="Temperature status",e.description=`Temperature: ${r}`,e.additional={high:n,low:i,temperature:parseFloat(r.toString())},this.dispatch("status:temperature",e.additional),e},te=function(t,e){const n=parseInt(t,16);let i="unknown";return n===1?(e.name="Relay on",e.description="Relay on",e.no_code=16,i="on"):n===0?(e.name="Relay off",e.description="Relay off",e.no_code=17,i="off"):(e.name="Status unknown",e.description="Status unknown",e.no_code=400),this.dispatch("status:relay",{enabled:i==="on"}),e},ne=function(t,e){const n=parseInt(t[2],16);if(e.no_code=20+n,e.name="Status unknown",e.description="The status of card reader does not identified correctly",n===0)e.request+=":disable",e.name="Card reader disabled",e.description="Card reader device was disabled successfully";else if(n===1||n===2)e.request+=":dispense",e.name="Card reader enabled",e.description="Card reader device is now enabled";else if(n===3)e.request+=":pre-authorize",e.name="Pre-authorized credit",e.description="The pre credit was authorized successfully";else if(n===4)e.request+=":cancel",e.name="Cancellation in progress",e.description="Cancellation request done successfully";else if(n===5)e.request+=":sell",e.name="Sell approved",e.description="Sell approved, starting dispense product";else if(n===6)e.request+=":sell",e.name="Sell denied",e.description="This sell was denied, try again";else if(n===7)e.request+=":end",e.name="Session ended",e.description="The session ended";else if(n===8)e.request+=":cancel",e.name="Cancelled",e.description="Cancellation complete";else if(n===10){const i=parseInt(t[8],16);i===1?(e.no_code=30,e.name="product not dispensed",e.description="The product requested wasn't delivered"):i===0?(e.no_code=31,e.name="product dispensed",e.description="The product requested was delivered"):(e.name="finished-unknown",e.no_code=400)}else e.no_code=400;return this.dispatch("card-reader:event",e),e},p=function(t,e){return this.appendToQueue(a(this,s,T).call(this,t),e)},T=function(t){return t[11]=this.serialBoardroidSumHex(t),t.map((e,n)=>{t[n]=this.hexMaker(e)}),t},se=function({enable:t=!1,scrow:e=!1}={}){const n=t?"FF":"00",i=e?"FF":"00";return["F1","C0",n,n,i,i,"00","00","00","00","F2","00"]},ie=function({enable:t=!1,scrow:e=!1}={}){return["F1","C0",t?"01":"00",e?"01":"00","00","00","00","00","00","00","F2","00"]},re=function(t=1){if(t<1)throw new Error("No banknotes to dispense");return t=this.decToHex(t),["F1","C5",this.decToHex(this.__banknote_purse.recycler.banknote.toString()),t,"00","00","00","00","00","00","F2","00"]},ae=function({$_20:t=0,$_50:e=0,$_100:n=0,$_200:i=0,$_500:r=0,$_1000:c=0}={}){if([t,e,n,i,r,c].some(o=>isNaN(o)||typeof o=="string"))throw new Error("One of the values is not a number");if(t<1&&e<1&&n<1&&i<1&&r<1&&c<1)throw new Error("No banknotes to dispense");return[t,e,n,i,r,c]=[this.decToHex(t),this.decToHex(e),this.decToHex(n),this.decToHex(i),this.decToHex(r),this.decToHex(c)],["F1","C5",t,e,n,i,r,c,"00","00","F2","00"]},S=function(){_(this,w,!1),_(this,f,0),_(this,y,0)},I=function({dispensed:t=null,limit:e=80}={}){_(this,y,Math.round(v(this,f)*100/e)),this.dispatch("percentage:test",{percentage:v(this,y),dispensed:t})},oe=function(t){const e=["20","50","100","200","500"],n=this.__banknote_purse.recycler.banknote,i="$_"+e[n],r=parseInt(e[n]),c=this.banknotes.recycler[`p${e[n]}`],o=Math.min(Math.floor(t/r),c),l={banknotes:{$_20:0,$_50:0,$_100:0,$_200:0,$_500:0,$_1000:0},pending:t,will_dispense:o>0};return this.totalInRecycler===0||o<1||t===0||(l.banknotes[i]=o,l.pending=parseFloat((t-o*r).toFixed(2))),l},ce=function(t){const e={banknotes:{$_20:0,$_50:0,$_100:0,$_200:0,$_500:0,$_1000:0},pending:t,will_dispense:!1};if(this.totalInRecycler===0||t===0)return e;const n=(i,r)=>{if(this.banknotes.recycler[r]>0){const c=Math.floor(e.pending/i),o=Math.min(c,this.banknotes.recycler[r]);e.banknotes[`$_${i}`]=o,e.pending=parseFloat((e.pending-o*i).toFixed(2))}};return n(1e3,"p1000"),n(500,"p500"),n(200,"p200"),n(100,"p100"),n(50,"p50"),n(20,"p20"),e.will_dispense=Object.values(e.banknotes).some(i=>i>0),e},P=function(t){return this.hasRecycler?a(this,s,x).call(this)?a(this,s,oe).call(this,t):a(this,s,ce).call(this,t):{banknotes:{$_20:0,$_50:0,$_100:0,$_200:0,$_500:0,$_1000:0},pending:t,will_dispense:!1}},E=function(t){const e={coins:{$_50c:0,$_1:0,$_2:0,$_5:0,$_10:0},pending:t,will_dispense:!1};if(!this.hasCoinPurse||t<=0||this.totalInTubes===0)return e;const n=(i,r,c=null)=>{if(this.coins.tubes[r]>0){c===null&&(c="$_"+i);const o=Math.floor(e.pending/i),l=Math.min(o,this.coins.tubes[r]);e.coins[c]=l,e.pending=parseFloat((e.pending-l*i).toFixed(2))}};return n(10,"p10"),n(5,"p5"),n(2,"p2"),n(1,"p1"),n(.5,"g50","$_50c"),e.will_dispense=Object.values(e.coins).some(i=>i>0),e},q=async function(t=null){if(!a(this,s,N).call(this))throw new Error("Change not available");let e=this.change,n=this.change;if(t!==null&&(e=t,n=t),n<=0)return!1;const i=a(this,s,P).call(this,n);n=i.pending;const r=a(this,s,E).call(this,n);return n=r.pending,n>0&&this.dispatch("change:pending",{pending:n}),this.dispatch("change:dispense",{recycler:i.banknotes,coins:r.coins,pending:n,delivery:e-n}),n===e?!1:(i.will_dispense&&await this.banknotePurseDispense(i.banknotes),r.will_dispense&&await this.coinPurseDispense(r.coins),!0)};exports.Boardroid=pe;
1
+ "use strict";var de=Object.defineProperty;var M=d=>{throw TypeError(d)};var ue=(d,u,t)=>u in d?de(d,u,{enumerable:!0,configurable:!0,writable:!0,value:t}):d[u]=t;var b=(d,u,t)=>ue(d,typeof u!="symbol"?u+"":u,t),F=(d,u,t)=>u.has(d)||M("Cannot "+t);var v=(d,u,t)=>(F(d,u,"read from private field"),t?t.call(d):u.get(d)),C=(d,u,t)=>u.has(d)?M("Cannot add the same private member more than once"):u instanceof WeakSet?u.add(d):u.set(d,t),_=(d,u,t,e)=>(F(d,u,"write to private field"),e?e.call(d,t):u.set(d,t),t),a=(d,u,t)=>(F(d,u,"access private method"),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const R=require("./kernel-C0epz_jB.cjs");var w,f,y,s,D,H,x,N,O,j,U,A,L,Q,z,B,W,m,V,Y,G,J,K,X,Z,g,$,ee,te,ne,p,T,se,ie,re,ae,S,I,oe,ce,P,E,q;class pe extends R.Kernel{constructor({filters:t=null,config_port:e=null,no_device:n=1}={}){super({filters:t,config_port:e,no_device:n});C(this,s);b(this,"__coin_purse",{available:!0});b(this,"__banknote_purse",{available:!0,isRecycler:!0,recycler:{ict:!0,banknote:1}});b(this,"__sale",{price:0,change:0,change_verified:0,dispense_all:!0,last_change:0,clear(){this.price=0,this.change=0,this.change_verified=0,this.dispense_all=!0,this.last_change=0}});b(this,"__money_session",{inserted:0,retired:0,clear(){this.inserted=0,this.retired=0}});b(this,"coins",{tubes:{g50:0,c50:0,p1:0,p2:0,p5:0,p10:0},box:{g50:0,c50:0,p1:0,p2:0,p5:0,p10:0},totals:{g50:0,c50:0,p1:0,p2:0,p5:0,p10:0},total:0});b(this,"banknotes",{stacker:{p20:0,p50:0,p100:0,p200:0,p500:0,p1000:0},recycler:{p20:0,p50:0,p100:0,p200:0,p500:0,p1000:0},out:{p20:0,p50:0,p100:0,p200:0,p500:0,p1000:0},totals:{p20:0,p50:0,p100:0,p200:0,p500:0,p1000:0},total:0});b(this,"card_reader",{available:!1,max_pre_credit:0});C(this,w,!1);C(this,f,0);C(this,y,0);if(this.__internal__.device.type="boardroid",R._.getCustom(this.typeDevice,n))throw new Error(`Device ${this.typeDevice} ${n} already exists`);this.__internal__.serial.config_port.baudRate=115200,this.__internal__.serial.response.length=14,this.__internal__.time.response_connection=600,this.__internal__.time.response_general=4e3,this.__internal__.time.response_engines=15e3,this.__internal__.dispense.limit_counter=15,this.__internal__.dispense.custom_limit_counter=null,this.__internal__.dispense.backup_dispense={channel:1,second_channel:null,sensor:!0,seconds:null},a(this,s,D).call(this),a(this,s,H).call(this)}get totalInTubes(){return this.coins.tubes.g50*.5+this.coins.tubes.c50*.5+this.coins.tubes.p1+this.coins.tubes.p2*2+this.coins.tubes.p5*5+this.coins.tubes.p10*10}get totalInRecycler(){return this.banknotes.recycler.p20*20+this.banknotes.recycler.p50*50+this.banknotes.recycler.p100*100+this.banknotes.recycler.p200*200+this.banknotes.recycler.p500*500+this.banknotes.recycler.p1000*1e3}get hasRecycler(){return this.__banknote_purse.available&&this.__banknote_purse.isRecycler}set hasRecycler(t){this.__banknote_purse.isRecycler=t}get hasICT(){return this.hasRecycler&&this.__banknote_purse.recycler.ict}set hasICT(t){this.__banknote_purse.recycler.ict=t}set banknoteICT(t){if(![20,50,100,200,500].includes(t))throw new Error(`Invalid banknote value: ${t}`);t=[20,50,100,200,500].indexOf(t),this.__banknote_purse.recycler.banknote=t}get banknoteICT(){return[20,50,100,200,500][this.__banknote_purse.recycler.banknote]}get hasCoinPurse(){return this.__coin_purse.available}set hasCoinPurse(t){if(typeof t!="boolean")throw new Error(`Invalid value: ${t}`);this.__coin_purse.available=t}set price(t){let e=parseFloat(t);(isNaN(e)||e<0)&&(e=0),this.__sale.price=e}get price(){return this.__sale.price}get change(){return this.__sale.price<=0||this.__money_session.inserted<=this.__sale.price?0:this.__money_session.inserted-this.__sale.price}softReload(){super.softReload(),this.__sale.clear(),this.__money_session.clear()}serialBoardroidSumHex(t){let e=0;return t.forEach((n,i)=>{i!==0&&i!==11&&(e+=parseInt(n,16))}),e.toString(16).toUpperCase()}serialMessage(t){let e={code:t,name:null,description:null,request:null,no_code:0};const n=(5+this.deviceNumber).toString(16).padStart(2,"0").toLowerCase();switch(t[1]){case n:e.request="connect",e=a(this,s,O).call(this,e);break;case"a0":e.request="--automatic",e=a(this,s,W).call(this,t,e);break;case"b0":e.request="--automatic",e=a(this,s,m).call(this,t,e);break;case"d0":e.request="coin-purse:config",e=a(this,s,V).call(this,t[2],e);break;case"d1":e.request="banknote-purse:config",e.additional={scrow:null},e=a(this,s,Y).call(this,t,e);break;case"d2":e.request="coin-purse:read-tubes",e=a(this,s,G).call(this,t,e);break;case"d3":e.request="banknote-purse:read-recycler",e=a(this,s,J).call(this,t,e);break;case"d4":e.request="banknote-purse:banknote-scrow-status",e=a(this,s,K).call(this,t[2],e);break;case"d5":e.request="banknote-purse:dispense",e=a(this,s,X).call(this,t,e);break;case"d6":e.request="coin-purse:dispense",e=a(this,s,Z).call(this,t,e);break;case"d7":e.request="dispense",e=a(this,s,g).call(this,t[5],e);break;case"d8":e.request="--automatic",e=a(this,s,$).call(this,t[13],e);break;case"d9":e.request="status:temperature",e=a(this,s,ee).call(this,t,e);break;case"da":e.request="status:relay",e=a(this,s,te).call(this,t[2],e);break;case"db":e.request="banknote-purse:save-memory",e.no_code=18,e.name="Bill purse memory saved?",e.description="The memory of bill purse was saved successfully?",this.dispatch("banknote-purse:save-memory",{message:e});break;case"dc":e.request="coin-purse:read-memory",e.no_code=19,e.name="Coin purse memory read?",e.description="The memory of coin purse was read successfully?",this.dispatch("banknote-purse:read-memory",{message:e});break;case"dd":e.request="card-reader",a(this,s,ne).call(this,t,e);break;default:e.request="--unknown",e.name="Response unrecognized",e.description="The response of application was received, but dont identify with any of current parameters",e.no_code=400,this.dispatch("unknown",e);break}this.dispatch("serial:message",e)}serialSetConnectionConstant(t=1){let e=["F1","06","00","00","00","00","00","00","00","00","F2","F8"];return e[1]=this.hexMaker(this.decToHex((5+t).toString())),e[11]=this.serialBoardroidSumHex(e),this.add0x(e)}async coinPurseConfigure({enable:t=!1,high:e="FF",low:n="FF"}={}){if(!this.__coin_purse.available)throw new Error("Coin purse not available");const r=["F1","C1",t?"01":"00",e,n,"00","00","00","00","00","F2","00"];await a(this,s,p).call(this,r,"coin-purse:config")}async coinPurseEnable(){await this.coinPurseConfigure({enable:!0})}async coinPurseDisable(){await this.coinPurseConfigure({enable:!1})}async coinPurseDispense({$_50c:t=0,$_1:e=0,$_2:n=0,$_5:i=0,$_10:r=0}={}){if(!this.__coin_purse.available)throw new Error("Coin purse not available");if([t,e,n,i,r].some(o=>isNaN(o)||typeof o=="string"))throw new Error("One of the values is not a number");if(t<1&&e<1&&n<1&&i<1&&r<1)throw new Error("No coins to dispense");[t,e,n,i,r]=[this.decToHex(t),this.decToHex(e),this.decToHex(n),this.decToHex(i),this.decToHex(r)];let c=["F1","C6",t,e,n,i,r,"00","00","00","F2","00"];await a(this,s,p).call(this,c,"coin-purse:dispense")}async coinPurseReadTubes(){const t=["F1","C2","00","00","00","00","00","00","00","00","F2","00"];await a(this,s,p).call(this,t,"coin-purse:read-tubes")}async banknotePurseConfigure({enable:t=!1,scrow:e=!1}={}){if(!this.__banknote_purse.available)throw new Error("Banknote purse not available");let n;return a(this,s,x).call(this)?n=a(this,s,se).call(this,{enable:t,scrow:e}):n=a(this,s,ie).call(this,{enable:t,scrow:e}),await a(this,s,p).call(this,n,"banknote-purse:config")}async banknotePurseDispense({$_20:t=0,$_50:e=0,$_100:n=0,$_200:i=0,$_500:r=0,$_1000:c=0}={}){if(!this.__banknote_purse.available)throw new Error("Banknote purse not available");if(!this.__banknote_purse.isRecycler)throw new Error("Banknote purse is not recycler");let o;if(a(this,s,x).call(this)){const l=[t,e,n,i,r];o=a(this,s,re).call(this,l[this.__banknote_purse.recycler.banknote])}else o=a(this,s,ae).call(this,{$_20:t,$_50:e,$_100:n,$_200:i,$_500:r,$_1000:c});await a(this,s,p).call(this,o,"banknote-purse:dispense")}async banknotePurseEnable({scrow:t=!1}){return await this.banknotePurseConfigure({enable:!0,scrow:t})}async banknotePurseDisable(){return await this.banknotePurseConfigure({enable:!1})}async banknotePurseAcceptInScrow(){if(!this.__banknote_purse.available)throw new Error("Banknote purse not available");const t=["F1","C4","01","00","00","00","00","00","00","00","F2","00"];await a(this,s,p).call(this,t,"banknote-purse:banknote-scrow-status")}async banknotePurseRejectInScrow(){if(!this.__banknote_purse.available)throw new Error("Banknote purse not available");const t=["F1","C4","00","00","00","00","00","00","00","00","F2","00"];await a(this,s,p).call(this,t,"banknote-purse:banknote-scrow-status")}async banknotePurseSaveMemory({channel:t=null,$_20:e=null,$_50:n=null,$_100:i=null,$_200:r=null,$_500:c=null,$_1000:o=null}={}){if(!this.__banknote_purse.available)throw new Error("Banknote purse not available");if(t===null||e===null||n===null||i===null||r===null||c===null||o===null)throw new Error("One of the values is not defined");const l=["F1","C8",this.decToHex(t),"00",this.decToHex(e),this.decToHex(n),this.decToHex(i),this.decToHex(r),this.decToHex(c),this.decToHex(o),"F2","00"];await a(this,s,p).call(this,l,"banknote-purse:save-memory")}async banknotePurseReadRecycler(){if(!this.__banknote_purse.available)throw new Error("Banknote purse not available");if(!this.__banknote_purse.isRecycler)throw new Error("Banknote purse is not recycler");const t=["F1","C3","00","00","00","00","00","00","00","00","F2","B5"];return await a(this,s,p).call(this,t,"banknote-purse:read-recycler")}async cardReaderDisable(){if(!this.card_reader.available)throw new Error("Card reader not available");const t=["F1","CD","00","00","00","00","00","00","00","00","F2","00"];return await a(this,s,p).call(this,t,"card-reader:disable")}async cardReaderDispense({channel:t=1,second_channel:e=null,sensor:n=!0,seconds:i=null,price:r=0}={}){if(!this.card_reader.available)throw new Error("Card reader not available");if(isNaN(this.card_reader.max_pre_credit)||this.card_reader.max_pre_credit===0)throw new Error("Card reader pre-credit not configured");if(isNaN(r)||r<=0)throw new Error("Price must be greater than 0");if(r>this.card_reader.max_pre_credit)throw new Error("Price is greater than pre-credit configured");if(!n&&(i===null||i<=0||i>40))throw new Error("Invalid time to dispense without sensor, must be between 0.1 and 40.0 seconds");const c=this.decToHex(r/256),o=this.decToHex(r%256),l=this.decToHex(t+9);let h="00";e&&(h=this.decToHex(e+9));let k="00";n||(k=this.decToHex(i*10));const le=["F1","CD","01",l,h,k,c,o,"00","00","F2","00"];await a(this,s,p).call(this,le,"card-reader:dispense")}async paymentPursesDisable({coin:t=!0,banknote:e=!0,cardReader:n=!1}={}){t&&await this.coinPurseDisable(),e&&await this.banknotePurseDisable(),n&&await this.cardReaderDisable()}async paymentPursesEnable({coin:t=!0,banknote:e=!0,scrowBanknote:n=!1}={}){t&&await this.coinPurseEnable(),e&&await this.banknotePurseEnable({scrow:n})}async coolingRelayConfigure({enable:t=!1}={}){const n=["F1","CC",t?"01":"00","00","00","00","00","00","00","00","F2","00"];return await a(this,s,p).call(this,n,"status:relay")}async coolingRelayEnable(){return await this.coolingRelayConfigure({enable:!0})}async coolingRelayDisable(){return await this.coolingRelayConfigure({enable:!1})}async readTemperature(){const t=["F1","CB","00","00","00","00","00","00","00","00","F2","00"];return await a(this,s,p).call(this,t,"status:temperature")}async dispense({selection:t=1,second_selection:e=null,sensor:n=!0,seconds:i=null,retry:r=!0}={}){if(t=parseInt(t),isNaN(t)||t<1||t>80)throw new Error("Invalid channel number");if(e!==null&&(e<1||e>80||e===t))throw new Error("Invalid second channel number");if(!n&&(i===null||i<=0||i>40))throw new Error("Invalid time to dispense without sensor, must be between 0.1 and 40.0 seconds");r&&(this.__internal__.dispense.backup_dispense={selection:t,second_selection:e,sensor:n,seconds:i}),t+=9;const c=this.decToHex(t);let o="00";e&&(e+=9,o=this.decToHex(e));let l="00";n||(l=this.decToHex(Math.round(i*6.2)),this.__internal__.dispense.custom_limit_counter=i);const h=a(this,s,T).call(this,["F1","C7",c,o,l,"00","00","00","00","00","F2","00"]);let k=await this.internalDispense(h);return!k.dispensed&&r&&(k=await this.internalDispense(h)),this.__internal__.dispense.custom_limit_counter=null,k}async testEngines({singleEngine:t=!1}={}){if(this.isDispensing)throw new Error("Another dispensing process is running");if(v(this,w))throw new Error("Another test is running");a(this,s,S).call(this),_(this,w,!0);const e=[];a(this,s,I).call(this);for(let n=1;n<=80;n++){const i=await this.dispense({selection:n,second_selection:t?null:n+1,sensor:!1,seconds:.4,retry:!1});e.push(i),_(this,f,n),a(this,s,I).call(this),t||n++}_(this,f,80),a(this,s,I).call(this,{dispensed:e}),a(this,s,S).call(this)}async sendCustomCode({code:t=[]}={}){if(t.length===0)throw new Error("Invalid code");const e=a(this,s,T).call(this,t);await this.appendToQueue(e,"custom")}hasToReturnChange(t=0){let e=t;return e<=0?!0:(e=a(this,s,P).call(this,e).pending,e=a(this,s,E).call(this,e).pending,!(e>0))}async returnChange(){return await a(this,s,q).call(this)}async returnInsertedMoney(){return this.__money_session.inserted<=0?!1:await a(this,s,q).call(this,this.__money_session.inserted)}async serialCorruptMessage(t,e){this.dispatch("corrupt:message",{data:t,message:e})}}w=new WeakMap,f=new WeakMap,y=new WeakMap,s=new WeakSet,D=function(){const t=["banknote-purse:banknote-scrow-status","banknote-purse:config","banknote-purse:event-banknote","banknote-purse:read-memory","banknote-purse:recycler","banknote-purse:save-memory","card-reader:event","change:pending","change:dispense","coin-purse:coin-event","coin-purse:config","coin-purse:reject-lever","coin-purse:reset","coin-purse:tubes","percentage:test","run:default-load","session:money-dispensed","session:money-request","event:door","door:event","status:relay","status:temperature"];for(const e of t)this.serialRegisterAvailableListener(e)},H=function(){R._.add(this)},x=function(){return this.__banknote_purse.isRecycler&&this.__banknote_purse.recycler.ict},N=function(){return this.hasCoinPurse||this.hasRecycler},O=function(t){return t.name="Connection with the serial device completed.",t.description="Your connection with the serial device was successfully completed.",t.no_code=1,this.dispatch("run:default-load",{}),t},j=function(t){const e={g50:["40","50","60","70","90"],c50:["41","51","61","71","91"],p1:["42","52","62","72","92"],p2:["43","53","63","73","93"],p5:["44","54","64","74","94"],p10:["45","55","65","75","95"],p20:["47","57","67","77","97"]};let n=null;for(let r in e)if(e[r].includes(t)){n=r;break}return n?[{g50:"50 pennies (the big one)",c0:"50 pennies (the little one)",p1:"1 peso",p2:"2 pesos",p5:"5 pesos",p10:"10 pesos",p20:"20 pesos"}[n],n]:[`Undefined value: ¿${t}?`,null]},U=function(t){return["g50","c50","p1","p2","p5","p10","p20"].includes(t)},A=function(t){const e={p20:["80","90","a0","b0"],p50:["81","91","a1","b1"],p100:["82","92","a2","b2"],p200:["83","93","a3","b3"],p500:["84","94","a4","b4"],p1000:["85","95","a5","b5"]};let n=null;for(let r in e)if(e[r].includes(t)){n=r;break}return n?[{p20:"20 pesos",p50:"50 pesos",p100:"100 pesos",p200:"200 pesos",p500:"500 pesos",p1000:"1000 pesos"}[n],n]:[`Undefined value: ¿${t}?`,null]},L=function(t){return["p20","p50","p100","p200","p500","p1000"].includes(t)},Q=function(t){return["r20","r50","r100"].includes(t)},z=function(){return["r20","r50","r100","r200","r500"][this.__banknote_purse.recycler.banknote]},B=function(t,e,n){if(!t)return;let i=!0;if(a(this,s,U).call(this,t)&&n==="coin"){if(typeof this.coins.tubes[t]>"u")return;e==="tube"?this.coins.tubes[t]+=1:e==="box"&&(this.coins.box[t]+=1);let r=0;["g50","c50"].includes(t)?r=.5:r+=parseInt(t.slice(1)),this.coins.totals[t]+=r,this.__money_session.inserted+=r,this.coins.total+=r}else if(a(this,s,L).call(this,t)&&n==="banknote"){if(typeof this.banknotes.recycler[t]>"u")return;e==="recycler"?this.banknotes.recycler[t]+=1:e==="stacker"&&(this.banknotes.stacker[t]+=1);let r=parseInt(t.slice(1));this.banknotes.totals[t]+=r,this.__money_session.inserted+=r,this.banknotes.total+=r}else if(a(this,s,Q).call(this,t)&&e==="out"&&n==="banknote"){if(typeof this.banknotes.out[t.replace("r","p")]>"u")return;this.banknotes.out[t.replace("r","p")]+=1;let r=parseInt(t.slice(1));this.__money_session.retired+=r,this.banknotes.recycler[t.replace("r","p")]-=1,this.banknotes.total-=r,i=!1,this.dispatch("session:money-dispensed",{type_money:t,retired:r,finish:!1,type:"banknotes"})}i&&this.dispatch("session:money-request",{})},W=function(t,e){const n=parseInt(t[2],16);return e.name="Coin Inserted",e.no_code=2,e.additional={where:null,coin:null},n===1?(e.name="Lever pressed",e.description="Reject lever",e.no_code=100,this.dispatch("coin-purse:reject-lever",{})):n===2?(e.name="Reset coin purse",e.description="The configuration of coin purse was reset",e.no_code=101,this.dispatch("coin-purse:reset",{})):n>=64&&n<=79?(e.name="Coin inserted in profit box",e.additional.where="box"):n>=80&&n<=95?(e.name="Coin inserted in tube",e.additional.where="tube"):n>=96&&n<=111?(e.name="Unused coin",e.description="Something come from coin changer but in MDB Docs is unused",e.additional.where="unused"):n>=112&&n<=127?(e.name="Coin rejected",e.additional.where="rejected"):n>=144&&n<=159?(e.name="Coin dispensed",e.additional.where="out",e.description=`Undefined value: ¿${t[2]}?`):(e.name="Coin inserted",e.description="Undefined status. Without information of this",e.no_code=400),n===1||n===2||n>=160||n>=128&&n<=143||([e.description,e.additional.coin]=a(this,s,j).call(this,t[2]),e.no_code=38+n,a(this,s,B).call(this,e.additional.coin,e.additional.where,"coin"),["tube","out"].includes(e.additional.where)&&this.dispatch("coin-purse:tubes",this.coins.tubes),this.dispatch("coin-purse:coin-event",this.coins)),e},m=function(t,e){const n=parseInt(t[2],16);return e.name="Banknote Inserted",e.no_code=2,e.additional={where:null,banknote:null},n===42?(e.name="Banknote dispensed",e.description="Banknote dispensed by request.",e.additional.banknote=a(this,s,z).call(this),e.additional.where="out",e.no_code=200):n>=128&&n<=143?(e.name="Banknote inserted",e.additional.where="stacker"):n>=144&&n<=159?(e.name="Banknote inserted in pre stacker",e.additional.where="tmp"):n>=160&&n<=175?(e.name="Banknote rejected",e.additional.where="nothing"):n>=176&&n<=191&&(e.name="Banknote inserted",e.additional.where="recycler"),n>=128&&n<=191&&([e.description,e.additional.banknote]=a(this,s,A).call(this,t[2]),e.no_code=74+n),a(this,s,B).call(this,e.additional.banknote,e.additional.where,"banknote"),this.dispatch("banknote-purse:event-banknote",this.banknotes),e},V=function(t,e){const n=parseInt(t,16);return n===1?(e.name="Coin purse enabled",e.description="Configuration complete, enabled",e.no_code=3):n===0?(e.name="Coin purse disabled",e.description="Disabled by system request",e.no_code=4):(e.name="Status unknown",e.description="The response of coin purse doesn't identify successfully",e.no_code=400),this.dispatch("coin-purse:config",{enabled:n===1}),e},Y=function(t,e){const n=parseInt(t[2],16),i=parseInt(t[3],16);return n===0?(e.name="Bill purse disabled",e.description="Configuration complete, disabled"):n===1&&(e.name="Bill purse enabled",e.description="Configuration complete, enabled"),i===0?e.additional.scrow="Scrow disabled, banknote received automatic":i===1&&(e.additional.scrow="Scrow enabled, require manual action"),e.no_code=5,this.dispatch("banknote-purse:config",{enabled:n===1,scrow:i===1}),e},G=function(t,e){e.no_code=6;const[n,i,r,c,o,l]=[parseInt(t[2],16),parseInt(t[3],16),parseInt(t[4],16),parseInt(t[5],16),parseInt(t[6],16),parseInt(t[7],16)];return e.additional={coins:{g50:n,c50:i,p1:r,p2:c,p5:o,p10:l}},this.coins.tubes.g50=n,this.coins.tubes.c50=i,this.coins.tubes.p1=r,this.coins.tubes.p2=c,this.coins.tubes.p5=o,this.coins.tubes.p10=l,this.coins.totals.g50=(this.coins.box.g50+n)*.5,this.coins.totals.c50=(this.coins.box.c50+i)*.5,this.coins.totals.p1=this.coins.box.p1+r,this.coins.totals.p2=(this.coins.box.p2+c)*2,this.coins.totals.p5=(this.coins.box.p5+o)*5,this.coins.totals.p10=(this.coins.box.p10+l)*10,this.coins.total=this.coins.totals.g50+this.coins.totals.c50+this.coins.totals.p1+this.coins.totals.p2+this.coins.totals.p5+this.coins.totals.p10,e.name="Read tubes",e.description="Quantity of coins approximated",this.dispatch("coin-purse:tubes",this.coins.tubes),e},J=function(t,e){e.no_code=7;const[n,i,r,c,o,l]=[parseInt(t[2],16),parseInt(t[3],16),parseInt(t[4],16),parseInt(t[5],16),parseInt(t[6],16),parseInt(t[7],16)];return e.additional={banknotes:{b20:n,b50:i,b100:r,b200:c,b500:o,b1000:l}},this.banknotes.recycler.p20=n,this.banknotes.recycler.p50=i,this.banknotes.recycler.p100=r,this.banknotes.recycler.p200=c,this.banknotes.recycler.p500=o,this.banknotes.recycler.p1000=l,this.banknotes.totals.p20=(this.banknotes.stacker.p20+n)*20,this.banknotes.totals.p50=(this.banknotes.stacker.p50+i)*50,this.banknotes.totals.p100=(this.banknotes.stacker.p100+r)*100,this.banknotes.totals.p200=(this.banknotes.stacker.p200+c)*200,this.banknotes.totals.p500=(this.banknotes.stacker.p500+o)*500,this.banknotes.totals.p1000=(this.banknotes.stacker.p1000+l)*1e3,this.banknotes.total=this.banknotes.totals.p20+this.banknotes.totals.p50+this.banknotes.totals.p100+this.banknotes.totals.p200+this.banknotes.totals.p500+this.banknotes.totals.p1000,e.name="Read recycler",e.description="Quantity of banknotes approximated",this.dispatch("banknote-purse:recycler",this.banknotes.recycler),e},K=function(t,e){const n=parseInt(t,16);return n===1?e.name="Banknote accepted":n===0?e.name="Banknote rejected":e.name="Unknown status banknote",e.no_code=8,this.dispatch("banknote-purse:banknote-scrow-status",{status:n===1}),e},X=function(t,e){const[n,i,r,c,o,l]=[parseInt(t[2],16),parseInt(t[3],16),parseInt(t[4],16),parseInt(t[5],16),parseInt(t[6],16),parseInt(t[7],16)],h=n*20+i*50+r*100+c*200+o*500+l*1e3;return e.name="Banknotes dispensed",e.description=h>0?"Banknotes dispensed by request":"No banknotes dispensed, recycler empty",e.no_code=9,e.additional={banknotes:{b20:n,b50:i,b100:r,b200:c,b500:o,b1000:l},total_dispensed:h},this.dispatch("session:money-dispensed",{type_money:null,retired:null,finish:!1,type:"banknotes",data:e}),e},Z=function(t,e){return e.name="Coins dispensed",e.no_code=10,e.description="Coins dispensed by request",isNaN(this.__sale.last_change)&&(this.__sale.last_change=0),this.__money_session.retired+=this.__sale.last_change,this.dispatchAsync("session:money-dispensed",{type_money:null,retired:null,finish:!1,type:"coins"},500),e},g=function(t,e){const n=parseInt(t,16);return n===1?(e.name="Product not delivered",e.description="The product requested wasn't delivered",e.no_code=11,this.__internal__.dispense.status=!1):n===0?(e.name="Product delivered",e.description="The product requested was delivered",e.no_code=12,this.__internal__.dispense.status=!0):(e.name="Unknown status product",e.description="The response of product doesn't identify successfully",e.no_code=400,this.__internal__.dispense.status=!1),this.dispatch("dispensed",{}),e},$=function(t,e){let n="closed";return t==="db"?(e.name="Door closed",e.no_code=13):t==="dc"?(e.name="Door open",e.no_code=14,n="open"):(e.name="Unknown status door",e.description="The response of door doesn't identify successfully",e.no_code=400,n="unknown"),this.__internal__.device.door_open=n==="open",this.dispatch("event:door",{open:n==="open"}),this.dispatch("door:event",{open:n==="open"}),e},ee=function(t,e){const n=parseInt(t[2],16)*255,i=parseInt(t[3],16),r=(n+i)*.1;return e.no_code=15,e.name="Temperature status",e.description=`Temperature: ${r}`,e.additional={high:n,low:i,temperature:parseFloat(r.toString())},this.dispatch("status:temperature",e.additional),e},te=function(t,e){const n=parseInt(t,16);let i="unknown";return n===1?(e.name="Relay on",e.description="Relay on",e.no_code=16,i="on"):n===0?(e.name="Relay off",e.description="Relay off",e.no_code=17,i="off"):(e.name="Status unknown",e.description="Status unknown",e.no_code=400),this.dispatch("status:relay",{enabled:i==="on"}),e},ne=function(t,e){const n=parseInt(t[2],16);if(e.no_code=20+n,e.name="Status unknown",e.description="The status of card reader does not identified correctly",n===0)e.request+=":disable",e.name="Card reader disabled",e.description="Card reader device was disabled successfully";else if(n===1||n===2)e.request+=":dispense",e.name="Card reader enabled",e.description="Card reader device is now enabled";else if(n===3)e.request+=":pre-authorize",e.name="Pre-authorized credit",e.description="The pre credit was authorized successfully";else if(n===4)e.request+=":cancel",e.name="Cancellation in progress",e.description="Cancellation request done successfully";else if(n===5)e.request+=":sell",e.name="Sell approved",e.description="Sell approved, starting dispense product";else if(n===6)e.request+=":sell",e.name="Sell denied",e.description="This sell was denied, try again";else if(n===7)e.request+=":end",e.name="Session ended",e.description="The session ended";else if(n===8)e.request+=":cancel",e.name="Cancelled",e.description="Cancellation complete";else if(n===10){const i=parseInt(t[8],16);i===1?(e.no_code=30,e.name="product not dispensed",e.description="The product requested wasn't delivered"):i===0?(e.no_code=31,e.name="product dispensed",e.description="The product requested was delivered"):(e.name="finished-unknown",e.no_code=400)}else e.no_code=400;return this.dispatch("card-reader:event",e),e},p=function(t,e){return this.appendToQueue(a(this,s,T).call(this,t),e)},T=function(t){return t[11]=this.serialBoardroidSumHex(t),t.map((e,n)=>{t[n]=this.hexMaker(e)}),t},se=function({enable:t=!1,scrow:e=!1}={}){const n=t?"FF":"00",i=e?"FF":"00";return["F1","C0",n,n,i,i,"00","00","00","00","F2","00"]},ie=function({enable:t=!1,scrow:e=!1}={}){return["F1","C0",t?"01":"00",e?"01":"00","00","00","00","00","00","00","F2","00"]},re=function(t=1){if(t<1)throw new Error("No banknotes to dispense");return t=this.decToHex(t),["F1","C5",this.decToHex(this.__banknote_purse.recycler.banknote.toString()),t,"00","00","00","00","00","00","F2","00"]},ae=function({$_20:t=0,$_50:e=0,$_100:n=0,$_200:i=0,$_500:r=0,$_1000:c=0}={}){if([t,e,n,i,r,c].some(o=>isNaN(o)||typeof o=="string"))throw new Error("One of the values is not a number");if(t<1&&e<1&&n<1&&i<1&&r<1&&c<1)throw new Error("No banknotes to dispense");return[t,e,n,i,r,c]=[this.decToHex(t),this.decToHex(e),this.decToHex(n),this.decToHex(i),this.decToHex(r),this.decToHex(c)],["F1","C5",t,e,n,i,r,c,"00","00","F2","00"]},S=function(){_(this,w,!1),_(this,f,0),_(this,y,0)},I=function({dispensed:t=null,limit:e=80}={}){_(this,y,Math.round(v(this,f)*100/e)),this.dispatch("percentage:test",{percentage:v(this,y),dispensed:t})},oe=function(t){const e=["20","50","100","200","500"],n=this.__banknote_purse.recycler.banknote,i="$_"+e[n],r=parseInt(e[n]),c=this.banknotes.recycler[`p${e[n]}`],o=Math.min(Math.floor(t/r),c),l={banknotes:{$_20:0,$_50:0,$_100:0,$_200:0,$_500:0,$_1000:0},pending:t,will_dispense:o>0};return this.totalInRecycler===0||o<1||t===0||(l.banknotes[i]=o,l.pending=parseFloat((t-o*r).toFixed(2))),l},ce=function(t){const e={banknotes:{$_20:0,$_50:0,$_100:0,$_200:0,$_500:0,$_1000:0},pending:t,will_dispense:!1};if(this.totalInRecycler===0||t===0)return e;const n=(i,r)=>{if(this.banknotes.recycler[r]>0){const c=Math.floor(e.pending/i),o=Math.min(c,this.banknotes.recycler[r]);e.banknotes[`$_${i}`]=o,e.pending=parseFloat((e.pending-o*i).toFixed(2))}};return n(1e3,"p1000"),n(500,"p500"),n(200,"p200"),n(100,"p100"),n(50,"p50"),n(20,"p20"),e.will_dispense=Object.values(e.banknotes).some(i=>i>0),e},P=function(t){return this.hasRecycler?a(this,s,x).call(this)?a(this,s,oe).call(this,t):a(this,s,ce).call(this,t):{banknotes:{$_20:0,$_50:0,$_100:0,$_200:0,$_500:0,$_1000:0},pending:t,will_dispense:!1}},E=function(t){const e={coins:{$_50c:0,$_1:0,$_2:0,$_5:0,$_10:0},pending:t,will_dispense:!1};if(!this.hasCoinPurse||t<=0||this.totalInTubes===0)return e;const n=(i,r,c=null)=>{if(this.coins.tubes[r]>0){c===null&&(c="$_"+i);const o=Math.floor(e.pending/i),l=Math.min(o,this.coins.tubes[r]);e.coins[c]=l,e.pending=parseFloat((e.pending-l*i).toFixed(2))}};return n(10,"p10"),n(5,"p5"),n(2,"p2"),n(1,"p1"),n(.5,"g50","$_50c"),e.will_dispense=Object.values(e.coins).some(i=>i>0),e},q=async function(t=null){if(!a(this,s,N).call(this))throw new Error("Change not available");let e=this.change,n=this.change;if(t!==null&&(e=t,n=t),n<=0)return!1;const i=a(this,s,P).call(this,n);n=i.pending;const r=a(this,s,E).call(this,n);return n=r.pending,n>0&&this.dispatch("change:pending",{pending:n}),this.dispatch("change:dispense",{recycler:i.banknotes,coins:r.coins,pending:n,delivery:e-n}),n===e?!1:(i.will_dispense&&await this.banknotePurseDispense(i.banknotes),r.will_dispense&&await this.coinPurseDispense(r.coins),!0)};exports.Boardroid=pe;
package/dist/boardroid.js CHANGED
@@ -5,7 +5,7 @@ var q = (d) => {
5
5
  var ue = (d, u, t) => u in d ? de(d, u, { enumerable: !0, configurable: !0, writable: !0, value: t }) : d[u] = t;
6
6
  var b = (d, u, t) => ue(d, typeof u != "symbol" ? u + "" : u, t), F = (d, u, t) => u.has(d) || q("Cannot " + t);
7
7
  var v = (d, u, t) => (F(d, u, "read from private field"), t ? t.call(d) : u.get(d)), C = (d, u, t) => u.has(d) ? q("Cannot add the same private member more than once") : u instanceof WeakSet ? u.add(d) : u.set(d, t), _ = (d, u, t, e) => (F(d, u, "write to private field"), e ? e.call(d, t) : u.set(d, t), t), a = (d, u, t) => (F(d, u, "access private method"), t);
8
- import { K as pe, c as D } from "./kernel-B15wfB2x.js";
8
+ import { K as pe, _ as D } from "./kernel-BFXQSiNz.js";
9
9
  var w, f, y, s, M, H, x, N, O, U, j, A, L, Q, m, R, z, W, K, V, Y, G, J, X, Z, g, $, ee, te, ne, p, T, se, ie, re, ae, B, I, oe, ce, S, P, E;
10
10
  class _e extends pe {
11
11
  constructor({ filters: t = null, config_port: e = null, no_device: n = 1 } = {}) {
package/dist/jofemar.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var _t=Object.defineProperty;var F=p=>{throw TypeError(p)};var ft=(p,h,e)=>h in p?_t(p,h,{enumerable:!0,configurable:!0,writable:!0,value:e}):p[h]=e;var N=(p,h,e)=>ft(p,typeof h!="symbol"?h+"":h,e),vt=(p,h,e)=>h.has(p)||F("Cannot "+e);var P=(p,h,e)=>h.has(p)?F("Cannot add the same private member more than once"):h instanceof WeakSet?h.add(p):h.set(p,e);var n=(p,h,e)=>(vt(p,h,"access private method"),e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const w=require("./kernel-CtyQRsMI.cjs");var i,A,g,B,u,E,$,W,q,O,j,R,J,L,U,H,V,K,G,z,Q,Y,Z,X,tt,et,it,nt,rt,at,ot,ct,_,l,m,d,f,st,ht,lt,dt,k,S,M,D,I,pt;class yt extends w.Kernel{constructor({filters:e=null,config_port:t=null,no_device:r=1,device_listen_on_port:a=1,type:o="esplus",support_cart:c=!0}={}){super({filters:e,config_port:t,no_device:r,device_listen_on_port:a});P(this,i);N(this,"__device",{type:"esplus",support_cart:!1,withdraw:{in_process:!1,seconds:60,interval:0},cart:{in_process:!1},channels:{verification:{clear(){this.running=!1,this.current=1,this.channels=[]},running:!1,start:1,end:80,current:1,channels:[]}}});if(this.__internal__.device.type="jofemar",w.c.getCustom(this.typeDevice,r))throw new Error(`Device ${this.typeDevice} ${r} already exists`);this.__internal__.dispense.must_response=!0,this.__internal__.time.response_general=800,this.__internal__.time.response_engines=800,this.__internal__.dispense.limit_counter=40,this.__internal__.dispense.timeout=0,this.__internal__.dispense.timeout_time=4e3,this.__internal__.dispense.interval=0,this.__internal__.dispense.interval_time=1e3,this.__internal__.device.hex_number=(128+this.listenOnChannel).toString(16),this.__internal__.device.door_open=!1,this.__internal__.dispense.elevator={locking_time:60,locking_interval:0,need_reset:!1},this.deviceType=o,this.supportCart=c,n(this,i,A).call(this),n(this,i,B).call(this),n(this,i,g).call(this)}set startChannelVerification(e){const t=parseInt(e);if(isNaN(t))throw new Error("Invalid start channel verification, must be a number");if(t<1||t>126)throw new Error("Invalid start channel verification, valid range is 1 to 126");this.__device.channels.verification.start=t}set endChannelVerification(e){const t=parseInt(e);if(isNaN(t))throw new Error("Invalid end channel verification, must be a number");if(t<1||t>126)throw new Error("Invalid end channel verification, valid range is 1 to 126");this.__device.channels.verification.end=t}set listenOnChannel(e){if(e=parseInt(e),isNaN(e)||e<1||e>31)throw new Error("Invalid port number, valid range is 1 to 31");this.__internal__.device.listen_on_port=e,this.__internal__.serial.bytes_connection=this.serialSetConnectionConstant(e),this.__internal__.device.hex_number=(128+e).toString(16)}set listenOnPort(e){this.listenOnChannel=e}set deviceType(e){if(typeof e!="string")throw new Error("Invalid device type, must be a string");this.__device.type=e}set supportCart(e){if(typeof e!="boolean")throw new Error("Invalid support cart, must be a boolean");this.__device.support_cart=e}serialJofemarMakeBytes(e){let t=this.hexToDec(this.sumHex(e)),r=this.calcCheckSums(t.toString());for(let a=0;a<2;a++)e.push(this.hexMaker(r[a]));return e.push("03"),this.add0x(e)}calcCheckSums(e){e=this.add0x([this.decToHex(parseInt(e).toString())]);let t=[];return t.push((e&255|240).toString(16).toUpperCase()),t.push((e&255|15).toString(16).toUpperCase()),t}serialSetConnectionConstant(e=1){let t=["02","30","30",(128+e).toString(16),"53","FF","FF"],r=[];return t.forEach(a=>{r.push(this.hexMaker(a))}),this.serialJofemarMakeBytes(r)}serialMessage(e){let r={code:e,name:null,description:null,request:"unknown",no_code:0,additional:{machine:{hex:null,dec:null}}};switch(e[0]){case"02":r=n(this,i,ct).call(this,e,r,128);break;case"06":r=n(this,i,st).call(this,e,r);break;case"15":r.name="Checksum error",r.description="The calculated checksum does not match the received checksum",r.no_code=38,n(this,i,l).call(this);break;default:r.name="unknown",r.description="The message received is unknown",r.no_code=404;break}this.dispatch("serial:message",r)}productRemovedContinueDispensing(){this.__internal__.dispense.elevator.locking_interval&&(this.__internal__.dispense.elevator.locking_time=0)}async dispense({selection:e=1,cart:t=!1}={}){if(e=parseInt(e),isNaN(e)||e<1||e>130)throw new Error("Invalid selection");const{channel:r,tray:a}=n(this,i,ht).call(this,e);this.__internal__.dispense.backup_dispense={selection:e,cart:t,channel:r,tray:a};let c=["02","30","30",this.__internal__.device.hex_number,"56",a,r];t&&(c[4]="4D"),c=n(this,i,E).call(this,c);let s;do s=await this.internalDispense(c),n(this,i,lt).call(this),s.error==="elevator-locked"?await n(this,i,$).call(this):s.error==="no-response"&&await w.wait(1e3);while(["elevator-locked","no-response"].includes(s.error));return this.__internal__.dispense.backup_dispense={},s}internalClearSensing(){super.internalClearSensing(),this.__internal__.dispense.timeout&&clearTimeout(this.__internal__.dispense.timeout),this.__internal__.dispense.interval&&clearInterval(this.__internal__.dispense.interval),this.__internal__.serial.queue.length>0&&(this.__internal__.serial.queue=this.__internal__.serial.queue.filter(e=>e.type!=="status"))}async endDispense(){let t=["02","30","30",this.__internal__.device.hex_number,"4D","80","80"];return t=n(this,i,E).call(this,t),await this.internalDispense(t)}async collect(){const e=["02","30","30","81","4E","FF","FF"];return await n(this,i,u).call(this,e,"collect")}async resetSoldOutErrors(){return await n(this,i,k).call(this,"80")}async resetWaitingProductRemovedError(){return await n(this,i,k).call(this,"81")}async resetMachineErrors(){return this.__internal__.serial.queue.length===0?(n(this,i,S).call(this),await n(this,i,k).call(this,"FF")):new Promise(e=>{const t=setInterval(async()=>{this.__internal__.serial.queue.length>0||(clearInterval(t),await n(this,i,k).call(this,"FF"),n(this,i,S).call(this),e(!0))},100)})}async resetAllErrors(){return await this.resetSoldOutErrors(),await w.wait(100),await this.resetWaitingProductRemovedError(),await w.wait(100),await this.resetMachineErrors()}async status(){const e=["02","30","30","81","53","FF","FF"];return await n(this,i,u).call(this,e,"status")}async lightsOn(){return await n(this,i,M).call(this,"81")}async lightsOff(){return await n(this,i,M).call(this,"80")}async program(e,t){const r=["02","30","30","81","50",e,t];return await n(this,i,u).call(this,r,"program")}async programDisplayLanguage({language:e="spanish"}={}){const t={spanish:"30",english:"31",french:"32"};if(!t[e])throw new Error("Invalid language");return await this.program("49",t[e])}async programBeeper({enable:e=!0}={}){const t=e?"31":"30";return await this.program("5A",t)}async programDisableWorkingTemperature(){if(this.__device.type==="iceplus")throw new Error("IcePlus does not support disable working temperature");return await this.program("54","80")}async programDisableThermometer(){return await this.programDisableWorkingTemperature()}async programWorkingTemperature({degrees:e=.5}={}){e=parseFloat(e);const t=this.__device.type==="iceplus"?6.5:32,r=this.__device.type==="iceplus"?-25:.5;if(isNaN(e)||e<r||e>t||e%.5!==0)throw new Error("Invalid degrees, must be a multiple of 0.5 and between 0.5 and 32");let a=e*2+128;return this.__device.type==="iceplus"&&(a+=51),a=Math.ceil(a),await this.program("54",a.toString(16))}async programIsolationTray({tray:e=0}={}){if(e=parseInt(e),isNaN(e)||e<0||e>12)throw new Error("Invalid tray, valid range is 0 to 12");const t=e===0?"80":(e+139).toString(16);return this.program("42",t)}async programTimeToStandbyAfterCollect({seconds:e=15}={}){if(e=parseInt(e),isNaN(e)||e<15||e>120)throw new Error("Invalid seconds, valid range is 15 to 120");const t=(128+e).toString(16);return await this.program("46",t)}async programTimeToStandbyWithoutCollect({minutes:e=1}={}){if(e=parseInt(e),isNaN(e)||e<1||e>10)throw new Error("Invalid minutes, valid range is 1 to 10");const t=(128+e).toString(16);return await this.program("48",t)}async programElevatorSpeed({speed:e="high"}={}){const t={high:"31",low:"30"};if(!t[e])throw new Error("Invalid speed, valid speeds are 'high' and 'low'");return await this.program("76",t[e])}async programTemperatureExpiration({enable:e=!1}={}){const t=e?"31":"30";return await this.program("63",t)}async programEnableTemperatureExpiration(){return await this.programTemperatureExpiration({enable:!0})}async programDisableTemperatureExpiration(){return await this.programTemperatureExpiration({enable:!1})}async programMachineAddress({address:e=1}={}){if(e=parseInt(e),isNaN(e)||e<1||e>31)throw new Error("Invalid address, valid range is 1 to 31");const t=(128+e).toString(16);return await this.program("64",t)}async programTemperatureBeforeExpiration({degrees:e=.5}={}){if(e=parseFloat(e),isNaN(e)||e<.5||e>30||e%.5!==0)throw new Error("Invalid degrees, must be a multiple of 0.5 and valid range is 0.5 to 30");const t=(128+e*2).toString(16);return await this.program("65",t)}async programTimeBeforeExpirationByTemperature({minutes:e=1}={}){if(e=parseInt(e),isNaN(e)||e<1||e>120)throw new Error("Invalid minutes, valid range is 1 to 120");const t=(128+e).toString(16);return await this.program("66",t)}async programTemperatureScale({scale:e="c"}={}){const t={c:"43",f:"46"};if(!t[e])throw new Error("Invalid scale, valid scales are 'c' for celsius and 'f' for fahrenheit");return await this.program("67",t[e])}async programVoltageEngine({selection:e=1,voltage:t=5}={}){if(t=parseFloat(t),e=parseInt(e),isNaN(e)||e<1||e>this.__device.channels.verification.end)throw new Error(`Invalid selection, valid range is 1 to ${this.__device.channels.verification.end}`);if(isNaN(t)||t<5||t>9.5||t%.5!==0)throw new Error("Invalid voltage, valid range is 5 to 9.5");const r=109+e,o=(128+(t-5)*2).toString(16),c=["02","30","30","81","47",r,o];return await n(this,i,u).call(this,c,"voltage-engine")}async programPushOverProducts({selection:e=1,enable:t=!0}={}){if(e=parseInt(e),isNaN(e)||e<1||e>this.__device.channels.verification.end)throw new Error(`Invalid selection, valid range is 1 to ${this.__device.channels.verification.end}`);const o=["02","30","30","81","4F",109+e,t?"31":"30"];return await n(this,i,u).call(this,o,"push-over-products")}async programChannelRunningAfterDispense({selection:e=1,seconds:t=0}={}){if(e=parseInt(e),t=parseFloat(t),isNaN(e)||e<1||e>this.__device.channels.verification.end)throw new Error(`Invalid selection, valid range is 1 to ${this.__device.channels.verification.end}`);if(isNaN(t)||t<0||t>10||t%.1!==0)throw new Error("Invalid seconds, valid range is 0.0 to 10.0 with a step of 0.1");const r=109+e;t=t.toFixed(1);const a=128+t*10,o=["02","30","30","81","45",r,a];return await n(this,i,u).call(this,o,"channel-running-after-dispense")}async checkData(e,t="FF"){const r=["02","30","30","81","43",e,t];return await n(this,i,u).call(this,r,"check-data")}async getDisplayLanguage(){return await this.checkData("49")}async getBeeper(){return await this.checkData("5A")}async getWorkingTemperature(){return await this.checkData("54")}async getIsolationTray(){return await this.checkData("42")}async getProgramVersion(){return await this.checkData("50")}async getFaults(){return await this.checkData("53")}async getMachineId(){return await this.checkData("4E")}async getCurrentTemperature(){return await this.checkData("74")}async getTimeToStandbyAfterCollect(){return await this.checkData("46")}async getTimeToStandbyWithoutCollect(){return await this.checkData("48")}async getElevatorSpeed(){return await this.checkData("76")}async getTemperatureExpiration(){return await this.checkData("63")}async getTemperatureBeforeExpiration(){return await this.checkData("65")}async getTimeBeforeExpirationByTemperature(){return await this.checkData("66")}async getTemperatureScale(){return await this.checkData("67")}async getClockRegisters(){return await this.checkData("72")}async getMachineActivity(){return await this.checkData("41")}async getVoltageEngine({selection:e=1}={}){if(e=parseInt(e),isNaN(e)||e<1||e>126)throw new Error("Invalid selection, valid range is 1 to 126");const t=(109+e).toString(16);return await this.checkData("47",t)}async getChannelPresence({selection:e=1}={}){if(e=parseInt(e),isNaN(e)||e<1||e>126)throw new Error("Invalid selection, valid range is 1 to 126");const t=(109+e).toString(16);return await this.checkData("43",t)}async getPushOverProducts({selection:e=1}={}){if(e=parseInt(e),isNaN(e)||e<1||e>126)throw new Error("Invalid selection, valid range is 1 to 126");const t=(109+e).toString(16);return await this.checkData("4F",t)}async getChannelRunningAfterDispense({selection:e=1}={}){if(e=parseInt(e),isNaN(e)||e<1||e>126)throw new Error("Invalid selection, valid range is 1 to 126");const t=(109+e).toString(16);return await this.checkData("45",t)}async setDisplayStandbyMessage({message:e=""}={}){e=e.substring(0,32);const t=n(this,i,I).call(this,e);return await n(this,i,D).call(this,"80",t)}async setDisplayMessageTemporarily({message:e="",seconds:t=1}){if(e=e.substring(0,32),t=parseInt(t),isNaN(t)||t<1||t>125)throw new Error("Invalid seconds, valid range is 1 to 125");const r=n(this,i,I).call(this,e),a=(128+t).toString(16);return await n(this,i,D).call(this,a,r)}async setDisplayMessageUnlimited({message:e=""}){e=e.substring(0,32);const t=n(this,i,I).call(this,e);return await n(this,i,D).call(this,"FF",t)}async programClock({date:e=new Date}={}){if(!(e instanceof Date))throw new Error("Invalid date, must be an instance of Date");const t=["02","30","30","81","72",...n(this,i,pt).call(this,e)];return await n(this,i,u).call(this,t,"clock")}async eventsConfig({event:e=null,enable:t=!0}={}){if(e===null)throw new Error("Invalid event");const a=["02","30","30","81","41",e,t?"31":"30"];return await n(this,i,u).call(this,a,"events-config")}async eventEnable({event:e=null}={}){if(e===null)throw new Error("Invalid event");const t=parseInt(e,16);if(isNaN(t)||t<38||t>100)throw new Error("Invalid event");return await this.eventsConfig({event:e,enable:!0})}async eventDisable({event:e=null}={}){if(e===null)throw new Error("Invalid event");const t=parseInt(e,16);if(isNaN(t)||t<38||t>100)throw new Error("Invalid event");return await this.eventsConfig({event:e,enable:!1})}async sendCustomCode({code:e=[]}={}){if(e.length<5)throw new Error("Invalid code, minimum length is 5");return await n(this,i,u).call(this,e,"custom")}async assignChannels(){const e=this.__device.channels.verification.start,t=this.__device.channels.verification.end;if(e>t)throw new Error("Invalid range, start must be less than end");this.__device.channels.verification.clear(),this.__device.channels.verification.running=!0;for(let r=e;r<=t;r++)this.__device.channels.verification.current=r,await this.getChannelPresence({selection:r});return new Promise(r=>{let a=setInterval(()=>{this.__device.channels.verification.channels.length===t-e+1&&(clearInterval(a),this.dispatch("channels",{channels:this.__device.channels.verification.channels}),this.__device.channels.verification.clear(),r(!0))},500)})}}i=new WeakSet,A=function(){const e=["dispensing:withdrawal","command-executed","keyboard:pressed","door:event","program:version","machine:faults","clock:registers","machine:activity","check:language","check:beeper","check:isolation-tray","check:engine-voltage","check:push-over","check:extractor-after-dispense","check:standby-after-collect","check:standby-without-collect","check:elevator-speed","check:expiration-by-temperature","check:temperature-before-expiration","check:expiration-after","check:temperature-scale","check:machine-id","temperature:working","temperature:current","jofemar:warning","jofemar:error","serial:message","reset:errors","channels","channel:status","machine:status"];for(const t of e)this.serialRegisterAvailableListener(t)},g=function(){this.on("internal:dispense:running",n(this,i,dt).bind(this))},B=function(){w.c.add(this)},u=function(e,t){return e[3]=this.__internal__.device.hex_number,this.appendToQueue(n(this,i,E).call(this,e),t)},E=function(e){let t=this.hexToDec(this.sumHex(e)),r=this.calcCheckSums(t.toString());for(let a=0;a<2;a++)e.push(this.hexMaker(r[a]));return e.push("03"),e},$=async function(){if(this.__internal__.dispense.elevator.locking_interval)return;this.__internal__.dispense.elevator.need_reset&&(this.__internal__.dispense.elevator.need_reset=!1,await this.resetWaitingProductRemovedError(),await w.wait(500));const e=this;return this.__internal__.dispense.status="elevator-locked",this.__internal__.dispense.elevator.locking_time=60,new Promise(t=>{e.__internal__.dispense.elevator.locking_interval=setInterval(()=>{e.dispatch("dispensing:withdrawal",{elevator:!0,seconds:e.__internal__.dispense.elevator.locking_time,description:"Please recall products from the elevator"}),e.__internal__.dispense.elevator.locking_time-=1,e.__internal__.dispense.elevator.locking_time<=0&&(clearInterval(e.__internal__.dispense.elevator.locking_interval),e.__internal__.dispense.elevator.locking_interval=0,t(!0))},1e3)})},W=function(e,t){return t.name="ok",t.description="The last command was executed successfully",t.no_code=1,this.dispatch("command-executed",t),t},q=function(e,t){t.additional={hex:e,dec:this.hexToDec(e),ascii:null};const r={30:"0",31:"1",32:"2",33:"3",34:"4",35:"5",36:"6",37:"7",38:"8",39:"9","2a":"*",23:"#",41:"A",42:"B",43:"C",44:"D"};return t.additional.ascii=r[e]??null,t.name="Key pressed",t.description=`The key ${t.additional.ascii} was pressed`,t.no_code=2,this.dispatch("keyboard:pressed",t.additional),t},O=function(e,t){return t.additional={open:!1},t.no_code=3,e==="4f"?(t.name="door open",t.description="The door was opened",t.additional.open=!0,this.__internal__.device.door_open=!0,this.dispatch("door:event",t.additional)):e==="43"?(t.name="door close",t.description="The door was closed",t.additional.open=!1,this.__internal__.device.door_open=!1,this.dispatch("door:event",t.additional)):(t.name="door event",t.description="The door event received is unknown",this.dispatch("door:event",{open:t.additional.open,message:t})),t},j=function(e,t){t.no_code=404;let r=e[5]??null;return r&&this.listenOnChannel>1&&(r=this.hexToDec(r)-this.listenOnChannel+1,r=this.decToHex(r)),r&&(r==="FD"?(t.no_code=4,t.name="channel disconnected",t.description="The channel is disconnected",t.additional={active:!1}):r==="FC"?(t.no_code=5,t.name="channel connected",t.description="The channel is connected",t.additional={active:!0}):(t.no_code=6,t.name="channel sold out",t.description="The channel is empty",t.additional={active:!0}),this.__device.channels.verification.running&&(this.__device.channels.verification.channels.push({selection:this.__device.channels.verification.current,active:t.additional.active}),t.additional.selection=this.__device.channels.verification.current),this.dispatch("channel:status",t.additional)),t},R=function(e,t){t.no_code=39,t.name="Program version";const r=e.slice(4,12),a=r.map(o=>String.fromCharCode(this.hexToDec(o))).join("");return t.additional={version:a,hex:r},t.description=`The program version is ${a}`,this.dispatch("program:version",t.additional),t},J=function(e,t){t.no_code=39,t.name="Machine faults",t.description="No faults detected",t.additional={no_faults:0,faults:[]};const r=e.slice(4,-3);if(r.length>1&&r[0]!=="30"){t.description="Machine has faults";const a={31:"Busy",32:"Invalid tray",33:"Invalid channel",34:"Empty channel",35:"Jam in elevator engine",36:"Malfunction in the elevator belt or product detector",37:"Failure in one of the photo transistors in the cabinet",38:"No channels detected",39:"Product detector fault",41:"Machine display is disconnected",42:"Product alarm under elevator",43:"Error when elevator approaching to a position",44:"Fault in keyboard",45:"Eeprom writing error",46:"Fault communicating with temperature control",47:"The thermometer is disconnected",48:"Thermometer programming lost",49:"Thermometer faulty","4a":"Channels power consumption detector faulty","4b":"Elevator does not find channel or tray","4c":"Elevator does not find delivery product position","4d":"Interior of elevator blocked","4e":"Error in tester of product detector","4f":"Waiting for product to be removed",50:"Product expired by temperature reasons",51:"Automatic door faulty",59:"Product is expired","5a":"Product is expired",61:"Product is expired",62:"Product is expired",63:"Product is expired",64:"Product detector didn't change during its verification test"};for(const o of r)a[o]&&(t.additional.faults.push(a[o]),t.additional.no_faults++)}return this.dispatch("machine:faults",t.additional),t},L=function(e,t){t.no_code=40,t.name="Clock registers",t.description="Clock registers";const r=e.slice(4,-3),a=r.map(C=>String.fromCharCode(this.hexToDec(C))).join(""),[o,c]=a.split(" "),[s,v]=o.split(":"),[y,b,x]=c.split("-"),T=new Date(2e3+parseInt(x),parseInt(b)-1,parseInt(y),parseInt(s),parseInt(v));return t.additional={day:y,month:b,year:x,hours:s,minutes:v,formatted:a,date:T,hex:r},this.dispatch("clock:registers",t.additional),t},U=function(e,t){t.no_code=41,t.name="Machine activity",t.description="Events from read machine activity";const r=String.fromCharCode(this.hexToDec(e[4]));if(r!=="0"){const a=e.slice(5,-3);if(r==="T"&&a.length===4){const o=String.fromCharCode(this.hexToDec(a[0])),c=String.fromCharCode(this.hexToDec(a[1])),s=String.fromCharCode(this.hexToDec(a[3]));t.additional={ascii:r,type:"DU.d",dozens:o,units:c,decimals:s,time:parseFloat(`${o}${c}.${s}`),meaning:"Extraction time (in seconds)"}}else if(["B","D","E","F","G"].includes(r)&&a.length===3){const o=String.fromCharCode(this.hexToDec(a[0])),c=String.fromCharCode(this.hexToDec(a[1])),s=String.fromCharCode(this.hexToDec(a[2])),v=parseInt(`${o}${c}${s}`),y={B:"Error on going to tray channel",D:"Error on product detector",E:"Extraction of channel ok",F:"Error on engine intensity detection",G:"Error on product exit door"};t.additional={type:"HDU",hundreds:o,dozens:c,decimals:s,channel:v,selection:v-109,ascii:r,meaning:y[r]??"Unknown"}}else if(a.length===13){const o=a.map(ut=>String.fromCharCode(this.hexToDec(ut))).join(""),c=parseInt(o.slice(0,2)),s=parseInt(o.slice(2,4)),v=parseInt(o.slice(4,6)),y=parseInt(o.slice(7,9)),b=parseInt(o.slice(9,11))-1,x=2e3+parseInt(o.slice(11,13)),T=new Date(x,b,y,c,s,v),C={A:"Attempt to close product exit door",C:"Closing of exterior door",H:"Error on opening of product exit door",I:"New attempt to arrive at product exit position after an error on first attempt",J:"Power on cooling unit",K:"Power off cooling unit",L:"Start of defrosting",M:"End of defrosting",O:"Opening of exterior door",R:"Memory reset",S:"Error on going to product exit position",Y:"Power on machine",Z:"Power off machine",c:"Closing of inner door",e:"New attempt to extract from channel due no product detection when elevator arrived to product exit position",o:"Opening of inner door"};t.additional={type:"hhmmssWddMMAA",date:T,hex:a,formatted:T.toLocaleString(),ascii:r,meaning:C[r]??"Unknown"}}}return this.dispatch("machine:activity",t.additional),t},H=function(e,t){const r={30:"Spanish",31:"English",32:"French"};return t.no_code=42,t.name="Language",t.description=`The language is ${r[e]??"unknown"}`,t.additional={hex:e,language:r[e]??"unknown"},this.dispatch("check:language",t.additional),t},V=function(e,t){return t.no_code=43,t.name="Beeper",t.description=`The beeper is ${e==="30"?"on":"off"}`,t.additional={hex:e,beeper:e==="30"},this.dispatch("check:beeper",t.additional),t},K=function(e,t){t.no_code=44,t.name="Isolation tray",t.description="Isolation tray";const r=this.hexToDec(e)-139;return t.additional={hex:e,tray:r},this.dispatch("check:isolation-tray",t.additional),t},G=function(e,t){t.no_code=45,t.name="Engine voltage",t.description="Engine voltage";const r=(this.hexToDec(e)-128)/2+5;return t.additional={hex:e,voltage:r},this.dispatch("check:engine-voltage",t.additional),t},z=function(e,t){t.no_code=46,t.name="Push over",t.description="Push over";const r=e==="30";return t.additional={hex:e,push:r},this.dispatch("check:push-over",t.additional),t},Q=function(e,t){t.no_code=47,t.name="Extractor after dispense",t.description="Extractor after dispense";const r=(this.hexToDec(e)-128)/10;return t.additional={hex:e,seconds:r},this.dispatch("check:extractor-after-dispense",t.additional),t},Y=function(e,t){t.no_code=48,t.name="Standby after collect",t.description="Time to standby after collect product";const r=this.hexToDec(e)-128;return t.additional={hex:e,seconds:r},this.dispatch("check:standby-after-collect",t.additional),t},Z=function(e,t){t.no_code=49,t.name="Standby without collect",t.description="Time to standby when product delivery is not collected";const r=this.hexToDec(e)-128;return t.additional={hex:e,minutes:r},this.dispatch("check:standby-without-collect",t.additional),t},X=function(e,t){t.no_code=50,t.name="Elevator speed",t.description="Elevator speed";const r=e==="30"?"low":"high";return t.additional={hex:e,speed:r},this.dispatch("check:elevator-speed",t.additional),t},tt=function(e,t){t.no_code=51,t.name="Temperature expiration",t.description="Temperature expiration";const r=e==="31";return t.additional={hex:e,enabled:r},this.dispatch("check:expiration-by-temperature",t.additional),t},et=function(e,t){t.no_code=52,t.name="Temperature before expiration",t.description="Temperature before expiration";const r=(this.hexToDec(e)-128)/2;return t.additional={hex:e,temperature:r},this.dispatch("check:temperature-before-expiration",t.additional),t},it=function(e,t){t.no_code=53,t.name="Time before expiration",t.description="Time before expiration";const r=this.hexToDec(e)-128;return t.additional={hex:e,minutes:r},this.dispatch("check:expiration-after",t.additional),t},nt=function(e,t){t.no_code=54,t.name="Temperature scale",t.description="Temperature scale";const r=e==="43"?"Celsius":"Fahrenheit";return t.additional={hex:e,scale:r},this.dispatch("check:temperature-scale",t.additional),t},rt=function(e,t){return t.no_code=54,t.name="Machine ID",t.description="Machine ID",t.additional={hex:e[4],full_hex:e},this.dispatch("check:machine-id",t.additional),t},at=function(e,t){return t.no_code=7,t.name="working temperature",t.description=`The working temperature is ${e}`,t.additional={hex:e,temperature:{traditional:(this.hexToDec(e)-this.hexToDec("80"))/2,ice_plus:(this.hexToDec(e)-this.hexToDec("80"))/2-25.5}},this.dispatch("temperature:working",t.additional),t},ot=function(e,t){return t.no_code=8,t.name="current temperature",t.additional={sign:null,tens:null,units:null,decimals:null,type_degrees:null,formatted:null,decimal_point:e[7]==="2e"?".":null,degrees:e[9]==="7f"?"°":null,error:null},e[4]==="2b"?t.additional.sign=e[4]="+":["2e","2d"].includes(e[4])?t.additional.sign=e[4]="-":e[4]==="20"&&(t.additional.error="Error in thermometer"),this.hexToDec(e[5])>=48&&this.hexToDec(e[5])<=57?t.additional.tens=this.hexToDec(e[5])-48:e[5]==="2a"&&(t.additional.error="Error in thermometer"),this.hexToDec(e[6])>=48&&this.hexToDec(e[6])<=57?t.additional.units=this.hexToDec(e[6])-48:e[6]==="2a"&&(t.additional.error="Error in thermometer"),this.hexToDec(e[8])>=48&&this.hexToDec(e[8])<=57?t.additional.decimals=this.hexToDec(e[8])-48:e[8]==="2a"&&(t.additional.error="Error in thermometer"),e[10]==="43"?t.additional.type_degrees="C":e[10]==="46"&&(t.additional.type_degrees="F"),t.additional.error==="Error in thermometer"?(t.additional.formatted="Error in thermometer",t.description="The current temperature cannot be read because there is an error in the thermometer"):(t.additional.formatted=(t.additional.sign??"")+(t.additional.tens??"")+(t.additional.units??"")+(t.additional.decimal_point??"")+(t.additional.decimals??"")+(t.additional.degrees??"")+(t.additional.type_degrees??""),t.description=`The current temperature is ${t.additional.formatted}`),this.dispatch("temperature:current",t.additional),t},ct=function(e,t,r=128){if(e[1]&&(t.additional.machine.hex=e[1],t.additional.machine.dec=this.hexToDec(e[1])-r),!(e[1]&&e[2]))t=n(this,i,W).call(this,e,t);else switch(e[2]){case"54":t.request="--automatic",t=n(this,i,q).call(this,e[3],t);break;case"50":t.request="--automatic",t=n(this,i,O).call(this,e[3],t);break;case"43":switch(t.request="check-data",e[3]){case"41":t=n(this,i,U).call(this,e,t);break;case"43":t.request="channel-status",t=n(this,i,j).call(this,e,t);break;case"50":t=n(this,i,R).call(this,e,t);break;case"53":t=n(this,i,J).call(this,e,t);break;case"54":t.request="working-temperature",t=n(this,i,at).call(this,e[4],t);break;case"72":t=n(this,i,L).call(this,e,t);break;case"74":t.request="current-temperature",t=n(this,i,ot).call(this,e,t);break;case"49":t=n(this,i,H).call(this,e[4],t);break;case"5a":t=n(this,i,V).call(this,e[4],t);break;case"42":t=n(this,i,K).call(this,e[4],t);break;case"47":t=n(this,i,G).call(this,e[4],t);break;case"4e":t=n(this,i,rt).call(this,e,t);break;case"4f":t=n(this,i,z).call(this,e[4],t);break;case"45":t=n(this,i,Q).call(this,e[4],t);break;case"46":t=n(this,i,Y).call(this,e[4],t);break;case"48":t=n(this,i,Z).call(this,e[4],t);break;case"76":t=n(this,i,X).call(this,e[4],t);break;case"63":t=n(this,i,tt).call(this,e[4],t);break;case"65":t=n(this,i,et).call(this,e[4],t);break;case"66":t=n(this,i,it).call(this,e[4],t);break;case"67":t=n(this,i,nt).call(this,e[4],t);break}break}return t},_=function(){this.__internal__.dispense.dispensing&&(this.__internal__.dispense.status=!0)},l=function(){this.__internal__.dispense.dispensing&&(this.__internal__.dispense.status=!1)},m=function(){this.__internal__.dispense.dispensing&&(this.__internal__.dispense.status="elevator-locked")},d=function({type:e=null,severity:t="low"}={}){this.dispatch("jofemar:warning",{type:e,severity:t})},f=function({type:e=null,severity:t="high"}={}){this.dispatch("jofemar:error",{type:e,severity:t})},st=function(e,t){if(t.request="status",e[1]&&!e[2]){switch(e[1]){case"30":t.name="Machine ready",t.description="The machine is ready for instructions",t.no_code=9,n(this,i,_).call(this);break;case"31":t.name="Machine busy",t.description="The machine is busy right now",t.no_code=10;break;case"32":t.name="Invalid tray",t.description="The tray requested is invalid",t.no_code=11,n(this,i,l).call(this),n(this,i,d).call(this,{type:"invalid-tray"});break;case"33":t.name="Invalid channel",t.description="The channel requested is invalid",t.no_code=12,n(this,i,l).call(this),n(this,i,d).call(this,{type:"invalid-channel"});break;case"34":t.name="Empty channel",t.description="The channel requested is empty",t.no_code=13,n(this,i,l).call(this),n(this,i,d).call(this,{type:"empty-channel"});break;case"35":t.name="Jam",t.description="Jam in elevator engine",t.no_code=14,n(this,i,l).call(this),n(this,i,f).call(this,{type:"jam"});break;case"36":t.name="Malfunction",t.description="Malfunction in the elevator belt or product detector",t.no_code=15,n(this,i,l).call(this),n(this,i,f).call(this,{type:"malfunction"});break;case"37":t.name="Photo transistors",t.description="Failure in one of the photo transistors in the cabinet",t.no_code=16,n(this,i,l).call(this),n(this,i,f).call(this,{type:"photo-transistors"});break;case"38":t.name="Without channels",t.description="No channels detected",t.no_code=17,n(this,i,l).call(this),n(this,i,f).call(this,{type:"without-channels"});break;case"39":t.name="Product detector fault",t.description="Product detector fault",t.no_code=18,n(this,i,m).call(this),n(this,i,d).call(this,{type:"fault-product-detector"});break;case"41":t.name="Fault in 485 BUS",t.description="Machine display is disconnected",t.no_code=19,n(this,i,_).call(this),n(this,i,d).call(this,{type:"display-disconnected"});break;case"42":t.name="Product under elevator",t.description="Product alarm under elevator",t.no_code=20,n(this,i,l).call(this),n(this,i,d).call(this,{type:"product-under-elevator"});break;case"43":t.name="Error when elevator approaching to a position",t.description="Error when elevator approaching to a position",t.no_code=21,n(this,i,_).call(this),n(this,i,d).call(this,{type:"error-approaching-position",severity:"high"});break;case"44":t.name="Fault in keyboard",t.description="Fault in keyboard",t.no_code=22,n(this,i,l).call(this),n(this,i,f).call(this,{type:"fault-keyboard"});break;case"45":t.name="Eeprom writing error",t.description="Eeprom writing error",t.no_code=23,n(this,i,l).call(this),n(this,i,f).call(this,{type:"eeprom-writing-error",severity:"critical"});break;case"46":t.name="Fault communicating with temperature control",t.description="Fault communicating with temperature control",t.no_code=24,n(this,i,_).call(this),n(this,i,d).call(this,{type:"fault-temperature-control"});break;case"47":t.name="Thermometer disconnected",t.description="The thermometer is disconnected",t.no_code=25,n(this,i,_).call(this),n(this,i,d).call(this,{type:"thermometer-disconnected"});break;case"48":t.name="Thermometer programming lost",t.description="Thermometer programming lost",t.no_code=26,n(this,i,_).call(this),n(this,i,d).call(this,{type:"thermometer-programming-lost"});break;case"49":t.name="Thermometer faulty",t.description="Thermometer faulty",t.no_code=27,n(this,i,_).call(this),n(this,i,d).call(this,{type:"thermometer-faulty"});break;case"4a":t.name="Channels power consumption detector faulty",t.description="Channels power consumption detector faulty",t.no_code=28,n(this,i,l).call(this),n(this,i,f).call(this,{type:"channels-power-consumption-detector-faulty",severity:"critical"});break;case"4b":t.name="Elevator does not find channel or tray",t.description="Elevator does not find channel or tray",t.no_code=29,n(this,i,l).call(this),n(this,i,d).call(this,{type:"elevator-not-find-channel-tray"});break;case"4c":t.name="Elevator does not find delivery product position",t.description="Elevator does not find delivery product position",t.no_code=30,n(this,i,l).call(this),n(this,i,f).call(this,{type:"elevator-not-find-delivery-position"});break;case"4d":t.name="Interior of elevator blocked",t.description="Interior of elevator blocked",t.no_code=31,n(this,i,m).call(this),this.__internal__.dispense.elevator.need_reset||(this.__internal__.dispense.elevator.need_reset=!0),n(this,i,f).call(this,{type:"interior-elevator-blocked",severity:"low"});break;case"4e":t.name="Error in tester of product detector",t.description="Error in tester of product detector",t.no_code=32,n(this,i,l).call(this),n(this,i,f).call(this,{type:"error-tester-product-detector"});break;case"4f":t.name="Waiting for product to be removed",t.description="Waiting for product to be removed",t.no_code=33,n(this,i,m).call(this);break;case"50":t.name="Product expired by temperature reasons",t.description="Product expired by temperature reasons",t.no_code=34,n(this,i,_).call(this),n(this,i,d).call(this,{type:"product-expired-temperature"});break;case"51":t.name="Automatic door faulty",t.description="Automatic door faulty",t.no_code=35,n(this,i,_).call(this),n(this,i,d).call(this,{type:"automatic-door-faulty"});break;case"59":case"5a":case"61":case"62":case"63":switch(t.name="Product is expired",t.description="Product is expired",t.additional={nsf_alarm:1},e[1]){case"5a":t.additional.nsf_alarm=2;break;case"61":t.additional.nsf_alarm=3;break;case"62":t.additional.nsf_alarm=4;break;case"63":t.additional.nsf_alarm=5;break}t.no_code=36,n(this,i,_).call(this),n(this,i,d).call(this,{type:"product-expired"});break;case"64":t.name="Product detector didn't change during its verification test",t.description="Product detector didn't change during its verification test",t.no_code=37,n(this,i,_).call(this),n(this,i,d).call(this,{type:"automatic-door-faulty"});break}this.dispatch("machine:status",t)}else t.name="executed",t.description="The last command was executed successfully",t.no_code=8,!e[1]&&this.__internal__.dispense.dispensing&&n(this,i,l).call(this);return t},ht=function(e){if(e=parseInt(e)+109,e=e.toString(),e.length!==3)throw new Error("Invalid selection");const t=(parseInt(e.substring(0,2))+128).toString(16).padStart(2,"0");return{channel:(parseInt(e.substring(2,3))+128).toString(16).padStart(2,"0"),tray:t}},lt=function(){this.__internal__.dispense.timeout&&clearTimeout(this.__internal__.dispense.timeout),this.__internal__.dispense.interval&&clearInterval(this.__internal__.dispense.interval),this.__internal__.dispense.timeout=0,this.__internal__.dispense.interval=0},dt=function(){this.__internal__.dispense.timeout&&clearTimeout(this.__internal__.dispense.timeout),this.__internal__.dispense.interval&&clearInterval(this.__internal__.dispense.interval);const e=this;e.__internal__.dispense.timeout=setTimeout(()=>{e.__internal__.dispense.interval=setInterval(()=>{e.status().then(()=>{})},e.__internal__.dispense.interval_time)},e.__internal__.dispense.timeout_time)},k=async function(e){const t=["02","30","30","81","52",e,"FF"];return await n(this,i,u).call(this,t,"reset")},S=function(){const e=this.__device.type==="iceplus"?w.getSeconds(40):w.getSeconds(25),t=new Date,r=1e3*e+t.getTime(),a=new Date(r);this.dispatch("reset:errors",{description:"Resetting machine errors",duration:e,started_at:t,finished_at:a})},M=async function(e){const t=["02","30","30","81","4C",e,"FF"];return await n(this,i,u).call(this,t,"lights")},D=async function(e="80",t=[]){const r=["02","30","30","81","44",e,...t];return await n(this,i,u).call(this,r,"display")},I=function(e=""){e=e.padEnd(32," ");const t=[];for(let r=0;r<32;r++)t.push(e.charCodeAt(r).toString(16));return t},pt=function(e){if(!(e instanceof Date))throw new Error("Invalid date, must be an instance of Date");const t=e.getHours().toString().padStart(2,"0"),r=e.getMinutes().toString().padStart(2,"0"),a=e.getDate().toString().padStart(2,"0"),o=(e.getMonth()+1).toString().padStart(2,"0"),c=e.getFullYear().toString().substring(2,4),s=`${t}:${r} ${a}-${o}-${c}`,v=[];for(let y=0;y<14;y++)v.push(s.charCodeAt(y).toString(16));return v};exports.Jofemar=yt;
1
+ "use strict";var _t=Object.defineProperty;var F=p=>{throw TypeError(p)};var ft=(p,h,e)=>h in p?_t(p,h,{enumerable:!0,configurable:!0,writable:!0,value:e}):p[h]=e;var N=(p,h,e)=>ft(p,typeof h!="symbol"?h+"":h,e),vt=(p,h,e)=>h.has(p)||F("Cannot "+e);var P=(p,h,e)=>h.has(p)?F("Cannot add the same private member more than once"):h instanceof WeakSet?h.add(p):h.set(p,e);var n=(p,h,e)=>(vt(p,h,"access private method"),e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const w=require("./kernel-C0epz_jB.cjs");var i,A,g,B,u,E,$,W,q,O,j,R,J,L,U,H,V,K,G,z,Q,Y,Z,X,tt,et,it,nt,rt,at,ot,ct,_,l,m,d,f,st,ht,lt,dt,k,S,M,D,I,pt;class yt extends w.Kernel{constructor({filters:e=null,config_port:t=null,no_device:r=1,device_listen_on_port:a=1,type:o="esplus",support_cart:c=!0}={}){super({filters:e,config_port:t,no_device:r,device_listen_on_port:a});P(this,i);N(this,"__device",{type:"esplus",support_cart:!1,withdraw:{in_process:!1,seconds:60,interval:0},cart:{in_process:!1},channels:{verification:{clear(){this.running=!1,this.current=1,this.channels=[]},running:!1,start:1,end:80,current:1,channels:[]}}});if(this.__internal__.device.type="jofemar",w._.getCustom(this.typeDevice,r))throw new Error(`Device ${this.typeDevice} ${r} already exists`);this.__internal__.dispense.must_response=!0,this.__internal__.time.response_general=800,this.__internal__.time.response_engines=800,this.__internal__.dispense.limit_counter=40,this.__internal__.dispense.timeout=0,this.__internal__.dispense.timeout_time=4e3,this.__internal__.dispense.interval=0,this.__internal__.dispense.interval_time=1e3,this.__internal__.device.hex_number=(128+this.listenOnChannel).toString(16),this.__internal__.device.door_open=!1,this.__internal__.dispense.elevator={locking_time:60,locking_interval:0,need_reset:!1},this.deviceType=o,this.supportCart=c,n(this,i,A).call(this),n(this,i,B).call(this),n(this,i,g).call(this)}set startChannelVerification(e){const t=parseInt(e);if(isNaN(t))throw new Error("Invalid start channel verification, must be a number");if(t<1||t>126)throw new Error("Invalid start channel verification, valid range is 1 to 126");this.__device.channels.verification.start=t}set endChannelVerification(e){const t=parseInt(e);if(isNaN(t))throw new Error("Invalid end channel verification, must be a number");if(t<1||t>126)throw new Error("Invalid end channel verification, valid range is 1 to 126");this.__device.channels.verification.end=t}set listenOnChannel(e){if(e=parseInt(e),isNaN(e)||e<1||e>31)throw new Error("Invalid port number, valid range is 1 to 31");this.__internal__.device.listen_on_port=e,this.__internal__.serial.bytes_connection=this.serialSetConnectionConstant(e),this.__internal__.device.hex_number=(128+e).toString(16)}set listenOnPort(e){this.listenOnChannel=e}set deviceType(e){if(typeof e!="string")throw new Error("Invalid device type, must be a string");this.__device.type=e}set supportCart(e){if(typeof e!="boolean")throw new Error("Invalid support cart, must be a boolean");this.__device.support_cart=e}serialJofemarMakeBytes(e){let t=this.hexToDec(this.sumHex(e)),r=this.calcCheckSums(t.toString());for(let a=0;a<2;a++)e.push(this.hexMaker(r[a]));return e.push("03"),this.add0x(e)}calcCheckSums(e){e=this.add0x([this.decToHex(parseInt(e).toString())]);let t=[];return t.push((e&255|240).toString(16).toUpperCase()),t.push((e&255|15).toString(16).toUpperCase()),t}serialSetConnectionConstant(e=1){let t=["02","30","30",(128+e).toString(16),"53","FF","FF"],r=[];return t.forEach(a=>{r.push(this.hexMaker(a))}),this.serialJofemarMakeBytes(r)}serialMessage(e){let r={code:e,name:null,description:null,request:"unknown",no_code:0,additional:{machine:{hex:null,dec:null}}};switch(e[0]){case"02":r=n(this,i,ct).call(this,e,r,128);break;case"06":r=n(this,i,st).call(this,e,r);break;case"15":r.name="Checksum error",r.description="The calculated checksum does not match the received checksum",r.no_code=38,n(this,i,l).call(this);break;default:r.name="unknown",r.description="The message received is unknown",r.no_code=404;break}this.dispatch("serial:message",r)}productRemovedContinueDispensing(){this.__internal__.dispense.elevator.locking_interval&&(this.__internal__.dispense.elevator.locking_time=0)}async dispense({selection:e=1,cart:t=!1}={}){if(e=parseInt(e),isNaN(e)||e<1||e>130)throw new Error("Invalid selection");const{channel:r,tray:a}=n(this,i,ht).call(this,e);this.__internal__.dispense.backup_dispense={selection:e,cart:t,channel:r,tray:a};let c=["02","30","30",this.__internal__.device.hex_number,"56",a,r];t&&(c[4]="4D"),c=n(this,i,E).call(this,c);let s;do s=await this.internalDispense(c),n(this,i,lt).call(this),s.error==="elevator-locked"?await n(this,i,$).call(this):s.error==="no-response"&&await w.wait(1e3);while(["elevator-locked","no-response"].includes(s.error));return this.__internal__.dispense.backup_dispense={},s}internalClearSensing(){super.internalClearSensing(),this.__internal__.dispense.timeout&&clearTimeout(this.__internal__.dispense.timeout),this.__internal__.dispense.interval&&clearInterval(this.__internal__.dispense.interval),this.__internal__.serial.queue.length>0&&(this.__internal__.serial.queue=this.__internal__.serial.queue.filter(e=>e.type!=="status"))}async endDispense(){let t=["02","30","30",this.__internal__.device.hex_number,"4D","80","80"];return t=n(this,i,E).call(this,t),await this.internalDispense(t)}async collect(){const e=["02","30","30","81","4E","FF","FF"];return await n(this,i,u).call(this,e,"collect")}async resetSoldOutErrors(){return await n(this,i,k).call(this,"80")}async resetWaitingProductRemovedError(){return await n(this,i,k).call(this,"81")}async resetMachineErrors(){return this.__internal__.serial.queue.length===0?(n(this,i,S).call(this),await n(this,i,k).call(this,"FF")):new Promise(e=>{const t=setInterval(async()=>{this.__internal__.serial.queue.length>0||(clearInterval(t),await n(this,i,k).call(this,"FF"),n(this,i,S).call(this),e(!0))},100)})}async resetAllErrors(){return await this.resetSoldOutErrors(),await w.wait(100),await this.resetWaitingProductRemovedError(),await w.wait(100),await this.resetMachineErrors()}async status(){const e=["02","30","30","81","53","FF","FF"];return await n(this,i,u).call(this,e,"status")}async lightsOn(){return await n(this,i,M).call(this,"81")}async lightsOff(){return await n(this,i,M).call(this,"80")}async program(e,t){const r=["02","30","30","81","50",e,t];return await n(this,i,u).call(this,r,"program")}async programDisplayLanguage({language:e="spanish"}={}){const t={spanish:"30",english:"31",french:"32"};if(!t[e])throw new Error("Invalid language");return await this.program("49",t[e])}async programBeeper({enable:e=!0}={}){const t=e?"31":"30";return await this.program("5A",t)}async programDisableWorkingTemperature(){if(this.__device.type==="iceplus")throw new Error("IcePlus does not support disable working temperature");return await this.program("54","80")}async programDisableThermometer(){return await this.programDisableWorkingTemperature()}async programWorkingTemperature({degrees:e=.5}={}){e=parseFloat(e);const t=this.__device.type==="iceplus"?6.5:32,r=this.__device.type==="iceplus"?-25:.5;if(isNaN(e)||e<r||e>t||e%.5!==0)throw new Error("Invalid degrees, must be a multiple of 0.5 and between 0.5 and 32");let a=e*2+128;return this.__device.type==="iceplus"&&(a+=51),a=Math.ceil(a),await this.program("54",a.toString(16))}async programIsolationTray({tray:e=0}={}){if(e=parseInt(e),isNaN(e)||e<0||e>12)throw new Error("Invalid tray, valid range is 0 to 12");const t=e===0?"80":(e+139).toString(16);return this.program("42",t)}async programTimeToStandbyAfterCollect({seconds:e=15}={}){if(e=parseInt(e),isNaN(e)||e<15||e>120)throw new Error("Invalid seconds, valid range is 15 to 120");const t=(128+e).toString(16);return await this.program("46",t)}async programTimeToStandbyWithoutCollect({minutes:e=1}={}){if(e=parseInt(e),isNaN(e)||e<1||e>10)throw new Error("Invalid minutes, valid range is 1 to 10");const t=(128+e).toString(16);return await this.program("48",t)}async programElevatorSpeed({speed:e="high"}={}){const t={high:"31",low:"30"};if(!t[e])throw new Error("Invalid speed, valid speeds are 'high' and 'low'");return await this.program("76",t[e])}async programTemperatureExpiration({enable:e=!1}={}){const t=e?"31":"30";return await this.program("63",t)}async programEnableTemperatureExpiration(){return await this.programTemperatureExpiration({enable:!0})}async programDisableTemperatureExpiration(){return await this.programTemperatureExpiration({enable:!1})}async programMachineAddress({address:e=1}={}){if(e=parseInt(e),isNaN(e)||e<1||e>31)throw new Error("Invalid address, valid range is 1 to 31");const t=(128+e).toString(16);return await this.program("64",t)}async programTemperatureBeforeExpiration({degrees:e=.5}={}){if(e=parseFloat(e),isNaN(e)||e<.5||e>30||e%.5!==0)throw new Error("Invalid degrees, must be a multiple of 0.5 and valid range is 0.5 to 30");const t=(128+e*2).toString(16);return await this.program("65",t)}async programTimeBeforeExpirationByTemperature({minutes:e=1}={}){if(e=parseInt(e),isNaN(e)||e<1||e>120)throw new Error("Invalid minutes, valid range is 1 to 120");const t=(128+e).toString(16);return await this.program("66",t)}async programTemperatureScale({scale:e="c"}={}){const t={c:"43",f:"46"};if(!t[e])throw new Error("Invalid scale, valid scales are 'c' for celsius and 'f' for fahrenheit");return await this.program("67",t[e])}async programVoltageEngine({selection:e=1,voltage:t=5}={}){if(t=parseFloat(t),e=parseInt(e),isNaN(e)||e<1||e>this.__device.channels.verification.end)throw new Error(`Invalid selection, valid range is 1 to ${this.__device.channels.verification.end}`);if(isNaN(t)||t<5||t>9.5||t%.5!==0)throw new Error("Invalid voltage, valid range is 5 to 9.5");const r=109+e,o=(128+(t-5)*2).toString(16),c=["02","30","30","81","47",r,o];return await n(this,i,u).call(this,c,"voltage-engine")}async programPushOverProducts({selection:e=1,enable:t=!0}={}){if(e=parseInt(e),isNaN(e)||e<1||e>this.__device.channels.verification.end)throw new Error(`Invalid selection, valid range is 1 to ${this.__device.channels.verification.end}`);const o=["02","30","30","81","4F",109+e,t?"31":"30"];return await n(this,i,u).call(this,o,"push-over-products")}async programChannelRunningAfterDispense({selection:e=1,seconds:t=0}={}){if(e=parseInt(e),t=parseFloat(t),isNaN(e)||e<1||e>this.__device.channels.verification.end)throw new Error(`Invalid selection, valid range is 1 to ${this.__device.channels.verification.end}`);if(isNaN(t)||t<0||t>10||t%.1!==0)throw new Error("Invalid seconds, valid range is 0.0 to 10.0 with a step of 0.1");const r=109+e;t=t.toFixed(1);const a=128+t*10,o=["02","30","30","81","45",r,a];return await n(this,i,u).call(this,o,"channel-running-after-dispense")}async checkData(e,t="FF"){const r=["02","30","30","81","43",e,t];return await n(this,i,u).call(this,r,"check-data")}async getDisplayLanguage(){return await this.checkData("49")}async getBeeper(){return await this.checkData("5A")}async getWorkingTemperature(){return await this.checkData("54")}async getIsolationTray(){return await this.checkData("42")}async getProgramVersion(){return await this.checkData("50")}async getFaults(){return await this.checkData("53")}async getMachineId(){return await this.checkData("4E")}async getCurrentTemperature(){return await this.checkData("74")}async getTimeToStandbyAfterCollect(){return await this.checkData("46")}async getTimeToStandbyWithoutCollect(){return await this.checkData("48")}async getElevatorSpeed(){return await this.checkData("76")}async getTemperatureExpiration(){return await this.checkData("63")}async getTemperatureBeforeExpiration(){return await this.checkData("65")}async getTimeBeforeExpirationByTemperature(){return await this.checkData("66")}async getTemperatureScale(){return await this.checkData("67")}async getClockRegisters(){return await this.checkData("72")}async getMachineActivity(){return await this.checkData("41")}async getVoltageEngine({selection:e=1}={}){if(e=parseInt(e),isNaN(e)||e<1||e>126)throw new Error("Invalid selection, valid range is 1 to 126");const t=(109+e).toString(16);return await this.checkData("47",t)}async getChannelPresence({selection:e=1}={}){if(e=parseInt(e),isNaN(e)||e<1||e>126)throw new Error("Invalid selection, valid range is 1 to 126");const t=(109+e).toString(16);return await this.checkData("43",t)}async getPushOverProducts({selection:e=1}={}){if(e=parseInt(e),isNaN(e)||e<1||e>126)throw new Error("Invalid selection, valid range is 1 to 126");const t=(109+e).toString(16);return await this.checkData("4F",t)}async getChannelRunningAfterDispense({selection:e=1}={}){if(e=parseInt(e),isNaN(e)||e<1||e>126)throw new Error("Invalid selection, valid range is 1 to 126");const t=(109+e).toString(16);return await this.checkData("45",t)}async setDisplayStandbyMessage({message:e=""}={}){e=e.substring(0,32);const t=n(this,i,I).call(this,e);return await n(this,i,D).call(this,"80",t)}async setDisplayMessageTemporarily({message:e="",seconds:t=1}){if(e=e.substring(0,32),t=parseInt(t),isNaN(t)||t<1||t>125)throw new Error("Invalid seconds, valid range is 1 to 125");const r=n(this,i,I).call(this,e),a=(128+t).toString(16);return await n(this,i,D).call(this,a,r)}async setDisplayMessageUnlimited({message:e=""}){e=e.substring(0,32);const t=n(this,i,I).call(this,e);return await n(this,i,D).call(this,"FF",t)}async programClock({date:e=new Date}={}){if(!(e instanceof Date))throw new Error("Invalid date, must be an instance of Date");const t=["02","30","30","81","72",...n(this,i,pt).call(this,e)];return await n(this,i,u).call(this,t,"clock")}async eventsConfig({event:e=null,enable:t=!0}={}){if(e===null)throw new Error("Invalid event");const a=["02","30","30","81","41",e,t?"31":"30"];return await n(this,i,u).call(this,a,"events-config")}async eventEnable({event:e=null}={}){if(e===null)throw new Error("Invalid event");const t=parseInt(e,16);if(isNaN(t)||t<38||t>100)throw new Error("Invalid event");return await this.eventsConfig({event:e,enable:!0})}async eventDisable({event:e=null}={}){if(e===null)throw new Error("Invalid event");const t=parseInt(e,16);if(isNaN(t)||t<38||t>100)throw new Error("Invalid event");return await this.eventsConfig({event:e,enable:!1})}async sendCustomCode({code:e=[]}={}){if(e.length<5)throw new Error("Invalid code, minimum length is 5");return await n(this,i,u).call(this,e,"custom")}async assignChannels(){const e=this.__device.channels.verification.start,t=this.__device.channels.verification.end;if(e>t)throw new Error("Invalid range, start must be less than end");this.__device.channels.verification.clear(),this.__device.channels.verification.running=!0;for(let r=e;r<=t;r++)this.__device.channels.verification.current=r,await this.getChannelPresence({selection:r});return new Promise(r=>{let a=setInterval(()=>{this.__device.channels.verification.channels.length===t-e+1&&(clearInterval(a),this.dispatch("channels",{channels:this.__device.channels.verification.channels}),this.__device.channels.verification.clear(),r(!0))},500)})}}i=new WeakSet,A=function(){const e=["dispensing:withdrawal","command-executed","keyboard:pressed","door:event","program:version","machine:faults","clock:registers","machine:activity","check:language","check:beeper","check:isolation-tray","check:engine-voltage","check:push-over","check:extractor-after-dispense","check:standby-after-collect","check:standby-without-collect","check:elevator-speed","check:expiration-by-temperature","check:temperature-before-expiration","check:expiration-after","check:temperature-scale","check:machine-id","temperature:working","temperature:current","jofemar:warning","jofemar:error","serial:message","reset:errors","channels","channel:status","machine:status"];for(const t of e)this.serialRegisterAvailableListener(t)},g=function(){this.on("internal:dispense:running",n(this,i,dt).bind(this))},B=function(){w._.add(this)},u=function(e,t){return e[3]=this.__internal__.device.hex_number,this.appendToQueue(n(this,i,E).call(this,e),t)},E=function(e){let t=this.hexToDec(this.sumHex(e)),r=this.calcCheckSums(t.toString());for(let a=0;a<2;a++)e.push(this.hexMaker(r[a]));return e.push("03"),e},$=async function(){if(this.__internal__.dispense.elevator.locking_interval)return;this.__internal__.dispense.elevator.need_reset&&(this.__internal__.dispense.elevator.need_reset=!1,await this.resetWaitingProductRemovedError(),await w.wait(500));const e=this;return this.__internal__.dispense.status="elevator-locked",this.__internal__.dispense.elevator.locking_time=60,new Promise(t=>{e.__internal__.dispense.elevator.locking_interval=setInterval(()=>{e.dispatch("dispensing:withdrawal",{elevator:!0,seconds:e.__internal__.dispense.elevator.locking_time,description:"Please recall products from the elevator"}),e.__internal__.dispense.elevator.locking_time-=1,e.__internal__.dispense.elevator.locking_time<=0&&(clearInterval(e.__internal__.dispense.elevator.locking_interval),e.__internal__.dispense.elevator.locking_interval=0,t(!0))},1e3)})},W=function(e,t){return t.name="ok",t.description="The last command was executed successfully",t.no_code=1,this.dispatch("command-executed",t),t},q=function(e,t){t.additional={hex:e,dec:this.hexToDec(e),ascii:null};const r={30:"0",31:"1",32:"2",33:"3",34:"4",35:"5",36:"6",37:"7",38:"8",39:"9","2a":"*",23:"#",41:"A",42:"B",43:"C",44:"D"};return t.additional.ascii=r[e]??null,t.name="Key pressed",t.description=`The key ${t.additional.ascii} was pressed`,t.no_code=2,this.dispatch("keyboard:pressed",t.additional),t},O=function(e,t){return t.additional={open:!1},t.no_code=3,e==="4f"?(t.name="door open",t.description="The door was opened",t.additional.open=!0,this.__internal__.device.door_open=!0,this.dispatch("door:event",t.additional)):e==="43"?(t.name="door close",t.description="The door was closed",t.additional.open=!1,this.__internal__.device.door_open=!1,this.dispatch("door:event",t.additional)):(t.name="door event",t.description="The door event received is unknown",this.dispatch("door:event",{open:t.additional.open,message:t})),t},j=function(e,t){t.no_code=404;let r=e[5]??null;return r&&this.listenOnChannel>1&&(r=this.hexToDec(r)-this.listenOnChannel+1,r=this.decToHex(r)),r&&(r==="FD"?(t.no_code=4,t.name="channel disconnected",t.description="The channel is disconnected",t.additional={active:!1}):r==="FC"?(t.no_code=5,t.name="channel connected",t.description="The channel is connected",t.additional={active:!0}):(t.no_code=6,t.name="channel sold out",t.description="The channel is empty",t.additional={active:!0}),this.__device.channels.verification.running&&(this.__device.channels.verification.channels.push({selection:this.__device.channels.verification.current,active:t.additional.active}),t.additional.selection=this.__device.channels.verification.current),this.dispatch("channel:status",t.additional)),t},R=function(e,t){t.no_code=39,t.name="Program version";const r=e.slice(4,12),a=r.map(o=>String.fromCharCode(this.hexToDec(o))).join("");return t.additional={version:a,hex:r},t.description=`The program version is ${a}`,this.dispatch("program:version",t.additional),t},J=function(e,t){t.no_code=39,t.name="Machine faults",t.description="No faults detected",t.additional={no_faults:0,faults:[]};const r=e.slice(4,-3);if(r.length>1&&r[0]!=="30"){t.description="Machine has faults";const a={31:"Busy",32:"Invalid tray",33:"Invalid channel",34:"Empty channel",35:"Jam in elevator engine",36:"Malfunction in the elevator belt or product detector",37:"Failure in one of the photo transistors in the cabinet",38:"No channels detected",39:"Product detector fault",41:"Machine display is disconnected",42:"Product alarm under elevator",43:"Error when elevator approaching to a position",44:"Fault in keyboard",45:"Eeprom writing error",46:"Fault communicating with temperature control",47:"The thermometer is disconnected",48:"Thermometer programming lost",49:"Thermometer faulty","4a":"Channels power consumption detector faulty","4b":"Elevator does not find channel or tray","4c":"Elevator does not find delivery product position","4d":"Interior of elevator blocked","4e":"Error in tester of product detector","4f":"Waiting for product to be removed",50:"Product expired by temperature reasons",51:"Automatic door faulty",59:"Product is expired","5a":"Product is expired",61:"Product is expired",62:"Product is expired",63:"Product is expired",64:"Product detector didn't change during its verification test"};for(const o of r)a[o]&&(t.additional.faults.push(a[o]),t.additional.no_faults++)}return this.dispatch("machine:faults",t.additional),t},L=function(e,t){t.no_code=40,t.name="Clock registers",t.description="Clock registers";const r=e.slice(4,-3),a=r.map(C=>String.fromCharCode(this.hexToDec(C))).join(""),[o,c]=a.split(" "),[s,v]=o.split(":"),[y,b,x]=c.split("-"),T=new Date(2e3+parseInt(x),parseInt(b)-1,parseInt(y),parseInt(s),parseInt(v));return t.additional={day:y,month:b,year:x,hours:s,minutes:v,formatted:a,date:T,hex:r},this.dispatch("clock:registers",t.additional),t},U=function(e,t){t.no_code=41,t.name="Machine activity",t.description="Events from read machine activity";const r=String.fromCharCode(this.hexToDec(e[4]));if(r!=="0"){const a=e.slice(5,-3);if(r==="T"&&a.length===4){const o=String.fromCharCode(this.hexToDec(a[0])),c=String.fromCharCode(this.hexToDec(a[1])),s=String.fromCharCode(this.hexToDec(a[3]));t.additional={ascii:r,type:"DU.d",dozens:o,units:c,decimals:s,time:parseFloat(`${o}${c}.${s}`),meaning:"Extraction time (in seconds)"}}else if(["B","D","E","F","G"].includes(r)&&a.length===3){const o=String.fromCharCode(this.hexToDec(a[0])),c=String.fromCharCode(this.hexToDec(a[1])),s=String.fromCharCode(this.hexToDec(a[2])),v=parseInt(`${o}${c}${s}`),y={B:"Error on going to tray channel",D:"Error on product detector",E:"Extraction of channel ok",F:"Error on engine intensity detection",G:"Error on product exit door"};t.additional={type:"HDU",hundreds:o,dozens:c,decimals:s,channel:v,selection:v-109,ascii:r,meaning:y[r]??"Unknown"}}else if(a.length===13){const o=a.map(ut=>String.fromCharCode(this.hexToDec(ut))).join(""),c=parseInt(o.slice(0,2)),s=parseInt(o.slice(2,4)),v=parseInt(o.slice(4,6)),y=parseInt(o.slice(7,9)),b=parseInt(o.slice(9,11))-1,x=2e3+parseInt(o.slice(11,13)),T=new Date(x,b,y,c,s,v),C={A:"Attempt to close product exit door",C:"Closing of exterior door",H:"Error on opening of product exit door",I:"New attempt to arrive at product exit position after an error on first attempt",J:"Power on cooling unit",K:"Power off cooling unit",L:"Start of defrosting",M:"End of defrosting",O:"Opening of exterior door",R:"Memory reset",S:"Error on going to product exit position",Y:"Power on machine",Z:"Power off machine",c:"Closing of inner door",e:"New attempt to extract from channel due no product detection when elevator arrived to product exit position",o:"Opening of inner door"};t.additional={type:"hhmmssWddMMAA",date:T,hex:a,formatted:T.toLocaleString(),ascii:r,meaning:C[r]??"Unknown"}}}return this.dispatch("machine:activity",t.additional),t},H=function(e,t){const r={30:"Spanish",31:"English",32:"French"};return t.no_code=42,t.name="Language",t.description=`The language is ${r[e]??"unknown"}`,t.additional={hex:e,language:r[e]??"unknown"},this.dispatch("check:language",t.additional),t},V=function(e,t){return t.no_code=43,t.name="Beeper",t.description=`The beeper is ${e==="30"?"on":"off"}`,t.additional={hex:e,beeper:e==="30"},this.dispatch("check:beeper",t.additional),t},K=function(e,t){t.no_code=44,t.name="Isolation tray",t.description="Isolation tray";const r=this.hexToDec(e)-139;return t.additional={hex:e,tray:r},this.dispatch("check:isolation-tray",t.additional),t},G=function(e,t){t.no_code=45,t.name="Engine voltage",t.description="Engine voltage";const r=(this.hexToDec(e)-128)/2+5;return t.additional={hex:e,voltage:r},this.dispatch("check:engine-voltage",t.additional),t},z=function(e,t){t.no_code=46,t.name="Push over",t.description="Push over";const r=e==="30";return t.additional={hex:e,push:r},this.dispatch("check:push-over",t.additional),t},Q=function(e,t){t.no_code=47,t.name="Extractor after dispense",t.description="Extractor after dispense";const r=(this.hexToDec(e)-128)/10;return t.additional={hex:e,seconds:r},this.dispatch("check:extractor-after-dispense",t.additional),t},Y=function(e,t){t.no_code=48,t.name="Standby after collect",t.description="Time to standby after collect product";const r=this.hexToDec(e)-128;return t.additional={hex:e,seconds:r},this.dispatch("check:standby-after-collect",t.additional),t},Z=function(e,t){t.no_code=49,t.name="Standby without collect",t.description="Time to standby when product delivery is not collected";const r=this.hexToDec(e)-128;return t.additional={hex:e,minutes:r},this.dispatch("check:standby-without-collect",t.additional),t},X=function(e,t){t.no_code=50,t.name="Elevator speed",t.description="Elevator speed";const r=e==="30"?"low":"high";return t.additional={hex:e,speed:r},this.dispatch("check:elevator-speed",t.additional),t},tt=function(e,t){t.no_code=51,t.name="Temperature expiration",t.description="Temperature expiration";const r=e==="31";return t.additional={hex:e,enabled:r},this.dispatch("check:expiration-by-temperature",t.additional),t},et=function(e,t){t.no_code=52,t.name="Temperature before expiration",t.description="Temperature before expiration";const r=(this.hexToDec(e)-128)/2;return t.additional={hex:e,temperature:r},this.dispatch("check:temperature-before-expiration",t.additional),t},it=function(e,t){t.no_code=53,t.name="Time before expiration",t.description="Time before expiration";const r=this.hexToDec(e)-128;return t.additional={hex:e,minutes:r},this.dispatch("check:expiration-after",t.additional),t},nt=function(e,t){t.no_code=54,t.name="Temperature scale",t.description="Temperature scale";const r=e==="43"?"Celsius":"Fahrenheit";return t.additional={hex:e,scale:r},this.dispatch("check:temperature-scale",t.additional),t},rt=function(e,t){return t.no_code=54,t.name="Machine ID",t.description="Machine ID",t.additional={hex:e[4],full_hex:e},this.dispatch("check:machine-id",t.additional),t},at=function(e,t){return t.no_code=7,t.name="working temperature",t.description=`The working temperature is ${e}`,t.additional={hex:e,temperature:{traditional:(this.hexToDec(e)-this.hexToDec("80"))/2,ice_plus:(this.hexToDec(e)-this.hexToDec("80"))/2-25.5}},this.dispatch("temperature:working",t.additional),t},ot=function(e,t){return t.no_code=8,t.name="current temperature",t.additional={sign:null,tens:null,units:null,decimals:null,type_degrees:null,formatted:null,decimal_point:e[7]==="2e"?".":null,degrees:e[9]==="7f"?"°":null,error:null},e[4]==="2b"?t.additional.sign=e[4]="+":["2e","2d"].includes(e[4])?t.additional.sign=e[4]="-":e[4]==="20"&&(t.additional.error="Error in thermometer"),this.hexToDec(e[5])>=48&&this.hexToDec(e[5])<=57?t.additional.tens=this.hexToDec(e[5])-48:e[5]==="2a"&&(t.additional.error="Error in thermometer"),this.hexToDec(e[6])>=48&&this.hexToDec(e[6])<=57?t.additional.units=this.hexToDec(e[6])-48:e[6]==="2a"&&(t.additional.error="Error in thermometer"),this.hexToDec(e[8])>=48&&this.hexToDec(e[8])<=57?t.additional.decimals=this.hexToDec(e[8])-48:e[8]==="2a"&&(t.additional.error="Error in thermometer"),e[10]==="43"?t.additional.type_degrees="C":e[10]==="46"&&(t.additional.type_degrees="F"),t.additional.error==="Error in thermometer"?(t.additional.formatted="Error in thermometer",t.description="The current temperature cannot be read because there is an error in the thermometer"):(t.additional.formatted=(t.additional.sign??"")+(t.additional.tens??"")+(t.additional.units??"")+(t.additional.decimal_point??"")+(t.additional.decimals??"")+(t.additional.degrees??"")+(t.additional.type_degrees??""),t.description=`The current temperature is ${t.additional.formatted}`),this.dispatch("temperature:current",t.additional),t},ct=function(e,t,r=128){if(e[1]&&(t.additional.machine.hex=e[1],t.additional.machine.dec=this.hexToDec(e[1])-r),!(e[1]&&e[2]))t=n(this,i,W).call(this,e,t);else switch(e[2]){case"54":t.request="--automatic",t=n(this,i,q).call(this,e[3],t);break;case"50":t.request="--automatic",t=n(this,i,O).call(this,e[3],t);break;case"43":switch(t.request="check-data",e[3]){case"41":t=n(this,i,U).call(this,e,t);break;case"43":t.request="channel-status",t=n(this,i,j).call(this,e,t);break;case"50":t=n(this,i,R).call(this,e,t);break;case"53":t=n(this,i,J).call(this,e,t);break;case"54":t.request="working-temperature",t=n(this,i,at).call(this,e[4],t);break;case"72":t=n(this,i,L).call(this,e,t);break;case"74":t.request="current-temperature",t=n(this,i,ot).call(this,e,t);break;case"49":t=n(this,i,H).call(this,e[4],t);break;case"5a":t=n(this,i,V).call(this,e[4],t);break;case"42":t=n(this,i,K).call(this,e[4],t);break;case"47":t=n(this,i,G).call(this,e[4],t);break;case"4e":t=n(this,i,rt).call(this,e,t);break;case"4f":t=n(this,i,z).call(this,e[4],t);break;case"45":t=n(this,i,Q).call(this,e[4],t);break;case"46":t=n(this,i,Y).call(this,e[4],t);break;case"48":t=n(this,i,Z).call(this,e[4],t);break;case"76":t=n(this,i,X).call(this,e[4],t);break;case"63":t=n(this,i,tt).call(this,e[4],t);break;case"65":t=n(this,i,et).call(this,e[4],t);break;case"66":t=n(this,i,it).call(this,e[4],t);break;case"67":t=n(this,i,nt).call(this,e[4],t);break}break}return t},_=function(){this.__internal__.dispense.dispensing&&(this.__internal__.dispense.status=!0)},l=function(){this.__internal__.dispense.dispensing&&(this.__internal__.dispense.status=!1)},m=function(){this.__internal__.dispense.dispensing&&(this.__internal__.dispense.status="elevator-locked")},d=function({type:e=null,severity:t="low"}={}){this.dispatch("jofemar:warning",{type:e,severity:t})},f=function({type:e=null,severity:t="high"}={}){this.dispatch("jofemar:error",{type:e,severity:t})},st=function(e,t){if(t.request="status",e[1]&&!e[2]){switch(e[1]){case"30":t.name="Machine ready",t.description="The machine is ready for instructions",t.no_code=9,n(this,i,_).call(this);break;case"31":t.name="Machine busy",t.description="The machine is busy right now",t.no_code=10;break;case"32":t.name="Invalid tray",t.description="The tray requested is invalid",t.no_code=11,n(this,i,l).call(this),n(this,i,d).call(this,{type:"invalid-tray"});break;case"33":t.name="Invalid channel",t.description="The channel requested is invalid",t.no_code=12,n(this,i,l).call(this),n(this,i,d).call(this,{type:"invalid-channel"});break;case"34":t.name="Empty channel",t.description="The channel requested is empty",t.no_code=13,n(this,i,l).call(this),n(this,i,d).call(this,{type:"empty-channel"});break;case"35":t.name="Jam",t.description="Jam in elevator engine",t.no_code=14,n(this,i,l).call(this),n(this,i,f).call(this,{type:"jam"});break;case"36":t.name="Malfunction",t.description="Malfunction in the elevator belt or product detector",t.no_code=15,n(this,i,l).call(this),n(this,i,f).call(this,{type:"malfunction"});break;case"37":t.name="Photo transistors",t.description="Failure in one of the photo transistors in the cabinet",t.no_code=16,n(this,i,l).call(this),n(this,i,f).call(this,{type:"photo-transistors"});break;case"38":t.name="Without channels",t.description="No channels detected",t.no_code=17,n(this,i,l).call(this),n(this,i,f).call(this,{type:"without-channels"});break;case"39":t.name="Product detector fault",t.description="Product detector fault",t.no_code=18,n(this,i,m).call(this),n(this,i,d).call(this,{type:"fault-product-detector"});break;case"41":t.name="Fault in 485 BUS",t.description="Machine display is disconnected",t.no_code=19,n(this,i,_).call(this),n(this,i,d).call(this,{type:"display-disconnected"});break;case"42":t.name="Product under elevator",t.description="Product alarm under elevator",t.no_code=20,n(this,i,l).call(this),n(this,i,d).call(this,{type:"product-under-elevator"});break;case"43":t.name="Error when elevator approaching to a position",t.description="Error when elevator approaching to a position",t.no_code=21,n(this,i,_).call(this),n(this,i,d).call(this,{type:"error-approaching-position",severity:"high"});break;case"44":t.name="Fault in keyboard",t.description="Fault in keyboard",t.no_code=22,n(this,i,l).call(this),n(this,i,f).call(this,{type:"fault-keyboard"});break;case"45":t.name="Eeprom writing error",t.description="Eeprom writing error",t.no_code=23,n(this,i,l).call(this),n(this,i,f).call(this,{type:"eeprom-writing-error",severity:"critical"});break;case"46":t.name="Fault communicating with temperature control",t.description="Fault communicating with temperature control",t.no_code=24,n(this,i,_).call(this),n(this,i,d).call(this,{type:"fault-temperature-control"});break;case"47":t.name="Thermometer disconnected",t.description="The thermometer is disconnected",t.no_code=25,n(this,i,_).call(this),n(this,i,d).call(this,{type:"thermometer-disconnected"});break;case"48":t.name="Thermometer programming lost",t.description="Thermometer programming lost",t.no_code=26,n(this,i,_).call(this),n(this,i,d).call(this,{type:"thermometer-programming-lost"});break;case"49":t.name="Thermometer faulty",t.description="Thermometer faulty",t.no_code=27,n(this,i,_).call(this),n(this,i,d).call(this,{type:"thermometer-faulty"});break;case"4a":t.name="Channels power consumption detector faulty",t.description="Channels power consumption detector faulty",t.no_code=28,n(this,i,l).call(this),n(this,i,f).call(this,{type:"channels-power-consumption-detector-faulty",severity:"critical"});break;case"4b":t.name="Elevator does not find channel or tray",t.description="Elevator does not find channel or tray",t.no_code=29,n(this,i,l).call(this),n(this,i,d).call(this,{type:"elevator-not-find-channel-tray"});break;case"4c":t.name="Elevator does not find delivery product position",t.description="Elevator does not find delivery product position",t.no_code=30,n(this,i,l).call(this),n(this,i,f).call(this,{type:"elevator-not-find-delivery-position"});break;case"4d":t.name="Interior of elevator blocked",t.description="Interior of elevator blocked",t.no_code=31,n(this,i,m).call(this),this.__internal__.dispense.elevator.need_reset||(this.__internal__.dispense.elevator.need_reset=!0),n(this,i,f).call(this,{type:"interior-elevator-blocked",severity:"low"});break;case"4e":t.name="Error in tester of product detector",t.description="Error in tester of product detector",t.no_code=32,n(this,i,l).call(this),n(this,i,f).call(this,{type:"error-tester-product-detector"});break;case"4f":t.name="Waiting for product to be removed",t.description="Waiting for product to be removed",t.no_code=33,n(this,i,m).call(this);break;case"50":t.name="Product expired by temperature reasons",t.description="Product expired by temperature reasons",t.no_code=34,n(this,i,_).call(this),n(this,i,d).call(this,{type:"product-expired-temperature"});break;case"51":t.name="Automatic door faulty",t.description="Automatic door faulty",t.no_code=35,n(this,i,_).call(this),n(this,i,d).call(this,{type:"automatic-door-faulty"});break;case"59":case"5a":case"61":case"62":case"63":switch(t.name="Product is expired",t.description="Product is expired",t.additional={nsf_alarm:1},e[1]){case"5a":t.additional.nsf_alarm=2;break;case"61":t.additional.nsf_alarm=3;break;case"62":t.additional.nsf_alarm=4;break;case"63":t.additional.nsf_alarm=5;break}t.no_code=36,n(this,i,_).call(this),n(this,i,d).call(this,{type:"product-expired"});break;case"64":t.name="Product detector didn't change during its verification test",t.description="Product detector didn't change during its verification test",t.no_code=37,n(this,i,_).call(this),n(this,i,d).call(this,{type:"automatic-door-faulty"});break}this.dispatch("machine:status",t)}else t.name="executed",t.description="The last command was executed successfully",t.no_code=8,!e[1]&&this.__internal__.dispense.dispensing&&n(this,i,l).call(this);return t},ht=function(e){if(e=parseInt(e)+109,e=e.toString(),e.length!==3)throw new Error("Invalid selection");const t=(parseInt(e.substring(0,2))+128).toString(16).padStart(2,"0");return{channel:(parseInt(e.substring(2,3))+128).toString(16).padStart(2,"0"),tray:t}},lt=function(){this.__internal__.dispense.timeout&&clearTimeout(this.__internal__.dispense.timeout),this.__internal__.dispense.interval&&clearInterval(this.__internal__.dispense.interval),this.__internal__.dispense.timeout=0,this.__internal__.dispense.interval=0},dt=function(){this.__internal__.dispense.timeout&&clearTimeout(this.__internal__.dispense.timeout),this.__internal__.dispense.interval&&clearInterval(this.__internal__.dispense.interval);const e=this;e.__internal__.dispense.timeout=setTimeout(()=>{e.__internal__.dispense.interval=setInterval(()=>{e.status().then(()=>{})},e.__internal__.dispense.interval_time)},e.__internal__.dispense.timeout_time)},k=async function(e){const t=["02","30","30","81","52",e,"FF"];return await n(this,i,u).call(this,t,"reset")},S=function(){const e=this.__device.type==="iceplus"?w.getSeconds(40):w.getSeconds(25),t=new Date,r=1e3*e+t.getTime(),a=new Date(r);this.dispatch("reset:errors",{description:"Resetting machine errors",duration:e,started_at:t,finished_at:a})},M=async function(e){const t=["02","30","30","81","4C",e,"FF"];return await n(this,i,u).call(this,t,"lights")},D=async function(e="80",t=[]){const r=["02","30","30","81","44",e,...t];return await n(this,i,u).call(this,r,"display")},I=function(e=""){e=e.padEnd(32," ");const t=[];for(let r=0;r<32;r++)t.push(e.charCodeAt(r).toString(16));return t},pt=function(e){if(!(e instanceof Date))throw new Error("Invalid date, must be an instance of Date");const t=e.getHours().toString().padStart(2,"0"),r=e.getMinutes().toString().padStart(2,"0"),a=e.getDate().toString().padStart(2,"0"),o=(e.getMonth()+1).toString().padStart(2,"0"),c=e.getFullYear().toString().substring(2,4),s=`${t}:${r} ${a}-${o}-${c}`,v=[];for(let y=0;y<14;y++)v.push(s.charCodeAt(y).toString(16));return v};exports.Jofemar=yt;
package/dist/jofemar.js CHANGED
@@ -6,7 +6,7 @@ var yt = (p, h, e) => h in p ? vt(p, h, { enumerable: !0, configurable: !0, writ
6
6
  var N = (p, h, e) => yt(p, typeof h != "symbol" ? h + "" : h, e), wt = (p, h, e) => h.has(p) || F("Cannot " + e);
7
7
  var P = (p, h, e) => h.has(p) ? F("Cannot add the same private member more than once") : h instanceof WeakSet ? h.add(p) : h.set(p, e);
8
8
  var n = (p, h, e) => (wt(p, h, "access private method"), e);
9
- import { K as kt, c as A, w as T, g as B } from "./kernel-B15wfB2x.js";
9
+ import { K as kt, _ as A, w as T, g as B } from "./kernel-BFXQSiNz.js";
10
10
  var i, $, W, g, u, E, q, O, j, R, J, L, U, H, V, K, G, z, Q, Y, Z, X, tt, et, it, nt, rt, at, ot, ct, st, ht, _, l, m, d, f, lt, dt, pt, ut, w, S, M, D, I, _t;
11
11
  class Tt extends kt {
12
12
  constructor({