@danidoble/webserial 4.2.16 → 4.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/arduino.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var d=t=>{throw TypeError(t)};var _=(t,s,n)=>s.has(t)||d("Cannot "+n);var l=(t,s,n)=>s.has(t)?d("Cannot add the same private member more than once"):s instanceof WeakSet?s.add(t):s.set(t,n);var u=(t,s,n)=>(_(t,s,"access private method"),n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("./kernel-BxvweHTG.cjs"),i=require("./relay-BsUsBpOv.cjs");var r,h;class p extends c.Kernel{constructor({filters:n=null,config_port:o=null,no_device:a=1}={}){super({filters:n,config_port:o,no_device:a});l(this,r);if(this.__internal__.device.type="arduino",c.h.getCustom(this.typeDevice,a))throw new Error(`Device ${this.typeDevice} ${a} already exists`);this.__internal__.time.response_connection=2e3,this.__internal__.time.response_general=2e3,this.__internal__.serial.delay_first_connection=1e3,u(this,r,h).call(this),c.h.add(this),this.getResponseAsString()}serialMessage(n){const o=this.stringToArrayHex(n),a=this.stringToArrayBuffer(n),e={original_code:o,arrayBuffer:a,code:null,name:null,description:null,request:null,no_code:0};switch(e.code=n,n){case"connected":e.name="connected",e.description="Connection established",e.request="connect",e.no_code=100;break;case"created by danidoble":e.name="thanks",e.description="thanks for using this software",e.request="credits",e.no_code=101;break;case"hello there":e.name="hello there",e.description="hi human",e.request="hi",e.no_code=102;break;case"ara ara":e.name="ara ara",e.description="troll",e.request="ara ara",e.no_code=404;break;default:e.name="unknown",e.description="Unknown command",e.request="unknown",e.no_code=400;break}this.dispatch("serial:message",e)}serialSetConnectionConstant(n=1){return i.i.connection(n)}async sayCredits(){await this.appendToQueue(i.i.credits(),"credits")}async sayHi(){await this.appendToQueue(i.i.hi(),"hi")}async sayAra(){await this.appendToQueue(i.i.ara(),"ara")}async sendCustomCode({code:n=""}={}){if(typeof n!="string")throw new Error("Invalid string");await this.appendToQueue(this.parseStringToTextEncoder(n),"custom")}async doSomething(){await this.sayCredits(),await this.sayAra(),await this.sayHi()}}r=new WeakSet,h=function(){};exports.Arduino=p;
1
+ "use strict";var c=t=>{throw TypeError(t)};var _=(t,s,n)=>s.has(t)||c("Cannot "+n);var d=(t,s,n)=>s.has(t)?c("Cannot add the same private member more than once"):s instanceof WeakSet?s.add(t):s.set(t,n);var l=(t,s,n)=>(_(t,s,"access private method"),n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("./kernel-BTqvt4pt.cjs"),a=require("./relay-BsUsBpOv.cjs"),u=require("./webserial-core-DlH0cFSH.cjs");var r,h;class y extends p.Kernel{constructor({filters:n=null,config_port:o=null,no_device:i=1}={}){super({filters:n,config_port:o,no_device:i});d(this,r);if(this.__internal__.device.type="arduino",u.h.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,l(this,r,h).call(this),u.h.add(this),this.getResponseAsString()}serialMessage(n){const o=this.stringToArrayHex(n),i=this.stringToArrayBuffer(n),e={original_code:o,arrayBuffer:i,code:null,name:null,description:null,request:null,no_code:0};switch(e.code=n,n){case"connected":e.name="connected",e.description="Connection established",e.request="connect",e.no_code=100;break;case"created by danidoble":e.name="thanks",e.description="thanks for using this software",e.request="credits",e.no_code=101;break;case"hello there":e.name="hello there",e.description="hi human",e.request="hi",e.no_code=102;break;case"ara ara":e.name="ara ara",e.description="troll",e.request="ara ara",e.no_code=404;break;default:e.name="unknown",e.description="Unknown command",e.request="unknown",e.no_code=400;break}this.dispatch("serial:message",e)}serialSetConnectionConstant(n=1){return a.i.connection(n)}async sayCredits(){await this.appendToQueue(a.i.credits(),"credits")}async sayHi(){await this.appendToQueue(a.i.hi(),"hi")}async sayAra(){await this.appendToQueue(a.i.ara(),"ara")}async sendCustomCode({code:n=""}={}){if(typeof n!="string")throw new Error("Invalid string");await this.appendToQueue(this.parseStringToTextEncoder(n),"custom")}async doSomething(){await this.sayCredits(),await this.sayAra(),await this.sayHi()}}r=new WeakSet,h=function(){};exports.Arduino=y;
package/dist/arduino.js CHANGED
@@ -4,10 +4,11 @@ var c = (n) => {
4
4
  var p = (n, s, t) => s.has(n) || c("Cannot " + t);
5
5
  var d = (n, s, t) => s.has(n) ? c("Cannot add the same private member more than once") : s instanceof WeakSet ? s.add(n) : s.set(n, t);
6
6
  var h = (n, s, t) => (p(n, s, "access private method"), t);
7
- import { K as _, h as l } from "./kernel-C4PiwwCb.js";
7
+ import { K as _ } from "./kernel-lcvN8cY0.js";
8
8
  import { i } from "./relay-Dop4mFk-.js";
9
+ import { h as l } from "./webserial-core-DGKQCs5a.js";
9
10
  var r, u;
10
- class w extends _ {
11
+ class f extends _ {
11
12
  constructor({ filters: t = null, config_port: o = null, no_device: a = 1 } = {}) {
12
13
  super({ filters: t, config_port: o, no_device: a });
13
14
  d(this, r);
@@ -67,5 +68,5 @@ class w extends _ {
67
68
  r = new WeakSet(), u = function() {
68
69
  };
69
70
  export {
70
- w as Arduino
71
+ f as Arduino
71
72
  };
@@ -1 +1 @@
1
- "use strict";var ce=Object.defineProperty;var x=c=>{throw TypeError(c)};var pe=(c,p,n)=>p in c?ce(c,p,{enumerable:!0,configurable:!0,writable:!0,value:n}):c[p]=n;var h=(c,p,n)=>pe(c,typeof p!="symbol"?p+"":p,n),I=(c,p,n)=>p.has(c)||x("Cannot "+n);var w=(c,p,n)=>(I(c,p,"read from private field"),n?n.call(c):p.get(c)),y=(c,p,n)=>p.has(c)?x("Cannot add the same private member more than once"):p instanceof WeakSet?p.add(c):p.set(c,n),b=(c,p,n,e)=>(I(c,p,"write to private field"),e?e.call(c,n):p.set(c,n),n),a=(c,p,n)=>(I(c,p,"access private method"),n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const T=require("./kernel-BxvweHTG.cjs"),d=require("./relay-BsUsBpOv.cjs");var f,_,k,s,E,M,v,S,Q,N,m,j,F,O,U,A,L,R,V,z,W,Y,G,H,J,K,X,Z,g,ee,ne,te,se,ie,re,ae,P,C,oe,le,$,B,q;class ue extends T.Kernel{constructor({filters:n=null,config_port:e=null,no_device:t=1}={}){super({filters:n,config_port:e,no_device:t});y(this,s);h(this,"__coin_purse",{available:!0});h(this,"__banknote_purse",{available:!0,isRecycler:!0,recycler:{ict:!0,banknote:1}});h(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}});h(this,"__money_session",{inserted:0,retired:0,clear(){this.inserted=0,this.retired=0}});h(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});h(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});h(this,"card_reader",{available:!1,max_pre_credit:0});y(this,f,!1);y(this,_,0);y(this,k,0);if(this.__internal__.device.type="boardroid",T.h.getCustom(this.typeDevice,t))throw new Error(`Device ${this.typeDevice} ${t} 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,E).call(this),a(this,s,M).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(n){this.__banknote_purse.isRecycler=n}get hasICT(){return this.hasRecycler&&this.__banknote_purse.recycler.ict}set hasICT(n){this.__banknote_purse.recycler.ict=n}set banknoteICT(n){if(![20,50,100,200,500].includes(n))throw new Error(`Invalid banknote value: ${n}`);n=[20,50,100,200,500].indexOf(n),this.__banknote_purse.recycler.banknote=n}get banknoteICT(){return[20,50,100,200,500][this.__banknote_purse.recycler.banknote]}get hasCoinPurse(){return this.__coin_purse.available}set hasCoinPurse(n){if(typeof n!="boolean")throw new Error(`Invalid value: ${n}`);this.__coin_purse.available=n}set price(n){let e=parseFloat(n);(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()}serialMessage(n){let e={code:n,name:null,description:null,request:null,no_code:0};const t=(5+this.deviceNumber).toString(16).padStart(2,"0").toLowerCase();switch(n[1]){case t:e.request="connect",e=a(this,s,Q).call(this,e);break;case"a0":e.request="--automatic",e=a(this,s,V).call(this,n,e);break;case"b0":e.request="--automatic",e=a(this,s,z).call(this,n,e);break;case"d0":e.request="coin-purse:config",e=a(this,s,W).call(this,n[2],e);break;case"d1":e.request="banknote-purse:config",e.additional={scrow:null},e=a(this,s,Y).call(this,n,e);break;case"d2":e.request="coin-purse:read-tubes",e=a(this,s,G).call(this,n,e);break;case"d3":e.request="banknote-purse:read-recycler",e=a(this,s,H).call(this,n,e);break;case"d4":e.request="banknote-purse:banknote-scrow-status",e=a(this,s,J).call(this,n[2],e);break;case"d5":e.request="banknote-purse:dispense",e=a(this,s,K).call(this,n,e);break;case"d6":e.request="coin-purse:dispense",e=a(this,s,X).call(this,n,e);break;case"d7":e.request="dispense",e=a(this,s,Z).call(this,n[5],e);break;case"d8":e.request="--automatic",e=a(this,s,g).call(this,n[13],e);break;case"d9":e.request="status:temperature",e=a(this,s,ee).call(this,n,e);break;case"da":e.request="status:relay",e=a(this,s,ne).call(this,n[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,te).call(this,n,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(n=1){return d.l.connection({channel:n})}async coinPurseConfigure({enable:n=!1,high:e="FF",low:t="FF"}={}){if(!this.__coin_purse.available)throw new Error("Coin purse not available");return e=this.hexToDec(e),t=this.hexToDec(t),await this.appendToQueue(d.l.coinPurseConfiguration({enable:n,high:e,low:t}),"coin-purse:config")}async coinPurseEnable(){await this.coinPurseConfigure({enable:!0})}async coinPurseDisable(){await this.coinPurseConfigure({enable:!1})}async coinPurseDispense({$_50c:n=0,$_1:e=0,$_2:t=0,$_5:i=0,$_10:r=0}={}){if(!this.__coin_purse.available)throw new Error("Coin purse not available");return await this.appendToQueue(d.l.coinPurseDispense({$50c:n,$1:e,$2:t,$5:i,$10:r}),"coin-purse:dispense")}async coinPurseReadTubes(){return await this.appendToQueue(d.l.coinPurseReadTubes(),"coin-purse:read-tubes")}async banknotePurseConfigure({enable:n=!1,scrow:e=!1}={}){if(!this.__banknote_purse.available)throw new Error("Banknote purse not available");let t;return a(this,s,v).call(this)?t=a(this,s,se).call(this,{enable:n,scrow:e}):t=a(this,s,ie).call(this,{enable:n,scrow:e}),await this.appendToQueue(t,"banknote-purse:config")}async banknotePurseDispense({$_20:n=0,$_50:e=0,$_100:t=0,$_200:i=0,$_500:r=0,$_1000:o=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 l;if(a(this,s,v).call(this)){const u=[n,e,t,i,r];l=a(this,s,re).call(this,u[this.__banknote_purse.recycler.banknote])}else l=a(this,s,ae).call(this,{$_20:n,$_50:e,$_100:t,$_200:i,$_500:r,$_1000:o});await this.appendToQueue(l,"banknote-purse:dispense")}async banknotePurseEnable({scrow:n=!1}){return await this.banknotePurseConfigure({enable:!0,scrow:n})}async banknotePurseDisable(){return await this.banknotePurseConfigure({enable:!1})}async banknotePurseAcceptInScrow(){if(!this.__banknote_purse.available)throw new Error("Banknote purse not available");return await this.appendToQueue(d.l.banknotePurseAcceptInScrow(),"banknote-purse:banknote-scrow-status")}async banknotePurseRejectInScrow(){if(!this.__banknote_purse.available)throw new Error("Banknote purse not available");return await this.appendToQueue(d.l.banknotePurseRejectInScrow(),"banknote-purse:banknote-scrow-status")}async banknotePurseSaveMemory({channel:n=null,$_20:e=null,$_50:t=null,$_100:i=null,$_200:r=null,$_500:o=null,$_1000:l=null}={}){if(!this.__banknote_purse.available)throw new Error("Banknote purse not available");return await this.appendToQueue(d.l.banknotePurseSaveMemory({channel:n,$20:e,$50:t,$100:i,$200:r,$500:o,$1000: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");return await this.appendToQueue(d.l.banknotePurseReadRecycler(),"banknote-purse:read-recycler")}async cardReaderDisable(){if(!this.card_reader.available)throw new Error("Card reader not available");return await this.appendToQueue(d.l.cardReaderDisable(),"card-reader:disable")}async cardReaderDispense({channel:n=1,second_channel:e=null,sensor:t=!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)&&(this.card_reader.max_pre_credit=r),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(!t&&(i===null||i<=0||i>40))throw new Error("Invalid time to dispense without sensor, must be between 0.1 and 40.0 seconds");return this.appendToQueue(d.l.cardReaderDispense({selection:n,second_selection:e,sensor:t,seconds:i,price:r}),"card-reader:dispense")}async paymentPursesDisable({coin:n=!0,banknote:e=!0,cardReader:t=!1}={}){n&&this.__coin_purse.available&&await this.coinPurseDisable(),e&&this.__banknote_purse.available&&await this.banknotePurseDisable(),t&&this.card_reader.available&&await this.cardReaderDisable()}async paymentPursesEnable({coin:n=!0,banknote:e=!0,scrowBanknote:t=!1}={}){n&&this.__coin_purse.available&&await this.coinPurseEnable(),e&&this.__banknote_purse.available&&await this.banknotePurseEnable({scrow:t})}async coolingRelayConfigure({enable:n=!1}={}){return await this.appendToQueue(d.l.coolingRelayConfigure({enable:n}),"status:relay")}async coolingRelayEnable(){return await this.coolingRelayConfigure({enable:!0})}async coolingRelayDisable(){return await this.coolingRelayConfigure({enable:!1})}async readTemperature(){return await this.appendToQueue(d.l.readTemperature(),"status:temperature")}async dispense({selection:n=1,second_selection:e=null,sensor:t=!0,seconds:i=null,retry:r=!0}={}){if(n=parseInt(n),isNaN(n)||n<1||n>80)throw new Error("Invalid channel number");if(e!==null&&(e<1||e>80||e===n))throw new Error("Invalid second channel number");if(!t&&(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:n,second_selection:e,sensor:t,seconds:i});const o=d.l.dispense({selection:n,second_selection:e,sensor:t,seconds:i});t||(i||(i=1.5),this.__internal__.dispense.custom_limit_counter=i+.2);let l=await this.internalDispense(o);return!l.status&&r&&(l=await this.internalDispense(o)),this.__internal__.dispense.custom_limit_counter=null,l}async testEngines({singleEngine:n=!1}={}){if(this.isDispensing)throw new Error("Another dispensing process is running");if(w(this,f))throw new Error("Another test is running");a(this,s,P).call(this),b(this,f,!0);const e=[];a(this,s,C).call(this);for(let t=1;t<=80;t++){const i=await this.dispense({selection:t,second_selection:n?null:t+1,sensor:!1,seconds:.4,retry:!1});e.push(i),b(this,_,t),a(this,s,C).call(this),n||t++}b(this,_,80),a(this,s,C).call(this,{dispensed:e}),a(this,s,P).call(this)}async sendCustomCode({code:n=[]}={}){if(n.length===0)throw new Error("Invalid code");return await this.appendToQueue(d.l.customCode(n),"custom")}hasToReturnChange(n=0){let e=n;return e<=0?!0:(e=a(this,s,$).call(this,e).pending,e=a(this,s,B).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(n,e){this.dispatch("corrupt:message",{data:n,message:e})}}f=new WeakMap,_=new WeakMap,k=new WeakMap,s=new WeakSet,E=function(){const n=["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","money:inserted"];for(const e of n)this.serialRegisterAvailableListener(e)},M=function(){T.h.add(this)},v=function(){return this.__banknote_purse.isRecycler&&this.__banknote_purse.recycler.ict},S=function(){return this.hasCoinPurse||this.hasRecycler},Q=function(n){return n.name="Connection with the serial device completed.",n.description="Your connection with the serial device was successfully completed.",n.no_code=1,this.dispatch("run:default-load",{}),n},N=function(n){const e={g50:{value:.5,name:"50 pennies (the big one)"},c0:{value:.5,name:"50 pennies (the little one)"},p1:{value:1,name:"1 peso"},p2:{value:2,name:"2 pesos"},p5:{value:5,name:"5 pesos"},p10:{value:10,name:"10 pesos"},p20:{value:20,name:"20 pesos"}};return e[n]?e[n]:!1},m=function(n){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 t=null;for(let r in e)if(e[r].includes(n)){t=r;break}return t?[{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"}[t],t]:[`Undefined value: ¿${n}?`,null]},j=function(n){return["g50","c50","p1","p2","p5","p10","p20"].includes(n)},F=function(n){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 t=null;for(let r in e)if(e[r].includes(n)){t=r;break}return t?[{p20:"20 pesos",p50:"50 pesos",p100:"100 pesos",p200:"200 pesos",p500:"500 pesos",p1000:"1000 pesos"}[t],t]:[`Undefined value: ¿${n}?`,null]},O=function(n){const e={p20:{value:20,name:"20 pesos"},p50:{value:50,name:"50 pesos"},p100:{value:100,name:"100 pesos"},p200:{value:200,name:"200 pesos"},p500:{value:500,name:"500 pesos"},p1000:{value:1e3,name:"1000 pesos"}};return e[n]?e[n]:!1},U=function(n){return["p20","p50","p100","p200","p500","p1000"].includes(n)},A=function(n){return["r20","r50","r100"].includes(n)},L=function(){return["r20","r50","r100","r200","r500"][this.__banknote_purse.recycler.banknote]},R=function(n,e,t){if(!n)return;let i=!0;if(a(this,s,j).call(this,n)&&t==="coin"){if(typeof this.coins.tubes[n]>"u")return;e==="tube"?this.coins.tubes[n]+=1:e==="box"&&(this.coins.box[n]+=1);let r=0;["g50","c50"].includes(n)?r=.5:r+=parseInt(n.slice(1)),this.coins.totals[n]+=r,this.__money_session.inserted+=r,this.coins.total+=r;const o=a(this,s,N).call(this,n);o&&this.dispatch("money:inserted",{type:"coin",money:o,where:e})}else if(a(this,s,U).call(this,n)&&t==="banknote"){if(typeof this.banknotes.recycler[n]>"u")return;e==="recycler"?this.banknotes.recycler[n]+=1:e==="stacker"&&(this.banknotes.stacker[n]+=1);let r=parseInt(n.slice(1));this.banknotes.totals[n]+=r,this.__money_session.inserted+=r,this.banknotes.total+=r;const o=a(this,s,O).call(this,n);o&&this.dispatch("money:inserted",{type:"banknote",money:o,where:e})}else if(a(this,s,A).call(this,n)&&e==="out"&&t==="banknote"){if(typeof this.banknotes.out[n.replace("r","p")]>"u")return;this.banknotes.out[n.replace("r","p")]+=1;let r=parseInt(n.slice(1));this.__money_session.retired+=r,this.banknotes.recycler[n.replace("r","p")]-=1,this.banknotes.total-=r,i=!1,this.dispatch("session:money-dispensed",{type_money:n,retired:r,finish:!1,type:"banknotes"})}i&&this.dispatch("session:money-request",{})},V=function(n,e){const t=parseInt(n[2],16);return e.name="Coin Inserted",e.no_code=2,e.additional={where:null,coin:null},t===1?(e.name="Lever pressed",e.description="Reject lever",e.no_code=100,this.dispatch("coin-purse:reject-lever",{})):t===2?(e.name="Reset coin purse",e.description="The configuration of coin purse was reset",e.no_code=101,this.dispatch("coin-purse:reset",{})):t>=64&&t<=79?(e.name="Coin inserted in profit box",e.additional.where="box"):t>=80&&t<=95?(e.name="Coin inserted in tube",e.additional.where="tube"):t>=96&&t<=111?(e.name="Unused coin",e.description="Something come from coin changer but in MDB Docs is unused",e.additional.where="unused"):t>=112&&t<=127?(e.name="Coin rejected",e.additional.where="rejected"):t>=144&&t<=159?(e.name="Coin dispensed",e.additional.where="out",e.description=`Undefined value: ¿${n[2]}?`):(e.name="Coin inserted",e.description="Undefined status. Without information of this",e.no_code=400),t===1||t===2||t>=160||t>=128&&t<=143||([e.description,e.additional.coin]=a(this,s,m).call(this,n[2]),e.no_code=38+t,a(this,s,R).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},z=function(n,e){const t=parseInt(n[2],16);return e.name="Banknote Inserted",e.no_code=2,e.additional={where:null,banknote:null},t===42?(e.name="Banknote dispensed",e.description="Banknote dispensed by request.",e.additional.banknote=a(this,s,L).call(this),e.additional.where="out",e.no_code=200):t>=128&&t<=143?(e.name="Banknote inserted",e.additional.where="stacker"):t>=144&&t<=159?(e.name="Banknote inserted in pre stacker",e.additional.where="tmp"):t>=160&&t<=175?(e.name="Banknote rejected",e.additional.where="nothing"):t>=176&&t<=191&&(e.name="Banknote inserted",e.additional.where="recycler"),t>=128&&t<=191&&([e.description,e.additional.banknote]=a(this,s,F).call(this,n[2]),e.no_code=74+t),a(this,s,R).call(this,e.additional.banknote,e.additional.where,"banknote"),this.dispatch("banknote-purse:event-banknote",this.banknotes),e},W=function(n,e){const t=parseInt(n,16);return t===1?(e.name="Coin purse enabled",e.description="Configuration complete, enabled",e.no_code=3):t===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:t===1}),e},Y=function(n,e){const t=parseInt(n[2],16),i=parseInt(n[3],16);return t===0?(e.name="Bill purse disabled",e.description="Configuration complete, disabled"):t===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:t===1,scrow:i===1}),e},G=function(n,e){e.no_code=6;const[t,i,r,o,l,u]=[parseInt(n[2],16),parseInt(n[3],16),parseInt(n[4],16),parseInt(n[5],16),parseInt(n[6],16),parseInt(n[7],16)];return e.additional={coins:{g50:t,c50:i,p1:r,p2:o,p5:l,p10:u}},this.coins.tubes.g50=t,this.coins.tubes.c50=i,this.coins.tubes.p1=r,this.coins.tubes.p2=o,this.coins.tubes.p5=l,this.coins.tubes.p10=u,this.coins.totals.g50=(this.coins.box.g50+t)*.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+o)*2,this.coins.totals.p5=(this.coins.box.p5+l)*5,this.coins.totals.p10=(this.coins.box.p10+u)*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},H=function(n,e){e.no_code=7;const[t,i,r,o,l,u]=[parseInt(n[2],16),parseInt(n[3],16),parseInt(n[4],16),parseInt(n[5],16),parseInt(n[6],16),parseInt(n[7],16)];return e.additional={banknotes:{b20:t,b50:i,b100:r,b200:o,b500:l,b1000:u}},this.banknotes.recycler.p20=t,this.banknotes.recycler.p50=i,this.banknotes.recycler.p100=r,this.banknotes.recycler.p200=o,this.banknotes.recycler.p500=l,this.banknotes.recycler.p1000=u,this.banknotes.totals.p20=(this.banknotes.stacker.p20+t)*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+o)*200,this.banknotes.totals.p500=(this.banknotes.stacker.p500+l)*500,this.banknotes.totals.p1000=(this.banknotes.stacker.p1000+u)*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},J=function(n,e){const t=parseInt(n,16);return t===1?e.name="Banknote accepted":t===0?e.name="Banknote rejected":e.name="Unknown status banknote",e.no_code=8,this.dispatch("banknote-purse:banknote-scrow-status",{status:t===1}),e},K=function(n,e){const[t,i,r,o,l,u]=[parseInt(n[2],16),parseInt(n[3],16),parseInt(n[4],16),parseInt(n[5],16),parseInt(n[6],16),parseInt(n[7],16)],D=t*20+i*50+r*100+o*200+l*500+u*1e3;return e.name="Banknotes dispensed",e.description=D>0?"Banknotes dispensed by request":"No banknotes dispensed, recycler empty",e.no_code=9,e.additional={banknotes:{b20:t,b50:i,b100:r,b200:o,b500:l,b1000:u},total_dispensed:D},this.dispatch("session:money-dispensed",{type_money:null,retired:null,finish:!1,type:"banknotes",data:e}),e},X=function(n,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},Z=function(n,e){const t=parseInt(n,16);return t===1?(e.name="Product not delivered",e.description="The product requested wasn't delivered",e.no_code=11,this.__internal__.dispense.status=!1):t===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},g=function(n,e){let t="closed";return n==="db"?(e.name="Door closed",e.no_code=13):n==="dc"?(e.name="Door open",e.no_code=14,t="open"):(e.name="Unknown status door",e.description="The response of door doesn't identify successfully",e.no_code=400,t="unknown"),this.__internal__.device.door_open=t==="open",this.dispatch("event:door",{open:t==="open"}),this.dispatch("door:event",{open:t==="open"}),e},ee=function(n,e){const t=parseInt(n[2],16)*255,i=parseInt(n[3],16),r=(t+i)*.1;return e.no_code=15,e.name="Temperature status",e.description=`Temperature: ${r}`,e.additional={high:t,low:i,temperature:parseFloat(r.toString())},this.dispatch("status:temperature",e.additional),e},ne=function(n,e){const t=parseInt(n,16);let i="unknown";return t===1?(e.name="Relay on",e.description="Relay on",e.no_code=16,i="on"):t===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},te=function(n,e){const t=parseInt(n[2],16);if(e.no_code=20+t,e.name="Status unknown",e.description="The status of card reader does not identified correctly",t===0)e.request+=":disable",e.name="Card reader disabled",e.description="Card reader device was disabled successfully";else if(t===1||t===2)e.request+=":dispense",e.name="Card reader enabled",e.description="Card reader device is now enabled";else if(t===3)e.request+=":pre-authorize",e.name="Pre-authorized credit",e.description="The pre credit was authorized successfully";else if(t===4)e.request+=":cancel",e.name="Cancellation in progress",e.description="Cancellation request done successfully";else if(t===5)e.request+=":sell",e.name="Sell approved",e.description="Sell approved, starting dispense product";else if(t===6)e.request+=":sell",e.name="Sell denied",e.description="This sell was denied, try again";else if(t===7)e.request+=":end",e.name="Session ended",e.description="The session ended";else if(t===8)e.request+=":cancel",e.name="Cancelled",e.description="Cancellation complete";else if(t===10){const i=parseInt(n[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},se=function({enable:n=!1,scrow:e=!1}={}){return d.l.banknotePurseICTConfigure({enable:n,scrow:e})},ie=function({enable:n=!1,scrow:e=!1}={}){return d.l.banknotePurseOtherConfigure({enable:n,scrow:e})},re=function(n=1){if(n<1)throw new Error("No banknotes to dispense");const e=[20,50,100,200,500][this.__banknote_purse.recycler.banknote];return d.l.banknotePurseICTDispense({quantity:n,denomination:e})},ae=function({$_20:n=0,$_50:e=0,$_100:t=0,$_200:i=0,$_500:r=0,$_1000:o=0}={}){return d.l.banknotePurseOtherDispense({$20:n,$50:e,$100:t,$200:i,$500:r,$1000:o})},P=function(){b(this,f,!1),b(this,_,0),b(this,k,0)},C=function({dispensed:n=null,limit:e=80}={}){b(this,k,Math.round(w(this,_)*100/e)),this.dispatch("percentage:test",{percentage:w(this,k),dispensed:n})},oe=function(n){const e=["20","50","100","200","500"],t=this.__banknote_purse.recycler.banknote,i="$_"+e[t],r=parseInt(e[t]),o=this.banknotes.recycler[`p${e[t]}`],l=Math.min(Math.floor(n/r),o),u={banknotes:{$_20:0,$_50:0,$_100:0,$_200:0,$_500:0,$_1000:0},pending:n,will_dispense:l>0};return this.totalInRecycler===0||l<1||n===0||(u.banknotes[i]=l,u.pending=parseFloat((n-l*r).toFixed(2))),u},le=function(n){const e={banknotes:{$_20:0,$_50:0,$_100:0,$_200:0,$_500:0,$_1000:0},pending:n,will_dispense:!1};if(this.totalInRecycler===0||n===0)return e;const t=(i,r)=>{if(this.banknotes.recycler[r]>0){const o=Math.floor(e.pending/i),l=Math.min(o,this.banknotes.recycler[r]);e.banknotes[`$_${i}`]=l,e.pending=parseFloat((e.pending-l*i).toFixed(2))}};return t(1e3,"p1000"),t(500,"p500"),t(200,"p200"),t(100,"p100"),t(50,"p50"),t(20,"p20"),e.will_dispense=Object.values(e.banknotes).some(i=>i>0),e},$=function(n){return this.hasRecycler?a(this,s,v).call(this)?a(this,s,oe).call(this,n):a(this,s,le).call(this,n):{banknotes:{$_20:0,$_50:0,$_100:0,$_200:0,$_500:0,$_1000:0},pending:n,will_dispense:!1}},B=function(n){const e={coins:{$_50c:0,$_1:0,$_2:0,$_5:0,$_10:0},pending:n,will_dispense:!1};if(!this.hasCoinPurse||n<=0||this.totalInTubes===0)return e;const t=(i,r,o=null)=>{if(this.coins.tubes[r]>0){o===null&&(o="$_"+i);const l=Math.floor(e.pending/i),u=Math.min(l,this.coins.tubes[r]);e.coins[o]=u,e.pending=parseFloat((e.pending-u*i).toFixed(2))}};return t(10,"p10"),t(5,"p5"),t(2,"p2"),t(1,"p1"),t(.5,"g50","$_50c"),e.will_dispense=Object.values(e.coins).some(i=>i>0),e},q=async function(n=null){if(!a(this,s,S).call(this))throw new Error("Change not available");let e=this.change,t=this.change;if(n!==null&&(e=n,t=n),t<=0)return!1;const i=a(this,s,$).call(this,t);t=i.pending;const r=a(this,s,B).call(this,t);return t=r.pending,t>0&&this.dispatch("change:pending",{pending:t}),this.dispatch("change:dispense",{recycler:i.banknotes,coins:r.coins,pending:t,delivery:e-t}),t===e?!1:(i.will_dispense&&await this.banknotePurseDispense(i.banknotes),r.will_dispense&&await this.coinPurseDispense(r.coins),!0)};exports.Boardroid=ue;
1
+ "use strict";var ce=Object.defineProperty;var D=c=>{throw TypeError(c)};var pe=(c,p,n)=>p in c?ce(c,p,{enumerable:!0,configurable:!0,writable:!0,value:n}):c[p]=n;var h=(c,p,n)=>pe(c,typeof p!="symbol"?p+"":p,n),I=(c,p,n)=>p.has(c)||D("Cannot "+n);var w=(c,p,n)=>(I(c,p,"read from private field"),n?n.call(c):p.get(c)),y=(c,p,n)=>p.has(c)?D("Cannot add the same private member more than once"):p instanceof WeakSet?p.add(c):p.set(c,n),b=(c,p,n,e)=>(I(c,p,"write to private field"),e?e.call(c,n):p.set(c,n),n),a=(c,p,n)=>(I(c,p,"access private method"),n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const ue=require("./kernel-BTqvt4pt.cjs"),d=require("./relay-BsUsBpOv.cjs"),x=require("./webserial-core-DlH0cFSH.cjs");var f,_,k,s,E,M,v,S,Q,N,m,j,F,O,U,A,L,T,V,z,W,Y,G,H,J,K,X,Z,g,ee,ne,te,se,ie,re,ae,R,C,oe,le,P,$,q;class de extends ue.Kernel{constructor({filters:n=null,config_port:e=null,no_device:t=1}={}){super({filters:n,config_port:e,no_device:t});y(this,s);h(this,"__coin_purse",{available:!0});h(this,"__banknote_purse",{available:!0,isRecycler:!0,recycler:{ict:!0,banknote:1}});h(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}});h(this,"__money_session",{inserted:0,retired:0,clear(){this.inserted=0,this.retired=0}});h(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});h(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});h(this,"card_reader",{available:!1,max_pre_credit:0});y(this,f,!1);y(this,_,0);y(this,k,0);if(this.__internal__.device.type="boardroid",x.h.getCustom(this.typeDevice,t))throw new Error(`Device ${this.typeDevice} ${t} 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,E).call(this),a(this,s,M).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(n){this.__banknote_purse.isRecycler=n}get hasICT(){return this.hasRecycler&&this.__banknote_purse.recycler.ict}set hasICT(n){this.__banknote_purse.recycler.ict=n}set banknoteICT(n){if(![20,50,100,200,500].includes(n))throw new Error(`Invalid banknote value: ${n}`);n=[20,50,100,200,500].indexOf(n),this.__banknote_purse.recycler.banknote=n}get banknoteICT(){return[20,50,100,200,500][this.__banknote_purse.recycler.banknote]}get hasCoinPurse(){return this.__coin_purse.available}set hasCoinPurse(n){if(typeof n!="boolean")throw new Error(`Invalid value: ${n}`);this.__coin_purse.available=n}set price(n){let e=parseFloat(n);(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()}serialMessage(n){let e={code:n,name:null,description:null,request:null,no_code:0};const t=(5+this.deviceNumber).toString(16).padStart(2,"0").toLowerCase();switch(n[1]){case t:e.request="connect",e=a(this,s,Q).call(this,e);break;case"a0":e.request="--automatic",e=a(this,s,V).call(this,n,e);break;case"b0":e.request="--automatic",e=a(this,s,z).call(this,n,e);break;case"d0":e.request="coin-purse:config",e=a(this,s,W).call(this,n[2],e);break;case"d1":e.request="banknote-purse:config",e.additional={scrow:null},e=a(this,s,Y).call(this,n,e);break;case"d2":e.request="coin-purse:read-tubes",e=a(this,s,G).call(this,n,e);break;case"d3":e.request="banknote-purse:read-recycler",e=a(this,s,H).call(this,n,e);break;case"d4":e.request="banknote-purse:banknote-scrow-status",e=a(this,s,J).call(this,n[2],e);break;case"d5":e.request="banknote-purse:dispense",e=a(this,s,K).call(this,n,e);break;case"d6":e.request="coin-purse:dispense",e=a(this,s,X).call(this,n,e);break;case"d7":e.request="dispense",e=a(this,s,Z).call(this,n[5],e);break;case"d8":e.request="--automatic",e=a(this,s,g).call(this,n[13],e);break;case"d9":e.request="status:temperature",e=a(this,s,ee).call(this,n,e);break;case"da":e.request="status:relay",e=a(this,s,ne).call(this,n[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,te).call(this,n,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(n=1){return d.l.connection({channel:n})}async coinPurseConfigure({enable:n=!1,high:e="FF",low:t="FF"}={}){if(!this.__coin_purse.available)throw new Error("Coin purse not available");return e=this.hexToDec(e),t=this.hexToDec(t),await this.appendToQueue(d.l.coinPurseConfiguration({enable:n,high:e,low:t}),"coin-purse:config")}async coinPurseEnable(){await this.coinPurseConfigure({enable:!0})}async coinPurseDisable(){await this.coinPurseConfigure({enable:!1})}async coinPurseDispense({$_50c:n=0,$_1:e=0,$_2:t=0,$_5:i=0,$_10:r=0}={}){if(!this.__coin_purse.available)throw new Error("Coin purse not available");return await this.appendToQueue(d.l.coinPurseDispense({$50c:n,$1:e,$2:t,$5:i,$10:r}),"coin-purse:dispense")}async coinPurseReadTubes(){return await this.appendToQueue(d.l.coinPurseReadTubes(),"coin-purse:read-tubes")}async banknotePurseConfigure({enable:n=!1,scrow:e=!1}={}){if(!this.__banknote_purse.available)throw new Error("Banknote purse not available");let t;return a(this,s,v).call(this)?t=a(this,s,se).call(this,{enable:n,scrow:e}):t=a(this,s,ie).call(this,{enable:n,scrow:e}),await this.appendToQueue(t,"banknote-purse:config")}async banknotePurseDispense({$_20:n=0,$_50:e=0,$_100:t=0,$_200:i=0,$_500:r=0,$_1000:o=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 l;if(a(this,s,v).call(this)){const u=[n,e,t,i,r];l=a(this,s,re).call(this,u[this.__banknote_purse.recycler.banknote])}else l=a(this,s,ae).call(this,{$_20:n,$_50:e,$_100:t,$_200:i,$_500:r,$_1000:o});await this.appendToQueue(l,"banknote-purse:dispense")}async banknotePurseEnable({scrow:n=!1}){return await this.banknotePurseConfigure({enable:!0,scrow:n})}async banknotePurseDisable(){return await this.banknotePurseConfigure({enable:!1})}async banknotePurseAcceptInScrow(){if(!this.__banknote_purse.available)throw new Error("Banknote purse not available");return await this.appendToQueue(d.l.banknotePurseAcceptInScrow(),"banknote-purse:banknote-scrow-status")}async banknotePurseRejectInScrow(){if(!this.__banknote_purse.available)throw new Error("Banknote purse not available");return await this.appendToQueue(d.l.banknotePurseRejectInScrow(),"banknote-purse:banknote-scrow-status")}async banknotePurseSaveMemory({channel:n=null,$_20:e=null,$_50:t=null,$_100:i=null,$_200:r=null,$_500:o=null,$_1000:l=null}={}){if(!this.__banknote_purse.available)throw new Error("Banknote purse not available");return await this.appendToQueue(d.l.banknotePurseSaveMemory({channel:n,$20:e,$50:t,$100:i,$200:r,$500:o,$1000: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");return await this.appendToQueue(d.l.banknotePurseReadRecycler(),"banknote-purse:read-recycler")}async cardReaderDisable(){if(!this.card_reader.available)throw new Error("Card reader not available");return await this.appendToQueue(d.l.cardReaderDisable(),"card-reader:disable")}async cardReaderDispense({channel:n=1,second_channel:e=null,sensor:t=!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)&&(this.card_reader.max_pre_credit=r),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(!t&&(i===null||i<=0||i>40))throw new Error("Invalid time to dispense without sensor, must be between 0.1 and 40.0 seconds");return this.appendToQueue(d.l.cardReaderDispense({selection:n,second_selection:e,sensor:t,seconds:i,price:r}),"card-reader:dispense")}async paymentPursesDisable({coin:n=!0,banknote:e=!0,cardReader:t=!1}={}){n&&this.__coin_purse.available&&await this.coinPurseDisable(),e&&this.__banknote_purse.available&&await this.banknotePurseDisable(),t&&this.card_reader.available&&await this.cardReaderDisable()}async paymentPursesEnable({coin:n=!0,banknote:e=!0,scrowBanknote:t=!1}={}){n&&this.__coin_purse.available&&await this.coinPurseEnable(),e&&this.__banknote_purse.available&&await this.banknotePurseEnable({scrow:t})}async coolingRelayConfigure({enable:n=!1}={}){return await this.appendToQueue(d.l.coolingRelayConfigure({enable:n}),"status:relay")}async coolingRelayEnable(){return await this.coolingRelayConfigure({enable:!0})}async coolingRelayDisable(){return await this.coolingRelayConfigure({enable:!1})}async readTemperature(){return await this.appendToQueue(d.l.readTemperature(),"status:temperature")}async dispense({selection:n=1,second_selection:e=null,sensor:t=!0,seconds:i=null,retry:r=!0}={}){if(n=parseInt(n),isNaN(n)||n<1||n>80)throw new Error("Invalid channel number");if(e!==null&&(e<1||e>80||e===n))throw new Error("Invalid second channel number");if(!t&&(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:n,second_selection:e,sensor:t,seconds:i});const o=d.l.dispense({selection:n,second_selection:e,sensor:t,seconds:i});t||(i||(i=1.5),this.__internal__.dispense.custom_limit_counter=i+.2);let l=await this.internalDispense(o);return!l.status&&r&&(l=await this.internalDispense(o)),this.__internal__.dispense.custom_limit_counter=null,l}async testEngines({singleEngine:n=!1}={}){if(this.isDispensing)throw new Error("Another dispensing process is running");if(w(this,f))throw new Error("Another test is running");a(this,s,R).call(this),b(this,f,!0);const e=[];a(this,s,C).call(this);for(let t=1;t<=80;t++){const i=await this.dispense({selection:t,second_selection:n?null:t+1,sensor:!1,seconds:.4,retry:!1});e.push(i),b(this,_,t),a(this,s,C).call(this),n||t++}b(this,_,80),a(this,s,C).call(this,{dispensed:e}),a(this,s,R).call(this)}async sendCustomCode({code:n=[]}={}){if(n.length===0)throw new Error("Invalid code");return await this.appendToQueue(d.l.customCode(n),"custom")}hasToReturnChange(n=0){let e=n;return e<=0?!0:(e=a(this,s,P).call(this,e).pending,e=a(this,s,$).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(n,e){this.dispatch("corrupt:message",{data:n,message:e})}}f=new WeakMap,_=new WeakMap,k=new WeakMap,s=new WeakSet,E=function(){const n=["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","money:inserted"];for(const e of n)this.serialRegisterAvailableListener(e)},M=function(){x.h.add(this)},v=function(){return this.__banknote_purse.isRecycler&&this.__banknote_purse.recycler.ict},S=function(){return this.hasCoinPurse||this.hasRecycler},Q=function(n){return n.name="Connection with the serial device completed.",n.description="Your connection with the serial device was successfully completed.",n.no_code=1,this.dispatch("run:default-load",{}),n},N=function(n){const e={g50:{value:.5,name:"50 pennies (the big one)"},c0:{value:.5,name:"50 pennies (the little one)"},p1:{value:1,name:"1 peso"},p2:{value:2,name:"2 pesos"},p5:{value:5,name:"5 pesos"},p10:{value:10,name:"10 pesos"},p20:{value:20,name:"20 pesos"}};return e[n]?e[n]:!1},m=function(n){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 t=null;for(let r in e)if(e[r].includes(n)){t=r;break}return t?[{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"}[t],t]:[`Undefined value: ¿${n}?`,null]},j=function(n){return["g50","c50","p1","p2","p5","p10","p20"].includes(n)},F=function(n){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 t=null;for(let r in e)if(e[r].includes(n)){t=r;break}return t?[{p20:"20 pesos",p50:"50 pesos",p100:"100 pesos",p200:"200 pesos",p500:"500 pesos",p1000:"1000 pesos"}[t],t]:[`Undefined value: ¿${n}?`,null]},O=function(n){const e={p20:{value:20,name:"20 pesos"},p50:{value:50,name:"50 pesos"},p100:{value:100,name:"100 pesos"},p200:{value:200,name:"200 pesos"},p500:{value:500,name:"500 pesos"},p1000:{value:1e3,name:"1000 pesos"}};return e[n]?e[n]:!1},U=function(n){return["p20","p50","p100","p200","p500","p1000"].includes(n)},A=function(n){return["r20","r50","r100"].includes(n)},L=function(){return["r20","r50","r100","r200","r500"][this.__banknote_purse.recycler.banknote]},T=function(n,e,t){if(!n)return;let i=!0;if(a(this,s,j).call(this,n)&&t==="coin"){if(typeof this.coins.tubes[n]>"u")return;e==="tube"?this.coins.tubes[n]+=1:e==="box"&&(this.coins.box[n]+=1);let r=0;["g50","c50"].includes(n)?r=.5:r+=parseInt(n.slice(1)),this.coins.totals[n]+=r,this.__money_session.inserted+=r,this.coins.total+=r;const o=a(this,s,N).call(this,n);o&&this.dispatch("money:inserted",{type:"coin",money:o,where:e})}else if(a(this,s,U).call(this,n)&&t==="banknote"){if(typeof this.banknotes.recycler[n]>"u")return;e==="recycler"?this.banknotes.recycler[n]+=1:e==="stacker"&&(this.banknotes.stacker[n]+=1);let r=parseInt(n.slice(1));this.banknotes.totals[n]+=r,this.__money_session.inserted+=r,this.banknotes.total+=r;const o=a(this,s,O).call(this,n);o&&this.dispatch("money:inserted",{type:"banknote",money:o,where:e})}else if(a(this,s,A).call(this,n)&&e==="out"&&t==="banknote"){if(typeof this.banknotes.out[n.replace("r","p")]>"u")return;this.banknotes.out[n.replace("r","p")]+=1;let r=parseInt(n.slice(1));this.__money_session.retired+=r,this.banknotes.recycler[n.replace("r","p")]-=1,this.banknotes.total-=r,i=!1,this.dispatch("session:money-dispensed",{type_money:n,retired:r,finish:!1,type:"banknotes"})}i&&this.dispatch("session:money-request",{})},V=function(n,e){const t=parseInt(n[2],16);return e.name="Coin Inserted",e.no_code=2,e.additional={where:null,coin:null},t===1?(e.name="Lever pressed",e.description="Reject lever",e.no_code=100,this.dispatch("coin-purse:reject-lever",{})):t===2?(e.name="Reset coin purse",e.description="The configuration of coin purse was reset",e.no_code=101,this.dispatch("coin-purse:reset",{})):t>=64&&t<=79?(e.name="Coin inserted in profit box",e.additional.where="box"):t>=80&&t<=95?(e.name="Coin inserted in tube",e.additional.where="tube"):t>=96&&t<=111?(e.name="Unused coin",e.description="Something come from coin changer but in MDB Docs is unused",e.additional.where="unused"):t>=112&&t<=127?(e.name="Coin rejected",e.additional.where="rejected"):t>=144&&t<=159?(e.name="Coin dispensed",e.additional.where="out",e.description=`Undefined value: ¿${n[2]}?`):(e.name="Coin inserted",e.description="Undefined status. Without information of this",e.no_code=400),t===1||t===2||t>=160||t>=128&&t<=143||([e.description,e.additional.coin]=a(this,s,m).call(this,n[2]),e.no_code=38+t,a(this,s,T).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},z=function(n,e){const t=parseInt(n[2],16);return e.name="Banknote Inserted",e.no_code=2,e.additional={where:null,banknote:null},t===42?(e.name="Banknote dispensed",e.description="Banknote dispensed by request.",e.additional.banknote=a(this,s,L).call(this),e.additional.where="out",e.no_code=200):t>=128&&t<=143?(e.name="Banknote inserted",e.additional.where="stacker"):t>=144&&t<=159?(e.name="Banknote inserted in pre stacker",e.additional.where="tmp"):t>=160&&t<=175?(e.name="Banknote rejected",e.additional.where="nothing"):t>=176&&t<=191&&(e.name="Banknote inserted",e.additional.where="recycler"),t>=128&&t<=191&&([e.description,e.additional.banknote]=a(this,s,F).call(this,n[2]),e.no_code=74+t),a(this,s,T).call(this,e.additional.banknote,e.additional.where,"banknote"),this.dispatch("banknote-purse:event-banknote",this.banknotes),e},W=function(n,e){const t=parseInt(n,16);return t===1?(e.name="Coin purse enabled",e.description="Configuration complete, enabled",e.no_code=3):t===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:t===1}),e},Y=function(n,e){const t=parseInt(n[2],16),i=parseInt(n[3],16);return t===0?(e.name="Bill purse disabled",e.description="Configuration complete, disabled"):t===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:t===1,scrow:i===1}),e},G=function(n,e){e.no_code=6;const[t,i,r,o,l,u]=[parseInt(n[2],16),parseInt(n[3],16),parseInt(n[4],16),parseInt(n[5],16),parseInt(n[6],16),parseInt(n[7],16)];return e.additional={coins:{g50:t,c50:i,p1:r,p2:o,p5:l,p10:u}},this.coins.tubes.g50=t,this.coins.tubes.c50=i,this.coins.tubes.p1=r,this.coins.tubes.p2=o,this.coins.tubes.p5=l,this.coins.tubes.p10=u,this.coins.totals.g50=(this.coins.box.g50+t)*.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+o)*2,this.coins.totals.p5=(this.coins.box.p5+l)*5,this.coins.totals.p10=(this.coins.box.p10+u)*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},H=function(n,e){e.no_code=7;const[t,i,r,o,l,u]=[parseInt(n[2],16),parseInt(n[3],16),parseInt(n[4],16),parseInt(n[5],16),parseInt(n[6],16),parseInt(n[7],16)];return e.additional={banknotes:{b20:t,b50:i,b100:r,b200:o,b500:l,b1000:u}},this.banknotes.recycler.p20=t,this.banknotes.recycler.p50=i,this.banknotes.recycler.p100=r,this.banknotes.recycler.p200=o,this.banknotes.recycler.p500=l,this.banknotes.recycler.p1000=u,this.banknotes.totals.p20=(this.banknotes.stacker.p20+t)*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+o)*200,this.banknotes.totals.p500=(this.banknotes.stacker.p500+l)*500,this.banknotes.totals.p1000=(this.banknotes.stacker.p1000+u)*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},J=function(n,e){const t=parseInt(n,16);return t===1?e.name="Banknote accepted":t===0?e.name="Banknote rejected":e.name="Unknown status banknote",e.no_code=8,this.dispatch("banknote-purse:banknote-scrow-status",{status:t===1}),e},K=function(n,e){const[t,i,r,o,l,u]=[parseInt(n[2],16),parseInt(n[3],16),parseInt(n[4],16),parseInt(n[5],16),parseInt(n[6],16),parseInt(n[7],16)],B=t*20+i*50+r*100+o*200+l*500+u*1e3;return e.name="Banknotes dispensed",e.description=B>0?"Banknotes dispensed by request":"No banknotes dispensed, recycler empty",e.no_code=9,e.additional={banknotes:{b20:t,b50:i,b100:r,b200:o,b500:l,b1000:u},total_dispensed:B},this.dispatch("session:money-dispensed",{type_money:null,retired:null,finish:!1,type:"banknotes",data:e}),e},X=function(n,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},Z=function(n,e){const t=parseInt(n,16);return t===1?(e.name="Product not delivered",e.description="The product requested wasn't delivered",e.no_code=11,this.__internal__.dispense.status=!1):t===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},g=function(n,e){let t="closed";return n==="db"?(e.name="Door closed",e.no_code=13):n==="dc"?(e.name="Door open",e.no_code=14,t="open"):(e.name="Unknown status door",e.description="The response of door doesn't identify successfully",e.no_code=400,t="unknown"),this.__internal__.device.door_open=t==="open",this.dispatch("event:door",{open:t==="open"}),this.dispatch("door:event",{open:t==="open"}),e},ee=function(n,e){const t=parseInt(n[2],16)*255,i=parseInt(n[3],16),r=(t+i)*.1;return e.no_code=15,e.name="Temperature status",e.description=`Temperature: ${r}`,e.additional={high:t,low:i,temperature:parseFloat(r.toString())},this.dispatch("status:temperature",e.additional),e},ne=function(n,e){const t=parseInt(n,16);let i="unknown";return t===1?(e.name="Relay on",e.description="Relay on",e.no_code=16,i="on"):t===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},te=function(n,e){const t=parseInt(n[2],16);if(e.no_code=20+t,e.name="Status unknown",e.description="The status of card reader does not identified correctly",t===0)e.request+=":disable",e.name="Card reader disabled",e.description="Card reader device was disabled successfully";else if(t===1||t===2)e.request+=":dispense",e.name="Card reader enabled",e.description="Card reader device is now enabled";else if(t===3)e.request+=":pre-authorize",e.name="Pre-authorized credit",e.description="The pre credit was authorized successfully";else if(t===4)e.request+=":cancel",e.name="Cancellation in progress",e.description="Cancellation request done successfully";else if(t===5)e.request+=":sell",e.name="Sell approved",e.description="Sell approved, starting dispense product";else if(t===6)e.request+=":sell",e.name="Sell denied",e.description="This sell was denied, try again";else if(t===7)e.request+=":end",e.name="Session ended",e.description="The session ended";else if(t===8)e.request+=":cancel",e.name="Cancelled",e.description="Cancellation complete";else if(t===10){const i=parseInt(n[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},se=function({enable:n=!1,scrow:e=!1}={}){return d.l.banknotePurseICTConfigure({enable:n,scrow:e})},ie=function({enable:n=!1,scrow:e=!1}={}){return d.l.banknotePurseOtherConfigure({enable:n,scrow:e})},re=function(n=1){if(n<1)throw new Error("No banknotes to dispense");const e=[20,50,100,200,500][this.__banknote_purse.recycler.banknote];return d.l.banknotePurseICTDispense({quantity:n,denomination:e})},ae=function({$_20:n=0,$_50:e=0,$_100:t=0,$_200:i=0,$_500:r=0,$_1000:o=0}={}){return d.l.banknotePurseOtherDispense({$20:n,$50:e,$100:t,$200:i,$500:r,$1000:o})},R=function(){b(this,f,!1),b(this,_,0),b(this,k,0)},C=function({dispensed:n=null,limit:e=80}={}){b(this,k,Math.round(w(this,_)*100/e)),this.dispatch("percentage:test",{percentage:w(this,k),dispensed:n})},oe=function(n){const e=["20","50","100","200","500"],t=this.__banknote_purse.recycler.banknote,i="$_"+e[t],r=parseInt(e[t]),o=this.banknotes.recycler[`p${e[t]}`],l=Math.min(Math.floor(n/r),o),u={banknotes:{$_20:0,$_50:0,$_100:0,$_200:0,$_500:0,$_1000:0},pending:n,will_dispense:l>0};return this.totalInRecycler===0||l<1||n===0||(u.banknotes[i]=l,u.pending=parseFloat((n-l*r).toFixed(2))),u},le=function(n){const e={banknotes:{$_20:0,$_50:0,$_100:0,$_200:0,$_500:0,$_1000:0},pending:n,will_dispense:!1};if(this.totalInRecycler===0||n===0)return e;const t=(i,r)=>{if(this.banknotes.recycler[r]>0){const o=Math.floor(e.pending/i),l=Math.min(o,this.banknotes.recycler[r]);e.banknotes[`$_${i}`]=l,e.pending=parseFloat((e.pending-l*i).toFixed(2))}};return t(1e3,"p1000"),t(500,"p500"),t(200,"p200"),t(100,"p100"),t(50,"p50"),t(20,"p20"),e.will_dispense=Object.values(e.banknotes).some(i=>i>0),e},P=function(n){return this.hasRecycler?a(this,s,v).call(this)?a(this,s,oe).call(this,n):a(this,s,le).call(this,n):{banknotes:{$_20:0,$_50:0,$_100:0,$_200:0,$_500:0,$_1000:0},pending:n,will_dispense:!1}},$=function(n){const e={coins:{$_50c:0,$_1:0,$_2:0,$_5:0,$_10:0},pending:n,will_dispense:!1};if(!this.hasCoinPurse||n<=0||this.totalInTubes===0)return e;const t=(i,r,o=null)=>{if(this.coins.tubes[r]>0){o===null&&(o="$_"+i);const l=Math.floor(e.pending/i),u=Math.min(l,this.coins.tubes[r]);e.coins[o]=u,e.pending=parseFloat((e.pending-u*i).toFixed(2))}};return t(10,"p10"),t(5,"p5"),t(2,"p2"),t(1,"p1"),t(.5,"g50","$_50c"),e.will_dispense=Object.values(e.coins).some(i=>i>0),e},q=async function(n=null){if(!a(this,s,S).call(this))throw new Error("Change not available");let e=this.change,t=this.change;if(n!==null&&(e=n,t=n),t<=0)return!1;const i=a(this,s,P).call(this,t);t=i.pending;const r=a(this,s,$).call(this,t);return t=r.pending,t>0&&this.dispatch("change:pending",{pending:t}),this.dispatch("change:dispense",{recycler:i.banknotes,coins:r.coins,pending:t,delivery:e-t}),t===e?!1:(i.will_dispense&&await this.banknotePurseDispense(i.banknotes),r.will_dispense&&await this.coinPurseDispense(r.coins),!0)};exports.Boardroid=de;
package/dist/boardroid.js CHANGED
@@ -5,10 +5,11 @@ var D = (c) => {
5
5
  var pe = (c, p, n) => p in c ? ce(c, p, { enumerable: !0, configurable: !0, writable: !0, value: n }) : c[p] = n;
6
6
  var h = (c, p, n) => pe(c, typeof p != "symbol" ? p + "" : p, n), I = (c, p, n) => p.has(c) || D("Cannot " + n);
7
7
  var w = (c, p, n) => (I(c, p, "read from private field"), n ? n.call(c) : p.get(c)), y = (c, p, n) => p.has(c) ? D("Cannot add the same private member more than once") : p instanceof WeakSet ? p.add(c) : p.set(c, n), b = (c, p, n, e) => (I(c, p, "write to private field"), e ? e.call(c, n) : p.set(c, n), n), a = (c, p, n) => (I(c, p, "access private method"), n);
8
- import { K as ue, h as x } from "./kernel-C4PiwwCb.js";
8
+ import { K as ue } from "./kernel-lcvN8cY0.js";
9
9
  import { l as d } from "./relay-Dop4mFk-.js";
10
+ import { h as x } from "./webserial-core-DGKQCs5a.js";
10
11
  var f, _, k, s, E, M, v, S, m, Q, N, F, j, O, U, A, L, T, V, z, W, K, Y, G, H, J, X, Z, g, ee, ne, te, se, ie, re, ae, R, C, oe, le, P, $, B;
11
- class _e extends ue {
12
+ class fe extends ue {
12
13
  constructor({ filters: n = null, config_port: e = null, no_device: t = 1 } = {}) {
13
14
  super({ filters: n, config_port: e, no_device: t });
14
15
  y(this, s);
@@ -727,5 +728,5 @@ C = function({ dispensed: n = null, limit: e = 80 } = {}) {
727
728
  }), t === e ? !1 : (i.will_dispense && await this.banknotePurseDispense(i.banknotes), r.will_dispense && await this.coinPurseDispense(r.coins), !0);
728
729
  };
729
730
  export {
730
- _e as Boardroid
731
+ fe as Boardroid
731
732
  };
@@ -0,0 +1,2 @@
1
+ "use strict";var N=Object.defineProperty;var w=p=>{throw TypeError(p)};var R=(p,a,e)=>a in p?N(p,a,{enumerable:!0,configurable:!0,writable:!0,value:e}):p[a]=e;var x=(p,a,e)=>R(p,typeof a!="symbol"?a+"":a,e),P=(p,a,e)=>a.has(p)||w("Cannot "+e);var E=(p,a,e)=>a.has(p)?w("Cannot add the same private member more than once"):a instanceof WeakSet?a.add(p):a.set(p,e);var n=(p,a,e)=>(P(p,a,"access private method"),e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("./webserial-core-DlH0cFSH.cjs");var t,H,u,f,c,_,b,A,v,s;class I extends l.K{constructor({filters:e=null,config_port:r={baudRate:115200,dataBits:8,stopBits:1,parity:"none",bufferSize:32768,flowControl:"none"},no_device:i=1}={filters:null,config_port:{baudRate:115200,dataBits:8,stopBits:1,parity:"none",bufferSize:32768,flowControl:"none"},no_device:1}){super({filters:e,config_port:r,no_device:i});E(this,t);x(this,"__hoppers__",{levels:[{id:1,currency:10,key:"Hopper 1",name:"10 Pesos",amount:0,capacity:1e3},{id:2,currency:5,key:"Hopper 2",name:"5 Pesos",amount:0,capacity:1e3},{id:3,currency:2,key:"Hopper 3",name:"2 Pesos",amount:0,capacity:1e3},{id:4,currency:1,key:"Hopper 4",name:"1 Peso",amount:0,capacity:1e3}],balance:0,current:null});if(this.__internal__.device.type="hopper",l.h.registerType(this.__internal__.device.type),l.h.getByNumber(this.typeDevice,i))throw new Error(`Device ${this.typeDevice} ${i} already exists`);this.__internal__.time.response_connection=7e3,this.__internal__.time.response_general=7e3,this.__internal__.serial.delay_first_connection=500,this.__internal__.serial.response.replacer="",this.__internal__.serial.response.limiter=`\r
2
+ `,l.h.add(this),n(this,t,H).call(this)}get balance(){return this.__hoppers__.balance}get currentHopper(){return this.__hoppers__.current}get levels(){return this.__hoppers__.levels}setMaxCapacity({hopper:e=null,capacity:r=1e3}={hopper:null,capacity:1e3}){return n(this,t,_).call(this,e),this.__hoppers__.levels[e-1].capacity=r,this}setHopperName({hopper:e=null,name:r=""}={hopper:null,name:""}){if(n(this,t,_).call(this,e),typeof r!="string"||r.length===0)throw new TypeError("Name must be a non-empty string");return this.__hoppers__.levels[e-1].name=r,this}setHopperKey({hopper:e=null,key:r=""}={hopper:null,key:""}){if(n(this,t,_).call(this,e),typeof r!="string"||r.length===0)throw new TypeError("Key must be a non-empty string");return this.__hoppers__.levels[e-1].key=r,this}setHopperCurrency({hopper:e=null,currency:r=1}={hopper:null,currency:1}){if(n(this,t,_).call(this,e),typeof r!="number"||r<=0)throw new RangeError("Currency must be a positive number");return this.__hoppers__.levels[e-1].currency=r,this}serialMessage(e){const r=this.parseUint8ArrayToString(e),o={ascii:this.asciiToHex(r),code:e,name:"",description:"",request:this.lastAction,no_code:0,error:!1,data:null};if(e.length===3){n(this,t,u).call(this,o);return}if(e.length!==13){const h=n(this,t,v).call(this,{array:e,chunkSize:13});for(const d of h){const y=this.parseUint8ArrayToString(new Uint8Array(d)),T=this.asciiToHex(y),C=this.stringToArrayHex(y);o.code=d,o.hex=C,o.ascii=T,d.length!==13?n(this,t,u).call(this,o):n(this,t,f).call(this,o)}return}n(this,t,f).call(this,o)}serialSetConnectionConstant(){return[10,0,0,0,0,0,0,0,0,0,0,0,15]}async sendConnect(){const e=n(this,t,s).call(this,[10]);return await this.appendToQueue(e,"connect")}async requestStatus(){const e=n(this,t,s).call(this,[10,10,11,12]);return await this.appendToQueue(e,"status")}async readBalance(){const e=n(this,t,s).call(this,[10,192,1]);return await this.appendToQueue(e,"readBalance")}async clearBalance(){const e=n(this,t,s).call(this,[10,192,2]);return await this.appendToQueue(e,"clearBalance")}async forceInvalid(){const e="0A000F00".match(/.{1,2}/g);return await this.appendToQueue(e,"ForceInvalid")}async readHopper({hopper:e=null}={hopper:null}){n(this,t,_).call(this,e),this.__hoppers__.current=e;const r=n(this,t,s).call(this,[10,e,e]);return await this.appendToQueue(r,"readHopper")}async writeHopper({hopper:e=null,quantity:r=0}={hopper:null,quantity:0}){n(this,t,_).call(this,e),n(this,t,b).call(this,r),this.__hoppers__.current=e;const[i,o]=n(this,t,A).call(this,r),h=n(this,t,s).call(this,[10,240,e,0,0,0,0,0,0,i,o]);return await this.appendToQueue(h,"writeHopper")}async dispenseHopper({hopper:e=null}={hopper:null}){n(this,t,_).call(this,e),this.__hoppers__.current=e;const r=n(this,t,s).call(this,[10,2,e]);return await this.appendToQueue(r,"dispenseHopper")}async dispenseChange({change:e=0}={change:0}){if(typeof e!="number"||e<0||e>32767)throw new RangeError("Change must be a number between 0 and 32767");if(typeof e!="number"||!Number.isInteger(e))throw new TypeError("Change must be an integer");const r=e&255,i=e>>8&255,o=n(this,t,s).call(this,[10,204,170,0,0,0,0,0,0,i,r]);return await this.appendToQueue(o,"dispenseChange")}async configValidator({enable:e=!1}={enable:!1}){if(typeof e!="boolean")throw new TypeError("Enable must be a boolean");const r=n(this,t,s).call(this,[10,176,e?1:0]);return await this.appendToQueue(r,"configValidator")}async disableValidator(){return await this.configValidator({enable:!1})}async enableValidator(){return await this.configValidator({enable:!0})}async change1x1({hopper:e=null}={hopper:null}){n(this,t,_).call(this,e),this.__hoppers__.current=e;const r=n(this,t,s).call(this,[10,224,e]);return await this.appendToQueue(r,"change1x1Hopper-"+e)}async sendCustomCode({code:e=[]}={code:[]}){if(!Array.isArray(e)||!e.every(i=>typeof i=="number"&&i>=0&&i<=255))throw new TypeError("Code must be an array of numbers between 0 and 255");const r=n(this,t,s).call(this,e);await this.appendToQueue(r,"custom")}}t=new WeakSet,H=function(){const e=["levels","hopper:updated","dispense-change","balance:updated","validator:status","change:1x1"];for(const r of e)this.serialRegisterAvailableListener(r)},u=function(e){e.error=!0,e.ascii.includes("ffffff")?(e.name="SINTAX",e.description="Error de Sintaxis",e.no_code=400):e.ascii.includes("ffaaaa")?(e.name="LOWLEVEL",e.description="Bajo nivel de monedas en Hopper (99)",e.no_code=401):e.ascii.includes("ffbbbb")?(e.name="TIMEOUT_DISPENSE",e.description="Error de dispensado, timeout",e.no_code=402):(e.name="UNKNOWN_ERROR",e.description="Unknown error occurred",e.no_code=999),this.dispatch("serial:message",e)},f=function(e){if(this.lastAction==="status")e.name="STATUS",e.description="Hoppers status",e.no_code=1,this.__hoppers__.levels[0].amount=n(this,t,c).call(this,e.code[9],e.code[10]),this.__hoppers__.levels[1].amount=n(this,t,c).call(this,e.code[7],e.code[8]),this.__hoppers__.levels[2].amount=n(this,t,c).call(this,e.code[5],e.code[6]),this.__hoppers__.levels[3].amount=n(this,t,c).call(this,e.code[3],e.code[4]),e.data=this.__hoppers__.levels,this.dispatch("levels",e.data);else if(this.lastAction==="readHopper"){e.name="READ_HOPPER",e.description=`Hopper ${this.__hoppers__.current} level`,e.no_code=2;const r=this.__hoppers__.current-1;this.__hoppers__.levels[r].amount=n(this,t,c).call(this,e.code[9],e.code[10]),e.data=this.__hoppers__.levels,e.hopperId=this.__hoppers__.current,this.dispatch("hopper:updated",this.__hoppers__.levels[r])}else this.lastAction==="writeHopper"?(e.name="WRITE_HOPPER",e.description="Hopper "+this.__hoppers__.current+" write",e.no_code=3,this.__hoppers__.levels[this.__hoppers__.current-1].amount=n(this,t,c).call(this,e.code[9],e.code[10]),e.data=this.__hoppers__.levels,e.hopperId=this.__hoppers__.current,this.dispatch("hopper:updated",this.__hoppers__.levels[this.__hoppers__.current=-1])):this.lastAction==="dispenseHopper"?(e.name="DISPENSEHOPPER",e.description="Hopper "+this.__hoppers__.current+" dispense",e.no_code=4,this.__hoppers__.levels[this.__hoppers__.current-1].amount=n(this,t,c).call(this,e.code[9],e.code[10]),e.data=this.__hoppers__.levels,e.hopperId=this.__hoppers__.current,this.dispatch("hopper:updated",this.__hoppers__.levels[this.__hoppers__.current=-1])):this.lastAction==="dispenseChange"?(e.name="DISPENSE_CHANGE",e.description="Change dispensed",e.no_code=5,e.data=n(this,t,c).call(this,e.code[9],e.code[10]),this.dispatch("dispense-change",{amount:e.data})):this.lastAction==="readBalance"?(e.name="READ_BALANCE",e.description="Read Balance",e.no_code=6,this.__hoppers__.balance=n(this,t,c).call(this,e.code[9],e.code[10]),e.data=this.__hoppers__.balance,this.dispatch("balance:updated",{balance:e.data})):this.lastAction==="clearBalance"?(e.name="CLEAR_BALANCE",e.description="Clared hoppers balance",e.no_code=7,this.__hoppers__.balance=n(this,t,c).call(this,e.code[9],e.code[10]),e.data=this.__hoppers__.balance,this.dispatch("balance:updated",{balance:e.data})):this.lastAction==="configValidator"?(e.code[2]===1?(e.name="ENABLE_VALIDATOR",e.description="Validator enabled",e.no_code=8,this.dispatch("validator:status",{enabled:!0})):(e.name="DISABLE_VALIDATOR",e.description="Validator disabled",e.no_code=9,this.dispatch("validator:status",{enabled:!1})),e.no_code=400,e.data=e.code[2]===1?"enabled":"disabled"):this.lastAction.includes("change1x1Hopper")&&(e.code[2]===1?(e.name="CHANGE_1X1_HOPPER_1",e.description="Change 1x1 Hopper 1",e.no_code=10):e.code[2]===2?(e.name="CHANGE_1X1_HOPPER_2",e.description="Change 1x1 Hopper 2",e.no_code=11):e.code[2]===3?(e.name="CHANGE_1X1_HOPPER_3",e.description="Change 1x1 Hopper 3",e.no_code=12):e.code[2]===4?(e.name="CHANGE_1X1_HOPPER_4",e.description="Change 1x1 Hopper 4",e.no_code=13):(e.name="CHANGE_1X1_HOPPER_UNKNOWN",e.description="Change 1x1 Hopper Unknown",e.no_code=14),this.dispatch("change:1x1",{hopperId:e.code[2]}));this.dispatch("serial:message",e)},c=function(e,r){return(e<<8|r)<<16>>16},_=function(e){if(typeof e!="number"||e<1||e>4)throw new RangeError("Hopper ID must be a number between 1 and 4");if(typeof e!="number"||!Number.isInteger(e))throw new TypeError("Hopper ID must be an integer")},b=function(e){if(typeof e!="number"||e<-32768||e>32767)throw new RangeError("Quantity must be a number between -32768 and 32767");if(typeof e!="number"||!Number.isInteger(e))throw new TypeError("Quantity must be an integer")},A=function(e){n(this,t,b).call(this,e);const r=e&65535,i=r>>8&255,o=r&255;return[i,o]},v=function({array:e,chunkSize:r=13}={}){if(!Array.isArray(e))throw new TypeError("Expected an array");if(typeof r!="number"||r<=0)throw new RangeError("Chunk size must be a positive number");const i=[];for(let o=0;o<e.length;o+=r)i.push(e.slice(o,o+r));return i},s=function(e){e.length<11&&(e=[...e,...Array(11-e.length).fill(0)]);const i=e.slice(1,11).reduce((o,h)=>{if(typeof h!="number")throw new TypeError("Array must contain only numbers");return o+h},0)&255;return e[11]=i,e[12]=15,e};exports.Hopper=I;
package/dist/hopper.js ADDED
@@ -0,0 +1,226 @@
1
+ var N = Object.defineProperty;
2
+ var w = (p) => {
3
+ throw TypeError(p);
4
+ };
5
+ var R = (p, a, e) => a in p ? N(p, a, { enumerable: !0, configurable: !0, writable: !0, value: e }) : p[a] = e;
6
+ var x = (p, a, e) => R(p, typeof a != "symbol" ? a + "" : a, e), P = (p, a, e) => a.has(p) || w("Cannot " + e);
7
+ var E = (p, a, e) => a.has(p) ? w("Cannot add the same private member more than once") : a instanceof WeakSet ? a.add(p) : a.set(p, e);
8
+ var n = (p, a, e) => (P(p, a, "access private method"), e);
9
+ import { K as I, h as d } from "./webserial-core-DGKQCs5a.js";
10
+ var t, H, u, f, c, _, b, A, v, s;
11
+ class O extends I {
12
+ constructor({
13
+ filters: e = null,
14
+ config_port: r = {
15
+ baudRate: 115200,
16
+ dataBits: 8,
17
+ stopBits: 1,
18
+ parity: "none",
19
+ bufferSize: 32768,
20
+ flowControl: "none"
21
+ },
22
+ no_device: i = 1
23
+ } = {
24
+ filters: null,
25
+ config_port: {
26
+ baudRate: 115200,
27
+ dataBits: 8,
28
+ stopBits: 1,
29
+ parity: "none",
30
+ bufferSize: 32768,
31
+ flowControl: "none"
32
+ },
33
+ no_device: 1
34
+ }) {
35
+ super({ filters: e, config_port: r, no_device: i });
36
+ E(this, t);
37
+ x(this, "__hoppers__", {
38
+ levels: [
39
+ { id: 1, currency: 10, key: "Hopper 1", name: "10 Pesos", amount: 0, capacity: 1e3 },
40
+ { id: 2, currency: 5, key: "Hopper 2", name: "5 Pesos", amount: 0, capacity: 1e3 },
41
+ { id: 3, currency: 2, key: "Hopper 3", name: "2 Pesos", amount: 0, capacity: 1e3 },
42
+ { id: 4, currency: 1, key: "Hopper 4", name: "1 Peso", amount: 0, capacity: 1e3 }
43
+ ],
44
+ balance: 0,
45
+ current: null
46
+ });
47
+ if (this.__internal__.device.type = "hopper", d.registerType(this.__internal__.device.type), d.getByNumber(this.typeDevice, i))
48
+ throw new Error(`Device ${this.typeDevice} ${i} already exists`);
49
+ this.__internal__.time.response_connection = 7e3, this.__internal__.time.response_general = 7e3, this.__internal__.serial.delay_first_connection = 500, this.__internal__.serial.response.replacer = "", this.__internal__.serial.response.limiter = `\r
50
+ `, d.add(this), n(this, t, H).call(this);
51
+ }
52
+ get balance() {
53
+ return this.__hoppers__.balance;
54
+ }
55
+ get currentHopper() {
56
+ return this.__hoppers__.current;
57
+ }
58
+ get levels() {
59
+ return this.__hoppers__.levels;
60
+ }
61
+ setMaxCapacity({ hopper: e = null, capacity: r = 1e3 } = { hopper: null, capacity: 1e3 }) {
62
+ return n(this, t, _).call(this, e), this.__hoppers__.levels[e - 1].capacity = r, this;
63
+ }
64
+ setHopperName({ hopper: e = null, name: r = "" } = { hopper: null, name: "" }) {
65
+ if (n(this, t, _).call(this, e), typeof r != "string" || r.length === 0)
66
+ throw new TypeError("Name must be a non-empty string");
67
+ return this.__hoppers__.levels[e - 1].name = r, this;
68
+ }
69
+ setHopperKey({ hopper: e = null, key: r = "" } = { hopper: null, key: "" }) {
70
+ if (n(this, t, _).call(this, e), typeof r != "string" || r.length === 0)
71
+ throw new TypeError("Key must be a non-empty string");
72
+ return this.__hoppers__.levels[e - 1].key = r, this;
73
+ }
74
+ setHopperCurrency({ hopper: e = null, currency: r = 1 } = { hopper: null, currency: 1 }) {
75
+ if (n(this, t, _).call(this, e), typeof r != "number" || r <= 0)
76
+ throw new RangeError("Currency must be a positive number");
77
+ return this.__hoppers__.levels[e - 1].currency = r, this;
78
+ }
79
+ serialMessage(e) {
80
+ const r = this.parseUint8ArrayToString(e), o = {
81
+ //hex,
82
+ ascii: this.asciiToHex(r),
83
+ code: e,
84
+ name: "",
85
+ description: "",
86
+ request: this.lastAction,
87
+ no_code: 0,
88
+ error: !1,
89
+ data: null
90
+ };
91
+ if (e.length === 3) {
92
+ n(this, t, u).call(this, o);
93
+ return;
94
+ }
95
+ if (e.length !== 13) {
96
+ const h = n(this, t, v).call(this, { array: e, chunkSize: 13 });
97
+ for (const l of h) {
98
+ const y = this.parseUint8ArrayToString(new Uint8Array(l)), T = this.asciiToHex(y), C = this.stringToArrayHex(y);
99
+ o.code = l, o.hex = C, o.ascii = T, l.length !== 13 ? n(this, t, u).call(this, o) : n(this, t, f).call(this, o);
100
+ }
101
+ return;
102
+ }
103
+ n(this, t, f).call(this, o);
104
+ }
105
+ serialSetConnectionConstant() {
106
+ return [10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15];
107
+ }
108
+ async sendConnect() {
109
+ const e = n(this, t, s).call(this, [10]);
110
+ return await this.appendToQueue(e, "connect");
111
+ }
112
+ async requestStatus() {
113
+ const e = n(this, t, s).call(this, [10, 10, 11, 12]);
114
+ return await this.appendToQueue(e, "status");
115
+ }
116
+ async readBalance() {
117
+ const e = n(this, t, s).call(this, [10, 192, 1]);
118
+ return await this.appendToQueue(e, "readBalance");
119
+ }
120
+ async clearBalance() {
121
+ const e = n(this, t, s).call(this, [10, 192, 2]);
122
+ return await this.appendToQueue(e, "clearBalance");
123
+ }
124
+ async forceInvalid() {
125
+ const e = "0A000F00".match(/.{1,2}/g);
126
+ return await this.appendToQueue(e, "ForceInvalid");
127
+ }
128
+ async readHopper({ hopper: e = null } = { hopper: null }) {
129
+ n(this, t, _).call(this, e), this.__hoppers__.current = e;
130
+ const r = n(this, t, s).call(this, [10, e, e]);
131
+ return await this.appendToQueue(r, "readHopper");
132
+ }
133
+ async writeHopper({ hopper: e = null, quantity: r = 0 } = { hopper: null, quantity: 0 }) {
134
+ n(this, t, _).call(this, e), n(this, t, b).call(this, r), this.__hoppers__.current = e;
135
+ const [i, o] = n(this, t, A).call(this, r), h = n(this, t, s).call(this, [10, 240, e, 0, 0, 0, 0, 0, 0, i, o]);
136
+ return await this.appendToQueue(h, "writeHopper");
137
+ }
138
+ async dispenseHopper({ hopper: e = null } = { hopper: null }) {
139
+ n(this, t, _).call(this, e), this.__hoppers__.current = e;
140
+ const r = n(this, t, s).call(this, [10, 2, e]);
141
+ return await this.appendToQueue(r, "dispenseHopper");
142
+ }
143
+ async dispenseChange({ change: e = 0 } = { change: 0 }) {
144
+ if (typeof e != "number" || e < 0 || e > 32767)
145
+ throw new RangeError("Change must be a number between 0 and 32767");
146
+ if (typeof e != "number" || !Number.isInteger(e))
147
+ throw new TypeError("Change must be an integer");
148
+ const r = e & 255, i = e >> 8 & 255, o = n(this, t, s).call(this, [10, 204, 170, 0, 0, 0, 0, 0, 0, i, r]);
149
+ return await this.appendToQueue(o, "dispenseChange");
150
+ }
151
+ async configValidator({ enable: e = !1 } = { enable: !1 }) {
152
+ if (typeof e != "boolean")
153
+ throw new TypeError("Enable must be a boolean");
154
+ const r = n(this, t, s).call(this, [10, 176, e ? 1 : 0]);
155
+ return await this.appendToQueue(r, "configValidator");
156
+ }
157
+ async disableValidator() {
158
+ return await this.configValidator({ enable: !1 });
159
+ }
160
+ async enableValidator() {
161
+ return await this.configValidator({ enable: !0 });
162
+ }
163
+ async change1x1({ hopper: e = null } = { hopper: null }) {
164
+ n(this, t, _).call(this, e), this.__hoppers__.current = e;
165
+ const r = n(this, t, s).call(this, [10, 224, e]);
166
+ return await this.appendToQueue(r, "change1x1Hopper-" + e);
167
+ }
168
+ async sendCustomCode({ code: e = [] } = { code: [] }) {
169
+ if (!Array.isArray(e) || !e.every((i) => typeof i == "number" && i >= 0 && i <= 255))
170
+ throw new TypeError("Code must be an array of numbers between 0 and 255");
171
+ const r = n(this, t, s).call(this, e);
172
+ await this.appendToQueue(r, "custom");
173
+ }
174
+ }
175
+ t = new WeakSet(), H = function() {
176
+ const e = ["levels", "hopper:updated", "dispense-change", "balance:updated", "validator:status", "change:1x1"];
177
+ for (const r of e)
178
+ this.serialRegisterAvailableListener(r);
179
+ }, u = function(e) {
180
+ e.error = !0, e.ascii.includes("ffffff") ? (e.name = "SINTAX", e.description = "Error de Sintaxis", e.no_code = 400) : e.ascii.includes("ffaaaa") ? (e.name = "LOWLEVEL", e.description = "Bajo nivel de monedas en Hopper (99)", e.no_code = 401) : e.ascii.includes("ffbbbb") ? (e.name = "TIMEOUT_DISPENSE", e.description = "Error de dispensado, timeout", e.no_code = 402) : (e.name = "UNKNOWN_ERROR", e.description = "Unknown error occurred", e.no_code = 999), this.dispatch("serial:message", e);
181
+ }, f = function(e) {
182
+ if (this.lastAction === "status")
183
+ e.name = "STATUS", e.description = "Hoppers status", e.no_code = 1, this.__hoppers__.levels[0].amount = n(this, t, c).call(this, e.code[9], e.code[10]), this.__hoppers__.levels[1].amount = n(this, t, c).call(this, e.code[7], e.code[8]), this.__hoppers__.levels[2].amount = n(this, t, c).call(this, e.code[5], e.code[6]), this.__hoppers__.levels[3].amount = n(this, t, c).call(this, e.code[3], e.code[4]), e.data = this.__hoppers__.levels, this.dispatch("levels", e.data);
184
+ else if (this.lastAction === "readHopper") {
185
+ e.name = "READ_HOPPER", e.description = `Hopper ${this.__hoppers__.current} level`, e.no_code = 2;
186
+ const r = this.__hoppers__.current - 1;
187
+ this.__hoppers__.levels[r].amount = n(this, t, c).call(this, e.code[9], e.code[10]), e.data = this.__hoppers__.levels, e.hopperId = this.__hoppers__.current, this.dispatch("hopper:updated", this.__hoppers__.levels[r]);
188
+ } else this.lastAction === "writeHopper" ? (e.name = "WRITE_HOPPER", e.description = "Hopper " + this.__hoppers__.current + " write", e.no_code = 3, this.__hoppers__.levels[this.__hoppers__.current - 1].amount = n(this, t, c).call(this, e.code[9], e.code[10]), e.data = this.__hoppers__.levels, e.hopperId = this.__hoppers__.current, this.dispatch("hopper:updated", this.__hoppers__.levels[this.__hoppers__.current = -1])) : this.lastAction === "dispenseHopper" ? (e.name = "DISPENSEHOPPER", e.description = "Hopper " + this.__hoppers__.current + " dispense", e.no_code = 4, this.__hoppers__.levels[this.__hoppers__.current - 1].amount = n(this, t, c).call(this, e.code[9], e.code[10]), e.data = this.__hoppers__.levels, e.hopperId = this.__hoppers__.current, this.dispatch("hopper:updated", this.__hoppers__.levels[this.__hoppers__.current = -1])) : this.lastAction === "dispenseChange" ? (e.name = "DISPENSE_CHANGE", e.description = "Change dispensed", e.no_code = 5, e.data = n(this, t, c).call(this, e.code[9], e.code[10]), this.dispatch("dispense-change", { amount: e.data })) : this.lastAction === "readBalance" ? (e.name = "READ_BALANCE", e.description = "Read Balance", e.no_code = 6, this.__hoppers__.balance = n(this, t, c).call(this, e.code[9], e.code[10]), e.data = this.__hoppers__.balance, this.dispatch("balance:updated", { balance: e.data })) : this.lastAction === "clearBalance" ? (e.name = "CLEAR_BALANCE", e.description = "Clared hoppers balance", e.no_code = 7, this.__hoppers__.balance = n(this, t, c).call(this, e.code[9], e.code[10]), e.data = this.__hoppers__.balance, this.dispatch("balance:updated", { balance: e.data })) : this.lastAction === "configValidator" ? (e.code[2] === 1 ? (e.name = "ENABLE_VALIDATOR", e.description = "Validator enabled", e.no_code = 8, this.dispatch("validator:status", { enabled: !0 })) : (e.name = "DISABLE_VALIDATOR", e.description = "Validator disabled", e.no_code = 9, this.dispatch("validator:status", { enabled: !1 })), e.no_code = 400, e.data = e.code[2] === 1 ? "enabled" : "disabled") : this.lastAction.includes("change1x1Hopper") && (e.code[2] === 1 ? (e.name = "CHANGE_1X1_HOPPER_1", e.description = "Change 1x1 Hopper 1", e.no_code = 10) : e.code[2] === 2 ? (e.name = "CHANGE_1X1_HOPPER_2", e.description = "Change 1x1 Hopper 2", e.no_code = 11) : e.code[2] === 3 ? (e.name = "CHANGE_1X1_HOPPER_3", e.description = "Change 1x1 Hopper 3", e.no_code = 12) : e.code[2] === 4 ? (e.name = "CHANGE_1X1_HOPPER_4", e.description = "Change 1x1 Hopper 4", e.no_code = 13) : (e.name = "CHANGE_1X1_HOPPER_UNKNOWN", e.description = "Change 1x1 Hopper Unknown", e.no_code = 14), this.dispatch("change:1x1", { hopperId: e.code[2] }));
189
+ this.dispatch("serial:message", e);
190
+ }, c = function(e, r) {
191
+ return (e << 8 | r) << 16 >> 16;
192
+ }, _ = function(e) {
193
+ if (typeof e != "number" || e < 1 || e > 4)
194
+ throw new RangeError("Hopper ID must be a number between 1 and 4");
195
+ if (typeof e != "number" || !Number.isInteger(e))
196
+ throw new TypeError("Hopper ID must be an integer");
197
+ }, b = function(e) {
198
+ if (typeof e != "number" || e < -32768 || e > 32767)
199
+ throw new RangeError("Quantity must be a number between -32768 and 32767");
200
+ if (typeof e != "number" || !Number.isInteger(e))
201
+ throw new TypeError("Quantity must be an integer");
202
+ }, A = function(e) {
203
+ n(this, t, b).call(this, e);
204
+ const r = e & 65535, i = r >> 8 & 255, o = r & 255;
205
+ return [i, o];
206
+ }, v = function({ array: e, chunkSize: r = 13 } = {}) {
207
+ if (!Array.isArray(e))
208
+ throw new TypeError("Expected an array");
209
+ if (typeof r != "number" || r <= 0)
210
+ throw new RangeError("Chunk size must be a positive number");
211
+ const i = [];
212
+ for (let o = 0; o < e.length; o += r)
213
+ i.push(e.slice(o, o + r));
214
+ return i;
215
+ }, s = function(e) {
216
+ e.length < 11 && (e = [...e, ...Array(11 - e.length).fill(0)]);
217
+ const i = e.slice(1, 11).reduce((o, h) => {
218
+ if (typeof h != "number")
219
+ throw new TypeError("Array must contain only numbers");
220
+ return o + h;
221
+ }, 0) & 255;
222
+ return e[11] = i, e[12] = 15, e;
223
+ };
224
+ export {
225
+ O as Hopper
226
+ };