API Reference¶
chumicro_knobs.encoder¶
Encoder reads one rotary encoder: detents counted into a running position, the signed delta for each tick, and the optional bounds and wrap that keep the count inside a range you choose.
chumicro_knobs.encoder
¶
Rotary encoders: detents counted into a position, with optional bounds and wrap.
Encoder
¶
One rotary encoder, read as a position in detents plus how far it just turned.
Every reading is a plain attribute refreshed by check(now_ms), and just_moved
is true only for the tick the turning landed on. position counts detents from
zero rather than reporting an angle, because an encoder knows how far its shaft moved
and never where it points. The push switch under the shaft is a separate part on its
own pin.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pin_a
|
object | None
|
First quadrature pin, named the way this runtime names pins. Pass both
pins or pass |
None
|
pin_b
|
object | None
|
Second quadrature pin. Swapping the two reverses which way counts up. |
None
|
source
|
object | None
|
Pre-built quadrature source; overrides the pins. Tests inject a fake here. |
None
|
detent_steps
|
int
|
Quadrature steps that make one detent. Four suits a panel-mount encoder with a click at every cycle; use 1 for a smooth one with no clicks. |
DEFAULT_DETENT_STEPS
|
bounds
|
tuple[int, int] | None
|
|
None
|
wrap
|
bool
|
True to carry |
False
|
check(now_ms)
¶
Read how far the shaft turned since the last tick and fold it into position.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
now_ms
|
int
|
Tick this pass of the loop is measured from. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True when |
handle(now_ms)
¶
Call on_change when this tick's turning earned it.
deinit()
¶
Release the pins and any interrupt the source installed.
chumicro_knobs.analog¶
AnalogKnob reads one potentiometer or slider: a converter held still by a deadband and quantized into steps, published as value, delta, and the settled raw reading behind them.
chumicro_knobs.analog
¶
Analog knobs: a converter reading held still by a deadband and quantized into steps.
AnalogKnob
¶
One potentiometer or slider, read as a step number that stops rattling.
Every reading is a plain attribute refreshed by check(now_ms), and just_moved is
true only for the tick the knob moved on. deadband is the analog counterpart of a
button's debounce, and steps gives the reading a size a person can aim at, so a
volume control lands on 47 and stays there. Sampling happens on the tick that asks for
it, because a voltage has no edge to miss between two passes of the loop.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pin
|
object | None
|
Analog-capable pin, named the way this runtime names pins. Pass a pin or pass
|
None
|
source
|
object | None
|
Pre-built converter; overrides |
None
|
steps
|
int
|
How many positions the sweep reports. |
DEFAULT_STEPS
|
deadband
|
int
|
How far the raw 0 to 65535 reading must move before |
DEFAULT_DEADBAND
|
check(now_ms)
¶
Sample the pin and let value follow it when the reading cleared the deadband.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
now_ms
|
int
|
Tick this pass of the loop is measured from. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True when |
handle(now_ms)
¶
Call on_change when this tick's movement earned it.
deinit()
¶
Release the pin the source claimed.
chumicro_knobs.testing¶
FakeEncoderSource and FakeAnalogSource stand in for the hardware so knob logic can be tested on a host. Turn the shaft or park the wiper, tick the knob, assert on what it made of them.
chumicro_knobs.testing
¶
Test-support helpers: a hand-turned :class:FakeEncoderSource and :class:FakeAnalogSource.
FakeEncoderSource
¶
Quadrature source a test turns by hand instead of by wrist.
turn moves it by whole detents, which is what the runtime sources publish once they
have divided the quadrature steps down. Several turns before one tick add up.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
raw_position
|
int
|
Detent count the source starts from. |
0
|
FakeAnalogSource
¶
Converter a test sets a reading on instead of turning a wiper.
set_raw takes the 0 to 65535 scale every runtime reports on, so small moves between
ticks exercise the deadband.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
raw
|
int
|
Reading the source starts from. |
0
|