@danidoble/webserial 4.4.0-beta.1 → 4.4.0-beta.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.
Files changed (63) hide show
  1. package/dist/boardroid.cjs +1 -1
  2. package/dist/boardroid.js +106 -101
  3. package/dist/hopper.cjs +2 -2
  4. package/dist/hopper.js +66 -51
  5. package/dist/jofemar.cjs +1 -1
  6. package/dist/jofemar.js +62 -144
  7. package/dist/kernel-C1HLYiV1.cjs +1 -0
  8. package/dist/kernel-C8ISUhzV.cjs +1 -0
  9. package/dist/kernel-CQcZ_OiG.js +831 -0
  10. package/dist/{kernel-505KqpPU.js → kernel-DkC7Kj3m.js} +151 -125
  11. package/dist/kernel-DtXV8d8B.js +831 -0
  12. package/dist/kernel-DyNuXvtW.cjs +1 -0
  13. package/dist/kernel-aqBCxtkj.js +831 -0
  14. package/dist/kernel-pO_elWba.cjs +1 -0
  15. package/dist/kernel.cjs +2 -2
  16. package/dist/kernel.d.ts +14 -0
  17. package/dist/kernel.d.ts.map +1 -0
  18. package/dist/kernel.js +3 -4
  19. package/dist/locker.cjs +1 -1
  20. package/dist/locker.js +33 -26
  21. package/dist/main.d.ts +28 -0
  22. package/dist/main.d.ts.map +1 -0
  23. package/dist/pinpad.cjs +15 -20
  24. package/dist/pinpad.js +1405 -1259
  25. package/dist/pinpax.cjs +4 -4
  26. package/dist/pinpax.js +68 -68
  27. package/dist/{relay-CsdB0FSa.js → relay-DP8PLsDP.js} +2 -2
  28. package/dist/{relay-DGFymXOw.cjs → relay-E3NCcSjS.cjs} +1 -1
  29. package/dist/relay.cjs +1 -1
  30. package/dist/relay.js +11 -29
  31. package/dist/serial/boardroid.d.ts +206 -0
  32. package/dist/serial/boardroid.d.ts.map +1 -0
  33. package/dist/serial/hopper.d.ts +85 -0
  34. package/dist/serial/hopper.d.ts.map +1 -0
  35. package/dist/serial/jofemar.d.ts +218 -0
  36. package/dist/serial/jofemar.d.ts.map +1 -0
  37. package/dist/serial/kernel.d.ts +137 -0
  38. package/dist/serial/kernel.d.ts.map +1 -0
  39. package/dist/serial/locker.d.ts +33 -0
  40. package/dist/serial/locker.d.ts.map +1 -0
  41. package/dist/serial/pinpad.d.ts +263 -0
  42. package/dist/serial/pinpad.d.ts.map +1 -0
  43. package/dist/serial/pinpax.d.ts +60 -0
  44. package/dist/serial/pinpax.d.ts.map +1 -0
  45. package/dist/serial/relay.d.ts +13 -0
  46. package/dist/serial/relay.d.ts.map +1 -0
  47. package/dist/utils/devices.d.ts +26 -0
  48. package/dist/utils/devices.d.ts.map +1 -0
  49. package/dist/utils/dispatcher.d.ts +17 -0
  50. package/dist/utils/dispatcher.d.ts.map +1 -0
  51. package/dist/utils/emulator.d.ts +80 -0
  52. package/dist/utils/emulator.d.ts.map +1 -0
  53. package/dist/utils/utils.d.ts +7 -0
  54. package/dist/utils/utils.d.ts.map +1 -0
  55. package/dist/{webserial-core-C0ZbaNYy.js → webserial-core-CH2Xov2y.js} +943 -933
  56. package/dist/webserial-core-Cj_EZjAU.cjs +4 -0
  57. package/dist/webserial-core-D3luFguv.js +3325 -0
  58. package/dist/webserial-core-YjdXyVOx.cjs +4 -0
  59. package/dist/webserial.cjs +2 -2
  60. package/dist/webserial.js +19 -19
  61. package/package.json +17 -14
  62. package/dist/kernel-Dq3Fv1y8.cjs +0 -1
  63. package/dist/webserial-core-B7vfLzGH.cjs +0 -4
