Skip to content

Only every second indent is detected. #11

@mickeprag

Description

@mickeprag

Hello and thanks for this library.

I am trying to setup the standard mode decoder but it is only detecting every second indent of the encoder as a rotation. I am wondering if I am using the API wrong?

This is the pulses from the encoder, the red lines are the indents.
Image

If I translate this to a simple test code this is the result. As you can see every second indent returns Direction::None.

let mut encoder = StandardMode::new();
encoder.update(true, false);
encoder.update(true, true);  // Returns Direction::None

encoder.update(false, true);
encoder.update(false, false);  // Returns Direction::Clockwise

encoder.update(true, false);
encoder.update(true, true);  // Returns Direction::None

encoder.update(false, true);
encoder.update(false, false);  // Returns Direction::Clockwise

Am I using the library wrong or is the algoritm missing this?
If I change the update code like this it works:

if a == PIN_EDGE && b == 0x00 {
    dir = Direction::Anticlockwise;
} else if b == PIN_EDGE && a == 0x00 {
    dir = Direction::Clockwise;
} else if b == 1 && a == 0x3 { // This is new
    dir = Direction::Clockwise;
} else if a == 1 && b == 0x3 { // This is new
    dir = Direction::Anticlockwise;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions