Crates.io | quadrature-decoder |
lib.rs | quadrature-decoder |
version | 0.1.1 |
source | src |
created_at | 2024-05-20 22:03:05.279551 |
updated_at | 2024-06-05 08:00:17.365431 |
description | Pure logic-level implementations of quadrature decoders with support for full-, half- an quad-stepping. |
homepage | https://github.com/regexident/quadrature |
repository | https://github.com/regexident/quadrature |
max_upload_size | |
id | 1246220 |
size | 80,177 |
quadrature-decoder
Pure logic-level implementations of quadrature decoders with support for full-, half- an quad-stepping.
use quadrature_decoder::{FullStep, IncrementalDecoder};
let mut decoder: IncrementalDecoder<...> = Default::default();
// Update the decoder with pulse trains `a` and `b` and handle the result:
match decoder.update(a, b) {
Ok(Some(change)) => println!("Change detected: {change:?}."),
Ok(None) => println!("No change detected."),
Err(error) => println!("Error detected: {error:?}."),
}
// Or, if you only care about correctly detected changes:
if let Some(change) = decoder.update(a, b).unwrap_or_default() {
println!("Change detected: {change:?}.")
}
println!("Decoder is at counter: {:?}.", decoder.counter());
See the examples directory for a more comprehensive example.
An indexed decoder resets its counter whenever a raising edge is detected on the z
pulse train.
use quadrature_decoder::{IndexedIncrementalDecoder};
let mut decoder: IndexedIncrementalDecoder<...> = Default::default();
// Update the decoder with pulse trains `a`, `b` and `z` and handle the result:
match decoder.update(a, b, z) {
Ok(Some(change)) => println!("Change detected: {change:?}."),
Ok(None) => println!("No change detected."),
Err(error) => println!("Error detected: {error:?}."),
}
// Or, if you only care about correctly detected changes:
if let Some(change) = decoder.update(a, b, z).unwrap_or_default() {
println!("Change detected: {change:?}.")
}
println!("Decoder is at counter: {:?}.", decoder.counter());
See the examples directory for a more comprehensive example.
A full-step decoder is able to detect up to 1 change(s) per quadrature cycle.
use quadrature_decoder::{FullStep, IncrementalDecoder};
let mut decoder: IncrementalDecoder<FullStep> = Default::default();
A full-step decoder is able to detect up to 2 change(s) per quadrature cycle.
use quadrature_decoder::{HalfStep, IncrementalDecoder};
let mut decoder: IncrementalDecoder<HalfStep> = Default::default();
A full-step decoder is able to detect up to 4 change(s) per quadrature cycle.
use quadrature_decoder::{QuadStep, IncrementalDecoder};
let mut decoder: IncrementalDecoder<QuadStep> = Default::default();
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.