![]() |
Deluge Firmware 1.3.0
Build date: 2026.10.14
|
#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) |
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. | |
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.
|
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.
|
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.
|
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.