libgpiod  2.0.1
Public Member Functions
gpiod::chip Class Referencefinal

Represents a GPIO chip. More...

#include <chip.hpp>

Public Member Functions

 chip (const ::std::filesystem::path &path)
 Instantiates a new chip object by opening the device file indicated by the path argument. More...
 
 chip (chip &&other) noexcept
 Move constructor. More...
 
chipoperator= (const chip &other)=delete
 
chipoperator= (chip &&other) noexcept
 Move assignment operator. More...
 
 operator bool () const noexcept
 Check if this object is valid. More...
 
void close ()
 Close the GPIO chip device file and free associated resources. More...
 
::std::filesystem::path path () const
 Get the filesystem path that was used to open this GPIO chip. More...
 
chip_info get_info () const
 Get information about the chip. More...
 
line_info get_line_info (line::offset offset) const
 Retrieve the current snapshot of line information for a single line. More...
 
line_info watch_line_info (line::offset offset) const
 Wrapper around gpiod::chip::get_line_info that retrieves the line info and starts watching the line for changes. More...
 
void unwatch_line_info (line::offset offset) const
 Stop watching the line at given offset for info events. More...
 
int fd () const
 Get the file descriptor associated with this chip. More...
 
bool wait_info_event (const ::std::chrono::nanoseconds &timeout) const
 Wait for line status events on any of the watched lines exposed by this chip. More...
 
info_event read_info_event () const
 Read a single line status change event from this chip. More...
 
int get_line_offset_from_name (const ::std::string &name) const
 Map a GPIO line's name to its offset within the chip. More...
 
request_builder prepare_request ()
 Create a request_builder associated with this chip. More...
 

Detailed Description

Represents a GPIO chip.

Definition at line 41 of file chip.hpp.

Constructor & Destructor Documentation

◆ chip() [1/2]

gpiod::chip::chip ( const ::std::filesystem::path &  path)
explicit

Instantiates a new chip object by opening the device file indicated by the path argument.

Parameters
pathPath to the device file to open.

◆ chip() [2/2]

gpiod::chip::chip ( chip &&  other)
noexcept

Move constructor.

Parameters
otherObject to move.

Member Function Documentation

◆ close()

void gpiod::chip::close ( )

Close the GPIO chip device file and free associated resources.

Note
The chip object can live after calling this method but any of the chip's mutators will throw a logic_error exception.

◆ fd()

int gpiod::chip::fd ( ) const

Get the file descriptor associated with this chip.

Returns
File descriptor number.

◆ get_info()

chip_info gpiod::chip::get_info ( ) const

Get information about the chip.

Returns
New chip_info object.

◆ get_line_info()

line_info gpiod::chip::get_line_info ( line::offset  offset) const

Retrieve the current snapshot of line information for a single line.

Parameters
offsetOffset of the line to get the info for.
Returns
New gpiod::line_info object.

◆ get_line_offset_from_name()

int gpiod::chip::get_line_offset_from_name ( const ::std::string &  name) const

Map a GPIO line's name to its offset within the chip.

Parameters
nameName of the GPIO line to map.
Returns
Offset of the line within the chip or -1 if the line with given name is not exposed by this chip.

◆ operator bool()

gpiod::chip::operator bool ( ) const
explicitnoexcept

Check if this object is valid.

Returns
True if this object's methods can be used, false otherwise. False usually means the chip was closed. 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.

◆ operator=()

chip& gpiod::chip::operator= ( chip &&  other)
noexcept

Move assignment operator.

Parameters
otherObject to move.
Returns
Reference to self.

◆ path()

::std::filesystem::path gpiod::chip::path ( ) const

Get the filesystem path that was used to open this GPIO chip.

Returns
Path to the underlying character device file.

◆ prepare_request()

request_builder gpiod::chip::prepare_request ( )

Create a request_builder associated with this chip.

Returns
New request_builder object.

◆ read_info_event()

info_event gpiod::chip::read_info_event ( ) const

Read a single line status change event from this chip.

Returns
New info_event object.

◆ unwatch_line_info()

void gpiod::chip::unwatch_line_info ( line::offset  offset) const

Stop watching the line at given offset for info events.

Parameters
offsetOffset of the line to get the info for.

◆ wait_info_event()

bool gpiod::chip::wait_info_event ( const ::std::chrono::nanoseconds &  timeout) const

Wait for line status events on any of the watched lines exposed by this chip.

Parameters
timeoutWait time limit in nanoseconds.
Returns
True if at least one event is ready to be read. False if the wait timed out.

◆ watch_line_info()

line_info gpiod::chip::watch_line_info ( line::offset  offset) const

Wrapper around gpiod::chip::get_line_info that retrieves the line info and starts watching the line for changes.

Parameters
offsetOffset of the line to get the info for.
Returns
New gpiod::line_info object.

The documentation for this class was generated from the following file: