node-toypad 2.0.0 → 3.0.0

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.
@@ -14,6 +14,7 @@ export declare class ToyPadConnection extends EventEmitter {
14
14
  private readonly handleDataBound;
15
15
  private readonly handleErrorBound;
16
16
  open(): Promise<void>;
17
+ send(command: ToyPadCommand): void;
17
18
  request(command: ToyPadCommand, timeoutMs?: number): Promise<Buffer>;
18
19
  close(): void;
19
20
  private handleData;
@@ -32,6 +32,15 @@ export class ToyPadConnection extends EventEmitter {
32
32
  hidDevice.on("error", this.handleErrorBound);
33
33
  this.writeRaw(WAKE_SEQUENCE);
34
34
  }
35
+ send(command) {
36
+ if (!this.device) {
37
+ throw new Error("ToyPad is not connected");
38
+ }
39
+ const requestId = this.nextRequestId();
40
+ const encoded = encodeCommand(command, requestId);
41
+ rawLog("tx %s", encoded.toString("hex"));
42
+ this.writeRaw(encoded);
43
+ }
35
44
  async request(command, timeoutMs = DEFAULT_REQUEST_TIMEOUT_MS) {
36
45
  if (!this.device) {
37
46
  throw new Error("ToyPad is not connected");
package/dist/toypad.d.ts CHANGED
@@ -49,10 +49,10 @@ export declare class ToyPad extends EventEmitter {
49
49
  private readonly activeTags;
50
50
  connect(): Promise<void>;
51
51
  disconnect(): void;
52
- setColor(panel: ToyPadPanel, color: number): Promise<void>;
52
+ setColor(panel: ToyPadPanel, color: number): void;
53
53
  getColor(panel: ToyPadPanel): Promise<number>;
54
- fade(panel: ToyPadPanel, speed: number, cycles: number, color: number): Promise<void>;
55
- flash(panel: ToyPadPanel, color: number, count: number, options?: FlashOptions): Promise<void>;
54
+ fade(panel: ToyPadPanel, speed: number, cycles: number, color: number): void;
55
+ flash(panel: ToyPadPanel, color: number, count: number, options?: FlashOptions): void;
56
56
  readTag(panel: ToyPadPanel, signature?: string): Promise<ToyPadTagInfo>;
57
57
  writeVehicle(panel: ToyPadPanel, vehicleId: VehicleId, options?: WriteVehicleOptions): Promise<void>;
58
58
  writeVehicleUpgrades(panel: ToyPadPanel, options: WriteVehicleUpgradesOptions): Promise<void>;
package/dist/toypad.js CHANGED
@@ -36,22 +36,22 @@ export class ToyPad extends EventEmitter {
36
36
  this.activeTags.clear();
37
37
  this.emit("disconnect");
38
38
  }
39
- async setColor(panel, color) {
39
+ setColor(panel, color) {
40
40
  const connection = this.ensureConnection();
41
- await connection.request(createSetColorCommand(panel, color));
41
+ connection.send(createSetColorCommand(panel, color));
42
42
  }
43
43
  async getColor(panel) {
44
44
  const connection = this.ensureConnection();
45
45
  const response = await connection.request(createGetColorCommand(panel));
46
46
  return decodeColor(response);
47
47
  }
48
- async fade(panel, speed, cycles, color) {
48
+ fade(panel, speed, cycles, color) {
49
49
  const connection = this.ensureConnection();
50
- await connection.request(createFadeCommand(panel, speed, cycles, color));
50
+ connection.send(createFadeCommand(panel, speed, cycles, color));
51
51
  }
52
- async flash(panel, color, count, options) {
52
+ flash(panel, color, count, options) {
53
53
  const connection = this.ensureConnection();
54
- await connection.request(createFlashCommand(panel, color, count, options));
54
+ connection.send(createFlashCommand(panel, color, count, options));
55
55
  }
56
56
  async readTag(panel, signature) {
57
57
  const tag = this.resolveActiveTag(panel, signature);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-toypad",
3
- "version": "2.0.0",
3
+ "version": "3.0.0",
4
4
  "description": "A JavaScript module to control the LEGO Dimensions ToyPad",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",