|
HF Interface Wrapper 0.1.0-dev
Embedded C++ hardware abstraction layer
|
DigitalOutputGuard class. More...
#include <DigitalOutputGuard.h>
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 | |
| DigitalOutputGuard & | operator= (const DigitalOutputGuard &)=delete |
| DigitalOutputGuard (DigitalOutputGuard &&) noexcept=default | |
| DigitalOutputGuard & | operator= (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 | |
| BaseGpio * | gpio_ |
| 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. | |
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:
Features:
|
explicitnoexcept |
Constructor with BaseGpio reference.
| gpio | Reference to the BaseGpio instance to manage |
| ensure_output_mode | If 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.
|
explicitnoexcept |
Constructor with BaseGpio pointer.
| gpio | Pointer to the BaseGpio instance to manage (must not be null) |
| ensure_output_mode | If 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.
|
noexcept |
Destructor.
Sets the associated BaseGpio instance to inactive state. Does not change the pin direction to preserve configuration.
|
delete |
|
defaultnoexcept |
|
noexcept |
Get the current state of the managed GPIO.
|
inlinenoexcept |
Get the last error that occurred during guard operations.
|
privatenoexcept |
Internal helper to initialize the guard state.
| ensure_output_mode | Whether to ensure output mode |
|
inlinenoexcept |
Check if the guard was successfully initialized.
Returns false if there were errors during construction or if the GPIO pointer is invalid.
|
delete |
|
defaultnoexcept |
|
noexcept |
Manually set the GPIO to active state.
Allows manual control while the guard is active. The destructor will still set the pin inactive when the guard goes out of scope.
|
noexcept |
Manually set the GPIO to inactive state.
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.
|
private |
Whether the guard is in a valid state.
|
private |
Last error code from operations.
|
private |
Whether the GPIO was already in output mode.