From 114761abeb972da7e651d5d63791154a4f9e9c02 Mon Sep 17 00:00:00 2001 From: Noah Manneschmidt Date: Tue, 16 Apr 2024 16:08:46 -0700 Subject: [PATCH] convert more plain arrays to typed --- sdk/packet.ts | 4 ++-- sdk/smx.ts | 20 ++++++++++---------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/sdk/packet.ts b/sdk/packet.ts index bb8e113..8bc627f 100644 --- a/sdk/packet.ts +++ b/sdk/packet.ts @@ -24,7 +24,7 @@ export const HID_REPORT_INPUT_STATE = 0x03; export const HID_REPORT_OUTPUT = 0x05; export const HID_REPORT_INPUT = 0x06; -export async function send_data(dev: HIDDevice, data: Array, debug = false) { +export async function send_data(dev: HIDDevice, data: Uint8Array, debug = false) { // Split data into packets const packets = make_packets(data); @@ -37,7 +37,7 @@ export async function send_data(dev: HIDDevice, data: Array, debug = fal } } -export function make_packets(data: Array): Array { +export function make_packets(data: Uint8Array): Array { const packets = []; const data_len = data.length; let idx = 0; diff --git a/sdk/smx.ts b/sdk/smx.ts index 9314e72..962029d 100644 --- a/sdk/smx.ts +++ b/sdk/smx.ts @@ -22,9 +22,9 @@ class SMXEvents { /** read from this to see if we've received an ACK */ public readonly ackReports$: Bacon.EventStream; /** push to this to write commands to the stage */ - public readonly output$: Bacon.Bus; + public readonly output$: Bacon.Bus; /** this is everything pushed to `output$` but properly throttled/timed to the device's ack responses */ - public readonly eventsToSend$: Bacon.EventStream; + public readonly eventsToSend$: Bacon.EventStream; constructor(dev: HIDDevice) { // Main USB Ingestor @@ -56,7 +56,7 @@ class SMXEvents { const okSend$ = finishedCommand$.startWith(true); // Main USB Output - this.output$ = new Bacon.Bus>(); + this.output$ = new Bacon.Bus(); // Config writes should only happen at most once per second. const configOutput$ = this.output$ @@ -170,7 +170,7 @@ export class SMXStage { const command = info.firmware_version < 5 ? API_COMMAND.WRITE_CONFIG : API_COMMAND.WRITE_CONFIG_V5; const encoded_config = config.encode(); - this.events.output$.push([command, encoded_config.length, ...encoded_config]); + this.events.output$.push(new Uint8Array([command, encoded_config.length, ...encoded_config])); return this.events.ackReports$.firstToPromise(); } @@ -185,7 +185,7 @@ export class SMXStage { light_command.push(...rgb); } - this.events.output$.push(light_command); + this.events.output$.push(new Uint8Array(light_command)); return this.events.ackReports$.firstToPromise(); } @@ -204,17 +204,17 @@ export class SMXStage { this.setLightStrip(new RGB(color.r, color.g, color.b)); } - this.events.output$.push([API_COMMAND.FACTORY_RESET]); + this.events.output$.push(Uint8Array.of(API_COMMAND.FACTORY_RESET)); return this.events.ackReports$.firstToPromise(); } forceRecalibration(): Promise { - this.events.output$.push([API_COMMAND.FORCE_RECALIBRATION]); + this.events.output$.push(Uint8Array.of(API_COMMAND.FORCE_RECALIBRATION)); return this.events.ackReports$.firstToPromise(); } updateDeviceInfo(): Promise { - this.events.output$.push([API_COMMAND.GET_DEVICE_INFO]); + this.events.output$.push(Uint8Array.of(API_COMMAND.GET_DEVICE_INFO)); return this.deviceInfo$.firstToPromise(); } @@ -222,14 +222,14 @@ export class SMXStage { const info = await this.needsInfo(); const command = info.firmware_version < 5 ? API_COMMAND.GET_CONFIG : API_COMMAND.GET_CONFIG_V5; - this.events.output$.push([command]); + this.events.output$.push(Uint8Array.of(command)); return this.configResponse$.firstToPromise(); } updateTestData(mode: SensorTestMode | null = null): Promise { if (mode) this.test_mode = mode; - this.events.output$.push([API_COMMAND.GET_SENSOR_TEST_DATA, this.test_mode]); + this.events.output$.push(Uint8Array.of(API_COMMAND.GET_SENSOR_TEST_DATA, this.test_mode)); return this.testDataResponse$.firstToPromise(); }