Skip to content
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

APP-7497: Add Button and Switch APIs #619

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
41 changes: 30 additions & 11 deletions proto/viam/component/switch/v1/switch.proto
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,23 @@ import "google/protobuf/struct.proto";
option go_package = "go.viam.com/api/component/switch/v1";
option java_package = "com.viam.component.switch.v1";

// A SwitchService services switches associated with a machine
// A SwitchService services switches associated with a machine.
// Switches can have multiple discrete positions - e.g. a simple
// switch has 2 positions, but a knob could have 10 positions.
service SwitchService {
stevebriskin marked this conversation as resolved.
Show resolved Hide resolved
// Turns on the switch
rpc On(OnRequest) returns (OnResponse) {
option (google.api.http) = {put: "/viam/api/v1/component/switch/{name}/on"};
// Set the position of the switch
rpc SetPosition(SetPositionRequest) returns (SetPositionResponse) {
option (google.api.http) = {put: "/viam/api/v1/component/switch/{name}/set_position"};
}

// Turns off the switch
rpc Off(OffRequest) returns (OffResponse) {
option (google.api.http) = {put: "/viam/api/v1/component/switch/{name}/off"};
// Get the position of the switch
rpc GetPosition(GetPositionRequest) returns (GetPositionResponse) {
option (google.api.http) = {put: "/viam/api/v1/component/switch/{name}/get_position"};
}

// Get the number of positions that the switch supports
rpc GetNumberOfPositions(GetNumberOfPositionsRequest) returns (GetNumberOfPositionsResponse) {
option (google.api.http) = {put: "/viam/api/v1/component/switch/{name}/get_number_of_positions"};
}

stevebriskin marked this conversation as resolved.
Show resolved Hide resolved
// DoCommand sends/receives arbitrary commands
Expand All @@ -27,17 +34,29 @@ service SwitchService {
}
}

message OnRequest {
message SetPositionRequest {
string name = 1;
uint32 position = 2;
Copy link
Member

Choose a reason for hiding this comment

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

hmm, do we want to allow negatives too?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't see a reason to - position should just be a non-negative index representing the possible positions. The only case I can think of is if we wanted a negative position to be an error state, but I don't see that being useful. In error cases, the handlers should return errors.

Copy link
Member

Choose a reason for hiding this comment

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

I'm thinking of the most common toggle switch to me - the power drill direction - where that switch makes sense to me as a -1, 0, 1 switch. But meh 🤷🏼‍♀️

google.protobuf.Struct extra = 99;
}

message OnResponse {}
message SetPositionResponse {}

message OffRequest {
message GetPositionRequest {
string name = 1;
google.protobuf.Struct extra = 99;
}

message OffResponse {}
message GetPositionResponse {
uint32 position = 1;
}

message GetNumberOfPositionsRequest {
string name = 1;
google.protobuf.Struct extra = 99;
}

message GetNumberOfPositionsResponse {
uint32 number_of_positions = 1;
}