Seeed Grove ++  v0.0.1-2019
Linux C++ Library For Seeed Grove Devices
SG::GpioManagement Class Referencefinal

Singleton object used to manage GPIO. More...

#include <sg_GpioManagement.hpp>

Public Types

enum  EDirection {
  EDirection::kUnknown = 0,
  EDirection::kInput,
  EDirection::kOutput
}
 
enum  EValue {
  EValue::kInvalid = -1,
  EValue::kLow = 0,
  EValue::kHigh = 1
}
 
typedef std::map< GPIO, EDirectionMGPIODirection
 

Public Member Functions

 ~GpioManagement (void)
 Destructor. More...
 
GpioManagementcleanup (void)
 Perform any necessary cleanup, such as releasing (unexporting) any GPIOs that were originally exported by this instance of the SG++ library. More...
 
SGPIO get_exported (void)
 Get the set of exported GPIO. More...
 
MGPIODirection get_direction_map (void)
 Get the map of exported GPIO and the direction for each one. More...
 
GpioManagementgpio_export (const GPIO gpio, const EDirection direction=EDirection::kOutput)
 Tell the Linux kernel to export a GPIO. More...
 
GpioManagementgpio_unexport (const GPIO gpio)
 Tell the Linux kernel a GPIO is no longer needed. More...
 
GpioManagementset_direction (const GPIO gpio, const EDirection direction=EDirection::kOutput)
 Tell the Linux kernel if a GPIO will be used to reading or writing. More...
 
bool is_exported (const GPIO gpio, int number_of_times_to_check=1)
 See if the given GPIO has been exported. More...
 
GpioManagementset_value (const GPIO gpio, const EValue &value)
 Set the given GPIO low or high. More...
 
EValue get_value (const GPIO gpio)
 Get the given GPIO value. More...
 
GpioManagementset_value (const GPIO gpio, const bool set_to_high)
 Set the given GPIO high when TRUE and to low when FALSE. More...
 
GpioManagementset_low (const GPIO gpio)
 Set the given GPIO high when TRUE and to low when FALSE. More...
 
GpioManagementset_high (const GPIO gpio)
 Set the given GPIO high when TRUE and to low when FALSE. More...
 
bool get_value (const GPIO gpio, bool &value)
 Alias for get_value(). More...
 
bool get_bool (const GPIO gpio)
 Alias for get_value(). More...
 

Static Public Member Functions

static GpioManagementget (void)
 Get the singleton. More...
 

Public Attributes

bool unexport_all_gpio_on_destruction
 Determine whether all exported GPIO are automatically unexported on destruction. More...
 

Friends

class SGpp
 Normally GpioManagement in created and managed by SGpp. More...
 

Detailed Description

Singleton object used to manage GPIO.

Obtain a copy of the singleton through SG::SGpp::gpio.

See also
GPIO in Linux is explained here: https://www.kernel.org/doc/Documentation/gpio/sysfs.txt

Member Typedef Documentation

Member Enumeration Documentation

Enumerator
kUnknown 
kInput 
kOutput 
Enumerator
kInvalid 
kLow 
kHigh 

Constructor & Destructor Documentation

SG::GpioManagement::~GpioManagement ( void  )

Destructor.

See also
unexport_all_gpio_on_destruction

References SG::SGpp::cleanup().

Here is the call graph for this function:

Member Function Documentation

SG::GpioManagement & SG::GpioManagement::cleanup ( void  )

Perform any necessary cleanup, such as releasing (unexporting) any GPIOs that were originally exported by this instance of the SG++ library.

See also
unexport_all_gpio_on_destruction

References SG::SGpp::gpio.

Referenced by SG::SGpp::cleanup().

Here is the caller graph for this function:

SG::GpioManagement & SG::GpioManagement::get ( void  )
static

Get the singleton.

bool SG::GpioManagement::get_bool ( const GPIO  gpio)
inline

Alias for get_value().

Returns
TRUE for high and FALSE for low.

References get_value().

Referenced by SG::Button::is_down(), and SG::LEDBar::send_data().

Here is the call graph for this function:

Here is the caller graph for this function:

SG::GpioManagement::MGPIODirection SG::GpioManagement::get_direction_map ( void  )

Get the map of exported GPIO and the direction for each one.

This only includes the GPIOs exported by this instance of the SG++ library.

See also
get_exported()
SG::SGPIO SG::GpioManagement::get_exported ( void  )

Get the set of exported GPIO.

This only includes the GPIOs exported by this instance of the SG++ library.

See also
get_direction_map()
SG::GpioManagement::EValue SG::GpioManagement::get_value ( const GPIO  gpio)

Get the given GPIO value.

The GPIO must be exported.

See also
/sys/class/gpio/gpioN/value where "N" is the GPIO number.
Exceptions
std::system_errorif the GPIO value file cannot be opened with read access.

References kHigh, and SG::BeagleBone::Detect::to_string().

Referenced by get_bool(), and set_high().

Here is the call graph for this function:

Here is the caller graph for this function:

bool SG::GpioManagement::get_value ( const GPIO  gpio,
bool &  value 
)
inline

Alias for get_value().

Returns
TRUE for high and FALSE for low.

References get_value(), and kHigh.

Referenced by get_value().

Here is the call graph for this function:

Here is the caller graph for this function:

SG::GpioManagement & SG::GpioManagement::gpio_export ( const GPIO  gpio,
const EDirection  direction = EDirection::kOutput 
)

Tell the Linux kernel to export a GPIO.

