idfxx 1.0.0
Modern C++23 components for ESP-IDF
Loading...
Searching...
No Matches
rotary_encoder.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2// Copyright 2026 Chris Leishman
3
4#pragma once
5
22#include <idfxx/error>
23#include <idfxx/gpio>
24
25#include <chrono>
26#include <functional>
27#include <optional>
28
29namespace idfxx {
30
41public:
62 struct config {
66 std::optional<gpio::pull_mode> encoder_pins_pull_mode = gpio::pull_mode::pullup;
67 std::chrono::milliseconds acceleration_threshold{200};
68 std::chrono::milliseconds acceleration_cap{4};
69 std::chrono::microseconds polling_interval{std::chrono::milliseconds{1}};
70 std::move_only_function<void(int32_t)> callback;
71 };
72
73#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
85#endif
86
97
109
118
125
130
131private:
132 explicit rotary_encoder(void* ctx);
133
134 void _delete() noexcept;
135
136 void* _context = nullptr;
137};
138
// end of idfxx_rotary_encoder
140
141} // namespace idfxx
A GPIO pin.
Definition gpio.hpp:61
static constexpr gpio nc()
Returns a GPIO representing "not connected".
Definition gpio.hpp:254
@ pullup
Pin pull up.
Incremental rotary encoder driver.
rotary_encoder & operator=(const rotary_encoder &)=delete
void enable_acceleration(uint16_t coeff)
Enables acceleration on the encoder.
void disable_acceleration()
Disables acceleration on the encoder.
~rotary_encoder()
Destroys the encoder.
static result< rotary_encoder > make(config cfg)
Creates a rotary encoder and begins tracking.
rotary_encoder(const rotary_encoder &)=delete
rotary_encoder & operator=(rotary_encoder &&other) noexcept
rotary_encoder(config cfg)
Creates a rotary encoder and begins tracking.
rotary_encoder(rotary_encoder &&other) noexcept
std::expected< T, std::error_code > result
result type wrapping a value or error code.
Definition error.hpp:120
Rotary encoder configuration.
std::move_only_function< void(int32_t)> callback
Event callback (required)
std::optional< gpio::pull_mode > encoder_pins_pull_mode
Pull mode for encoder pins A and B, or std::nullopt to leave unchanged.
std::chrono::microseconds polling_interval
GPIO polling interval.
std::chrono::milliseconds acceleration_cap
Minimum interval (limits max acceleration)
idfxx::gpio pin_a
Encoder pin A (required)
std::chrono::milliseconds acceleration_threshold
Acceleration starts below this interval.
idfxx::gpio pin_b
Encoder pin B (required)