Skip to content

Commit

Permalink
RSDK-5029 Add writeAnalog to TS SDK (#175)
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviamiller authored Oct 11, 2023
1 parent e05927f commit 46c03eb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/components/board/board.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export interface Board extends Resource {
* Set the PWM frequency of the given pin of a board.
*
* @param pin - The pin.
* @param frequencyHz - The PWN frequency, in hertz. 0 will use the board's
* @param frequencyHz - The PWM frequency, in hertz. 0 will use the board's
* default PWM frequency.
*/
setPWMFrequency(
Expand All @@ -72,6 +72,13 @@ export interface Board extends Resource {
* @param analogReader - The name of the analog reader.
*/
readAnalogReader(analogReader: string, extra?: StructType): Promise<number>;
/**
* Write an analog value to a pin on the board.
*
* @param pin - The pin name.
* @param value - An integer value to write.
*/
writeAnalog(pin: string, value: number, extra?: StructType): Promise<void>;
/**
* Return the current value of the interrupt which is based on the type of
* interrupt.
Expand Down
16 changes: 16 additions & 0 deletions src/components/board/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,22 @@ export class BoardClient implements Board {
return response.getValue();
}

async writeAnalog(pin: string, value: number, extra = {}) {
const { boardService } = this;
const request = new pb.WriteAnalogRequest();
request.setName(this.name);
request.setPin(pin);
request.setValue(value);
request.setExtra(Struct.fromJavaScript(extra));

this.options.requestLogger?.(request);

await promisify<pb.WriteAnalogRequest, pb.WriteAnalogResponse>(
boardService.writeAnalog.bind(boardService),
request
);
}

async getDigitalInterruptValue(digitalInteruptName: string, extra = {}) {
const { boardService } = this;
const request = new pb.GetDigitalInterruptValueRequest();
Expand Down

0 comments on commit 46c03eb

Please sign in to comment.