Leosac  0.8.0
Open Source Access Control
Leosac::Module::Libgpiod::LibgpiodPin Class Reference

This is a implementation class. More...

#include <LibgpiodPin.hpp>

+ Collaboration diagram for Leosac::Module::Libgpiod::LibgpiodPin:

Public Types

enum  InterruptMode { InterruptMode::None, InterruptMode::Rising, InterruptMode::Falling, InterruptMode::Both }
 
using Direction = Hardware::GPIO::Direction
 

Public Member Functions

 LibgpiodPin (zmqpp::context &ctx, const std::string &name, const std::string &gpio_device, int gpio_offset, Direction direction, InterruptMode interrupt_mode, bool initial_value, LibgpiodModule &module)
 
 ~LibgpiodPin ()
 
 LibgpiodPin (const LibgpiodPin &)=delete
 
LibgpiodPinoperator= (const LibgpiodPin &)=delete
 
LibgpiodPinoperator= (LibgpiodPin &&)=delete
 
 LibgpiodPin (LibgpiodPin &&o)=delete
 
void release ()
 Release Libgpiod resources. More...
 
void register_sockets (zmqpp::reactor *reactor)
 Register own socket to the module's reactor. More...
 
std::chrono::system_clock::time_point next_update () const
 This method shall returns the time point at which we want to be updated. More...
 
void update ()
 Update the PIN. More...
 

Private Member Functions

void handle_interrupt ()
 Interrupt happened for this GPIO ping. More...
 
bool read_value ()
 Read value from filesystem. More...
 
bool turn_on (zmqpp::message *msg=nullptr)
 Write to sysfs to turn the gpio on. More...
 
bool turn_off ()
 Write to sysfs to turn the gpio on. More...
 
bool toggle ()
 Read to sysfs and then write the opposite value. More...
 
void handle_message ()
 The SysFsGpioModule will register this method so its called when a message is ready on the pin socket. More...
 
void set_direction (Direction dir)
 Write direction to the direction file. More...
 
void set_interrupt (InterruptMode mode)
 Write interrupt mode to the edge file. More...
 

Private Attributes

zmqpp::socket sock_
 listen to command from other component. More...
 
std::string name_
 
std::string gpio_device_
 File descriptor of the GPIO in sysfs. More...
 
int gpio_offset_
 Offset of the GPIO. More...
 
const Direction direction_
 Direction of the PIN. More...
 
const bool initial_value_
 Initial value of the PIN. More...
 
LibgpiodModulemodule_
 Reference to the module. More...
 
std::chrono::system_clock::time_point next_update_time_
 Time point of next wished update. More...
 
gpiod_chip * gpiod_chip_
 
gpiod_line * gpiod_line_
 
int gpiod_fd_
 

Detailed Description

This is a implementation class.

It's not exposed to the user and is for this module internal code only.

It abstract a GPIO pin.

Definition at line 42 of file LibgpiodPin.hpp.

Member Typedef Documentation

◆ Direction

Member Enumeration Documentation

◆ InterruptMode

Enumerator
None 
Rising 
Falling 
Both 

Definition at line 47 of file LibgpiodPin.hpp.

Constructor & Destructor Documentation

◆ LibgpiodPin() [1/3]

LibgpiodPin::LibgpiodPin ( zmqpp::context &  ctx,
const std::string &  name,
const std::string &  gpio_device,
int  gpio_offset,
Direction  direction,
InterruptMode  interrupt_mode,
bool  initial_value,
LibgpiodModule module 
)

Definition at line 27 of file LibgpiodPin.cpp.

◆ ~LibgpiodPin()

LibgpiodPin::~LibgpiodPin ( )

Definition at line 54 of file LibgpiodPin.cpp.

◆ LibgpiodPin() [2/3]

Leosac::Module::Libgpiod::LibgpiodPin::LibgpiodPin ( const LibgpiodPin )
delete

◆ LibgpiodPin() [3/3]

Leosac::Module::Libgpiod::LibgpiodPin::LibgpiodPin ( LibgpiodPin &&  o)
delete

Member Function Documentation

◆ handle_interrupt()

void LibgpiodPin::handle_interrupt ( )
private

Interrupt happened for this GPIO ping.

Definition at line 162 of file LibgpiodPin.cpp.

◆ handle_message()

void LibgpiodPin::handle_message ( )
private

The SysFsGpioModule will register this method so its called when a message is ready on the pin socket.

Definition at line 100 of file LibgpiodPin.cpp.

◆ next_update()

