Skip to content

Commit

Permalink
use uint8array in most places
Browse files Browse the repository at this point in the history
  • Loading branch information
noahm committed Apr 16, 2024
1 parent feb0e7e commit 926b35b
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
8 changes: 4 additions & 4 deletions sdk/commands/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ export class SMXConfig {
/**
* Take in the data array and decode it into this.
*/
constructor(data: Array<number>, firmwareVersion: number) {
constructor(data: Uint8Array, firmwareVersion: number) {
this.firmwareVersion = firmwareVersion;
console.log("Config Firmware Version: ", this.firmwareVersion);
console.log("CONFIG RAW DATA: ", data.toString());
Expand All @@ -362,15 +362,15 @@ export class SMXConfig {
}
}

encode(): Array<number> {
encode(): Uint8Array {
if (this.firmwareVersion >= 5) {
return Array.from(new Uint8Array(smx_config_t.encode(this.config, true).buffer));
return new Uint8Array(smx_config_t.encode(this.config, true).buffer);
}

if (!this.oldConfig) throw new ReferenceError("Can not encode old config as it is null");
console.log("Writing Old Config");
this.convertNewToOld();
return Array.from(new Uint8Array(smx_old_config_t.encode(this.oldConfig, true).buffer));
return new Uint8Array(smx_old_config_t.encode(this.oldConfig, true).buffer);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions sdk/commands/data_info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ export class SMXDeviceInfo {
firmware_version = 0;
player = 0;

constructor(data: Array<number>) {
constructor(data: Uint8Array) {
console.log("DEVICEINFO RAW DATA: ", data.toString());
this.#decode(data);
}

#decode(data: Array<number>) {
#decode(data: Uint8Array) {
const info_packet = data_info_packet_t.decode(data, true);

this.player = Number.parseInt(String.fromCharCode(info_packet.player)) + 1;
Expand Down
2 changes: 1 addition & 1 deletion sdk/commands/sensor_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ export class SMXPanelTestData {
export class SMXSensorTestData {
panels: Array<SMXPanelTestData> = [];

constructor(data: Array<number>, mode: SensorTestMode, isFsr: boolean) {
constructor(data: Uint8Array, mode: SensorTestMode, isFsr: boolean) {
/**
* The first 3 bytes are the preamble.
*
Expand Down
8 changes: 4 additions & 4 deletions sdk/smx.ts
Original file line number Diff line number Diff line change
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].concat(encoded_config));
this.events.output$.push([command, encoded_config.length, ...encoded_config]);

return this.events.ackReports$.firstToPromise();
}
Expand Down Expand Up @@ -235,7 +235,7 @@ export class SMXStage {

private handleConfig(data: Uint8Array): SMXConfig {
// biome-ignore lint/style/noNonNullAssertion: info should very much be defined here
this._config = new SMXConfig(Array.from(data), this.info!.firmware_version);
this._config = new SMXConfig(data, this.info!.firmware_version);

// Right now I just want to confirm that decoding and encoding gives us back the same data
const encoded_config = this._config.encode();
Expand All @@ -250,15 +250,15 @@ export class SMXStage {

private handleTestData(data: Uint8Array): SMXSensorTestData {
// biome-ignore lint/style/noNonNullAssertion: config should very much be defined here
this.test = new SMXSensorTestData(Array.from(data), this.test_mode, this.config!.flags.PlatformFlags_FSR);
this.test = new SMXSensorTestData(data, this.test_mode, this.config!.flags.PlatformFlags_FSR);

this.debug && console.log("Got Test: ", this.test);

return this.test;
}

private handleDeviceInfo(data: Uint8Array): SMXDeviceInfo {
this.info = new SMXDeviceInfo(Array.from(data));
this.info = new SMXDeviceInfo(data);

this.debug && console.log("Got Info: ", this.info);

Expand Down

0 comments on commit 926b35b

Please sign in to comment.