@danidoble/webserial 4.3.3 → 4.3.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/hopper.cjs +2 -2
- package/dist/hopper.js +69 -61
- package/dist/kernel.cjs +1 -1
- package/dist/kernel.js +1 -1
- package/dist/webserial.cjs +1 -1
- package/dist/webserial.js +1 -1
- package/package.json +1 -1
package/dist/hopper.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var R=Object.defineProperty;var w=p=>{throw TypeError(p)};var N=(p,a,e)=>a in p?R(p,a,{enumerable:!0,configurable:!0,writable:!0,value:e}):p[a]=e;var x=(p,a,e)=>N(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 d=require("./webserial-core-5B5nYtyR.cjs");var
|
|
2
|
-
`,d.h.add(this),n(this,
|
|
1
|
+
"use strict";var R=Object.defineProperty;var w=p=>{throw TypeError(p)};var N=(p,a,e)=>a in p?R(p,a,{enumerable:!0,configurable:!0,writable:!0,value:e}):p[a]=e;var x=(p,a,e)=>N(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 d=require("./webserial-core-5B5nYtyR.cjs");var r,H,u,f,c,h,b,A,v,s;class I extends d.K{constructor({filters:e=null,config_port:t={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:t,no_device:i});E(this,r);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",d.h.getCustom(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
|
+
`,d.h.add(this),n(this,r,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:t=1e3}={hopper:null,capacity:1e3}){return n(this,r,h).call(this,e),this.__hoppers__.levels[e-1].capacity=t,this}setHopperName({hopper:e=null,name:t=""}={hopper:null,name:""}){if(n(this,r,h).call(this,e),typeof t!="string"||t.length===0)throw new TypeError("Name must be a non-empty string");return this.__hoppers__.levels[e-1].name=t,this}setHopperKey({hopper:e=null,key:t=""}={hopper:null,key:""}){if(n(this,r,h).call(this,e),typeof t!="string"||t.length===0)throw new TypeError("Key must be a non-empty string");return this.__hoppers__.levels[e-1].key=t,this}setHopperCurrency({hopper:e=null,currency:t=1}={hopper:null,currency:1}){if(n(this,r,h).call(this,e),typeof t!="number"||t<=0)throw new RangeError("Currency must be a positive number");return this.__hoppers__.levels[e-1].currency=t,this}serialMessage(e){const t=this.parseUint8ArrayToString(e),o={ascii:this.asciiToHex(t),code:e,name:"",description:"",request:this.lastAction,no_code:0,error:!1,data:null};if(e.length===3){n(this,r,u).call(this,o);return}if(e.length!==13){const _=n(this,r,v).call(this,{array:e,chunkSize:13});for(const l of _){const y=this.parseUint8ArrayToString(new Uint8Array(l)),T=this.asciiToHex(y),C=this.stringToArrayHex(y);o.code=l,o.hex=C,o.ascii=T,l.length!==13?n(this,r,u).call(this,o):n(this,r,f).call(this,o)}return}n(this,r,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,r,s).call(this,[10]);return await this.appendToQueue(e,"connect")}async requestStatus(){const e=n(this,r,s).call(this,[10,10,11,12]);return await this.appendToQueue(e,"status")}async readBalance(){const e=n(this,r,s).call(this,[10,192,1]);return await this.appendToQueue(e,"readBalance")}async clearBalance(){const e=n(this,r,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,r,h).call(this,e),this.__hoppers__.current=e;const t=n(this,r,s).call(this,[10,e,e]);return await this.appendToQueue(t,"readHopper")}async writeHopper({hopper:e=null,quantity:t=0}={hopper:null,quantity:0}){n(this,r,h).call(this,e),n(this,r,b).call(this,t),this.__hoppers__.current=e;const[i,o]=n(this,r,A).call(this,t),_=n(this,r,s).call(this,[10,240,e,0,0,0,0,0,0,i,o]);return await this.appendToQueue(_,"writeHopper")}async dispenseHopper({hopper:e=null}={hopper:null}){n(this,r,h).call(this,e),this.__hoppers__.current=e;const t=n(this,r,s).call(this,[10,2,e]);return await this.appendToQueue(t,"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 t=e&255,i=e>>8&255,o=n(this,r,s).call(this,[10,204,170,0,0,0,0,0,0,i,t]);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 t=n(this,r,s).call(this,[10,176,e?1:0]);return await this.appendToQueue(t,"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,r,h).call(this,e),this.__hoppers__.current=e;const t=n(this,r,s).call(this,[10,224,e]);return await this.appendToQueue(t,"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 t=n(this,r,s).call(this,e);await this.appendToQueue(t,"custom")}}r=new WeakSet,H=function(){const e=["levels","hopper:updated","dispense-change","balance:updated","validator:status","change:1x1"];for(const t of e)this.serialRegisterAvailableListener(t)},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,r,c).call(this,e.code[9],e.code[10]),this.__hoppers__.levels[1].amount=n(this,r,c).call(this,e.code[7],e.code[8]),this.__hoppers__.levels[2].amount=n(this,r,c).call(this,e.code[5],e.code[6]),this.__hoppers__.levels[3].amount=n(this,r,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 t=this.__hoppers__.current-1;this.__hoppers__.levels[t].amount=n(this,r,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[t])}else if(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,r,c).call(this,e.code[9],e.code[10]),e.data=this.__hoppers__.levels,e.hopperId=this.__hoppers__.current;const t=this.__hoppers__.current-1;this.dispatch("hopper:updated",this.__hoppers__.levels[t])}else if(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,r,c).call(this,e.code[9],e.code[10]),e.data=this.__hoppers__.levels,e.hopperId=this.__hoppers__.current;const t=this.__hoppers__.current-1;this.dispatch("hopper:updated",this.__hoppers__.levels[t])}else this.lastAction==="dispenseChange"?(e.name="DISPENSE_CHANGE",e.description="Change dispensed",e.no_code=5,e.data=n(this,r,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,r,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,r,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,t){return(e<<8|t)<<16>>16},h=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,r,b).call(this,e);const t=e&65535,i=t>>8&255,o=t&255;return[i,o]},v=function({array:e,chunkSize:t=13}={}){if(!Array.isArray(e))throw new TypeError("Expected an array");if(typeof t!="number"||t<=0)throw new RangeError("Chunk size must be a positive number");const i=[];for(let o=0;o<e.length;o+=t)i.push(e.slice(o,o+t));return i},s=function(e){e.length<11&&(e=[...e,...Array(11-e.length).fill(0)]);const i=e.slice(1,11).reduce((o,_)=>{if(typeof _!="number")throw new TypeError("Array must contain only numbers");return o+_},0)&255;return e[11]=i,e[12]=15,e};exports.Hopper=I;
|
package/dist/hopper.js
CHANGED
|
@@ -3,15 +3,15 @@ var y = (p) => {
|
|
|
3
3
|
throw TypeError(p);
|
|
4
4
|
};
|
|
5
5
|
var N = (p, a, e) => a in p ? R(p, a, { enumerable: !0, configurable: !0, writable: !0, value: e }) : p[a] = e;
|
|
6
|
-
var
|
|
7
|
-
var
|
|
6
|
+
var x = (p, a, e) => N(p, typeof a != "symbol" ? a + "" : a, e), P = (p, a, e) => a.has(p) || y("Cannot " + e);
|
|
7
|
+
var w = (p, a, e) => a.has(p) ? y("Cannot add the same private member more than once") : a instanceof WeakSet ? a.add(p) : a.set(p, e);
|
|
8
8
|
var n = (p, a, e) => (P(p, a, "access private method"), e);
|
|
9
9
|
import { K as I, h as E } from "./webserial-core-ByrJ7tlu.js";
|
|
10
|
-
var
|
|
10
|
+
var r, H, d, u, c, h, f, A, v, s;
|
|
11
11
|
class O extends I {
|
|
12
12
|
constructor({
|
|
13
13
|
filters: e = null,
|
|
14
|
-
config_port:
|
|
14
|
+
config_port: t = {
|
|
15
15
|
baudRate: 115200,
|
|
16
16
|
dataBits: 8,
|
|
17
17
|
stopBits: 1,
|
|
@@ -32,9 +32,9 @@ class O extends I {
|
|
|
32
32
|
},
|
|
33
33
|
no_device: 1
|
|
34
34
|
}) {
|
|
35
|
-
super({ filters: e, config_port:
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
super({ filters: e, config_port: t, no_device: i });
|
|
36
|
+
w(this, r);
|
|
37
|
+
x(this, "__hoppers__", {
|
|
38
38
|
levels: [
|
|
39
39
|
{ id: 1, currency: 10, key: "Hopper 1", name: "10 Pesos", amount: 0, capacity: 1e3 },
|
|
40
40
|
{ id: 2, currency: 5, key: "Hopper 2", name: "5 Pesos", amount: 0, capacity: 1e3 },
|
|
@@ -47,7 +47,7 @@ class O extends I {
|
|
|
47
47
|
if (this.__internal__.device.type = "hopper", E.getCustom(this.typeDevice, i))
|
|
48
48
|
throw new Error(`Device ${this.typeDevice} ${i} already exists`);
|
|
49
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
|
-
`, E.add(this), n(this,
|
|
50
|
+
`, E.add(this), n(this, r, H).call(this);
|
|
51
51
|
}
|
|
52
52
|
get balance() {
|
|
53
53
|
return this.__hoppers__.balance;
|
|
@@ -58,28 +58,28 @@ class O extends I {
|
|
|
58
58
|
get levels() {
|
|
59
59
|
return this.__hoppers__.levels;
|
|
60
60
|
}
|
|
61
|
-
setMaxCapacity({ hopper: e = null, capacity:
|
|
62
|
-
return n(this,
|
|
61
|
+
setMaxCapacity({ hopper: e = null, capacity: t = 1e3 } = { hopper: null, capacity: 1e3 }) {
|
|
62
|
+
return n(this, r, h).call(this, e), this.__hoppers__.levels[e - 1].capacity = t, this;
|
|
63
63
|
}
|
|
64
|
-
setHopperName({ hopper: e = null, name:
|
|
65
|
-
if (n(this,
|
|
64
|
+
setHopperName({ hopper: e = null, name: t = "" } = { hopper: null, name: "" }) {
|
|
65
|
+
if (n(this, r, h).call(this, e), typeof t != "string" || t.length === 0)
|
|
66
66
|
throw new TypeError("Name must be a non-empty string");
|
|
67
|
-
return this.__hoppers__.levels[e - 1].name =
|
|
67
|
+
return this.__hoppers__.levels[e - 1].name = t, this;
|
|
68
68
|
}
|
|
69
|
-
setHopperKey({ hopper: e = null, key:
|
|
70
|
-
if (n(this,
|
|
69
|
+
setHopperKey({ hopper: e = null, key: t = "" } = { hopper: null, key: "" }) {
|
|
70
|
+
if (n(this, r, h).call(this, e), typeof t != "string" || t.length === 0)
|
|
71
71
|
throw new TypeError("Key must be a non-empty string");
|
|
72
|
-
return this.__hoppers__.levels[e - 1].key =
|
|
72
|
+
return this.__hoppers__.levels[e - 1].key = t, this;
|
|
73
73
|
}
|
|
74
|
-
setHopperCurrency({ hopper: e = null, currency:
|
|
75
|
-
if (n(this,
|
|
74
|
+
setHopperCurrency({ hopper: e = null, currency: t = 1 } = { hopper: null, currency: 1 }) {
|
|
75
|
+
if (n(this, r, h).call(this, e), typeof t != "number" || t <= 0)
|
|
76
76
|
throw new RangeError("Currency must be a positive number");
|
|
77
|
-
return this.__hoppers__.levels[e - 1].currency =
|
|
77
|
+
return this.__hoppers__.levels[e - 1].currency = t, this;
|
|
78
78
|
}
|
|
79
79
|
serialMessage(e) {
|
|
80
|
-
const
|
|
80
|
+
const t = this.parseUint8ArrayToString(e), o = {
|
|
81
81
|
//hex,
|
|
82
|
-
ascii: this.asciiToHex(
|
|
82
|
+
ascii: this.asciiToHex(t),
|
|
83
83
|
code: e,
|
|
84
84
|
name: "",
|
|
85
85
|
description: "",
|
|
@@ -89,36 +89,36 @@ class O extends I {
|
|
|
89
89
|
data: null
|
|
90
90
|
};
|
|
91
91
|
if (e.length === 3) {
|
|
92
|
-
n(this,
|
|
92
|
+
n(this, r, d).call(this, o);
|
|
93
93
|
return;
|
|
94
94
|
}
|
|
95
95
|
if (e.length !== 13) {
|
|
96
|
-
const _ = n(this,
|
|
96
|
+
const _ = n(this, r, v).call(this, { array: e, chunkSize: 13 });
|
|
97
97
|
for (const l of _) {
|
|
98
98
|
const b = this.parseUint8ArrayToString(new Uint8Array(l)), T = this.asciiToHex(b), C = this.stringToArrayHex(b);
|
|
99
|
-
o.code = l, o.hex = C, o.ascii = T, l.length !== 13 ? n(this,
|
|
99
|
+
o.code = l, o.hex = C, o.ascii = T, l.length !== 13 ? n(this, r, d).call(this, o) : n(this, r, u).call(this, o);
|
|
100
100
|
}
|
|
101
101
|
return;
|
|
102
102
|
}
|
|
103
|
-
n(this,
|
|
103
|
+
n(this, r, u).call(this, o);
|
|
104
104
|
}
|
|
105
105
|
serialSetConnectionConstant() {
|
|
106
106
|
return [10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15];
|
|
107
107
|
}
|
|
108
108
|
async sendConnect() {
|
|
109
|
-
const e = n(this,
|
|
109
|
+
const e = n(this, r, s).call(this, [10]);
|
|
110
110
|
return await this.appendToQueue(e, "connect");
|
|
111
111
|
}
|
|
112
112
|
async requestStatus() {
|
|
113
|
-
const e = n(this,
|
|
113
|
+
const e = n(this, r, s).call(this, [10, 10, 11, 12]);
|
|
114
114
|
return await this.appendToQueue(e, "status");
|
|
115
115
|
}
|
|
116
116
|
async readBalance() {
|
|
117
|
-
const e = n(this,
|
|
117
|
+
const e = n(this, r, s).call(this, [10, 192, 1]);
|
|
118
118
|
return await this.appendToQueue(e, "readBalance");
|
|
119
119
|
}
|
|
120
120
|
async clearBalance() {
|
|
121
|
-
const e = n(this,
|
|
121
|
+
const e = n(this, r, s).call(this, [10, 192, 2]);
|
|
122
122
|
return await this.appendToQueue(e, "clearBalance");
|
|
123
123
|
}
|
|
124
124
|
async forceInvalid() {
|
|
@@ -126,33 +126,33 @@ class O extends I {
|
|
|
126
126
|
return await this.appendToQueue(e, "ForceInvalid");
|
|
127
127
|
}
|
|
128
128
|
async readHopper({ hopper: e = null } = { hopper: null }) {
|
|
129
|
-
n(this,
|
|
130
|
-
const
|
|
131
|
-
return await this.appendToQueue(
|
|
129
|
+
n(this, r, h).call(this, e), this.__hoppers__.current = e;
|
|
130
|
+
const t = n(this, r, s).call(this, [10, e, e]);
|
|
131
|
+
return await this.appendToQueue(t, "readHopper");
|
|
132
132
|
}
|
|
133
|
-
async writeHopper({ hopper: e = null, quantity:
|
|
134
|
-
n(this,
|
|
135
|
-
const [i, o] = n(this,
|
|
133
|
+
async writeHopper({ hopper: e = null, quantity: t = 0 } = { hopper: null, quantity: 0 }) {
|
|
134
|
+
n(this, r, h).call(this, e), n(this, r, f).call(this, t), this.__hoppers__.current = e;
|
|
135
|
+
const [i, o] = n(this, r, A).call(this, t), _ = n(this, r, s).call(this, [10, 240, e, 0, 0, 0, 0, 0, 0, i, o]);
|
|
136
136
|
return await this.appendToQueue(_, "writeHopper");
|
|
137
137
|
}
|
|
138
138
|
async dispenseHopper({ hopper: e = null } = { hopper: null }) {
|
|
139
|
-
n(this,
|
|
140
|
-
const
|
|
141
|
-
return await this.appendToQueue(
|
|
139
|
+
n(this, r, h).call(this, e), this.__hoppers__.current = e;
|
|
140
|
+
const t = n(this, r, s).call(this, [10, 2, e]);
|
|
141
|
+
return await this.appendToQueue(t, "dispenseHopper");
|
|
142
142
|
}
|
|
143
143
|
async dispenseChange({ change: e = 0 } = { change: 0 }) {
|
|
144
144
|
if (typeof e != "number" || e < 0 || e > 32767)
|
|
145
145
|
throw new RangeError("Change must be a number between 0 and 32767");
|
|
146
146
|
if (typeof e != "number" || !Number.isInteger(e))
|
|
147
147
|
throw new TypeError("Change must be an integer");
|
|
148
|
-
const
|
|
148
|
+
const t = e & 255, i = e >> 8 & 255, o = n(this, r, s).call(this, [10, 204, 170, 0, 0, 0, 0, 0, 0, i, t]);
|
|
149
149
|
return await this.appendToQueue(o, "dispenseChange");
|
|
150
150
|
}
|
|
151
151
|
async configValidator({ enable: e = !1 } = { enable: !1 }) {
|
|
152
152
|
if (typeof e != "boolean")
|
|
153
153
|
throw new TypeError("Enable must be a boolean");
|
|
154
|
-
const
|
|
155
|
-
return await this.appendToQueue(
|
|
154
|
+
const t = n(this, r, s).call(this, [10, 176, e ? 1 : 0]);
|
|
155
|
+
return await this.appendToQueue(t, "configValidator");
|
|
156
156
|
}
|
|
157
157
|
async disableValidator() {
|
|
158
158
|
return await this.configValidator({ enable: !1 });
|
|
@@ -161,34 +161,42 @@ class O extends I {
|
|
|
161
161
|
return await this.configValidator({ enable: !0 });
|
|
162
162
|
}
|
|
163
163
|
async change1x1({ hopper: e = null } = { hopper: null }) {
|
|
164
|
-
n(this,
|
|
165
|
-
const
|
|
166
|
-
return await this.appendToQueue(
|
|
164
|
+
n(this, r, h).call(this, e), this.__hoppers__.current = e;
|
|
165
|
+
const t = n(this, r, s).call(this, [10, 224, e]);
|
|
166
|
+
return await this.appendToQueue(t, "change1x1Hopper-" + e);
|
|
167
167
|
}
|
|
168
168
|
async sendCustomCode({ code: e = [] } = { code: [] }) {
|
|
169
169
|
if (!Array.isArray(e) || !e.every((i) => typeof i == "number" && i >= 0 && i <= 255))
|
|
170
170
|
throw new TypeError("Code must be an array of numbers between 0 and 255");
|
|
171
|
-
const
|
|
172
|
-
await this.appendToQueue(
|
|
171
|
+
const t = n(this, r, s).call(this, e);
|
|
172
|
+
await this.appendToQueue(t, "custom");
|
|
173
173
|
}
|
|
174
174
|
}
|
|
175
|
-
|
|
175
|
+
r = new WeakSet(), H = function() {
|
|
176
176
|
const e = ["levels", "hopper:updated", "dispense-change", "balance:updated", "validator:status", "change:1x1"];
|
|
177
|
-
for (const
|
|
178
|
-
this.serialRegisterAvailableListener(
|
|
177
|
+
for (const t of e)
|
|
178
|
+
this.serialRegisterAvailableListener(t);
|
|
179
179
|
}, d = function(e) {
|
|
180
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
181
|
}, u = function(e) {
|
|
182
182
|
if (this.lastAction === "status")
|
|
183
|
-
e.name = "STATUS", e.description = "Hoppers status", e.no_code = 1, this.__hoppers__.levels[0].amount = n(this,
|
|
183
|
+
e.name = "STATUS", e.description = "Hoppers status", e.no_code = 1, this.__hoppers__.levels[0].amount = n(this, r, c).call(this, e.code[9], e.code[10]), this.__hoppers__.levels[1].amount = n(this, r, c).call(this, e.code[7], e.code[8]), this.__hoppers__.levels[2].amount = n(this, r, c).call(this, e.code[5], e.code[6]), this.__hoppers__.levels[3].amount = n(this, r, c).call(this, e.code[3], e.code[4]), e.data = this.__hoppers__.levels, this.dispatch("levels", e.data);
|
|
184
184
|
else if (this.lastAction === "readHopper") {
|
|
185
185
|
e.name = "READ_HOPPER", e.description = `Hopper ${this.__hoppers__.current} level`, e.no_code = 2;
|
|
186
|
-
const
|
|
187
|
-
this.__hoppers__.levels[
|
|
188
|
-
} else
|
|
186
|
+
const t = this.__hoppers__.current - 1;
|
|
187
|
+
this.__hoppers__.levels[t].amount = n(this, r, 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[t]);
|
|
188
|
+
} else if (this.lastAction === "writeHopper") {
|
|
189
|
+
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, r, c).call(this, e.code[9], e.code[10]), e.data = this.__hoppers__.levels, e.hopperId = this.__hoppers__.current;
|
|
190
|
+
const t = this.__hoppers__.current - 1;
|
|
191
|
+
this.dispatch("hopper:updated", this.__hoppers__.levels[t]);
|
|
192
|
+
} else if (this.lastAction === "dispenseHopper") {
|
|
193
|
+
e.name = "DISPENSEHOPPER", e.description = "Hopper " + this.__hoppers__.current + " dispense", e.no_code = 4, this.__hoppers__.levels[this.__hoppers__.current - 1].amount = n(this, r, c).call(this, e.code[9], e.code[10]), e.data = this.__hoppers__.levels, e.hopperId = this.__hoppers__.current;
|
|
194
|
+
const t = this.__hoppers__.current - 1;
|
|
195
|
+
this.dispatch("hopper:updated", this.__hoppers__.levels[t]);
|
|
196
|
+
} else this.lastAction === "dispenseChange" ? (e.name = "DISPENSE_CHANGE", e.description = "Change dispensed", e.no_code = 5, e.data = n(this, r, 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, r, 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, r, 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
197
|
this.dispatch("serial:message", e);
|
|
190
|
-
}, c = function(e,
|
|
191
|
-
return (e << 8 |
|
|
198
|
+
}, c = function(e, t) {
|
|
199
|
+
return (e << 8 | t) << 16 >> 16;
|
|
192
200
|
}, h = function(e) {
|
|
193
201
|
if (typeof e != "number" || e < 1 || e > 4)
|
|
194
202
|
throw new RangeError("Hopper ID must be a number between 1 and 4");
|
|
@@ -200,17 +208,17 @@ t = new WeakSet(), H = function() {
|
|
|
200
208
|
if (typeof e != "number" || !Number.isInteger(e))
|
|
201
209
|
throw new TypeError("Quantity must be an integer");
|
|
202
210
|
}, A = function(e) {
|
|
203
|
-
n(this,
|
|
204
|
-
const
|
|
211
|
+
n(this, r, f).call(this, e);
|
|
212
|
+
const t = e & 65535, i = t >> 8 & 255, o = t & 255;
|
|
205
213
|
return [i, o];
|
|
206
|
-
}, v = function({ array: e, chunkSize:
|
|
214
|
+
}, v = function({ array: e, chunkSize: t = 13 } = {}) {
|
|
207
215
|
if (!Array.isArray(e))
|
|
208
216
|
throw new TypeError("Expected an array");
|
|
209
|
-
if (typeof
|
|
217
|
+
if (typeof t != "number" || t <= 0)
|
|
210
218
|
throw new RangeError("Chunk size must be a positive number");
|
|
211
219
|
const i = [];
|
|
212
|
-
for (let o = 0; o < e.length; o +=
|
|
213
|
-
i.push(e.slice(o, o +
|
|
220
|
+
for (let o = 0; o < e.length; o += t)
|
|
221
|
+
i.push(e.slice(o, o + t));
|
|
214
222
|
return i;
|
|
215
223
|
}, s = function(e) {
|
|
216
224
|
e.length < 11 && (e = [...e, ...Array(11 - e.length).fill(0)]);
|
package/dist/kernel.cjs
CHANGED
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
* This source code is licensed under the MIT license found in the
|
|
8
8
|
* LICENSE file in the root directory of this source tree.
|
|
9
|
-
*/const n="4.1.
|
|
9
|
+
*/const n="4.1.9";exports.Kernel=e.Kernel;exports.Devices=r.h;exports.version=n;
|
package/dist/kernel.js
CHANGED
|
@@ -9,7 +9,7 @@ import { h as n } from "./webserial-core-ByrJ7tlu.js";
|
|
|
9
9
|
* This source code is licensed under the MIT license found in the
|
|
10
10
|
* LICENSE file in the root directory of this source tree.
|
|
11
11
|
*/
|
|
12
|
-
const e = "4.1.
|
|
12
|
+
const e = "4.1.9";
|
|
13
13
|
export {
|
|
14
14
|
n as Devices,
|
|
15
15
|
s as Kernel,
|
package/dist/webserial.cjs
CHANGED
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
* This source code is licensed under the MIT license found in the
|
|
8
8
|
* LICENSE file in the root directory of this source tree.
|
|
9
|
-
*/const u={wait:e.wait,getSeconds:e.getSeconds,supportWebSerial:e.supportWebSerial},l="4.1.
|
|
9
|
+
*/const u={wait:e.wait,getSeconds:e.getSeconds,supportWebSerial:e.supportWebSerial},l="4.1.9";exports.Emulator=e.Emulator;exports.Kernel=e.Kernel;exports.Relay=r.Relay;exports.Locker=o.Locker;exports.PinPad=i.PinPad;exports.PinPax=t.PinPax;exports.Jofemar=n.Jofemar;exports.Boardroid=a.Boardroid;exports.Hopper=s.Hopper;exports.Devices=c.h;exports.utils=u;exports.version=l;
|
package/dist/webserial.js
CHANGED