HF Interface Wrapper 0.1.0-dev
Embedded C++ hardware abstraction layer
Loading...
Searching...
No Matches
DigitalOutputGuard Class Reference

DigitalOutputGuard class. More...

#include <DigitalOutputGuard.h>

Collaboration diagram for DigitalOutputGuard:
[legend]

Public Member Functions

 DigitalOutputGuard (BaseGpio &gpio, bool ensure_output_mode=true) noexcept
 Constructor with BaseGpio reference.
 
 DigitalOutputGuard (BaseGpio *gpio, bool ensure_output_mode=true) noexcept
 Constructor with BaseGpio pointer.
 
 ~DigitalOutputGuard () noexcept
 Destructor.
 
 DigitalOutputGuard (const DigitalOutputGuard &)=delete
 
DigitalOutputGuardoperator= (const DigitalOutputGuard &)=delete
 
 DigitalOutputGuard (DigitalOutputGuard &&) noexcept=default
 
DigitalOutputGuardoperator= (DigitalOutputGuard &&) noexcept=default
 
bool IsValid () const noexcept
 Check if the guard was successfully initialized.
 
hf_gpio_err_t GetLastError () const noexcept
 Get the last error that occurred during guard operations.
 
hf_gpio_err_t SetActive () noexcept
 Manually set the GPIO to active state.
 
hf_gpio_err_t SetInactive () noexcept
 Manually set the GPIO to inactive state.
 
hf_gpio_state_t GetCurrentState () const noexcept
 Get the current state of the managed GPIO.
 

Private Member Functions

bool InitializeGuard (bool ensure_output_mode) noexcept
 Internal helper to initialize the guard state.
 

Private Attributes

BaseGpiogpio_
 Pointer to the managed BaseGpio instance.
 
bool was_output_mode_
 Whether the GPIO was already in output mode.
 
bool is_valid_
 Whether the guard is in a valid state.
 
hf_gpio_err_t last_error_
 Last error code from operations.
 

Detailed Description

DigitalOutputGuard class.

This class ensures that a BaseGpio instance is configured as output and set active in its constructor, and set inactive in its destructor. This ensures proper resource management and consistent behavior using RAII principles.

Features:

  • Automatic output mode configuration
  • Safe state management with error handling
  • RAII pattern for exception safety
  • Supports both reference and pointer interfaces The DigitalOutputGuard ensures that a BaseGpio instance is configured as output and set active in its constructor, and set inactive in its destructor. This ensures proper resource management and consistent behavior using RAII principles.

Features:

  • Automatic output mode configuration
  • Safe state management with error handling
  • RAII pattern for exception safety
  • Supports both reference and pointer interfaces

Constructor & Destructor Documentation

◆ DigitalOutputGuard() [1/4]

DigitalOutputGuard::DigitalOutputGuard ( BaseGpio & gpio,
bool ensure_output_mode = true )
explicitnoexcept

Constructor with BaseGpio reference.

Parameters
gpioReference to the BaseGpio instance to manage
ensure_output_modeIf true, automatically switch to output mode (default: true)

Configures the GPIO as output (if needed) and sets it to active state. If the GPIO is already in output mode, it just sets the active state.

◆ DigitalOutputGuard() [2/4]

DigitalOutputGuard::DigitalOutputGuard ( BaseGpio * gpio,
bool ensure_output_mode = true )
explicitnoexcept

Constructor with BaseGpio pointer.

Parameters
gpioPointer to the BaseGpio instance to manage (must not be null)
ensure_output_modeIf true, automatically switch to output mode (default: true)

Configures the GPIO as output (if needed) and sets it to active state. If the GPIO is already in output mode, it just sets the active state.

◆ ~DigitalOutputGuard()

DigitalOutputGuard::~DigitalOutputGuard ( )
noexcept

Destructor.

Sets the associated BaseGpio instance to inactive state. Does not change the pin direction to preserve configuration.

◆ DigitalOutputGuard() [3/4]

DigitalOutputGuard::DigitalOutputGuard ( const DigitalOutputGuard & )
delete

◆ DigitalOutputGuard() [4/4]

DigitalOutputGuard::DigitalOutputGuard ( DigitalOutputGuard && )
defaultnoexcept

Member Function Documentation

◆ GetCurrentState()

hf_gpio_state_t DigitalOutputGuard::GetCurrentState ( ) const
noexcept

Get the current state of the managed GPIO.

Returns
Current BaseGpio::hf_gpio_state_t (Active or Inactive)

◆ GetLastError()

hf_gpio_err_t DigitalOutputGuard::GetLastError ( ) const
inlinenoexcept

Get the last error that occurred during guard operations.

Returns
hf_gpio_err_t error code from the last operation

◆ InitializeGuard()

bool DigitalOutputGuard::InitializeGuard ( bool ensure_output_mode)
privatenoexcept

Internal helper to initialize the guard state.

Parameters
ensure_output_modeWhether to ensure output mode
Returns
true if initialization successful, false otherwise

◆ IsValid()

bool DigitalOutputGuard::IsValid ( ) const
inlinenoexcept

Check if the guard was successfully initialized.

Returns
true if the GPIO is properly configured and managed, false otherwise

Returns false if there were errors during construction or if the GPIO pointer is invalid.

◆ operator=() [1/2]

DigitalOutputGuard & DigitalOutputGuard::operator= ( const DigitalOutputGuard & )
delete

◆ operator=() [2/2]

DigitalOutputGuard & DigitalOutputGuard::operator= ( DigitalOutputGuard && )
defaultnoexcept

◆ SetActive()

hf_gpio_err_t DigitalOutputGuard::SetActive ( )
noexcept

Manually set the GPIO to active state.

Returns
hf_gpio_err_t::GPIO_SUCCESS if successful, error code otherwise

Allows manual control while the guard is active. The destructor will still set the pin inactive when the guard goes out of scope.

◆ SetInactive()

hf_gpio_err_t DigitalOutputGuard::SetInactive ( )
noexcept

Manually set the GPIO to inactive state.

Returns
hf_gpio_err_t::GPIO_SUCCESS if successful, error code otherwise

Allows manual control while the guard is active. The destructor will still attempt to set the pin inactive when the guard goes out of scope.

Member Data Documentation

◆ gpio_

BaseGpio* DigitalOutputGuard::gpio_
private

Pointer to the managed BaseGpio instance.

◆ is_valid_

bool DigitalOutputGuard::is_valid_
private

Whether the guard is in a valid state.

◆ last_error_

hf_gpio_err_t DigitalOutputGuard::last_error_
private

Last error code from operations.

◆ was_output_mode_

bool DigitalOutputGuard::was_output_mode_
private

Whether the GPIO was already in output mode.


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