Skip to content

rotaryio: Add the ability to set the divisor #5468

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 18, 2021

Conversation

jepler
Copy link

@jepler jepler commented Oct 15, 2021

At present, Adafruit's rotary encoders all move 1 quadrature cycle per detent, so we originally hard-coded division-by-4. However, other encoders exist, including ones without detents, ones with 2 detents per cycle, and others with 4 detents per cycle.

The new divisor property and constructor argument allows selecting a divisor of 1, 2, or 4; with the default of 4 giving backward compatibility.

The property is not supported (yet?) on espressif MCUs; it throws an error if a value other than 4 is set.

It doesn't quite fit but it may after #5466 goes in. Or we could turn off rotaryio in a few more places, like adalogger_m0.

Closes: #5431

@jepler jepler changed the title Encoder divisor rotaryio: Add the ability to set the divisor Oct 15, 2021
Copy link
Collaborator

@dhalbert dhalbert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy-editing, and perhaps you don't need to shrink those two builds.

Thanks for simplifying the BAD transitions. I derived that table from first principles, before I actually coded the rest.

All we do on a BAD state transition is avoid counting up or down,
but the same is accomplished by using the "0" table value instead.
At present, Adafruit's rotary encoders all move 1 quadrature cycle per
detent, so we originally hard-coded division-by-4.  However, other
encoders exist, including ones without detents, ones with 2 detents per
cycle, and others with 4 detents per cycle.

The new `divisor` property and constructor argument allows selecting
a divisor of 1, 2, or 4; with the default of 4 giving backward
compatibility.

The property is not supported (yet?) on espressif MCUs; it throws an
error if a value other than 4 is set.
@jepler jepler requested a review from dhalbert October 16, 2021 14:44
@jepler
Copy link
Author

jepler commented Oct 16, 2021

Thanks, rebased & re-enabled on those two boards. They're still within 100 bytes of full in the de_DE translation..

@evildave666
Copy link

I can confirm that 9eebb3d allows my half-cycle encoder to work properly, one increment per click, with divisor=2

Copy link
Collaborator

@dhalbert dhalbert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@evildave666 Thank you for testing! @jepler thank you for solving this!

@dhalbert dhalbert merged commit 00aeb6b into adafruit:main Oct 18, 2021
@domdfcoding
Copy link

What was the reason for the lack of support for espressif boards?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

rotaryio does not work properly with half-cycle-per-detent encoders
4 participants