Trait arduino_hal::prelude::_embedded_hal_Capture
source · pub trait _embedded_hal_Capture {
type Error;
type Channel;
type Time;
type Capture;
// Required methods
fn capture(
&mut self,
channel: Self::Channel
) -> Result<Self::Capture, Error<Self::Error>>;
fn disable(&mut self, channel: Self::Channel);
fn enable(&mut self, channel: Self::Channel);
fn get_resolution(&self) -> Self::Time;
fn set_resolution<R>(&mut self, resolution: R)
where R: Into<Self::Time>;
}
Expand description
Input capture
This trait is available if embedded-hal is built with the "unproven"
feature.
§Examples
You can use this interface to measure the period of (quasi) periodic signals / events
extern crate embedded_hal as hal;
#[macro_use(block)]
extern crate nb;
use hal::prelude::*;
fn main() {
let mut capture: Capture1 = {
// ..
};
capture.set_resolution(1.ms());
let before = block!(capture.capture(Channel::_1)).unwrap();
let after = block!(capture.capture(Channel::_1)).unwrap();
let period = after.wrapping_sub(before);
println!("Period: {} ms", period);
}
Required Associated Types§
sourcetype Error
type Error
Enumeration of Capture
errors
Possible errors:
- overcapture, the previous capture value was overwritten because it was not read in a timely manner
Required Methods§
sourcefn capture(
&mut self,
channel: Self::Channel
) -> Result<Self::Capture, Error<Self::Error>>
fn capture( &mut self, channel: Self::Channel ) -> Result<Self::Capture, Error<Self::Error>>
“Waits” for a transition in the capture channel
and returns the value
of counter at that instant
NOTE that you must multiply the returned value by the resolution of
this Capture
interface to get a human time unit (e.g. seconds)
sourcefn get_resolution(&self) -> Self::Time
fn get_resolution(&self) -> Self::Time
Returns the current resolution
sourcefn set_resolution<R>(&mut self, resolution: R)
fn set_resolution<R>(&mut self, resolution: R)
Sets the resolution of the capture timer
Object Safety§
This trait is not object safe.