@danidoble/webserial 4.2.2 → 4.2.3

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.
@@ -0,0 +1,729 @@
1
+ var de = Object.defineProperty;
2
+ var q = (d) => {
3
+ throw TypeError(d);
4
+ };
5
+ var ue = (d, u, t) => u in d ? de(d, u, { enumerable: !0, configurable: !0, writable: !0, value: t }) : d[u] = t;
6
+ var b = (d, u, t) => ue(d, typeof u != "symbol" ? u + "" : u, t), F = (d, u, t) => u.has(d) || q("Cannot " + t);
7
+ var v = (d, u, t) => (F(d, u, "read from private field"), t ? t.call(d) : u.get(d)), C = (d, u, t) => u.has(d) ? q("Cannot add the same private member more than once") : u instanceof WeakSet ? u.add(d) : u.set(d, t), _ = (d, u, t, e) => (F(d, u, "write to private field"), e ? e.call(d, t) : u.set(d, t), t), a = (d, u, t) => (F(d, u, "access private method"), t);
8
+ import { K as pe, c as D } from "./kernel-B15wfB2x.js";
9
+ var w, f, y, s, M, H, x, N, O, U, j, A, L, Q, m, R, z, W, K, V, Y, G, J, X, Z, g, $, ee, te, ne, p, T, se, ie, re, ae, B, I, oe, ce, S, P, E;
10
+ class _e extends pe {
11
+ constructor({ filters: t = null, config_port: e = null, no_device: n = 1 } = {}) {
12
+ super({ filters: t, config_port: e, no_device: n });
13
+ C(this, s);
14
+ b(this, "__coin_purse", {
15
+ available: !0
16
+ });
17
+ b(this, "__banknote_purse", {
18
+ available: !0,
19
+ isRecycler: !0,
20
+ recycler: {
21
+ ict: !0,
22
+ banknote: 1
23
+ // 0: $20, 1: $50, 2: $100, 3: $200, 4: $500
24
+ }
25
+ });
26
+ b(this, "__sale", {
27
+ price: 0,
28
+ change: 0,
29
+ change_verified: 0,
30
+ dispense_all: !0,
31
+ last_change: 0,
32
+ clear() {
33
+ this.price = 0, this.change = 0, this.change_verified = 0, this.dispense_all = !0, this.last_change = 0;
34
+ }
35
+ });
36
+ b(this, "__money_session", {
37
+ inserted: 0,
38
+ retired: 0,
39
+ clear() {
40
+ this.inserted = 0, this.retired = 0;
41
+ }
42
+ });
43
+ b(this, "coins", {
44
+ tubes: { g50: 0, c50: 0, p1: 0, p2: 0, p5: 0, p10: 0 },
45
+ box: { g50: 0, c50: 0, p1: 0, p2: 0, p5: 0, p10: 0 },
46
+ totals: { g50: 0, c50: 0, p1: 0, p2: 0, p5: 0, p10: 0 },
47
+ total: 0
48
+ });
49
+ b(this, "banknotes", {
50
+ stacker: { p20: 0, p50: 0, p100: 0, p200: 0, p500: 0, p1000: 0 },
51
+ recycler: { p20: 0, p50: 0, p100: 0, p200: 0, p500: 0, p1000: 0 },
52
+ out: { p20: 0, p50: 0, p100: 0, p200: 0, p500: 0, p1000: 0 },
53
+ totals: { p20: 0, p50: 0, p100: 0, p200: 0, p500: 0, p1000: 0 },
54
+ total: 0
55
+ });
56
+ b(this, "card_reader", {
57
+ available: !1,
58
+ max_pre_credit: 0
59
+ });
60
+ C(this, w, !1);
61
+ C(this, f, 0);
62
+ C(this, y, 0);
63
+ if (this.__internal__.device.type = "boardroid", D.getCustom(this.typeDevice, n))
64
+ throw new Error(`Device ${this.typeDevice} ${n} already exists`);
65
+ 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 = {
66
+ channel: 1,
67
+ second_channel: null,
68
+ sensor: !0,
69
+ seconds: null
70
+ }, a(this, s, M).call(this), a(this, s, H).call(this);
71
+ }
72
+ get totalInTubes() {
73
+ return this.coins.tubes.g50 * 0.5 + this.coins.tubes.c50 * 0.5 + this.coins.tubes.p1 + this.coins.tubes.p2 * 2 + this.coins.tubes.p5 * 5 + this.coins.tubes.p10 * 10;
74
+ }
75
+ get totalInRecycler() {
76
+ 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;
77
+ }
78
+ get hasRecycler() {
79
+ return this.__banknote_purse.available && this.__banknote_purse.isRecycler;
80
+ }
81
+ set hasRecycler(t) {
82
+ this.__banknote_purse.isRecycler = t;
83
+ }
84
+ get hasICT() {
85
+ return this.hasRecycler && this.__banknote_purse.recycler.ict;
86
+ }
87
+ set hasICT(t) {
88
+ this.__banknote_purse.recycler.ict = t;
89
+ }
90
+ set banknoteICT(t) {
91
+ if (![20, 50, 100, 200, 500].includes(t)) throw new Error(`Invalid banknote value: ${t}`);
92
+ t = [20, 50, 100, 200, 500].indexOf(t), this.__banknote_purse.recycler.banknote = t;
93
+ }
94
+ get banknoteICT() {
95
+ return [20, 50, 100, 200, 500][this.__banknote_purse.recycler.banknote];
96
+ }
97
+ get hasCoinPurse() {
98
+ return this.__coin_purse.available;
99
+ }
100
+ set hasCoinPurse(t) {
101
+ if (typeof t != "boolean")
102
+ throw new Error(`Invalid value: ${t}`);
103
+ this.__coin_purse.available = t;
104
+ }
105
+ set price(t) {
106
+ let e = parseFloat(t);
107
+ (isNaN(e) || e < 0) && (e = 0), this.__sale.price = e;
108
+ }
109
+ get price() {
110
+ return this.__sale.price;
111
+ }
112
+ get change() {
113
+ return this.__sale.price <= 0 || this.__money_session.inserted <= this.__sale.price ? 0 : this.__money_session.inserted - this.__sale.price;
114
+ }
115
+ softReload() {
116
+ super.softReload(), this.__sale.clear(), this.__money_session.clear();
117
+ }
118
+ serialBoardroidSumHex(t) {
119
+ let e = 0;
120
+ return t.forEach((n, i) => {
121
+ i !== 0 && i !== 11 && (e += parseInt(n, 16));
122
+ }), e.toString(16).toUpperCase();
123
+ }
124
+ serialMessage(t) {
125
+ let e = {
126
+ code: t,
127
+ name: null,
128
+ description: null,
129
+ request: null,
130
+ no_code: 0
131
+ };
132
+ const n = (5 + this.deviceNumber).toString(16).padStart(2, "0").toLowerCase();
133
+ switch (t[1]) {
134
+ case n:
135
+ e.request = "connect", e = a(this, s, O).call(this, e);
136
+ break;
137
+ case "a0":
138
+ e.request = "--automatic", e = a(this, s, z).call(this, t, e);
139
+ break;
140
+ case "b0":
141
+ e.request = "--automatic", e = a(this, s, W).call(this, t, e);
142
+ break;
143
+ case "d0":
144
+ e.request = "coin-purse:config", e = a(this, s, K).call(this, t[2], e);
145
+ break;
146
+ case "d1":
147
+ e.request = "banknote-purse:config", e.additional = { scrow: null }, e = a(this, s, V).call(this, t, e);
148
+ break;
149
+ case "d2":
150
+ e.request = "coin-purse:read-tubes", e = a(this, s, Y).call(this, t, e);
151
+ break;
152
+ case "d3":
153
+ e.request = "banknote-purse:read-recycler", e = a(this, s, G).call(this, t, e);
154
+ break;
155
+ case "d4":
156
+ e.request = "banknote-purse:banknote-scrow-status", e = a(this, s, J).call(this, t[2], e);
157
+ break;
158
+ case "d5":
159
+ e.request = "banknote-purse:dispense", e = a(this, s, X).call(this, t, e);
160
+ break;
161
+ case "d6":
162
+ e.request = "coin-purse:dispense", e = a(this, s, Z).call(this, t, e);
163
+ break;
164
+ case "d7":
165
+ e.request = "dispense", e = a(this, s, g).call(this, t[5], e);
166
+ break;
167
+ case "d8":
168
+ e.request = "--automatic", e = a(this, s, $).call(this, t[13], e);
169
+ break;
170
+ case "d9":
171
+ e.request = "status:temperature", e = a(this, s, ee).call(this, t, e);
172
+ break;
173
+ case "da":
174
+ e.request = "status:relay", e = a(this, s, te).call(this, t[2], e);
175
+ break;
176
+ case "db":
177
+ 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 });
178
+ break;
179
+ case "dc":
180
+ 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 });
181
+ break;
182
+ case "dd":
183
+ e.request = "card-reader", a(this, s, ne).call(this, t, e);
184
+ break;
185
+ default:
186
+ 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);
187
+ break;
188
+ }
189
+ this.dispatch("serial:message", e);
190
+ }
191
+ serialSetConnectionConstant(t = 1) {
192
+ let e = ["F1", "06", "00", "00", "00", "00", "00", "00", "00", "00", "F2", "F8"];
193
+ return e[1] = this.hexMaker(this.decToHex((5 + t).toString())), e[11] = this.serialBoardroidSumHex(e), this.add0x(e);
194
+ }
195
+ async coinPurseConfigure({ enable: t = !1, high: e = "FF", low: n = "FF" } = {}) {
196
+ if (!this.__coin_purse.available) throw new Error("Coin purse not available");
197
+ const r = ["F1", "C1", t ? "01" : "00", e, n, "00", "00", "00", "00", "00", "F2", "00"];
198
+ await a(this, s, p).call(this, r, "coin-purse:config");
199
+ }
200
+ async coinPurseEnable() {
201
+ await this.coinPurseConfigure({ enable: !0 });
202
+ }
203
+ async coinPurseDisable() {
204
+ await this.coinPurseConfigure({ enable: !1 });
205
+ }
206
+ async coinPurseDispense({ $_50c: t = 0, $_1: e = 0, $_2: n = 0, $_5: i = 0, $_10: r = 0 } = {}) {
207
+ if (!this.__coin_purse.available) throw new Error("Coin purse not available");
208
+ if ([t, e, n, i, r].some((o) => isNaN(o) || typeof o == "string"))
209
+ throw new Error("One of the values is not a number");
210
+ if (t < 1 && e < 1 && n < 1 && i < 1 && r < 1) throw new Error("No coins to dispense");
211
+ [t, e, n, i, r] = [
212
+ this.decToHex(t),
213
+ this.decToHex(e),
214
+ this.decToHex(n),
215
+ this.decToHex(i),
216
+ this.decToHex(r)
217
+ ];
218
+ let c = ["F1", "C6", t, e, n, i, r, "00", "00", "00", "F2", "00"];
219
+ await a(this, s, p).call(this, c, "coin-purse:dispense");
220
+ }
221
+ async coinPurseReadTubes() {
222
+ const t = ["F1", "C2", "00", "00", "00", "00", "00", "00", "00", "00", "F2", "00"];
223
+ await a(this, s, p).call(this, t, "coin-purse:read-tubes");
224
+ }
225
+ async banknotePurseConfigure({ enable: t = !1, scrow: e = !1 } = {}) {
226
+ if (!this.__banknote_purse.available) throw new Error("Banknote purse not available");
227
+ let n;
228
+ return a(this, s, x).call(this) ? n = a(this, s, se).call(this, { enable: t, scrow: e }) : n = a(this, s, ie).call(this, { enable: t, scrow: e }), await a(this, s, p).call(this, n, "banknote-purse:config");
229
+ }
230
+ async banknotePurseDispense({ $_20: t = 0, $_50: e = 0, $_100: n = 0, $_200: i = 0, $_500: r = 0, $_1000: c = 0 } = {}) {
231
+ if (!this.__banknote_purse.available) throw new Error("Banknote purse not available");
232
+ if (!this.__banknote_purse.isRecycler) throw new Error("Banknote purse is not recycler");
233
+ let o;
234
+ if (a(this, s, x).call(this)) {
235
+ const l = [t, e, n, i, r];
236
+ o = a(this, s, re).call(this, l[this.__banknote_purse.recycler.banknote]);
237
+ } else
238
+ o = a(this, s, ae).call(this, { $_20: t, $_50: e, $_100: n, $_200: i, $_500: r, $_1000: c });
239
+ await a(this, s, p).call(this, o, "banknote-purse:dispense");
240
+ }
241
+ async banknotePurseEnable({ scrow: t = !1 }) {
242
+ return await this.banknotePurseConfigure({ enable: !0, scrow: t });
243
+ }
244
+ async banknotePurseDisable() {
245
+ return await this.banknotePurseConfigure({ enable: !1 });
246
+ }
247
+ async banknotePurseAcceptInScrow() {
248
+ if (!this.__banknote_purse.available) throw new Error("Banknote purse not available");
249
+ const t = ["F1", "C4", "01", "00", "00", "00", "00", "00", "00", "00", "F2", "00"];
250
+ await a(this, s, p).call(this, t, "banknote-purse:banknote-scrow-status");
251
+ }
252
+ async banknotePurseRejectInScrow() {
253
+ if (!this.__banknote_purse.available) throw new Error("Banknote purse not available");
254
+ const t = ["F1", "C4", "00", "00", "00", "00", "00", "00", "00", "00", "F2", "00"];
255
+ await a(this, s, p).call(this, t, "banknote-purse:banknote-scrow-status");
256
+ }
257
+ async banknotePurseSaveMemory({
258
+ channel: t = null,
259
+ $_20: e = null,
260
+ $_50: n = null,
261
+ $_100: i = null,
262
+ $_200: r = null,
263
+ $_500: c = null,
264
+ $_1000: o = null
265
+ } = {}) {
266
+ if (!this.__banknote_purse.available) throw new Error("Banknote purse not available");
267
+ if (t === null || e === null || n === null || i === null || r === null || c === null || o === null)
268
+ throw new Error("One of the values is not defined");
269
+ const l = [
270
+ "F1",
271
+ "C8",
272
+ this.decToHex(t),
273
+ "00",
274
+ this.decToHex(e),
275
+ this.decToHex(n),
276
+ this.decToHex(i),
277
+ this.decToHex(r),
278
+ this.decToHex(c),
279
+ this.decToHex(o),
280
+ "F2",
281
+ "00"
282
+ ];
283
+ await a(this, s, p).call(this, l, "banknote-purse:save-memory");
284
+ }
285
+ async banknotePurseReadRecycler() {
286
+ if (!this.__banknote_purse.available) throw new Error("Banknote purse not available");
287
+ if (!this.__banknote_purse.isRecycler) throw new Error("Banknote purse is not recycler");
288
+ const t = ["F1", "C3", "00", "00", "00", "00", "00", "00", "00", "00", "F2", "B5"];
289
+ return await a(this, s, p).call(this, t, "banknote-purse:read-recycler");
290
+ }
291
+ async cardReaderDisable() {
292
+ if (!this.card_reader.available) throw new Error("Card reader not available");
293
+ const t = ["F1", "CD", "00", "00", "00", "00", "00", "00", "00", "00", "F2", "00"];
294
+ return await a(this, s, p).call(this, t, "card-reader:disable");
295
+ }
296
+ async cardReaderDispense({ channel: t = 1, second_channel: e = null, sensor: n = !0, seconds: i = null, price: r = 0 } = {}) {
297
+ if (!this.card_reader.available) throw new Error("Card reader not available");
298
+ if (isNaN(this.card_reader.max_pre_credit) || this.card_reader.max_pre_credit === 0)
299
+ throw new Error("Card reader pre-credit not configured");
300
+ if (isNaN(r) || r <= 0) throw new Error("Price must be greater than 0");
301
+ if (r > this.card_reader.max_pre_credit) throw new Error("Price is greater than pre-credit configured");
302
+ if (!n && (i === null || i <= 0 || i > 40))
303
+ throw new Error("Invalid time to dispense without sensor, must be between 0.1 and 40.0 seconds");
304
+ const c = this.decToHex(r / 256), o = this.decToHex(r % 256), l = this.decToHex(t + 9);
305
+ let h = "00";
306
+ e && (h = this.decToHex(e + 9));
307
+ let k = "00";
308
+ n || (k = this.decToHex(i * 10));
309
+ const le = ["F1", "CD", "01", l, h, k, c, o, "00", "00", "F2", "00"];
310
+ await a(this, s, p).call(this, le, "card-reader:dispense");
311
+ }
312
+ async paymentPursesDisable({ coin: t = !0, banknote: e = !0, cardReader: n = !1 } = {}) {
313
+ t && await this.coinPurseDisable(), e && await this.banknotePurseDisable(), n && await this.cardReaderDisable();
314
+ }
315
+ async paymentPursesEnable({ coin: t = !0, banknote: e = !0, scrowBanknote: n = !1 } = {}) {
316
+ t && await this.coinPurseEnable(), e && await this.banknotePurseEnable({ scrow: n });
317
+ }
318
+ async coolingRelayConfigure({ enable: t = !1 } = {}) {
319
+ const n = ["F1", "CC", t ? "01" : "00", "00", "00", "00", "00", "00", "00", "00", "F2", "00"];
320
+ return await a(this, s, p).call(this, n, "status:relay");
321
+ }
322
+ async coolingRelayEnable() {
323
+ return await this.coolingRelayConfigure({ enable: !0 });
324
+ }
325
+ async coolingRelayDisable() {
326
+ return await this.coolingRelayConfigure({ enable: !1 });
327
+ }
328
+ async readTemperature() {
329
+ const t = ["F1", "CB", "00", "00", "00", "00", "00", "00", "00", "00", "F2", "00"];
330
+ return await a(this, s, p).call(this, t, "status:temperature");
331
+ }
332
+ /**
333
+ * Dispense a product from the machine
334
+ * @param {number|string} selection
335
+ * @param {null|number|string} second_selection
336
+ * @param {boolean} sensor
337
+ * @param {null|number} seconds
338
+ * @param {boolean} retry
339
+ * @return {Promise<unknown>}
340
+ */
341
+ async dispense({ selection: t = 1, second_selection: e = null, sensor: n = !0, seconds: i = null, retry: r = !0 } = {}) {
342
+ if (t = parseInt(t), isNaN(t) || t < 1 || t > 80) throw new Error("Invalid channel number");
343
+ if (e !== null && (e < 1 || e > 80 || e === t))
344
+ throw new Error("Invalid second channel number");
345
+ if (!n && (i === null || i <= 0 || i > 40))
346
+ throw new Error("Invalid time to dispense without sensor, must be between 0.1 and 40.0 seconds");
347
+ r && (this.__internal__.dispense.backup_dispense = {
348
+ selection: t,
349
+ second_selection: e,
350
+ sensor: n,
351
+ seconds: i
352
+ }), t += 9;
353
+ const c = this.decToHex(t);
354
+ let o = "00";
355
+ e && (e += 9, o = this.decToHex(e));
356
+ let l = "00";
357
+ n || (l = this.decToHex(Math.round(i * 6.2)), this.__internal__.dispense.custom_limit_counter = i);
358
+ const h = a(this, s, T).call(this, [
359
+ "F1",
360
+ "C7",
361
+ c,
362
+ o,
363
+ l,
364
+ "00",
365
+ "00",
366
+ "00",
367
+ "00",
368
+ "00",
369
+ "F2",
370
+ "00"
371
+ ]);
372
+ let k = await this.internalDispense(h);
373
+ return !k.dispensed && r && (k = await this.internalDispense(h)), this.__internal__.dispense.custom_limit_counter = null, k;
374
+ }
375
+ async testEngines({ singleEngine: t = !1 } = {}) {
376
+ if (this.isDispensing) throw new Error("Another dispensing process is running");
377
+ if (v(this, w)) throw new Error("Another test is running");
378
+ a(this, s, B).call(this), _(this, w, !0);
379
+ const e = [];
380
+ a(this, s, I).call(this);
381
+ for (let n = 1; n <= 80; n++) {
382
+ const i = await this.dispense({
383
+ selection: n,
384
+ second_selection: t ? null : n + 1,
385
+ sensor: !1,
386
+ seconds: 0.4,
387
+ retry: !1
388
+ });
389
+ e.push(i), _(this, f, n), a(this, s, I).call(this), t || n++;
390
+ }
391
+ _(this, f, 80), a(this, s, I).call(this, { dispensed: e }), a(this, s, B).call(this);
392
+ }
393
+ async sendCustomCode({ code: t = [] } = {}) {
394
+ if (t.length === 0) throw new Error("Invalid code");
395
+ const e = a(this, s, T).call(this, t);
396
+ await this.appendToQueue(e, "custom");
397
+ }
398
+ hasToReturnChange(t = 0) {
399
+ let e = t;
400
+ return e <= 0 ? !0 : (e = a(this, s, S).call(this, e).pending, e = a(this, s, P).call(this, e).pending, !(e > 0));
401
+ }
402
+ async returnChange() {
403
+ return await a(this, s, E).call(this);
404
+ }
405
+ async returnInsertedMoney() {
406
+ return this.__money_session.inserted <= 0 ? !1 : await a(this, s, E).call(this, this.__money_session.inserted);
407
+ }
408
+ async serialCorruptMessage(t, e) {
409
+ this.dispatch("corrupt:message", { data: t, message: e });
410
+ }
411
+ }
412
+ w = new WeakMap(), f = new WeakMap(), y = new WeakMap(), s = new WeakSet(), M = function() {
413
+ const t = [
414
+ "banknote-purse:banknote-scrow-status",
415
+ "banknote-purse:config",
416
+ "banknote-purse:event-banknote",
417
+ "banknote-purse:read-memory",
418
+ "banknote-purse:recycler",
419
+ "banknote-purse:save-memory",
420
+ "card-reader:event",
421
+ "change:pending",
422
+ "change:dispense",
423
+ "coin-purse:coin-event",
424
+ "coin-purse:config",
425
+ "coin-purse:reject-lever",
426
+ "coin-purse:reset",
427
+ "coin-purse:tubes",
428
+ "percentage:test",
429
+ "run:default-load",
430
+ "session:money-dispensed",
431
+ "session:money-request",
432
+ "event:door",
433
+ "door:event",
434
+ "status:relay",
435
+ "status:temperature"
436
+ ];
437
+ for (const e of t)
438
+ this.serialRegisterAvailableListener(e);
439
+ }, H = function() {
440
+ D.add(this);
441
+ }, x = function() {
442
+ return this.__banknote_purse.isRecycler && this.__banknote_purse.recycler.ict;
443
+ }, N = function() {
444
+ return this.hasCoinPurse || this.hasRecycler;
445
+ }, O = function(t) {
446
+ return t.name = "Connection with the serial device completed.", t.description = "Your connection with the serial device was successfully completed.", t.no_code = 1, this.dispatch("run:default-load", {}), t;
447
+ }, U = function(t) {
448
+ const e = {
449
+ g50: ["40", "50", "60", "70", "90"],
450
+ c50: ["41", "51", "61", "71", "91"],
451
+ p1: ["42", "52", "62", "72", "92"],
452
+ p2: ["43", "53", "63", "73", "93"],
453
+ p5: ["44", "54", "64", "74", "94"],
454
+ p10: ["45", "55", "65", "75", "95"],
455
+ p20: ["47", "57", "67", "77", "97"]
456
+ };
457
+ let n = null;
458
+ for (let r in e)
459
+ if (e[r].includes(t)) {
460
+ n = r;
461
+ break;
462
+ }
463
+ return n ? [{
464
+ g50: "50 pennies (the big one)",
465
+ c0: "50 pennies (the little one)",
466
+ p1: "1 peso",
467
+ p2: "2 pesos",
468
+ p5: "5 pesos",
469
+ p10: "10 pesos",
470
+ p20: "20 pesos"
471
+ }[n], n] : [`Undefined value: ¿${t}?`, null];
472
+ }, j = function(t) {
473
+ return ["g50", "c50", "p1", "p2", "p5", "p10", "p20"].includes(t);
474
+ }, A = function(t) {
475
+ const e = {
476
+ p20: ["80", "90", "a0", "b0"],
477
+ p50: ["81", "91", "a1", "b1"],
478
+ p100: ["82", "92", "a2", "b2"],
479
+ p200: ["83", "93", "a3", "b3"],
480
+ p500: ["84", "94", "a4", "b4"],
481
+ p1000: ["85", "95", "a5", "b5"]
482
+ };
483
+ let n = null;
484
+ for (let r in e)
485
+ if (e[r].includes(t)) {
486
+ n = r;
487
+ break;
488
+ }
489
+ return n ? [{
490
+ p20: "20 pesos",
491
+ p50: "50 pesos",
492
+ p100: "100 pesos",
493
+ p200: "200 pesos",
494
+ p500: "500 pesos",
495
+ p1000: "1000 pesos"
496
+ }[n], n] : [`Undefined value: ¿${t}?`, null];
497
+ }, L = function(t) {
498
+ return ["p20", "p50", "p100", "p200", "p500", "p1000"].includes(t);
499
+ }, Q = function(t) {
500
+ return ["r20", "r50", "r100"].includes(t);
501
+ }, m = function() {
502
+ return ["r20", "r50", "r100", "r200", "r500"][this.__banknote_purse.recycler.banknote];
503
+ }, R = function(t, e, n) {
504
+ if (!t) return;
505
+ let i = !0;
506
+ if (a(this, s, j).call(this, t) && n === "coin") {
507
+ if (typeof this.coins.tubes[t] > "u") return;
508
+ e === "tube" ? this.coins.tubes[t] += 1 : e === "box" && (this.coins.box[t] += 1);
509
+ let r = 0;
510
+ ["g50", "c50"].includes(t) ? r = 0.5 : r += parseInt(t.slice(1)), this.coins.totals[t] += r, this.__money_session.inserted += r, this.coins.total += r;
511
+ } else if (a(this, s, L).call(this, t) && n === "banknote") {
512
+ if (typeof this.banknotes.recycler[t] > "u") return;
513
+ e === "recycler" ? this.banknotes.recycler[t] += 1 : e === "stacker" && (this.banknotes.stacker[t] += 1);
514
+ let r = parseInt(t.slice(1));
515
+ this.banknotes.totals[t] += r, this.__money_session.inserted += r, this.banknotes.total += r;
516
+ } else if (a(this, s, Q).call(this, t) && e === "out" && n === "banknote") {
517
+ if (typeof this.banknotes.out[t.replace("r", "p")] > "u") return;
518
+ this.banknotes.out[t.replace("r", "p")] += 1;
519
+ let r = parseInt(t.slice(1));
520
+ this.__money_session.retired += r, this.banknotes.recycler[t.replace("r", "p")] -= 1, this.banknotes.total -= r, i = !1, this.dispatch("session:money-dispensed", { type_money: t, retired: r, finish: !1, type: "banknotes" });
521
+ }
522
+ i && this.dispatch("session:money-request", {});
523
+ }, z = function(t, e) {
524
+ const n = parseInt(t[2], 16);
525
+ return e.name = "Coin Inserted", e.no_code = 2, e.additional = { where: null, coin: null }, n === 1 ? (e.name = "Lever pressed", e.description = "Reject lever", e.no_code = 100, this.dispatch("coin-purse:reject-lever", {})) : n === 2 ? (e.name = "Reset coin purse", e.description = "The configuration of coin purse was reset", e.no_code = 101, this.dispatch("coin-purse:reset", {})) : n >= 64 && n <= 79 ? (e.name = "Coin inserted in profit box", e.additional.where = "box") : n >= 80 && n <= 95 ? (e.name = "Coin inserted in tube", e.additional.where = "tube") : n >= 96 && n <= 111 ? (e.name = "Unused coin", e.description = "Something come from coin changer but in MDB Docs is unused", e.additional.where = "unused") : n >= 112 && n <= 127 ? (e.name = "Coin rejected", e.additional.where = "rejected") : n >= 144 && n <= 159 ? (e.name = "Coin dispensed", e.additional.where = "out", e.description = `Undefined value: ¿${t[2]}?`) : (e.name = "Coin inserted", e.description = "Undefined status. Without information of this", e.no_code = 400), n === 1 || n === 2 || n >= 160 || n >= 128 && n <= 143 || ([e.description, e.additional.coin] = a(this, s, U).call(this, t[2]), e.no_code = 38 + n, 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;
526
+ }, W = function(t, e) {
527
+ const n = parseInt(t[2], 16);
528
+ return e.name = "Banknote Inserted", e.no_code = 2, e.additional = { where: null, banknote: null }, n === 42 ? (e.name = "Banknote dispensed", e.description = "Banknote dispensed by request.", e.additional.banknote = a(this, s, m).call(this), e.additional.where = "out", e.no_code = 200) : n >= 128 && n <= 143 ? (e.name = "Banknote inserted", e.additional.where = "stacker") : n >= 144 && n <= 159 ? (e.name = "Banknote inserted in pre stacker", e.additional.where = "tmp") : n >= 160 && n <= 175 ? (e.name = "Banknote rejected", e.additional.where = "nothing") : n >= 176 && n <= 191 && (e.name = "Banknote inserted", e.additional.where = "recycler"), n >= 128 && n <= 191 && ([e.description, e.additional.banknote] = a(this, s, A).call(this, t[2]), e.no_code = 74 + n), a(this, s, R).call(this, e.additional.banknote, e.additional.where, "banknote"), this.dispatch("banknote-purse:event-banknote", this.banknotes), e;
529
+ }, K = function(t, e) {
530
+ const n = parseInt(t, 16);
531
+ return n === 1 ? (e.name = "Coin purse enabled", e.description = "Configuration complete, enabled", e.no_code = 3) : n === 0 ? (e.name = "Coin purse disabled", e.description = "Disabled by system request", e.no_code = 4) : (e.name = "Status unknown", e.description = "The response of coin purse doesn't identify successfully", e.no_code = 400), this.dispatch("coin-purse:config", { enabled: n === 1 }), e;
532
+ }, V = function(t, e) {
533
+ const n = parseInt(t[2], 16), i = parseInt(t[3], 16);
534
+ return n === 0 ? (e.name = "Bill purse disabled", e.description = "Configuration complete, disabled") : n === 1 && (e.name = "Bill purse enabled", e.description = "Configuration complete, enabled"), i === 0 ? e.additional.scrow = "Scrow disabled, banknote received automatic" : i === 1 && (e.additional.scrow = "Scrow enabled, require manual action"), e.no_code = 5, this.dispatch("banknote-purse:config", { enabled: n === 1, scrow: i === 1 }), e;
535
+ }, Y = function(t, e) {
536
+ e.no_code = 6;
537
+ const [n, i, r, c, o, l] = [
538
+ parseInt(t[2], 16),
539
+ parseInt(t[3], 16),
540
+ parseInt(t[4], 16),
541
+ parseInt(t[5], 16),
542
+ parseInt(t[6], 16),
543
+ parseInt(t[7], 16)
544
+ ];
545
+ return e.additional = {
546
+ coins: { g50: n, c50: i, p1: r, p2: c, p5: o, p10: l }
547
+ }, this.coins.tubes.g50 = n, this.coins.tubes.c50 = i, this.coins.tubes.p1 = r, this.coins.tubes.p2 = c, this.coins.tubes.p5 = o, this.coins.tubes.p10 = l, this.coins.totals.g50 = (this.coins.box.g50 + n) * 0.5, this.coins.totals.c50 = (this.coins.box.c50 + i) * 0.5, this.coins.totals.p1 = this.coins.box.p1 + r, this.coins.totals.p2 = (this.coins.box.p2 + c) * 2, this.coins.totals.p5 = (this.coins.box.p5 + o) * 5, this.coins.totals.p10 = (this.coins.box.p10 + l) * 10, this.coins.total = this.coins.totals.g50 + this.coins.totals.c50 + this.coins.totals.p1 + this.coins.totals.p2 + this.coins.totals.p5 + this.coins.totals.p10, e.name = "Read tubes", e.description = "Quantity of coins approximated", this.dispatch("coin-purse:tubes", this.coins.tubes), e;
548
+ }, G = function(t, e) {
549
+ e.no_code = 7;
550
+ const [n, i, r, c, o, l] = [
551
+ parseInt(t[2], 16),
552
+ parseInt(t[3], 16),
553
+ parseInt(t[4], 16),
554
+ parseInt(t[5], 16),
555
+ parseInt(t[6], 16),
556
+ parseInt(t[7], 16)
557
+ ];
558
+ return e.additional = {
559
+ banknotes: { b20: n, b50: i, b100: r, b200: c, b500: o, b1000: l }
560
+ }, this.banknotes.recycler.p20 = n, this.banknotes.recycler.p50 = i, this.banknotes.recycler.p100 = r, this.banknotes.recycler.p200 = c, this.banknotes.recycler.p500 = o, this.banknotes.recycler.p1000 = l, this.banknotes.totals.p20 = (this.banknotes.stacker.p20 + n) * 20, this.banknotes.totals.p50 = (this.banknotes.stacker.p50 + i) * 50, this.banknotes.totals.p100 = (this.banknotes.stacker.p100 + r) * 100, this.banknotes.totals.p200 = (this.banknotes.stacker.p200 + c) * 200, this.banknotes.totals.p500 = (this.banknotes.stacker.p500 + o) * 500, this.banknotes.totals.p1000 = (this.banknotes.stacker.p1000 + l) * 1e3, this.banknotes.total = this.banknotes.totals.p20 + this.banknotes.totals.p50 + this.banknotes.totals.p100 + this.banknotes.totals.p200 + this.banknotes.totals.p500 + this.banknotes.totals.p1000, e.name = "Read recycler", e.description = "Quantity of banknotes approximated", this.dispatch("banknote-purse:recycler", this.banknotes.recycler), e;
561
+ }, J = function(t, e) {
562
+ const n = parseInt(t, 16);
563
+ return n === 1 ? e.name = "Banknote accepted" : n === 0 ? e.name = "Banknote rejected" : e.name = "Unknown status banknote", e.no_code = 8, this.dispatch("banknote-purse:banknote-scrow-status", { status: n === 1 }), e;
564
+ }, X = function(t, e) {
565
+ const [n, i, r, c, o, l] = [
566
+ parseInt(t[2], 16),
567
+ parseInt(t[3], 16),
568
+ parseInt(t[4], 16),
569
+ parseInt(t[5], 16),
570
+ parseInt(t[6], 16),
571
+ parseInt(t[7], 16)
572
+ ], h = n * 20 + i * 50 + r * 100 + c * 200 + o * 500 + l * 1e3;
573
+ return e.name = "Banknotes dispensed", e.description = h > 0 ? "Banknotes dispensed by request" : "No banknotes dispensed, recycler empty", e.no_code = 9, e.additional = {
574
+ banknotes: { b20: n, b50: i, b100: r, b200: c, b500: o, b1000: l },
575
+ total_dispensed: h
576
+ }, this.dispatch("session:money-dispensed", {
577
+ type_money: null,
578
+ retired: null,
579
+ finish: !1,
580
+ type: "banknotes",
581
+ data: e
582
+ }), e;
583
+ }, Z = function(t, e) {
584
+ 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(
585
+ "session:money-dispensed",
586
+ {
587
+ type_money: null,
588
+ retired: null,
589
+ finish: !1,
590
+ type: "coins"
591
+ },
592
+ 500
593
+ ), e;
594
+ }, g = function(t, e) {
595
+ const n = parseInt(t, 16);
596
+ return n === 1 ? (e.name = "Product not delivered", e.description = "The product requested wasn't delivered", e.no_code = 11, this.__internal__.dispense.status = !1) : n === 0 ? (e.name = "Product delivered", e.description = "The product requested was delivered", e.no_code = 12, this.__internal__.dispense.status = !0) : (e.name = "Unknown status product", e.description = "The response of product doesn't identify successfully", e.no_code = 400, this.__internal__.dispense.status = !1), this.dispatch("dispensed", {}), e;
597
+ }, $ = function(t, e) {
598
+ let n = "closed";
599
+ return t === "db" ? (e.name = "Door closed", e.no_code = 13) : t === "dc" ? (e.name = "Door open", e.no_code = 14, n = "open") : (e.name = "Unknown status door", e.description = "The response of door doesn't identify successfully", e.no_code = 400, n = "unknown"), this.__internal__.device.door_open = n === "open", this.dispatch("event:door", { open: n === "open" }), this.dispatch("door:event", { open: n === "open" }), e;
600
+ }, ee = function(t, e) {
601
+ const n = parseInt(t[2], 16) * 255, i = parseInt(t[3], 16), r = (n + i) * 0.1;
602
+ return e.no_code = 15, e.name = "Temperature status", e.description = `Temperature: ${r}`, e.additional = {
603
+ high: n,
604
+ low: i,
605
+ temperature: parseFloat(r.toString())
606
+ }, this.dispatch("status:temperature", e.additional), e;
607
+ }, te = function(t, e) {
608
+ const n = parseInt(t, 16);
609
+ let i = "unknown";
610
+ return n === 1 ? (e.name = "Relay on", e.description = "Relay on", e.no_code = 16, i = "on") : n === 0 ? (e.name = "Relay off", e.description = "Relay off", e.no_code = 17, i = "off") : (e.name = "Status unknown", e.description = "Status unknown", e.no_code = 400), this.dispatch("status:relay", { enabled: i === "on" }), e;
611
+ }, ne = function(t, e) {
612
+ const n = parseInt(t[2], 16);
613
+ if (e.no_code = 20 + n, e.name = "Status unknown", e.description = "The status of card reader does not identified correctly", n === 0)
614
+ e.request += ":disable", e.name = "Card reader disabled", e.description = "Card reader device was disabled successfully";
615
+ else if (n === 1 || n === 2)
616
+ e.request += ":dispense", e.name = "Card reader enabled", e.description = "Card reader device is now enabled";
617
+ else if (n === 3)
618
+ e.request += ":pre-authorize", e.name = "Pre-authorized credit", e.description = "The pre credit was authorized successfully";
619
+ else if (n === 4)
620
+ e.request += ":cancel", e.name = "Cancellation in progress", e.description = "Cancellation request done successfully";
621
+ else if (n === 5)
622
+ e.request += ":sell", e.name = "Sell approved", e.description = "Sell approved, starting dispense product";
623
+ else if (n === 6)
624
+ e.request += ":sell", e.name = "Sell denied", e.description = "This sell was denied, try again";
625
+ else if (n === 7)
626
+ e.request += ":end", e.name = "Session ended", e.description = "The session ended";
627
+ else if (n === 8)
628
+ e.request += ":cancel", e.name = "Cancelled", e.description = "Cancellation complete";
629
+ else if (n === 10) {
630
+ const i = parseInt(t[8], 16);
631
+ 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);
632
+ } else
633
+ e.no_code = 400;
634
+ return this.dispatch("card-reader:event", e), e;
635
+ }, p = function(t, e) {
636
+ return this.appendToQueue(a(this, s, T).call(this, t), e);
637
+ }, T = function(t) {
638
+ return t[11] = this.serialBoardroidSumHex(t), t.map((e, n) => {
639
+ t[n] = this.hexMaker(e);
640
+ }), t;
641
+ }, se = function({ enable: t = !1, scrow: e = !1 } = {}) {
642
+ const n = t ? "FF" : "00", i = e ? "FF" : "00";
643
+ return ["F1", "C0", n, n, i, i, "00", "00", "00", "00", "F2", "00"];
644
+ }, ie = function({ enable: t = !1, scrow: e = !1 } = {}) {
645
+ return ["F1", "C0", t ? "01" : "00", e ? "01" : "00", "00", "00", "00", "00", "00", "00", "F2", "00"];
646
+ }, re = function(t = 1) {
647
+ if (t < 1) throw new Error("No banknotes to dispense");
648
+ return t = this.decToHex(t), ["F1", "C5", this.decToHex(this.__banknote_purse.recycler.banknote.toString()), t, "00", "00", "00", "00", "00", "00", "F2", "00"];
649
+ }, ae = function({ $_20: t = 0, $_50: e = 0, $_100: n = 0, $_200: i = 0, $_500: r = 0, $_1000: c = 0 } = {}) {
650
+ if ([t, e, n, i, r, c].some((o) => isNaN(o) || typeof o == "string"))
651
+ throw new Error("One of the values is not a number");
652
+ if (t < 1 && e < 1 && n < 1 && i < 1 && r < 1 && c < 1)
653
+ throw new Error("No banknotes to dispense");
654
+ return [t, e, n, i, r, c] = [
655
+ this.decToHex(t),
656
+ this.decToHex(e),
657
+ this.decToHex(n),
658
+ this.decToHex(i),
659
+ this.decToHex(r),
660
+ this.decToHex(c)
661
+ ], ["F1", "C5", t, e, n, i, r, c, "00", "00", "F2", "00"];
662
+ }, B = function() {
663
+ _(this, w, !1), _(this, f, 0), _(this, y, 0);
664
+ }, /**
665
+ *
666
+ * @param {null|object} dispensed
667
+ * @param {number} limit
668
+ */
669
+ I = function({ dispensed: t = null, limit: e = 80 } = {}) {
670
+ _(this, y, Math.round(v(this, f) * 100 / e)), this.dispatch("percentage:test", { percentage: v(this, y), dispensed: t });
671
+ }, oe = function(t) {
672
+ const e = ["20", "50", "100", "200", "500"], n = this.__banknote_purse.recycler.banknote, i = "$_" + e[n], r = parseInt(e[n]), c = this.banknotes.recycler[`p${e[n]}`], o = Math.min(Math.floor(t / r), c), l = {
673
+ banknotes: { $_20: 0, $_50: 0, $_100: 0, $_200: 0, $_500: 0, $_1000: 0 },
674
+ pending: t,
675
+ will_dispense: o > 0
676
+ };
677
+ return this.totalInRecycler === 0 || o < 1 || t === 0 || (l.banknotes[i] = o, l.pending = parseFloat((t - o * r).toFixed(2))), l;
678
+ }, ce = function(t) {
679
+ const e = {
680
+ banknotes: { $_20: 0, $_50: 0, $_100: 0, $_200: 0, $_500: 0, $_1000: 0 },
681
+ pending: t,
682
+ will_dispense: !1
683
+ };
684
+ if (this.totalInRecycler === 0 || t === 0) return e;
685
+ const n = (i, r) => {
686
+ if (this.banknotes.recycler[r] > 0) {
687
+ const c = Math.floor(e.pending / i), o = Math.min(c, this.banknotes.recycler[r]);
688
+ e.banknotes[`$_${i}`] = o, e.pending = parseFloat((e.pending - o * i).toFixed(2));
689
+ }
690
+ };
691
+ return n(1e3, "p1000"), n(500, "p500"), n(200, "p200"), n(100, "p100"), n(50, "p50"), n(20, "p20"), e.will_dispense = Object.values(e.banknotes).some((i) => i > 0), e;
692
+ }, S = function(t) {
693
+ return this.hasRecycler ? a(this, s, x).call(this) ? a(this, s, oe).call(this, t) : a(this, s, ce).call(this, t) : {
694
+ banknotes: { $_20: 0, $_50: 0, $_100: 0, $_200: 0, $_500: 0, $_1000: 0 },
695
+ pending: t,
696
+ will_dispense: !1
697
+ };
698
+ }, P = function(t) {
699
+ const e = {
700
+ coins: { $_50c: 0, $_1: 0, $_2: 0, $_5: 0, $_10: 0 },
701
+ pending: t,
702
+ will_dispense: !1
703
+ };
704
+ if (!this.hasCoinPurse || t <= 0 || this.totalInTubes === 0) return e;
705
+ const n = (i, r, c = null) => {
706
+ if (this.coins.tubes[r] > 0) {
707
+ c === null && (c = "$_" + i);
708
+ const o = Math.floor(e.pending / i), l = Math.min(o, this.coins.tubes[r]);
709
+ e.coins[c] = l, e.pending = parseFloat((e.pending - l * i).toFixed(2));
710
+ }
711
+ };
712
+ return n(10, "p10"), n(5, "p5"), n(2, "p2"), n(1, "p1"), n(0.5, "g50", "$_50c"), e.will_dispense = Object.values(e.coins).some((i) => i > 0), e;
713
+ }, E = async function(t = null) {
714
+ if (!a(this, s, N).call(this)) throw new Error("Change not available");
715
+ let e = this.change, n = this.change;
716
+ if (t !== null && (e = t, n = t), n <= 0) return !1;
717
+ const i = a(this, s, S).call(this, n);
718
+ n = i.pending;
719
+ const r = a(this, s, P).call(this, n);
720
+ return n = r.pending, n > 0 && this.dispatch("change:pending", { pending: n }), this.dispatch("change:dispense", {
721
+ recycler: i.banknotes,
722
+ coins: r.coins,
723
+ pending: n,
724
+ delivery: e - n
725
+ }), n === e ? !1 : (i.will_dispense && await this.banknotePurseDispense(i.banknotes), r.will_dispense && await this.coinPurseDispense(r.coins), !0);
726
+ };
727
+ export {
728
+ _e as Boardroid
729
+ };