std::chrono::system_clock::time_point LibgpiodPin::next_update ( ) const

This method shall returns the time point at which we want to be updated.

Definition at line 183 of file LibgpiodPin.cpp.

◆ operator=() [1/2]

LibgpiodPin& Leosac::Module::Libgpiod::LibgpiodPin::operator= ( const LibgpiodPin )
delete

◆ operator=() [2/2]

LibgpiodPin& Leosac::Module::Libgpiod::LibgpiodPin::operator= ( LibgpiodPin &&  )
delete

◆ read_value()

bool LibgpiodPin::read_value ( )
private

Read value from filesystem.

Definition at line 155 of file LibgpiodPin.cpp.

◆ register_sockets()

void LibgpiodPin::register_sockets ( zmqpp::reactor *  reactor)

Register own socket to the module's reactor.

Parameters
reactorReactor object owned by the module.

Definition at line 171 of file LibgpiodPin.cpp.

◆ release()

void LibgpiodPin::release ( )

Release Libgpiod resources.

Definition at line 59 of file LibgpiodPin.cpp.

◆ set_direction()

void LibgpiodPin::set_direction ( Direction  dir)
private

Write direction to the direction file.

Definition at line 71 of file LibgpiodPin.cpp.

◆ set_interrupt()

void LibgpiodPin::set_interrupt ( InterruptMode  mode)
private

Write interrupt mode to the edge file.

Definition at line 83 of file LibgpiodPin.cpp.

◆ toggle()

bool LibgpiodPin::toggle ( )
private

Read to sysfs and then write the opposite value.

Definition at line 148 of file LibgpiodPin.cpp.

◆ turn_off()

bool LibgpiodPin::turn_off ( )
private

Write to sysfs to turn the gpio on.

Definition at line 142 of file LibgpiodPin.cpp.

◆ turn_on()

bool LibgpiodPin::turn_on ( zmqpp::message *  msg = nullptr)
private

Write to sysfs to turn the gpio on.

Definition at line 121 of file LibgpiodPin.cpp.

◆ update()

void LibgpiodPin::update ( )

Update the PIN.

The update will simply turn the PIN off (as a timeout for ON command).

Note
This is similar to PFDigitalPin.

Definition at line 188 of file LibgpiodPin.cpp.

Member Data Documentation

◆ direction_

const Direction Leosac::Module::Libgpiod::LibgpiodPin::direction_
private

Direction of the PIN.

Definition at line 156 of file LibgpiodPin.hpp.

◆ gpio_device_

std::string Leosac::Module::Libgpiod::LibgpiodPin::gpio_device_
private

File descriptor of the GPIO in sysfs.

Definition at line 146 of file LibgpiodPin.hpp.

◆ gpio_offset_

int Leosac::Module::Libgpiod::LibgpiodPin::gpio_offset_
private

Offset of the GPIO.

Definition at line 151 of file LibgpiodPin.hpp.

◆ gpiod_chip_

gpiod_chip* Leosac::Module::Libgpiod::LibgpiodPin::gpiod_chip_
private

Definition at line 173 of file LibgpiodPin.hpp.

◆ gpiod_fd_

int Leosac::Module::Libgpiod::LibgpiodPin::gpiod_fd_
private

Definition at line 177 of file LibgpiodPin.hpp.

◆ gpiod_line_

gpiod_line* Leosac::Module::Libgpiod::LibgpiodPin::gpiod_line_
private

Definition at line 175 of file LibgpiodPin.hpp.

◆ initial_value_

const bool Leosac::Module::Libgpiod::LibgpiodPin::initial_value_
private

Initial value of the PIN.

We set the pin's value to this on module shutdown.

Definition at line 161 of file LibgpiodPin.hpp.

◆ module_

LibgpiodModule& Leosac::Module::Libgpiod::LibgpiodPin::module_
private

Reference to the module.

We use this to publish on the bus.

Definition at line 166 of file LibgpiodPin.hpp.

◆ name_

std::string Leosac::Module::Libgpiod::LibgpiodPin::name_
private

Definition at line 141 of file LibgpiodPin.hpp.

◆ next_update_time_

std::chrono::system_clock::time_point Leosac::Module::Libgpiod::LibgpiodPin::next_update_time_
private

Time point of next wished update.

(Used for timeout on ON)

Definition at line 171 of file LibgpiodPin.hpp.

◆ sock_

zmqpp::socket Leosac::Module::Libgpiod::LibgpiodPin::sock_
private

listen to command from other component.

Definition at line 139 of file LibgpiodPin.hpp.


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