package/dist/boardroid.js CHANGED
@@ -1,7 +1,6 @@
1
- import { K as u } from "./kernel-505KqpPU.js";
2
- import { l } from "./relay-CsdB0FSa.js";
3
- import { a as p } from "./webserial-core-C0ZbaNYy.js";
4
- class f extends u {
1
+ import { K as u, D as p } from "./kernel-DtXV8d8B.js";
2
+ import { l } from "./relay-DP8PLsDP.js";
3
+ class _ extends u {
5
4
  __coin_purse = {
6
5
  available: !0
7
6
  };
@@ -51,7 +50,7 @@ class f extends u {
51
50
  #n = !1;
52
51
  #e = 0;
53
52
  #t = 0;
54
- constructor({ filters: n = null, config_port: e = null, no_device: t = 1, socket: s = !1 } = {}) {
53
+ constructor({ filters: n = null, config_port: e, no_device: t = 1, socket: s = !1 } = {}) {
55
54
  if (super({ filters: n, config_port: e, no_device: t, socket: s }), this.__internal__.device.type = "boardroid", p.getCustom(this.typeDevice, t))
56
55
  throw new Error(`Device ${this.typeDevice} ${t} already exists`);
57
56
  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 = {
@@ -59,7 +58,7 @@ class f extends u {
59
58
  second_channel: null,
60
59
  sensor: !0,
61
60
  seconds: null
62
- }, this.#p(), this.#u();
61
+ }, this.#p(), p.add(this);
63
62
  }
64
63
  #p() {
65
64
  const n = [
@@ -133,22 +132,19 @@ class f extends u {
133
132
  get change() {
134
133
  return this.__sale.price <= 0 || this.__money_session.inserted <= this.__sale.price ? 0 : this.__money_session.inserted - this.__sale.price;
135
134
  }
136
- #u() {
137
- p.add(this);
138
- }
139
135
  #s() {
140
136
  return this.__banknote_purse.isRecycler && this.__banknote_purse.recycler.ict;
141
137
  }
142
- #d() {
138
+ #u() {
143
139
  return this.hasCoinPurse || this.hasRecycler;
144
140
  }
145
141
  softReload() {
146
142
  super.softReload(), this.__sale.clear(), this.__money_session.clear();
147
143
  }
148
- #h(n) {
144
+ #d(n) {
149
145
  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;
150
146
  }
151
- #b(n) {
147
+ #h(n) {
152
148
  const e = {
153
149
  g50: { value: 0.5, name: "50 pennies (the big one)" },
154
150
  c0: { value: 0.5, name: "50 pennies (the little one)" },
@@ -160,7 +156,7 @@ class f extends u {
160
156
  };
161
157
  return e[n] ? e[n] : !1;
162
158
  }
163
- #_(n) {
159
+ #b(n) {
164
160
  const e = {
165
161
  g50: ["40", "50", "60", "70", "90"],
166
162
  c50: ["41", "51", "61", "71", "91"],
@@ -171,7 +167,7 @@ class f extends u {
171
167
  p20: ["47", "57", "67", "77", "97"]
172
168
  };
173
169
  let t = null;
174
- for (let i in e)
170
+ for (const i in e)
175
171
  if (e[i].includes(n)) {
176
172
  t = i;
177
173
  break;
@@ -186,10 +182,10 @@ class f extends u {
186
182
  p20: "20 pesos"
187
183
  }[t], t] : [`Undefined value: ¿${n}?`, null];
188
184
  }
189
- #f(n) {
185
+ #_(n) {
190
186
  return ["g50", "c50", "p1", "p2", "p5", "p10", "p20"].includes(n);
191
187
  }
192
- #k(n) {
188
+ #f(n) {
193
189
  const e = {
194
190
  p20: ["80", "90", "a0", "b0"],
195
191
  p50: ["81", "91", "a1", "b1"],
@@ -199,7 +195,7 @@ class f extends u {
199
195
  p1000: ["85", "95", "a5", "b5"]
200
196
  };
201
197
  let t = null;
202
- for (let i in e)
198
+ for (const i in e)
203
199
  if (e[i].includes(n)) {
204
200
  t = i;
205
201
  break;
@@ -213,7 +209,7 @@ class f extends u {
213
209
  p1000: "1000 pesos"
214
210
  }[t], t] : [`Undefined value: ¿${n}?`, null];
215
211
  }
216
- #y(n) {
212
+ #k(n) {
217
213
  const e = {
218
214
  p20: { value: 20, name: "20 pesos" },
219
215
  p50: { value: 50, name: "50 pesos" },
@@ -224,67 +220,68 @@ class f extends u {
224
220
  };
225
221
  return e[n] ? e[n] : !1;
226
222
  }
227
- #w(n) {
223
+ #y(n) {
228
224
  return ["p20", "p50", "p100", "p200", "p500", "p1000"].includes(n);
229
225
  }
230
- #v(n) {
226
+ #w(n) {
231
227
  return ["r20", "r50", "r100"].includes(n);
232
228
  }
233
- #C() {
229
+ #v() {
234
230
  return ["r20", "r50", "r100", "r200", "r500"][this.__banknote_purse.recycler.banknote];
235
231
  }
236
232
  #r(n, e, t) {
237
233
  if (!n) return;
238
234
  let s = !0;