See also
/sys/class/gpio/export
Exceptions
std::invalid_argumentif the specified GPIO has already been exported.
std::system_errorif the GPIO export file cannot be opened with write access.
std::runtime_errorif the specified GPIO fails to export after several tries.

References SG::SGpp::gpio, SG::kUnknown, and SG::BeagleBone::Detect::to_string().

Referenced by SG::Button::Button(), SG::Buzzer::Buzzer(), SG::ChainableRGBLED::ChainableRGBLED(), SG::LEDBar::LEDBar(), and SG::VariableColorLED::VariableColorLED().

Here is the call graph for this function:

Here is the caller graph for this function:

SG::GpioManagement & SG::GpioManagement::gpio_unexport ( const GPIO  gpio)

Tell the Linux kernel a GPIO is no longer needed.

See also
/sys/class/gpio/unexport
Exceptions
std::system_errorif the GPIO unexport file cannot be opened with write access.

Referenced by SG::Button::~Button(), SG::Buzzer::~Buzzer(), SG::ChainableRGBLED::~ChainableRGBLED(), SG::LEDBar::~LEDBar(), and SG::VariableColorLED::~VariableColorLED().

Here is the caller graph for this function:

bool SG::GpioManagement::is_exported ( const GPIO  gpio,
int  number_of_times_to_check = 1 
)

See if the given GPIO has been exported.

If the GPIO was just exported, it may be necessary to retry several times, where it pauses briefly between each attempt. By default, it only checks once.

Returns
true if the GPIO is already exported.
false if the GPIO has not been exported.
Note
This method checks all GPIOs, not only the ones originally exported by this library.
See also
/sys/class/gpio/gpioN where "N" is the GPIO number.

References SG::BeagleBone::Detect::to_string().

Here is the call graph for this function:

SG::GpioManagement & SG::GpioManagement::set_direction ( const GPIO  gpio,
const EDirection  direction = EDirection::kOutput 
)

Tell the Linux kernel if a GPIO will be used to reading or writing.

A GPIO must first be exported for this to work. This normally doesn't need to be called unless the direction is changing, since gpio_export() allows the direction to be set when the GPIO is originally exported.

See also
gpio_export()
/sys/class/gpio/gpioN/direction where "N" is the GPIO number.
Exceptions
invalid_argumentif the specified GPIO has not been exported.
std::system_errorif the GPIO direction file cannot be opened with write access.

References SG::SGpp::gpio, and SG::BeagleBone::Detect::to_string().

Here is the call graph for this function:

GpioManagement& SG::GpioManagement::set_high ( const GPIO  gpio)
inline

Set the given GPIO high when TRUE and to low when FALSE.

The GPIO must be exported, and the direction must be set to EDirection::kOutput.

See also
gpio_export()
set_direction()
/sys/class/gpio/gpioN/value where "N" is the GPIO number.Alias for set_value()

References get_value(), and set_value().

Referenced by SG::GroveGPIO::send_byte(), SG::LEDBar::send_data(), SG::VariableColorLED::turn_off(), SG::Buzzer::turn_off(), SG::Buzzer::turn_on(), and SG::VariableColorLED::turn_on().

Here is the call graph for this function:

Here is the caller graph for this function:

GpioManagement& SG::GpioManagement::set_low ( const GPIO  gpio)
inline

Set the given GPIO high when TRUE and to low when FALSE.

The GPIO must be exported, and the direction must be set to EDirection::kOutput.

See also
gpio_export()
set_direction()
/sys/class/gpio/gpioN/value where "N" is the GPIO number.Alias for set_value()

References set_value().

Referenced by SG::GroveGPIO::send_byte(), SG::LEDBar::send_data(), SG::Buzzer::turn_off(), SG::VariableColorLED::turn_off(), SG::VariableColorLED::turn_on(), and SG::Buzzer::turn_on().

Here is the call graph for this function:

Here is the caller graph for this function:

SG::GpioManagement & SG::GpioManagement::set_value ( const GPIO  gpio,
const EValue value 
)

Set the given GPIO low or high.

The GPIO must be exported, and the direction must be set to EDirection::kOutput.

See also
gpio_export()
set_direction()
/sys/class/gpio/gpioN/value where "N" is the GPIO number.
Exceptions
invalid_argumentif the value is anything other than kLow or kHigh.
invalid_argumentif the specified GPIO has not been exported.
std::system_errorif the GPIO value file cannot be opened with write access.

References SG::BeagleBone::Detect::to_string().

Referenced by SG::LEDBar::send_data(), set_high(), and set_low().

Here is the call graph for this function:

Here is the caller graph for this function:

GpioManagement& SG::GpioManagement::set_value ( const GPIO  gpio,
const bool  set_to_high 
)
inline

Set the given GPIO high when TRUE and to low when FALSE.

The GPIO must be exported, and the direction must be set to EDirection::kOutput.

See also
gpio_export()
set_direction()
/sys/class/gpio/gpioN/value where "N" is the GPIO number.Alias for set_value()

Friends And Related Function Documentation

friend class SGpp
friend

Normally GpioManagement in created and managed by SGpp.

See also
SG::SGpp::gpio;

Member Data Documentation

bool SG::GpioManagement::unexport_all_gpio_on_destruction

Determine whether all exported GPIO are automatically unexported on destruction.

This only includes GPIOs that were exported by the SG++ library. Default is true to ensure all GPIOs are released. The equivalent functionality can be obtained at any time by manually calling cleanup().


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