|
| 1 | +import '../../gen/common/v1/common.pb.dart'; |
| 2 | +import '../../resource/base.dart'; |
| 3 | +import '../../robot/client.dart'; |
| 4 | + |
| 5 | +/// {@category Components} |
| 6 | +/// Switch represents a set of finite positions. |
| 7 | +/// |
| 8 | +/// For more information, see [Switch component](https://docs.viam.com/dev/reference/apis/components/switch/). |
| 9 | +abstract class Switch extends Resource { |
| 10 | + static const Subtype subtype = Subtype(resourceNamespaceRDK, resourceTypeComponent, 'switch'); |
| 11 | + |
| 12 | + /// Update the [Switch] to the provided position. |
| 13 | + /// |
| 14 | + /// ``` |
| 15 | + /// await mySwitch.setPosition(2); |
| 16 | + /// ``` |
| 17 | + /// |
| 18 | + /// For more information, see [Switch component](https://docs.viam.com/dev/reference/apis/components/servo/#setposition). |
| 19 | + Future<void> setPosition(int position, {Map<String, dynamic>? extra}); |
| 20 | + |
| 21 | + /// Get the current position (int) of the [Switch]. |
| 22 | + /// |
| 23 | + /// ``` |
| 24 | + /// var position = await mySwitch.getPosition(); |
| 25 | + /// ``` |
| 26 | + /// |
| 27 | + /// For more information, see [Switch component](https://docs.viam.com/dev/reference/apis/components/switch/#position). |
| 28 | + Future<int> getPosition({Map<String, dynamic>? extra}); |
| 29 | + |
| 30 | + /// Get the number of available positions (int) of the [Switch]. |
| 31 | + /// |
| 32 | + /// ``` |
| 33 | + /// await myServo.getNumberOfPositions(); |
| 34 | + /// ``` |
| 35 | + /// |
| 36 | + /// For more information, see [Switch component](https://docs.viam.com/dev/reference/apis/components/servo/#getnumberofpositions). |
| 37 | + Future<int> getNumberOfPositions({Map<String, dynamic>? extra}); |
| 38 | + |
| 39 | + /// Get the [ResourceName] for this [Switch] with the given [name]. |
| 40 | + /// |
| 41 | + /// ``` |
| 42 | + /// // Example: |
| 43 | + /// var name = Switch.getResourceName('my_switch'); |
| 44 | + /// ``` |
| 45 | + /// |
| 46 | + /// For more information, see [Switch component](https://docs.viam.com/dev/reference/apis/components/switch/#getresourcename). |
| 47 | + static ResourceName getResourceName(String name) { |
| 48 | + return Switch.subtype.getResourceName(name); |
| 49 | + } |
| 50 | + |
| 51 | + /// Get the [Switch] named [name] from the provided robot. |
| 52 | + /// |
| 53 | + /// ``` |
| 54 | + /// final mySwitch = Switch.fromRobot(myRobotClient, "my_switch"); |
| 55 | + /// ``` |
| 56 | + /// |
| 57 | + /// For more information, see [Switch component](https://docs.viam.com/dev/reference/apis/components/switch/). |
| 58 | + static Switch fromRobot(RobotClient robot, String name) { |
| 59 | + return robot.getResource(Switch.getResourceName(name)); |
| 60 | + } |
| 61 | +} |
0 commit comments