239
- if (this.#f(n) && t === "coin") {
235
+ if (this.#_(n) && t === "coin") {
240
236
  if (typeof this.coins.tubes[n] > "u") return;
241
237
  e === "tube" ? this.coins.tubes[n] += 1 : e === "box" && (this.coins.box[n] += 1);
242
238
  let i = 0;
243
239
  ["g50", "c50"].includes(n) ? i = 0.5 : i += parseInt(n.slice(1)), this.coins.totals[n] += i, this.__money_session.inserted += i, this.coins.total += i;
244
- const r = this.#b(n);
240
+ const r = this.#h(n);
245
241
  r && this.dispatch("money:inserted", {
246
242
  type: "coin",
247
243
  money: r,
248
244
  // {value:number,name:string}
249
245
  where: e
250
246
  });
251
- } else if (this.#w(n) && t === "banknote") {
247
+ } else if (this.#y(n) && t === "banknote") {
252
248
  if (typeof this.banknotes.recycler[n] > "u") return;
253
249
  e === "recycler" ? this.banknotes.recycler[n] += 1 : e === "stacker" && (this.banknotes.stacker[n] += 1);
254
- let i = parseInt(n.slice(1));
250
+ const i = parseInt(n.slice(1));
255
251
  this.banknotes.totals[n] += i, this.__money_session.inserted += i, this.banknotes.total += i;
256
- const r = this.#y(n);
252
+ const r = this.#k(n);
257
253
  r && this.dispatch("money:inserted", {
258
254
  type: "banknote",
259
255
  money: r,
260
256
  // {value:number,name:string}
261
257
  where: e
262
258
  });
263
- } else if (this.#v(n) && e === "out" && t === "banknote") {
264
- if (typeof this.banknotes.out[n.replace("r", "p")] > "u") return;
259
+ } else if (this.#w(n) && e === "out" && t === "banknote") {
260
+ if (typeof this.banknotes.out[n.replace("r", "p")] > "u")
261
+ return;
265
262
  this.banknotes.out[n.replace("r", "p")] += 1;
266
- let i = parseInt(n.slice(1));
263
+ const i = parseInt(n.slice(1));
267
264
  this.__money_session.retired += i, this.banknotes.recycler[n.replace("r", "p")] -= 1, this.banknotes.total -= i, s = !1, this.dispatch("session:money-dispensed", { type_money: n, retired: i, finish: !1, type: "banknotes" });
268
265
  }
269
266
  s && this.dispatch("session:money-request", {});
270
267
  }
271
- #I(n, e) {
268
+ #C(n, e) {
272
269
  const t = parseInt(n[2], 16);
273
- 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] = this.#_(n[2]), e.no_code = 38 + t, this.#r(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;
270
+ 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] = this.#b(n[2]), e.no_code = 38 + t, this.#r(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;
274
271
  }
275
- #T(n, e) {
272
+ #I(n, e) {
276
273
  const t = parseInt(n[2], 16);
277
- 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 = this.#C(), 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] = this.#k(n[2]), e.no_code = 74 + t), this.#r(e.additional.banknote, e.additional.where, "banknote"), this.dispatch("banknote-purse:event-banknote", this.banknotes), e;
274
+ 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 = this.#v(), 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] = this.#f(n[2]), e.no_code = 74 + t), this.#r(e.additional.banknote, e.additional.where, "banknote"), this.dispatch("banknote-purse:event-banknote", this.banknotes), e;
278
275
  }
279
- #R(n, e) {
276
+ #T(n, e) {
280
277
  const t = parseInt(n, 16);
281
278
  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;
282
279
  }
283
- #P(n, e) {
280
+ #R(n, e) {
284
281
  const t = parseInt(n[2], 16), s = parseInt(n[3], 16);
285
282
  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"), s === 0 ? e.additional.scrow = "Scrow disabled, banknote received automatic" : s === 1 && (e.additional.scrow = "Scrow enabled, require manual action"), e.no_code = 5, this.dispatch("banknote-purse:config", { enabled: t === 1, scrow: s === 1 }), e;
286
283
  }
287
- #$(n, e) {
284
+ #P(n, e) {
288
285
  e.no_code = 6;
289
286
  const [t, s, i, r, a, o] = [
290
287
  parseInt(n[2], 16),
@@ -298,7 +295,7 @@ class f extends u {
298
295
  coins: { g50: t, c50: s, p1: i, p2: r, p5: a, p10: o }
299
296
  }, this.coins.tubes.g50 = t, this.coins.tubes.c50 = s, this.coins.tubes.p1 = i, this.coins.tubes.p2 = r, this.coins.tubes.p5 = a, this.coins.tubes.p10 = o, this.coins.totals.g50 = (this.coins.box.g50 + t) * 0.5, this.coins.totals.c50 = (this.coins.box.c50 + s) * 0.5, this.coins.totals.p1 = this.coins.box.p1 + i, this.coins.totals.p2 = (this.coins.box.p2 + r) * 2, this.coins.totals.p5 = (this.coins.box.p5 + a) * 5, this.coins.totals.p10 = (this.coins.box.p10 + o) * 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;
300
297
  }
301
- #B(n, e) {
298
+ #$(n, e) {
302
299
  e.no_code = 7;
303
300
  const [t, s, i, r, a, o] = [
304
301
  parseInt(n[2], 16),
@@ -312,11 +309,11 @@ class f extends u {
312
309
  banknotes: { b20: t, b50: s, b100: i, b200: r, b500: a, b1000: o }
313
310
  }, this.banknotes.recycler.p20 = t, this.banknotes.recycler.p50 = s, this.banknotes.recycler.p100 = i, this.banknotes.recycler.p200 = r, this.banknotes.recycler.p500 = a, this.banknotes.recycler.p1000 = o, this.banknotes.totals.p20 = (this.banknotes.stacker.p20 + t) * 20, this.banknotes.totals.p50 = (this.banknotes.stacker.p50 + s) * 50, this.banknotes.totals.p100 = (this.banknotes.stacker.p100 + i) * 100, this.banknotes.totals.p200 = (this.banknotes.stacker.p200 + r) * 200, this.banknotes.totals.p500 = (this.banknotes.stacker.p500 + a) * 500, this.banknotes.totals.p1000 = (this.banknotes.stacker.p1000 + o) * 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;
314
311
  }
315
- #q(n, e) {
312
+ #B(n, e) {
316
313
  const t = parseInt(n, 16);
