Skip to content

Commit

Permalink
convert more plain arrays to typed
Browse files Browse the repository at this point in the history
  • Loading branch information
noahm committed Apr 16, 2024
1 parent db66d0d commit 114761a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions sdk/packet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<number>, debug = false) {
export async function send_data(dev: HIDDevice, data: Uint8Array, debug = false) {
// Split data into packets
const packets = make_packets(data);

Expand All @@ -37,7 +37,7 @@ export async function send_data(dev: HIDDevice, data: Array<number>, debug = fal
}
}

export function make_packets(data: Array<number>): Array<Uint8Array> {
export function make_packets(data: Uint8Array): Array<Uint8Array> {
const packets = [];
const data_len = data.length;
let idx = 0;
Expand Down
20 changes: 10 additions & 10 deletions sdk/smx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ class SMXEvents {
/** read from this to see if we've received an ACK */
public readonly ackReports$: Bacon.EventStream<AckPacket>;
/** push to this to write commands to the stage */
public readonly output$: Bacon.Bus<number[]>;
public readonly output$: Bacon.Bus<Uint8Array>;
/** this is everything pushed to `output$` but properly throttled/timed to the device's ack responses */
public readonly eventsToSend$: Bacon.EventStream<number[]>;
public readonly eventsToSend$: Bacon.EventStream<Uint8Array>;

constructor(dev: HIDDevice) {
// Main USB Ingestor
Expand Down Expand Up @@ -56,7 +56,7 @@ class SMXEvents {
const okSend$ = finishedCommand$.startWith(true);

// Main USB Output
this.output$ = new Bacon.Bus<Array<number>>();
this.output$ = new Bacon.Bus<Uint8Array>();

// Config writes should only happen at most once per second.
const configOutput$ = this.output$
Expand Down Expand Up @@ -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();
}
Expand All @@ -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();
}

Expand All @@ -204,32 +204,32 @@ 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<AckPacket> {
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<SMXDeviceInfo> {
this.events.output$.push([API_COMMAND.GET_DEVICE_INFO]);
this.events.output$.push(Uint8Array.of(API_COMMAND.GET_DEVICE_INFO));
return this.deviceInfo$.firstToPromise();
}

async updateConfig(): Promise<SMXConfig> {
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<SMXSensorTestData> {
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();
}

Expand Down

0 comments on commit 114761a

Please sign in to comment.