idfxx 1.0.0
Modern C++23 components for ESP-IDF
Loading...
Searching...
No Matches
idfxx::rotary_encoder Class Reference

Incremental rotary encoder driver. More...

Classes

struct  config
 Rotary encoder configuration. More...
 

Public Member Functions

 rotary_encoder (config cfg)
 Creates a rotary encoder and begins tracking.
 
void enable_acceleration (uint16_t coeff)
 Enables acceleration on the encoder.
 
void disable_acceleration ()
 Disables acceleration on the encoder.
 
 ~rotary_encoder ()
 Destroys the encoder.
 
 rotary_encoder (const rotary_encoder &)=delete
 
rotary_encoderoperator= (const rotary_encoder &)=delete
 
 rotary_encoder (rotary_encoder &&other) noexcept
 
rotary_encoderoperator= (rotary_encoder &&other) noexcept
 

Static Public Member Functions

static result< rotary_encodermake (config cfg)
 Creates a rotary encoder and begins tracking.
 

Detailed Description

Incremental rotary encoder driver.

Tracks rotary encoder shaft rotation and delivers position change deltas via a callback. Supports acceleration for faster turning.

This type is non-copyable and move-only.

Definition at line 40 of file rotary_encoder.hpp.

Constructor & Destructor Documentation

◆ rotary_encoder() [1/3]

idfxx::rotary_encoder::rotary_encoder ( config  cfg)
explicit

Creates a rotary encoder and begins tracking.

Parameters
cfgEncoder configuration. pin_a, pin_b, and callback must be set. The pull mode field defaults to pullup as a convenience; set to gpio::pull_mode::floating when using external pull-ups (recommended), or std::nullopt if the pins have already been configured.
Note
Only available when CONFIG_COMPILER_CXX_EXCEPTIONS is enabled.
Exceptions
std::system_erroron failure.
std::system_errorwith errc::invalid_arg if pin_a or pin_b is not connected, or callback is not set.

◆ ~rotary_encoder()

idfxx::rotary_encoder::~rotary_encoder ( )

Destroys the encoder.

Stops tracking and releases resources.

◆ rotary_encoder() [2/3]

idfxx::rotary_encoder::rotary_encoder ( const rotary_encoder )
delete

◆ rotary_encoder() [3/3]

idfxx::rotary_encoder::rotary_encoder ( rotary_encoder &&  other)
noexcept

Member Function Documentation

◆ disable_acceleration()

void idfxx::rotary_encoder::disable_acceleration ( )

Disables acceleration on the encoder.

Position deltas return to reporting single steps regardless of turning speed.

Has no effect on a moved-from encoder.

◆ enable_acceleration()

void idfxx::rotary_encoder::enable_acceleration ( uint16_t  coeff)

Enables acceleration on the encoder.

When enabled, faster turning produces larger position deltas. The acceleration coefficient controls the sensitivity.

Has no effect on a moved-from encoder.

Parameters
coeffAcceleration coefficient. Higher values increase acceleration.

◆ make()

static result< rotary_encoder > idfxx::rotary_encoder::make ( config  cfg)
static

Creates a rotary encoder and begins tracking.

Parameters
cfgEncoder configuration. pin_a, pin_b, and callback must be set. The pull mode field defaults to pullup as a convenience; set to gpio::pull_mode::floating when using external pull-ups (recommended), or std::nullopt if the pins have already been configured.
Returns
The new rotary encoder, or an error.
Return values
invalid_argpin_a or pin_b is not connected, or callback is not set.

◆ operator=() [1/2]

rotary_encoder & idfxx::rotary_encoder::operator= ( const rotary_encoder )
delete

◆ operator=() [2/2]

rotary_encoder & idfxx::rotary_encoder::operator= ( rotary_encoder &&  other)
noexcept

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