8#include <unordered_map>
10#include <viam/sdk/common/proto_value.hpp>
11#include <viam/sdk/common/utils.hpp>
12#include <viam/sdk/config/resource.hpp>
53 std::unordered_map<std::string, analog_value> analog_reader_values;
54 std::unordered_map<std::string, digital_value> digital_interrupt_values;
64 std::chrono::nanoseconds
time;
73 enum class power_mode : uint8_t { normal = 0, offline_deep = 1 };
88 virtual bool get_gpio(
const std::string& pin,
const ProtoStruct& extra) = 0;
92 inline void set_gpio(
const std::string& pin,
bool high) {
99 virtual void set_gpio(
const std::string& pin,
bool high,
const ProtoStruct& extra) = 0;
126 double duty_cycle_pct,
127 const ProtoStruct& extra) = 0;
154 uint64_t frequency_hz,
155 const ProtoStruct& extra) = 0;
169 const ProtoStruct& extra) = 0;
182 virtual void write_analog(
const std::string& pin,
int value,
const ProtoStruct& extra) = 0;
196 const ProtoStruct& extra) = 0;
203 inline void stream_ticks(std::vector<std::string>
const& digital_interrupt_names,
204 std::function<
bool(
Tick&&
tick)>
const& tick_handler) {
205 return stream_ticks(digital_interrupt_names, tick_handler, {});
212 virtual void stream_ticks(std::vector<std::string>
const& digital_interrupt_names,
213 std::function<
bool(
Tick&&
tick)>
const& tick_handler,
214 const ProtoStruct& extra) = 0;
221 const boost::optional<std::chrono::microseconds>& duration = {}) {
232 const ProtoStruct& extra,
233 const boost::optional<std::chrono::microseconds>& duration = {}) = 0;
238 virtual ProtoStruct
do_command(
const ProtoStruct& command) = 0;
249 virtual std::vector<GeometryConfig>
get_geometries(
const ProtoStruct& extra) = 0;
Extends APIType to additionally define a resource's subtype (e.g., camera).
Definition resource_api.hpp:33
Represents a physical board with gpio pins, digital interrupts, and analog voltage reading.
Definition board.hpp:24
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....
virtual std::vector< GeometryConfig > get_geometries(const ProtoStruct &extra)=0
Returns GeometryConfigs associated with the calling board.
power_mode
Power mode of the board The effect of these power modes depends on your physical board.
Definition board.hpp:73
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 frequenc...
std::vector< GeometryConfig > get_geometries()
Returns GeometryConfigs associated with the calling board.
Definition board.hpp:242
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.
Definition board.hpp:220
virtual ProtoStruct do_command(const ProtoStruct &command)=0
Send/receive arbitrary commands to the resource.
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.
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 d...
Definition board.hpp:160
void set_gpio(const std::string &pin, bool high)
Set the gpio high/low state of the given pin on a board.
Definition board.hpp:92
virtual bool get_gpio(const std::string &pin, const ProtoStruct &extra)=0
Gets the high/low state of the given pin on a board.
uint64_t get_pwm_frequency(const std::string &pin)
Gets the PWM frequency of the given pin on a board.
Definition board.hpp:131
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 d...
int64_t digital_value
Depending on the type of digital interrupt, this can have different meanings. If a basic (default) in...
Definition board.hpp:47
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.
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....
Definition board.hpp:187
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.
Definition board.hpp:117
int32_t analog_value
Represents the raw value received by the registered analog to digital converter (ADC)....
Definition board.hpp:29
API api() const override
Returns the API associated with a particular resource.
virtual void write_analog(const std::string &pin, int value, const ProtoStruct &extra)=0
Writes the value to the analog writer of the board.
void write_analog(const std::string &pin, int value)
Writes the value to the analog writer of the board.
Definition board.hpp:174
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.
Definition board.hpp:203
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_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 frequenc...
Definition board.hpp:144
bool get_gpio(const std::string &pin)
Gets the high/low state of the given pin on a board.
Definition board.hpp:80
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.
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.
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.
double get_pwm_duty_cycle(const std::string &pin)
Gets the duty cycle of the given pin on a board.
Definition board.hpp:104
Definition component.hpp:10
virtual std::string name() const
Return the resource's name.
A board's digital interrupt.
Definition resource_api.hpp:50
std::chrono::nanoseconds time
time in nanoseconds the tick occured. This does not represent an absolute time.
Definition board.hpp:64
std::string pin_name
name of the digital interrupt pin.
Definition board.hpp:61
bool high
bool high or low.
Definition board.hpp:67
Represents the response received when reading the registered analog to digital converter (ADC)....
Definition board.hpp:36
This contains all of the values for all of the registered analog readers and digital interrupts that ...
Definition board.hpp:52