Skip to content

Commit

Permalink
implement I2C commands
Browse files Browse the repository at this point in the history
  • Loading branch information
LandryNorris committed Aug 16, 2023
1 parent a38111d commit 230c40d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 32 deletions.
14 changes: 0 additions & 14 deletions packages/control-hub/src/internal/ControlHub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -502,20 +502,6 @@ export class ControlHubInternal implements ControlHub {
return await this.embedded.writeI2CMultipleBytes(i2cChannel, targetAddress, bytes);
}

async writeI2CReadMultipleBytes(
i2cChannel: number,
targetAddress: number,
numBytesToRead: number,
startAddress: number,
): Promise<void> {
return await this.embedded.writeI2CReadMultipleBytes(
i2cChannel,
targetAddress,
numBytesToRead,
startAddress,
);
}

async writeI2CSingleByte(
i2cChannel: number,
targetAddress: number,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -506,44 +506,51 @@ export class ControlHubConnectedExpansionHub implements ParentExpansionHub {
numBytesToRead: number,
register: number,
): Promise<number[]> {
throw new Error("not implemented");
return await this.sendCommand("readI2cRegister", {
hId: this.id,
a: targetAddress,
c: i2cChannel,
cb: numBytesToRead,
r: register,
});
}

readI2CMultipleBytes(
async readI2CMultipleBytes(
i2cChannel: number,
targetAddress: number,
numBytesToRead: number,
): Promise<number[]> {
throw new Error("not implemented");
return await this.sendCommand("readI2cData", {
hId: this.id,
a: targetAddress,
c: i2cChannel,
cb: numBytesToRead,
});
}

readI2CSingleByte(i2cChannel: number, targetAddress: number): Promise<number> {
throw new Error("not implemented");
async readI2CSingleByte(i2cChannel: number, targetAddress: number): Promise<number> {
return (await this.readI2CMultipleBytes(i2cChannel, targetAddress, 1))[0];
}

writeI2CMultipleBytes(
async writeI2CMultipleBytes(
i2cChannel: number,
targetAddress: number,
bytes: number[],
): Promise<void> {
throw new Error("not implemented");
}

writeI2CReadMultipleBytes(
i2cChannel: number,
targetAddress: number,
numBytesToRead: number,
startAddress: number,
): Promise<void> {
throw new Error("not implemented");
await this.sendCommand("writeI2cData", {
hId: this.id,
a: targetAddress,
c: i2cChannel,
d: bytes,
});
}

writeI2CSingleByte(
async writeI2CSingleByte(
i2cChannel: number,
targetAddress: number,
byte: number,
): Promise<void> {
throw new Error("not implemented");
await this.writeI2CMultipleBytes(i2cChannel, targetAddress, [byte]);
}

async readVersion(): Promise<Version> {
Expand Down

0 comments on commit 230c40d

Please sign in to comment.