Skip to content

#3875 fix for rotary reverse direction dead spot #3895

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ports/nrf/common-hal/rotaryio/IncrementalEncoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ static void _intr_handler(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action) {

// logic from the atmel-samd port: provides some damping and scales movement
// down by 4:1.
if (self->quarter >= 4) {
if (self->quarter > 0 && new_state == 2) {
Copy link
Author

@nmorse nmorse Dec 30, 2020

Choose a reason for hiding this comment

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

Oh a finer point might be to refactor this to be ever so slightly more efficient:

  1. switch the order of the conditional (new_state == 2 && self->quarter > 0) because the quarter will be non-zero more often than the state is 2
  2. I guess to go even further it could be refactored with an outer if clause and an inner case, perhaps like this:
if (new_state == 2 && self->quarter != 0) {
    if (self->quarter > 0) { // increment
        ...
    } else { // decrement 
        ...
    }
}

What do you think @dhalbert or anyone else?

self->position++;
self->quarter = 0;
} else if (self->quarter <= -4) {
} else if (self->quarter < 0 && new_state == 2) {
self->position--;
self->quarter = 0;
}
Expand Down