|
| 1 | +/// @file components/switch.hpp |
| 2 | +/// |
| 3 | +/// @brief Defines a `Switch` component |
| 4 | +#pragma once |
| 5 | + |
| 6 | +#include <cstdint> |
| 7 | + |
| 8 | +#include <string> |
| 9 | + |
| 10 | +#include <viam/sdk/common/proto_value.hpp> |
| 11 | +#include <viam/sdk/components/component.hpp> |
| 12 | +#include <viam/sdk/resource/resource_api.hpp> |
| 13 | + |
| 14 | +namespace viam { |
| 15 | +namespace sdk { |
| 16 | + |
| 17 | +/// @defgroup Switch Classes related to the Switch component. |
| 18 | + |
| 19 | +/// @class Switch switch.hpp "components/switch.hpp" |
| 20 | +/// @brief A `Switch` represents a physical switch with multiple positions. |
| 21 | +/// @ingroup Switch |
| 22 | +/// |
| 23 | +/// This acts as an abstract parent class to be inherited from by any drivers representing |
| 24 | +/// specific switch implementations. This class cannot be used on its own. |
| 25 | +class Switch : public Component { |
| 26 | + public: |
| 27 | + /// @brief Set the position of the switch. |
| 28 | + /// @param position The position to set the switch to. |
| 29 | + inline void set_position(uint32_t position) { |
| 30 | + set_position(position, {}); |
| 31 | + } |
| 32 | + |
| 33 | + /// @brief Set the position of the switch. |
| 34 | + /// @param position The position to set the switch to. |
| 35 | + /// @param extra Any additional arguments to the method. |
| 36 | + virtual void set_position(uint32_t position, const ProtoStruct& extra) = 0; |
| 37 | + |
| 38 | + /// @brief Get the current position of the switch. |
| 39 | + /// @return The current position of the switch. |
| 40 | + inline uint32_t get_position() { |
| 41 | + return get_position({}); |
| 42 | + } |
| 43 | + |
| 44 | + /// @brief Get the current position of the switch. |
| 45 | + /// @param extra Any additional arguments to the method. |
| 46 | + /// @return The current position of the switch. |
| 47 | + virtual uint32_t get_position(const ProtoStruct& extra) = 0; |
| 48 | + |
| 49 | + /// @brief Get the number of positions that the switch supports. |
| 50 | + /// @return The number of positions that the switch supports. |
| 51 | + inline uint32_t get_number_of_positions() { |
| 52 | + return get_number_of_positions({}); |
| 53 | + } |
| 54 | + |
| 55 | + /// @brief Get the number of positions that the switch supports. |
| 56 | + /// @param extra Any additional arguments to the method. |
| 57 | + /// @return The number of positions that the switch supports. |
| 58 | + virtual uint32_t get_number_of_positions(const ProtoStruct& extra) = 0; |
| 59 | + |
| 60 | + /// @brief Send/receive arbitrary commands to the resource. |
| 61 | + /// @param command The command to execute. |
| 62 | + /// @return The result of the executed command. |
| 63 | + virtual ProtoStruct do_command(const ProtoStruct& command) = 0; |
| 64 | + |
| 65 | + API api() const override; |
| 66 | + |
| 67 | + protected: |
| 68 | + explicit Switch(std::string name); |
| 69 | +}; |
| 70 | + |
| 71 | +template <> |
| 72 | +struct API::traits<Switch> { |
| 73 | + static API api(); |
| 74 | +}; |
| 75 | + |
| 76 | +} // namespace sdk |
| 77 | +} // namespace viam |
0 commit comments