317
314
  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;
318
315
  }
319
- #D(n, e) {
316
+ #q(n, e) {
320
317
  const [t, s, i, r, a, o] = [
321
318
  parseInt(n[2], 16),
322
319
  parseInt(n[3], 16),
@@ -336,27 +333,25 @@ class f extends u {
336
333
  data: e
337
334
  }), e;
338
335
  }
339
- #x(n, e) {
340
- 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(
341
- "session:money-dispensed",
342
- {
343
- type_money: null,
344
- retired: null,
345
- finish: !1,
346
- type: "coins"
347
- },
348
- 500
349
- ), e;
336
+ #D(n) {
337
+ n.name = "Coins dispensed", n.no_code = 10, n.description = "Coins dispensed by request", isNaN(this.__sale.last_change) && (this.__sale.last_change = 0), this.__money_session.retired += this.__sale.last_change;
338
+ const e = {
339
+ type_money: null,
340
+ retired: null,
341
+ finish: !1,
342
+ type: "coins"
343
+ };
344
+ return this.dispatchAsync("session:money-dispensed", e, 500), n;
350
345
  }
351
- #E(n, e) {
346
+ #x(n, e) {
352
347
  const t = parseInt(n, 16);
353
348
  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;
354
349
  }
355
- #M(n, e) {
350
+ #E(n, e) {
356
351
  let t = "closed";
357
352
  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;
358
353
  }
359
- #S(n, e) {
354
+ #M(n, e) {
360
355
  const t = parseInt(n[2], 16) * 255, s = parseInt(n[3], 16), i = (t + s) * 0.1;
361
356
  return e.no_code = 15, e.name = "Temperature status", e.description = `Temperature: ${i}`, e.additional = {
362
357
  high: t,
@@ -364,12 +359,12 @@ class f extends u {
364
359
  temperature: parseFloat(i.toString())
365
360
  }, this.dispatch("status:temperature", e.additional), e;
366
361
  }
367
- #m(n, e) {
362
+ #S(n, e) {
368
363
  const t = parseInt(n, 16);
369
364
  let s = "unknown";
370
365
  return t === 1 ? (e.name = "Relay on", e.description = "Relay on", e.no_code = 16, s = "on") : t === 0 ? (e.name = "Relay off", e.description = "Relay off", e.no_code = 17, s = "off") : (e.name = "Status unknown", e.description = "Status unknown", e.no_code = 400), this.dispatch("status:relay", { enabled: s === "on" }), e;
371
366
  }
372
- #Q(n, e) {
367
+ #m(n, e) {
373
368
  const t = parseInt(n[2], 16);
374
369
  if (e.no_code = 20 + t, e.name = "Status unknown", e.description = "The status of card reader does not identified correctly", t === 0)
375
370
  e.request += ":disable", e.name = "Card reader disabled", e.description = "Card reader device was disabled successfully";
@@ -395,6 +390,7 @@ class f extends u {
395
390
  return this.dispatch("card-reader:event", e), e;
396
391
  }
397
392
  serialMessage(n) {
393
+ n = this.fixHexArray(n);
398
394
  let e = {
399
395
  code: n,
400
396
  name: null,
@@ -405,46 +401,46 @@ class f extends u {
405
401
  const t = (5 + this.deviceNumber).toString(16).padStart(2, "0").toLowerCase();
406
402
  switch (n[1]) {
407
403
  case t:
408
- e.request = "connect", e = this.#h(e);
404
+ e.request = "connect", e = this.#d(e);
409
405
  break;
410
406
  case "a0":
411
- e.request = "--automatic", e = this.#I(n, e);
407
+ e.request = "--automatic", e = this.#C(n, e);
412
408
  break;
413
409
  case "b0":
414
- e.request = "--automatic", e = this.#T(n, e);
410
+ e.request = "--automatic", e = this.#I(n, e);
415
411
  break;
416
412
  case "d0":
417
- e.request = "coin-purse:config", e = this.#R(n[2], e);
413
+ e.request = "coin-purse:config", e = this.#T(n[2], e);
418
414
  break;
419
415
  case "d1":
420
- e.request = "banknote-purse:config", e.additional = { scrow: null }, e = this.#P(n, e);
416
+ e.request = "banknote-purse:config", e.additional = { scrow: null }, e = this.#R(n, e);
421
417
  break;
422
418
  case "d2":
423
- e.request = "coin-purse:read-tubes", e = this.#$(n, e);
419
+ e.request = "coin-purse:read-tubes", e = this.#P(n, e);
424
420
  break;
425
421
  case "d3":
426
- e.request = "banknote-purse:read-recycler", e = this.#B(n, e);
422
+ e.request = "banknote-purse:read-recycler", e = this.#$(n, e);
427
423
  break;
428
424
  case "d4":
429
- e.request = "banknote-purse:banknote-scrow-status", e = this.#q(n[2], e);
425
+ e.request = "banknote-purse:banknote-scrow-status", e = this.#B(n[2], e);
430
426
  break;
431
427
  case "d5":
432
- e.request = "banknote-purse:dispense", e = this.#D(n, e);
428
+ e.request = "banknote-purse:dispense", e = this.#q(n, e);
433
429
  break;
434
430
  case "d6":
435
- e.request = "coin-purse:dispense", e = this.#x(n, e);
431
+ e.request = "coin-purse:dispense", e = this.#D(e);
436
432
  break;
437
433
  case "d7":
438
- e.request = "dispense", e = this.#E(n[5], e);
434
+ e.request = "dispense", e = this.#x(n[5], e);
439
435
  break;
440
436
  case "d8":
441
- e.request = "--automatic", e = this.#M(n[13], e);
437
+ e.request = "--automatic", e = this.#E(n[13], e);
442
438
  break;
443
439
  case "d9":
444
- e.request = "status:temperature", e = this.#S(n, e);
440
+ e.request = "status:temperature", e = this.#M(n, e);
445
441
  break;
446
442
  case "da":
447
- e.request = "status:relay", e = this.#m(n[2], e);
443
+ e.request = "status:relay", e = this.#S(n[2], e);
448
444
  break;
449
445
  case "db":
450
446
  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 });
@@ -453,7 +449,7 @@ class f extends u {
453
449
  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 });
454
450
  break;
455
451
  case "dd":
456
- e.request = "card-reader", this.#Q(n, e);
452
+ e.request = "card-reader", this.#m(n, e);
457
453
  break;
458
454
  default:
459
455
  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);
