Skip to content

Add code samples for button and switch #4927

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions components/button/button.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@ func Named(name string) resource.Name {
}

// A Button represents a physical button.
// For more information, see the [Push component docs].
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// For more information, see the [Push component docs].
// For more information, see the [Button component docs].

//
// Push example:
//
// myButton, err := switch.FromRobot(machine, "my_button")
//
// err := myButton.Push(context.Background(), nil)
//
// For more information, see the [Push method docs].
//
// [Button component docs]: https://docs.viam.com/dev/reference/apis/components/button/
// [Push method docs]: https://docs.viam.com/dev/reference/apis/components/button/#push
type Button interface {
resource.Resource

Expand Down
30 changes: 30 additions & 0 deletions components/switch/switch.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,36 @@ func Named(name string) resource.Name {
}

// A Switch represents a physical multi-position switch.
// For more information, see the [Switch component docs].
//
// SetPosition example:
//
// mySwitch, err := switch.FromRobot(machine, "my_switch")
//
// err := mySwitch.SetPosition(context.Background(), 0 , nil)
//
// For more information, see the [SetPosition method docs].
//
// GetPosition example:
//
// mySwitch, err := switch.FromRobot(machine, "my_switch")
//
// position, err := mySwitch.GetPosition(context.Background(), nil)
//
// For more information, see the [GetPosition method docs].
//
// GetNumberOfPositions example:
//
// mySwitch, err := switch.FromRobot(machine, "my_switch")
//
// positions, err := mySwitch.GetNumberOfPositions(context.Background(), nil)
//
// For more information, see the [GetNumberOfPositions method docs].
//
// [Switch component docs]: https://docs.viam.com/dev/reference/apis/components/switch/
// [SetPosition method docs]: https://docs.viam.com/dev/reference/apis/components/switch/#setposition
// [GetPosition method docs]: https://docs.viam.com/dev/reference/apis/components/switch/#getposition
// [GetNumberOfPositions method docs]: https://docs.viam.com/dev/reference/apis/components/switch/#getnumberofpositions
type Switch interface {
resource.Resource

Expand Down
Loading