Crates.io | quadrature-encoder |
lib.rs | quadrature-encoder |
version | 0.1.1 |
source | src |
created_at | 2024-05-20 22:05:17.482402 |
updated_at | 2024-06-05 08:00:26.895521 |
description | Hardware-level implementations of drivers for incremental encoders with support for full-, half- an quad-stepping. |
homepage | https://github.com/regexident/quadrature |
repository | https://github.com/regexident/quadrature |
max_upload_size | |
id | 1246225 |
size | 25,295 |
quadrature-encoder
Hardware-level implementations of drivers for incremental encoders with support for full-, half- an quad-stepping.
use quadrature_encoder::{FullStep, IncrementalEncoder};
let mut encoder: IncrementalEncoder<...> = Default::new(pin_clk, pin_dt);
// Update the encoder with pulse trains `a` and `b` and handle the result:
match encoder.poll() {
Ok(Some(movement)) => println!("Movement detected: {movement:?}."),
Ok(None) => println!("No movement detected."),
Err(error) => println!("Error detected: {error:?}."),
}
// Or, if you only care about correctly detected movement:
if let Some(movement) = encoder.poll().unwrap_or_default() {
println!("Movement detected: {movement:?}.")
}
println!("Encoder is at position: {:?}.", encoder.position());
See the examples directory for a more comprehensive example.
An indexed encoder resets its position whenever a raising edge is detected on the idx
pin.
use quadrature_encoder::{IndexedIncrementalEncoder};
let mut encoder: IndexedIncrementalEncoder<...> = Default::new(pin_clk, pin_dt, pin_idx);
// Update the encoder with pulse trains `a`, `b` and `z` and handle the result:
match encoder.poll() {
Ok(Some(movement)) => println!("Movement detected: {movement:?}."),
Ok(None) => println!("No movement detected."),
Err(error) => println!("Error detected: {error:?}."),
}
// Or, if you only care about correctly detected movement:
if let Some(movement) = encoder.poll().unwrap_or_default() {
println!("Movement detected: {movement:?}.")
}
println!("Encoder is at position: {:?}.", encoder.position());
See the examples directory for a more comprehensive example.
Since the full typename IncrementalEncoder<Mode, ..., Step, T>
can be quite a mouth-full a couple of convenience type-aliases are provided for the most common use-cases:
use quadrature_encoder::{RotaryEncoder, IndexedRotaryEncoder};
let mut encoder: RotaryEncoder::new(pin_clk, pin_dt);
let mut indexed_encoder: IndexedRotaryEncoder::new(pin_clk, pin_dt, pin_idx);
use quadrature_encoder::{LinearEncoder, IndexedLinearEncoder};
let mut encoder: LinearEncoder::new(pin_clk, pin_dt);
let mut indexed_encoder: IndexedLinearEncoder::new(pin_clk, pin_dt, pin_idx);
A full-step encoder is able to detect up to 1 change(s) per quadrature cycle.
use quadrature_encoder::{FullStep, IncrementalEncoder};
let mut encoder: IncrementalEncoder<_, _, FullStep> = Default::new(...);
A full-step encoder is able to detect up to 2 change(s) per quadrature cycle.
use quadrature_encoder::{HalfStep, IncrementalEncoder};
let mut encoder: IncrementalEncoder<_, _, HalfStep> = Default::new(...);
A full-step encoder is able to detect up to 4 change(s) per quadrature cycle.
use quadrature_encoder::{QuadStep, IncrementalEncoder};
let mut encoder: IncrementalEncoder<_, _, QuadStep> = Default::new(...);
Please refer to the documentation on docs.rs.
Please read CONTRIBUTING.md for details on our code of conduct,
and the process for submitting pull requests to us.
We use SemVer for versioning. For the versions available, see the tags on this repository.
This project is licensed under the MPL-2.0 – see the LICENSE.md file for details.