@@ -464,9 +460,9 @@ class f extends u {
464
460
  serialSetConnectionConstant(n = 1) {
465
461
  return l.connection({ channel: n });
466
462
  }
467
- async coinPurseConfigure({ enable: n = !1, high: e = "FF", low: t = "FF" } = {}) {
463
+ async coinPurseConfigure({ enable: n = !1, high: e = 255, low: t = 255 } = {}) {
468
464
  if (!this.__coin_purse.available) throw new Error("Coin purse not available");
469
- return e = this.hexToDec(e), t = this.hexToDec(t), await this.appendToQueue(
465
+ return await this.appendToQueue(
470
466
  l.coinPurseConfiguration({ enable: n, high: e, low: t }),
471
467
  "coin-purse:config"
472
468
  );
@@ -493,23 +489,23 @@ class f extends u {
493
489
  async coinPurseReadTubes() {
494
490
  return await this.appendToQueue(l.coinPurseReadTubes(), "coin-purse:read-tubes");
495
491
  }
496
- #N({ enable: n = !1, scrow: e = !1 } = {}) {
492
+ #Q({ enable: n = !1, scrow: e = !1 } = {}) {
497
493
  return l.banknotePurseICTConfigure({ enable: n, scrow: e });
498
494
  }
499
- #F({ enable: n = !1, scrow: e = !1 } = {}) {
495
+ #N({ enable: n = !1, scrow: e = !1 } = {}) {
500
496
  return l.banknotePurseOtherConfigure({ enable: n, scrow: e });
501
497
  }
502
498
  async banknotePurseConfigure({ enable: n = !1, scrow: e = !1 } = {}) {
503
499
  if (!this.__banknote_purse.available) throw new Error("Banknote purse not available");
504
500
  let t;
505
- return this.#s() ? t = this.#N({ enable: n, scrow: e }) : t = this.#F({ enable: n, scrow: e }), await this.appendToQueue(t, "banknote-purse:config");
501
+ return this.#s() ? t = this.#Q({ enable: n, scrow: e }) : t = this.#N({ enable: n, scrow: e }), await this.appendToQueue(t, "banknote-purse:config");
506
502
  }
507
503
  #j(n = 1) {
508
504
  if (n < 1) throw new Error("No banknotes to dispense");
509
505
  const e = [20, 50, 100, 200, 500][this.__banknote_purse.recycler.banknote];
510
506
  return l.banknotePurseICTDispense({ quantity: n, denomination: e });
511
507
  }
512
- #O({ $_20: n = 0, $_50: e = 0, $_100: t = 0, $_200: s = 0, $_500: i = 0, $_1000: r = 0 } = {}) {
508
+ #A({ $_20: n = 0, $_50: e = 0, $_100: t = 0, $_200: s = 0, $_500: i = 0, $_1000: r = 0 } = {}) {
513
509
  return l.banknotePurseOtherDispense({
514
510
  $20: n,
515
511
  $50: e,
@@ -527,7 +523,7 @@ class f extends u {
527
523
  const o = [n, e, t, s, i];
528
524
  a = this.#j(o[this.__banknote_purse.recycler.banknote]);
529
525
  } else
530
- a = this.#O({ $_20: n, $_50: e, $_100: t, $_200: s, $_500: i, $_1000: r });
526
+ a = this.#A({ $_20: n, $_50: e, $_100: t, $_200: s, $_500: i, $_1000: r });
531
527
  await this.appendToQueue(a, "banknote-purse:dispense");
532
528
  }
533
529
  async banknotePurseEnable({ scrow: n = !1 }) {
@@ -617,17 +613,20 @@ class f extends u {
617
613
  async readTemperature() {
618
614
  return await this.appendToQueue(l.readTemperature(), "status:temperature");
619
615
  }
620
- /**
621
- * Dispense a product from the machine
622
- * @param {number|string} selection
623
- * @param {null|number|string} second_selection
624
- * @param {boolean} sensor
625
- * @param {null|number} seconds
626
- * @param {boolean} retry
627
- * @return {Promise<unknown>}
628
- */
629
- async dispense({ selection: n = 1, second_selection: e = null, sensor: t = !0, seconds: s = null, retry: i = !0 } = {}) {
630
- if (n = parseInt(n), isNaN(n) || n < 1 || n > 80) throw new Error("Invalid channel number");
616
+ async dispense({
617
+ selection: n = 1,
618
+ second_selection: e = null,
619
+ sensor: t = !0,
620
+ seconds: s = null,
621
+ retry: i = !0
622
+ } = {
623
+ selection: 1,
624
+ second_selection: null,
625
+ sensor: !0,
626
+ seconds: null,
627
+ retry: !0
628
+ }) {
629
+ if (n = parseInt(n, 10), isNaN(n) || n < 1 || n > 80) throw new Error("Invalid channel number");
631
630
  if (e !== null && (e < 1 || e > 80 || e === n))
632
631
  throw new Error("Invalid second channel number");
633
632
  if (!t && (s === null || s <= 0 || s > 40))
@@ -651,12 +650,10 @@ class f extends u {
651
650
  #a() {
652
651
  this.#n = !1, this.#e = 0, this.#t = 0;
653
652
  }
654
- /**
655
- *
656
- * @param {null|object} dispensed
657
- * @param {number} limit
658
- */
659
- #i({ dispensed: n = null, limit: e = 80 } = {}) {
653
+ #i({
654
+ dispensed: n = null,
655
+ limit: e = 80
656
+ } = {}) {
660
657
  this.#t = Math.round(this.#e * 100 / e), this.dispatch("percentage:test", { percentage: this.#t, dispensed: n });
661
658
  }
662
659
  async testEngines({ singleEngine: n = !1 } = {}) {
@@ -677,11 +674,15 @@ class f extends u {
677
674
  }
678
675
  this.#e = 80, this.#i({ dispensed: e }), this.#a();
679
676
  }
680
- async sendCustomCode({ code: n = [] } = {}) {
677
+ async sendCustomCode({
678
+ code: n = []
679
+ } = {
680
+ code: []
681
+ }) {
681
682
  if (n.length === 0) throw new Error("Invalid code");
682
683
  return await this.appendToQueue(l.customCode(n), "custom");
683
684
  }
684
- #U(n) {
685
+ #O(n) {
685
686
  const e = ["20", "50", "100", "200", "500"], t = this.__banknote_purse.recycler.banknote, s = "$_" + e[t], i = parseInt(e[t]), r = this.banknotes.recycler[`p${e[t]}`], a = Math.min(Math.floor(n / i), r), o = {
686
687
  banknotes: { $_20: 0, $_50: 0, $_100: 0, $_200: 0, $_500: 0, $_1000: 0 },
687
688
  pending: n,
@@ -689,7 +690,7 @@ class f extends u {
689
690
  };
690
691
  return this.totalInRecycler === 0 || a < 1 || n === 0 || (o.banknotes[s] = a, o.pending = parseFloat((n - a * i).toFixed(2))), o;
691
692
  }
692
- #A(n) {
693
+ #U(n) {
693
694
  const e = {
694
695
  banknotes: { $_20: 0, $_50: 0, $_100: 0, $_200: 0, $_500: 0, $_1000: 0 },
695
696
  pending: n,
@@ -698,14 +699,17 @@ class f extends u {
698
699
  if (this.totalInRecycler === 0 || n === 0) return e;
699
700
  const t = (s, i) => {
700
701
  if (this.banknotes.recycler[i] > 0) {
701
- const r = Math.floor(e.pending / s), a = Math.min(r, this.banknotes.recycler[i]);
702
+ const r = Math.floor(e.pending / s), a = Math.min(
703
+ r,
704
+ this.banknotes.recycler[i]
705
+ );
702
706
  e.banknotes[`$_${s}`] = a, e.pending = parseFloat((e.pending - a * s).toFixed(2));
703
707
  }
704
708
  };
705
709
  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((s) => s > 0), e;
706
710
  }
707
711
  #o(n) {
708
- return this.hasRecycler ? this.#s() ? this.#U(n) : this.#A(n) : {
712
+ return this.hasRecycler ? this.#s() ? this.#O(n) : this.#U(n) : {
709
713
  banknotes: { $_20: 0, $_50: 0, $_100: 0, $_200: 0, $_500: 0, $_1000: 0 },
710
714
  pending: n,
711
715
  will_dispense: !1
@@ -732,7 +736,7 @@ class f extends u {
732
736
  return e <= 0 ? !0 : (e = this.#o(e).pending, e = this.#l(e).pending, !(e > 0));
733
737
  }
734
738
  async #c(n = null) {
735
- if (!this.#d()) throw new Error("Change not available");
739
+ if (!this.#u()) throw new Error("Change not available");
736
740
  let e = this.change, t = this.change;
737
741
  if (n !== null && (e = n, t = n), t <= 0) return !1;
738
742
  const s = this.#o(t);
@@ -751,10 +755,11 @@ class f extends u {
751
755
  async returnInsertedMoney() {
752
756
  return this.__money_session.inserted <= 0 ? !1 : await this.#c(this.__money_session.inserted);
753
757
  }
758
+ // @ts-expect-error override function in Core
754
759
  async serialCorruptMessage(n, e) {
755
760
  this.dispatch("corrupt:message", { data: n, message: e });
756
761
  }
757
762
  }
758
763
  export {
759
- f as Boardroid
764
+ _ as Boardroid
760
765
  };
package/dist/hopper.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("./webserial-core-B7vfLzGH.cjs");class _ extends a.ut{__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};constructor({filters:e=null,config_port:t={baudRate:115200,dataBits:8,stopBits:1,parity:"none",bufferSize:32768,flowControl:"none"},no_device:n=1,socket:r=!1}={filters:null,config_port:{baudRate:115200,dataBits:8,stopBits:1,parity:"none",bufferSize:32768,flowControl:"none"},no_device:1,socket:!1}){if(super({filters:e,config_port:t,no_device:n,socket:r}),this.__internal__.device.type="hopper",a.a.getCustom(this.typeDevice,n))throw new Error(`Device ${this.typeDevice} ${n} 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
- `,a.a.add(this),this.#a()}#a(){const e=["levels","hopper:updated","dispense-change","balance:updated","validator:status","change:1x1"];for(const t of e)this.serialRegisterAvailableListener(t)}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 this.#r(e),this.__hoppers__.levels[e-1].capacity=t,this}setHopperName({hopper:e=null,name:t=""}={hopper:null,name:""}){if(this.#r(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(this.#r(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(this.#r(e),typeof t!="number"||t<=0)throw new RangeError("Currency must be a positive number");return this.__hoppers__.levels[e-1].currency=t,this}#n(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)}#i(e){if(this.lastAction==="status")e.name="STATUS",e.description="Hoppers status",e.no_code=1,this.__hoppers__.levels[0].amount=this.#t(e.code[9],e.code[10]),this.__hoppers__.levels[1].amount=this.#t(e.code[7],e.code[8]),this.__hoppers__.levels[2].amount=this.#t(e.code[5],e.code[6]),this.__hoppers__.levels[3].amount=this.#t(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=this.#t(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=this.#t(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=this.#t(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=this.#t(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=this.#t(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=this.#t(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)}serialMessage(e){const t=this.parseUint8ArrayToString(e),r={ascii:this.asciiToHex(t),code:e,name:"",description:"",request:this.lastAction,no_code:0,error:!1,data:null};if(e.length===3){this.#n(r);return}if(e.length!==13){const i=this.#p({array:e,chunkSize:13});for(const o of i){const s=this.parseUint8ArrayToString(new Uint8Array(o)),p=this.asciiToHex(s),c=this.stringToArrayHex(s);r.code=o,r.hex=c,r.ascii=p,o.length!==13?this.#n(r):this.#i(r)}return}this.#i(r)}#t(e,t){return(e<<8|t)<<16>>16}#r(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")}#o(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")}#s(e){this.#o(e);const t=e&65535,n=t>>8&255,r=t&255;return[n,r]}#p({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 n=[];for(let r=0;r<e.length;r+=t)n.push(e.slice(r,r+t));return n}#e(e){e.length<11&&(e=[...e,...Array(11-e.length).fill(0)]);const n=e.slice(1,11).reduce((r,i)=>{if(typeof i!="number")throw new TypeError("Array must contain only numbers");return r+i},0)&255;return e[11]=n,e[12]=15,e}serialSetConnectionConstant(){return[10,0,0,0,0,0,0,0,0,0,0,0,15]}async sendConnect(){const e=this.#e([10]);return await this.appendToQueue(e,"connect")}async requestStatus(){const e=this.#e([10,10,11,12]);return await this.appendToQueue(e,"status")}async readBalance(){const e=this.#e([10,192,1]);return await this.appendToQueue(e,"readBalance")}async clearBalance(){const e=this.#e([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}){this.#r(e),this.__hoppers__.current=e;const t=this.#e([10,e,e]);return await this.appendToQueue(t,"readHopper")}async writeHopper({hopper:e=null,quantity:t=0}={hopper:null,quantity:0}){this.#r(e),this.#o(t),this.__hoppers__.current=e;const[n,r]=this.#s(t),i=this.#e([10,240,e,0,0,0,0,0,0,n,r]);return await this.appendToQueue(i,"writeHopper")}async dispenseHopper({hopper:e=null}={hopper:null}){this.#r(e),this.__hoppers__.current=e;const t=this.#e([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,n=e>>8&255,r=this.#e([10,204,170,0,0,0,0,0,0,n,t]);return await this.appendToQueue(r,"dispenseChange")}async configValidator({enable:e=!1}={enable:!1}){if(typeof e!="boolean")throw new TypeError("Enable must be a boolean");const t=this.#e([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}){this.#r(e),this.__hoppers__.current=e;const t=this.#e([10,224,e]);return await this.appendToQueue(t,"change1x1Hopper-"+e)}async sendCustomCode({code:e=[]}={code:[]}){if(!Array.isArray(e)||!e.every(n=>typeof n=="number"&&n>=0&&n<=255))throw new TypeError("Code must be an array of numbers between 0 and 255");const t=this.#e(e);await this.appendToQueue(t,"custom")}}exports.Hopper=_;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("./webserial-core-YjdXyVOx.cjs");class d extends s.ut{__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};constructor({filters:e=null,config_port:t={baudRate:115200,dataBits:8,stopBits:1,parity:"none",bufferSize:32768,flowControl:"none"},no_device:r=1,socket:n=!1}={filters:null,config_port:{baudRate:115200,dataBits:8,stopBits:1,parity:"none",bufferSize:32768,flowControl:"none"},no_device:1,socket:!1}){if(super({filters:e,config_port:t,no_device:r,socket:n}),this.__internal__.device.type="hopper",s.a.getCustom(this.typeDevice,r))throw new Error(`Device ${this.typeDevice} ${r} 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
+ `,s.a.add(this),this.#s()}#s(){const e=["levels","hopper:updated","dispense-change","balance:updated","validator:status","change:1x1"];for(const t of e)this.serialRegisterAvailableListener(t)}get balance(){return this.__hoppers__.balance}get currentHopper(){return this.__hoppers__.current}get levels(){return this.__hoppers__.levels}setMaxCapacity({hopper:e=1,capacity:t=1e3}={hopper:1,capacity:1e3}){return this.#r(e),this.__hoppers__.levels[e-1].capacity=t,this}setHopperName({hopper:e=1,name:t=""}={hopper:1,name:""}){if(this.#r(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=1,key:t=""}={hopper:1,key:""}){if(this.#r(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=1,currency:t=1}={hopper:1,currency:1}){if(this.#r(e),typeof t!="number"||t<=0)throw new RangeError("Currency must be a positive number");return this.__hoppers__.levels[e-1].currency=t,this}#n(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)}#i(e){if(this.lastAction==="status")e.name="STATUS",e.description="Hoppers status",e.no_code=1,this.__hoppers__.levels[0].amount=this.#t(e.code[9],e.code[10]),this.__hoppers__.levels[1].amount=this.#t(e.code[7],e.code[8]),this.__hoppers__.levels[2].amount=this.#t(e.code[5],e.code[6]),this.__hoppers__.levels[3].amount=this.#t(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)-1;this.__hoppers__.levels[t].amount=this.#t(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)-1].amount=this.#t(e.code[9],e.code[10]),e.data=this.__hoppers__.levels,e.hopperId=this.__hoppers__.current;const t=(this.__hoppers__.current||1)-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)-1].amount=this.#t(e.code[9],e.code[10]),e.data=this.__hoppers__.levels,e.hopperId=this.__hoppers__.current;const t=(this.__hoppers__.current||0)-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=this.#t(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=this.#t(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=this.#t(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)}serialMessage(e){const t=e,r=this.parseUint8ArrayToString(t),i={ascii:this.asciiToHex(r),code:t,name:"",description:"",request:this.lastAction,no_code:0,error:!1,data:null};if(t.length===3){this.#n(i);return}const p=Array.from(t);if(t.length!==13){const c=this.#p({array:p,chunkSize:13});for(const o of c){const a=this.parseUint8ArrayToString(new Uint8Array(o)),h=this.asciiToHex(a),_=this.stringToArrayHex(a);i.code=o,i.hex=_,i.ascii=h,o.length!==13?this.#n(i):this.#i(i)}return}this.#i(i)}#t(e,t){return(e<<8|t)<<16>>16}#r(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")}#o(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(e){this.#o(e);const t=e&65535,r=t>>8&255,n=t&255;return[r,n]}#p({array:e,chunkSize:t=13}={array:[],chunkSize: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 r=[];for(let n=0;n<e.length;n+=t)r.push(e.slice(n,n+t));return r}#e(e){e.length<11&&(e=[...e,...Array(11-e.length).fill(0)]);const r=e.slice(1,11).reduce((n,i)=>{if(typeof i!="number")throw new TypeError("Array must contain only numbers");return n+i},0)&255;return e[11]=r,e[12]=15,e}serialSetConnectionConstant(){return[10,0,0,0,0,0,0,0,0,0,0,0,15]}async sendConnect(){const e=this.#e([10]);return await this.appendToQueue(e,"connect")}async requestStatus(){const e=this.#e([10,10,11,12]);return await this.appendToQueue(e,"status")}async readBalance(){const e=this.#e([10,192,1]);return await this.appendToQueue(e,"readBalance")}async clearBalance(){const e=this.#e([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=1}={hopper:1}){this.#r(e),this.__hoppers__.current=e;const t=this.#e([10,e,e]);return await this.appendToQueue(t,"readHopper")}async writeHopper({hopper:e=1,quantity:t=0}={hopper:1,quantity:0}){this.#r(e),this.#o(t),this.__hoppers__.current=e;const[r,n]=this.#a(t),i=this.#e([10,240,e,0,0,0,0,0,0,r,n]);return await this.appendToQueue(i,"writeHopper")}async dispenseHopper({hopper:e=1}={hopper:1}){this.#r(e),this.__hoppers__.current=e;const t=this.#e([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,r=e>>8&255,n=this.#e([10,204,170,0,0,0,0,0,0,r,t]);return await this.appendToQueue(n,"dispenseChange")}async configValidator({enable:e=!1}={enable:!1}){if(typeof e!="boolean")throw new TypeError("Enable must be a boolean");const t=this.#e([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=1}={hopper:1}){this.#r(e),this.__hoppers__.current=e;const t=this.#e([10,224,e]);return await this.appendToQueue(t,"change1x1Hopper-"+e)}async sendCustomCode({code:e=[]}={code:[]}){if(!Array.isArray(e)||!e.every(r=>typeof r=="number"&&r>=0&&r<=255))throw new TypeError("Code must be an array of numbers between 0 and 255");const t=this.#e(e);await this.appendToQueue(t,"custom")}}exports.Hopper=d;