Viam C++ SDK current
|
Represents a physical board with gpio pins, digital interrupts, and analog voltage reading. More...
#include "components/board.hpp"
Classes | |
struct | analog_response |
Represents the response received when reading the registered analog to digital converter (ADC). The range and conversion mechanism to voltage will vary depending on the specific ADC registered to the pin, though the min and max voltages and step_size can often help with this conversion. Consult your ADC's documentation and Viam's Board documentation for more details. More... | |
struct | status |
This contains all of the values for all of the registered analog readers and digital interrupts that have been registered on the board. More... | |
struct | Tick |
Public Types | |
enum class | power_mode : uint8_t { normal = 0 , offline_deep = 1 } |
Power mode of the board The effect of these power modes depends on your physical board. | |
using | analog_value = int32_t |
Represents the raw value received by the registered analog to digital converter (ADC). The range and conversion mechanism to voltage will vary depending on the specific ADC registered to the pin. | |
using | digital_value = int64_t |
Depending on the type of digital interrupt, this can have different meanings. If a basic (default) interrupt is configured, then this is the total interrupt count. If a servo interrupt is configured this tracks the pulse width value. Consult Viam's Board documentation for more details. | |
Public Member Functions | |
API | api () const override |
Returns the API associated with a particular resource. | |
bool | get_gpio (const std::string &pin) |
Gets the high/low state of the given pin on a board. | |
virtual bool | get_gpio (const std::string &pin, const ProtoStruct &extra)=0 |
Gets the high/low state of the given pin on a board. | |
void | set_gpio (const std::string &pin, bool high) |
Set the gpio high/low state of the given pin on a board. | |
virtual void | set_gpio (const std::string &pin, bool high, const ProtoStruct &extra)=0 |
Set the gpio high/low state of the given pin on a board. | |
double | get_pwm_duty_cycle (const std::string &pin) |
Gets the duty cycle of the given pin on a board. | |
virtual double | get_pwm_duty_cycle (const std::string &pin, const ProtoStruct &extra)=0 |
Gets the duty cycle of the given pin on a board. | |
void | set_pwm_duty_cycle (const std::string &pin, double duty_cycle_pct) |
Sets the given pin of a board to the given duty cycle. | |
virtual void | set_pwm_duty_cycle (const std::string &pin, double duty_cycle_pct, const ProtoStruct &extra)=0 |
Sets the given pin of a board to the given duty cycle. | |
uint64_t | get_pwm_frequency (const std::string &pin) |
Gets the PWM frequency of the given pin on a board. | |
virtual uint64_t | get_pwm_frequency (const std::string &pin, const ProtoStruct &extra)=0 |
Gets the PWM frequency of the given pin on a board. | |
void | set_pwm_frequency (const std::string &pin, uint64_t frequency_hz) |
Sets the given pin on a board to the given PWM frequency. 0 will use the board's default PWM frequency. | |
virtual void | set_pwm_frequency (const std::string &pin, uint64_t frequency_hz, const ProtoStruct &extra)=0 |
Sets the given pin on a board to the given PWM frequency. 0 will use the board's default PWM frequency. | |
analog_response | read_analog (const std::string &analog_reader_name) |
Reads off the current value of an analog reader on a board. Consult your ADC's docs or Viam's Board docs for more information. | |
virtual analog_response | read_analog (const std::string &analog_reader_name, const ProtoStruct &extra)=0 |
Reads off the current value of an analog reader on a board. Consult your ADC's docs or Viam's Board docs for more information. | |
void | write_analog (const std::string &pin, int value) |
Writes the value to the analog writer of the board. | |
virtual void | write_analog (const std::string &pin, int value, const ProtoStruct &extra)=0 |
Writes the value to the analog writer of the board. | |
digital_value | read_digital_interrupt (const std::string &digital_interrupt_name) |
Returns the current value of the interrupt which is based on the type of interrupt. Consult Viam's Board docs for more information. | |
virtual digital_value | read_digital_interrupt (const std::string &digital_interrupt_name, const ProtoStruct &extra)=0 |
Returns the current value of the interrupt which is based on the type of interrupt. Consult Viam's Board docs for more information. | |
void | stream_ticks (std::vector< std::string > const &digital_interrupt_names, std::function< bool(Tick &&tick)> const &tick_handler) |
Returns a stream of digital interrupt ticks. | |
virtual void | stream_ticks (std::vector< std::string > const &digital_interrupt_names, std::function< bool(Tick &&tick)> const &tick_handler, const ProtoStruct &extra)=0 |
Returns a stream of digital interrupt ticks. | |
void | set_power_mode (power_mode power_mode, const boost::optional< std::chrono::microseconds > &duration={}) |
Sets the power consumption mode of the board to the requested setting for the given duration. | |
virtual void | set_power_mode (power_mode power_mode, const ProtoStruct &extra, const boost::optional< std::chrono::microseconds > &duration={})=0 |
Sets the power consumption mode of the board to the requested setting for the given duration. | |
virtual ProtoStruct | do_command (const ProtoStruct &command)=0 |
Send/receive arbitrary commands to the resource. | |
std::vector< GeometryConfig > | get_geometries () |
Returns GeometryConfig s associated with the calling board. | |
virtual std::vector< GeometryConfig > | get_geometries (const ProtoStruct &extra)=0 |
Returns GeometryConfig s associated with the calling board. | |
Public Member Functions inherited from viam::sdk::Component | |
Name | get_resource_name () const override |
Returns the Name for a particular resource. | |
Public Member Functions inherited from viam::sdk::Resource | |
Resource (std::string name) | |
virtual std::string | name () const |
Return the resource's name. | |
Protected Member Functions | |
Board (std::string name) | |
Protected Member Functions inherited from viam::sdk::Component | |
Component (std::string name) | |
Protected Member Functions inherited from viam::sdk::Resource | |
Name | get_resource_name (const std::string &type) const |
Represents a physical board with gpio pins, digital interrupts, and analog voltage reading.
This acts as an abstract base class to be inherited from by any drivers representing specific board implementations. This class cannot be used on its own.
|
overridevirtual |
Returns the API
associated with a particular resource.
Implements viam::sdk::Resource.
|
pure virtual |
Send/receive arbitrary commands to the resource.
Command | the command to execute. |
Implemented in viam::sdk::impl::BoardClient.
|
inline |
Returns GeometryConfig
s associated with the calling board.
GeometryConfig
s associated with the component.
|
pure virtual |
Returns GeometryConfig
s associated with the calling board.
extra | Any additional arguments to the method. |
GeometryConfig
s associated with the component. Implemented in viam::sdk::impl::BoardClient, and viam::sdk::impl::BoardClient.
|
inline |
Gets the high/low state of the given pin on a board.
pin | board pin name |
|
pure virtual |
Gets the high/low state of the given pin on a board.
pin | board pin name |
extra | Any additional arguments to the method |
Implemented in viam::sdk::impl::BoardClient, and viam::sdk::impl::BoardClient.
|
inline |
Gets the duty cycle of the given pin on a board.
pin | board pin name |
|
pure virtual |
Gets the duty cycle of the given pin on a board.
pin | board pin name |
extra | Any additional arguments to the method |
Implemented in viam::sdk::impl::BoardClient, and viam::sdk::impl::BoardClient.
|
inline |
Gets the PWM frequency of the given pin on a board.
pin | board pin name |
|
pure virtual |
Gets the PWM frequency of the given pin on a board.
pin | board pin name |
extra | Any additional arguments to the method |
Implemented in viam::sdk::impl::BoardClient, and viam::sdk::impl::BoardClient.
|
inline |
Reads off the current value of an analog reader on a board. Consult your ADC's docs or Viam's Board
docs for more information.
analog_reader_name | analog reader to read from |
|
pure virtual |
Reads off the current value of an analog reader on a board. Consult your ADC's docs or Viam's Board
docs for more information.
analog_reader_name | analog reader to read from |
extra | Any additional arguments to the method |
Implemented in viam::sdk::impl::BoardClient, and viam::sdk::impl::BoardClient.
|
inline |
Returns the current value of the interrupt which is based on the type of interrupt. Consult Viam's Board
docs for more information.
digital_interrupt_name | digital interrupt to check |
|
pure virtual |
Returns the current value of the interrupt which is based on the type of interrupt. Consult Viam's Board
docs for more information.
digital_interrupt_name | digital interrupt to check |
extra | Any additional arguments to the method |
Implemented in viam::sdk::impl::BoardClient, and viam::sdk::impl::BoardClient.
|
inline |
Set the gpio high/low state of the given pin on a board.
high | true if the pin should be set to high (on) or false if it should be low (off) |
|
pure virtual |
Set the gpio high/low state of the given pin on a board.
high | true if the pin should be set to high (on) or false if it should be low (off) |
extra | Any additional arguments to the method |
Implemented in viam::sdk::impl::BoardClient, and viam::sdk::impl::BoardClient.
|
inline |
Sets the power consumption mode of the board to the requested setting for the given duration.
power_mode | Requested power mode |
duration | Requested duration to stay in power_mode (in microseconds) |
|
pure virtual |
Sets the power consumption mode of the board to the requested setting for the given duration.
power_mode | Requested power mode |
extra | Any additional arguments to the method |
duration | Requested duration to stay in power_mode (in microseconds) |
Implemented in viam::sdk::impl::BoardClient, and viam::sdk::impl::BoardClient.
|
inline |
Sets the given pin of a board to the given duty cycle.
pin | board pin name |
duty_cycle_pct | duty cycle percentage 0 to 1 |
|
pure virtual |
Sets the given pin of a board to the given duty cycle.
pin | board pin name |
duty_cycle_pct | duty cycle percentage 0 to 1 |
extra | Any additional arguments to the method |
Implemented in viam::sdk::impl::BoardClient, and viam::sdk::impl::BoardClient.
|
inline |
Sets the given pin on a board to the given PWM frequency. 0 will use the board's default PWM frequency.
pin | board pin name |
frequency_hz | frequency in hz (0 = use board default frequency) |
|
pure virtual |
Sets the given pin on a board to the given PWM frequency. 0 will use the board's default PWM frequency.
pin | board pin name |
frequency_hz | frequency in hz (0 = use board default frequency) |
extra | Any additional arguments to the method |
Implemented in viam::sdk::impl::BoardClient, and viam::sdk::impl::BoardClient.
|
inline |
Returns a stream of digital interrupt ticks.
digital_interrupt_names | digital interrupts to stream |
tick_handler | callback function to call when a tick occurs. This should return true to keep streaming ticks and false to indicate that the stream of ticks should terminate. The callback function should not be blocking. |
|
pure virtual |
Returns a stream of digital interrupt ticks.
digital_interrupt_names | digital interrupts to stream |
tick_handler | callback function to call when a tick occurs. |
extra | Any additional arguments to the method |
Implemented in viam::sdk::impl::BoardClient, and viam::sdk::impl::BoardClient.
|
inline |
Writes the value to the analog writer of the board.
pin | the pin to write to |
value | the value to set the pin to |
|
pure virtual |
Writes the value to the analog writer of the board.
pin | the pin to write to |
value | the value to set the pin to |
extra | any additional arguments to the method |
Implemented in viam::sdk::impl::BoardClient, and viam::sdk::impl::BoardClient.