Skip to content

Commit cf6d277

Browse files
committed
implement I2C commands
1 parent a38111d commit cf6d277

File tree

1 file changed

+25
-18
lines changed

1 file changed

+25
-18
lines changed

packages/control-hub/src/internal/ControlHubConnectedExpansionHub.ts

+25-18
Original file line numberDiff line numberDiff line change
@@ -506,44 +506,51 @@ export class ControlHubConnectedExpansionHub implements ParentExpansionHub {
506506
numBytesToRead: number,
507507
register: number,
508508
): Promise<number[]> {
509-
throw new Error("not implemented");
509+
return await this.sendCommand("readI2cRegister", {
510+
hId: this.id,
511+
a: targetAddress,
512+
c: i2cChannel,
513+
cb: numBytesToRead,
514+
r: register,
515+
});
510516
}
511517

512-
readI2CMultipleBytes(
518+
async readI2CMultipleBytes(
513519
i2cChannel: number,
514520
targetAddress: number,
515521
numBytesToRead: number,
516522
): Promise<number[]> {
517-
throw new Error("not implemented");
523+
return await this.sendCommand("readI2cData", {
524+
hId: this.id,
525+
a: targetAddress,
526+
c: i2cChannel,
527+
cb: numBytesToRead,
528+
});
518529
}
519530

520-
readI2CSingleByte(i2cChannel: number, targetAddress: number): Promise<number> {
521-
throw new Error("not implemented");
531+
async readI2CSingleByte(i2cChannel: number, targetAddress: number): Promise<number> {
532+
return (await this.readI2CMultipleBytes(i2cChannel, targetAddress, 1))[0];
522533
}
523534

524-
writeI2CMultipleBytes(
535+
async writeI2CMultipleBytes(
525536
i2cChannel: number,
526537
targetAddress: number,
527538
bytes: number[],
528539
): Promise<void> {
529-
throw new Error("not implemented");
530-
}
531-
532-
writeI2CReadMultipleBytes(
533-
i2cChannel: number,
534-
targetAddress: number,
535-
numBytesToRead: number,
536-
startAddress: number,
537-
): Promise<void> {
538-
throw new Error("not implemented");
540+
await this.sendCommand("writeI2cData", {
541+
hId: this.id,
542+
a: targetAddress,
543+
c: i2cChannel,
544+
d: bytes,
545+
});
539546
}
540547

541-
writeI2CSingleByte(
548+
async writeI2CSingleByte(
542549
i2cChannel: number,
543550
targetAddress: number,
544551
byte: number,
545552
): Promise<void> {
546-
throw new Error("not implemented");
553+
await this.writeI2CMultipleBytes(i2cChannel, targetAddress, [byte]);
547554
}
548555

549556
async readVersion(): Promise<Version> {

0 commit comments

Comments
 (0)