button: Support half-stepping encoders

Adds support for half-stepping encoders (encoders that only emit two
steps per detent, instead of four). Incorporates the feedback from
@susisstrolch's PR: https://github.com/KevinOConnor/klipper/pull/4202
, which was itself built upon a previous PR from @nickbrennan01:
https://github.com/KevinOConnor/klipper/pull/730

Uses the table from the Rotary Arduino library linked in buttons.py:
6b784cca67/Rotary.cpp (L21-L40)

Signed-off-by: Rufo Sanchez <rufo@rufosanchez.com>
This commit is contained in:
Rufo Sanchez 2021-09-12 16:59:15 -05:00 committed by KevinOConnor
parent 5f184e3f98
commit b336a21fe7
3 changed files with 96 additions and 35 deletions

View file

@ -17,6 +17,8 @@ class MenuKeys:
buttons = self.printer.load_object(config, "buttons")
# Register rotary encoder
encoder_pins = config.get('encoder_pins', None)
encoder_steps_per_detent = config.getchoice('encoder_steps_per_detent',
{2: 2, 4: 4}, 4)
if encoder_pins is not None:
try:
pin1, pin2 = encoder_pins.split(',')
@ -24,7 +26,8 @@ class MenuKeys:
raise config.error("Unable to parse encoder_pins")
buttons.register_rotary_encoder(pin1.strip(), pin2.strip(),
self.encoder_cw_callback,
self.encoder_ccw_callback)
self.encoder_ccw_callback,
encoder_steps_per_detent)
self.encoder_fast_rate = config.getfloat('encoder_fast_rate',
.030, above=0.)
self.last_encoder_cw_eventtime = 0