GPIO line request
-
class request_builder
Intermediate object storing the configuration for a line request.
Public Functions
-
request_builder(request_builder &&other) noexcept
Move constructor.
- Parameters:
other – Object to be moved.
-
request_builder &operator=(request_builder &&other) noexcept
Move assignment operator.
- Parameters:
other – Object to be moved.
- Returns:
Reference to self.
-
request_builder &set_request_config(request_config &req_cfg)
Set the request config for the request.
- Parameters:
req_cfg – Request config to use.
- Returns:
Reference to self.
-
const request_config &get_request_config() const noexcept
Get the current request config.
- Returns:
Const reference to the current request config stored by this object.
-
request_builder &set_consumer(const ::std::string &consumer) noexcept
Set consumer in the request config stored by this object.
- Parameters:
consumer – New consumer string.
- Returns:
Reference to self.
-
request_builder &set_event_buffer_size(::std::size_t event_buffer_size) noexcept
Set the event buffer size in the request config stored by this object.
- Parameters:
event_buffer_size – New event buffer size.
- Returns:
Reference to self.
-
request_builder &set_line_config(line_config &line_cfg)
Set the line config for this request.
- Parameters:
line_cfg – Line config to use.
- Returns:
Reference to self.
-
const line_config &get_line_config() const noexcept
Get the current line config.
- Returns:
Const reference to the current line config stored by this object.
-
request_builder &add_line_settings(line::offset offset, const line_settings &settings)
Add line settings to the line config stored by this object for a single offset.
- Parameters:
offset – Offset for which to add settings.
settings – Line settings to use.
- Returns:
Reference to self.
-
request_builder &add_line_settings(const line::offsets &offsets, const line_settings &settings)
Add line settings to the line config stored by this object for a set of offsets.
- Parameters:
offsets – Offsets for which to add settings.
settings – Settings to add.
- Returns:
Reference to self.
-
request_builder &set_output_values(const line::values &values)
Set output values for a number of lines in the line config stored by this object.
- Parameters:
values – Buffer containing the output values.
- Returns:
Reference to self.
-
line_request do_request()
Make the line request.
- Returns:
New line_request object.
-
request_builder(request_builder &&other) noexcept
-
class line_request
Stores the context of a set of requested GPIO lines.
Public Functions
-
line_request(line_request &&other) noexcept
Move constructor.
- Parameters:
other – Object to move.
-
line_request &operator=(line_request &&other) noexcept
Move assignment operator.
- Parameters:
other – Object to move.
- Returns:
Reference to self.
-
explicit operator bool() const noexcept
Check if this object is valid.
- Returns:
True if this object’s methods can be used, false otherwise. False usually means the request was released. If the user calls any of the methods of this class on an object for which this operator returned false, a logic_error will be thrown.
-
void release()
Release the requested lines and free all associated resources.
Note
The object can still be used after this method is called but using any of the mutators will result in throwing a logic_error exception.
-
::std::string chip_name() const
Get the name of the chip this request was made on.
- Returns:
Name to the GPIO chip.
-
::std::size_t num_lines() const
Get the number of requested lines.
- Returns:
Number of lines in this request.
-
line::offsets offsets() const
Get the list of offsets of requested lines.
- Returns:
List of hardware offsets of the lines in this request.
-
line::value get_value(line::offset offset)
Get the value of a single requested line.
- Parameters:
offset – Offset of the line to read within the chip.
- Returns:
Current line value.
-
line::values get_values(const line::offsets &offsets)
Get the values of a subset of requested lines.
- Parameters:
offsets – Vector of line offsets
- Returns:
Vector of lines values with indexes of values corresponding to those of the offsets.
-
line::values get_values()
Get the values of all requested lines.
- Returns:
List of read values.
-
void get_values(const line::offsets &offsets, line::values &values)
Get the values of a subset of requested lines into a vector supplied by the caller.
- Parameters:
offsets – Vector of line offsets.
values – Vector for storing the values. Its size must be at least that of the offsets vector. The indexes of read values will correspond with those in the offsets vector.
-
void get_values(line::values &values)
Get the values of all requested lines.
- Parameters:
values – Array in which the values will be stored. Must hold at least the number of elements returned by line_request::num_lines.
-
line_request &set_value(line::offset offset, line::value value)
Set the value of a single requested line.
- Parameters:
offset – Offset of the line to set within the chip.
value – New line value.
- Returns:
Reference to self.
-
line_request &set_values(const line::value_mappings &values)
Set the values of a subset of requested lines.
- Parameters:
values – Vector containing a set of offset->value mappings.
- Returns:
Reference to self.
-
line_request &set_values(const line::offsets &offsets, const line::values &values)
Set the values of a subset of requested lines.
- Parameters:
offsets – Vector containing the offsets of lines to set.
values – Vector containing new values with indexes corresponding with those in the offsets vector.
- Returns:
Reference to self.
-
line_request &set_values(const line::values &values)
Set the values of all requested lines.
- Parameters:
values – Array of new line values. The size must be equal to the value returned by line_request::num_lines.
- Returns:
Reference to self.
-
line_request &reconfigure_lines(const line_config &config)
Apply new config options to requested lines.
- Parameters:
config – New configuration.
- Returns:
Reference to self.
-
int fd() const
Get the file descriptor number associated with this line request.
- Returns:
File descriptor number.
-
bool wait_edge_events(const ::std::chrono::nanoseconds &timeout) const
Wait for edge events on any of the lines requested with edge detection enabled.
- Parameters:
timeout – Wait time limit in nanoseconds. If set to 0, the function returns immediately. If set to a negative number, the function blocks indefinitely until an event becomes available.
- Returns:
True if at least one event is ready to be read. False if the wait timed out.
-
::std::size_t read_edge_events(edge_event_buffer &buffer)
Read a number of edge events from this request up to the maximum capacity of the buffer.
- Parameters:
buffer – Edge event buffer to read events into.
- Returns:
Number of events read.
-
::std::size_t read_edge_events(edge_event_buffer &buffer, ::std::size_t max_events)
Read a number of edge events from this request.
- Parameters:
buffer – Edge event buffer to read events into.
max_events – Maximum number of events to read. Limited by the capacity of the buffer.
- Returns:
Number of events read.
-
line_request(line_request &&other) noexcept