[][src]Trait embedded_hal::Capture

pub trait Capture {
    type Error;
    type Channel;
    type Time;
    type Capture;
    pub fn capture(
        &mut self,
        channel: Self::Channel
    ) -> Result<Self::Capture, Self::Error>;
pub fn disable(&mut self, channel: Self::Channel);
pub fn enable(&mut self, channel: Self::Channel);
pub fn get_resolution(&self) -> Self::Time;
pub fn set_resolution<R>(&mut self, resolution: R)
    where
        R: Into<Self::Time>
; }

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);
}

Associated Types

type Error[src]

Enumeration of Capture errors

Possible errors:

  • overcapture, the previous capture value was overwritten because it was not read in a timely manner

type Channel[src]

Enumeration of channels that can be used with this Capture interface

If your Capture interface has no channels you can use the type () here

type Time[src]

A time unit that can be converted into a human time unit (e.g. seconds)

type Capture[src]

The type of the value returned by capture

Loading content...

Required methods

pub fn capture(
    &mut self,
    channel: Self::Channel
) -> Result<Self::Capture, Self::Error>
[src]

"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)

pub fn disable(&mut self, channel: Self::Channel)[src]

Disables a capture channel

pub fn enable(&mut self, channel: Self::Channel)[src]

Enables a capture channel

pub fn get_resolution(&self) -> Self::Time[src]

Returns the current resolution

pub fn set_resolution<R>(&mut self, resolution: R) where
    R: Into<Self::Time>, 
[src]

Sets the resolution of the capture timer

Loading content...

Implementors

Loading content...