Deluge Firmware 1.3.0
Build date: 2026.10.14
Loading...
Searching...
No Matches
deluge::hid::encoders::QuadratureDecoder Class Reference

#include <encoder_quadrature.h>

Public Member Functions

void initialize (bool a, bool b)
 Record the initial electrical state without reporting it as movement.
int8_t observe (bool a, bool b, bool invert=false)
int8_t observeAEdge (bool a, bool b, bool invert=false)

Private Member Functions

int8_t step (uint8_t next)

Static Private Member Functions

static constexpr uint8_t encode (bool a, bool b)
 Pack the two Boolean pin levels into the lookup-table state order AB.
static constexpr int8_t transition (uint8_t from, uint8_t to)
 Map every previous/current state pair to positive, negative, or no movement.

Private Attributes

uint8_t committed_ = 0
 Last state whose edge has been confirmed and reported.
uint8_t sampled_ = 0
 Most recently observed packed A/B state.

Detailed Description

Decode the two out-of-phase digital signals produced by a rotary encoder.

A complete positive cycle follows 00 -> 01 -> 11 -> 10 -> 00; reversing that sequence produces negative movement. Each valid one-bit transition is one signed edge, giving four edges per cycle. Gold encoders consume every edge as a movement tick, while black encoders accumulate four edges per physical detent.

Glitch rejection (as in the 1.x Encoder::read()): a pin change is only treated as movement once the other pin has also changed. A single pin bouncing or flickering around its threshold therefore never reports movement, at the cost of each edge being confirmed one edge late.

The firmware polls both phases to catch slow B-only transitions, but only A is connected to a hardware interrupt. observeAEdge() can therefore reconstruct an adjacent B+A pair when fast movement changes both bits between observations.

Member Function Documentation

◆ observe()

int8_t deluge::hid::encoders::QuadratureDecoder::observe ( bool a,
bool b,
bool invert = false )
inline

Process a regularly polled A/B sample. Returns the signed number of edges confirmed by this sample. If both bits changed since the previous sample the order is ambiguous, so the sample is ignored: A has changed, so its interrupt is pending and observeAEdge() will resolve the order.

◆ observeAEdge()

int8_t deluge::hid::encoders::QuadratureDecoder::observeAEdge ( bool a,
bool b,
bool invert = false )
inline

Process a sample taken in response to an A-edge interrupt. If both bits changed since the previous sample, the known A interrupt implies the missed B transition came first, so both transitions are replayed in that order.

◆ step()

int8_t deluge::hid::encoders::QuadratureDecoder::step ( uint8_t next)
inlineprivate

Advance by one sample that is at most one bit away from sampled_. Returns +1 or -1 when the sample confirms the previous edge, otherwise zero.


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