[][src]Struct gp2y1014au::sensor::Gp2y1014au

pub struct Gp2y1014au<PinLed, OneShotReader, Adc, Word, PinData> where
    PinLed: OutputPin,
    OneShotReader: OneShot<Adc, Word, PinData>,
    PinData: Channel<Adc>, 
{ /* fields omitted */ }

Implementations

impl<PinLed, OneShotReader, Adc, Word, PinData> Gp2y1014au<PinLed, OneShotReader, Adc, Word, PinData> where
    PinLed: OutputPin,
    OneShotReader: OneShot<Adc, Word, PinData>,
    PinData: Channel<Adc>, 
[src]

pub fn new(
    pin_led: PinLed,
    pin_data: PinData,
    one_shot_reader: OneShotReader
) -> Self
[src]

Creates a new instance of the Gp2y1014au dust sensor

Arguments

  • pin_led - The pin connected to the led for the sensor.
  • pin_data - The pin connected to data/out on the sensor.
  • one_shot_reader - A structure that implements "embedded_hal::adc::OneShot"

Example

This example is not tested
use stm32f4xx_hal::
    adc::{
      Adc,
      config::AdcConfig
    };
 
// ... 
let pc1_led = gpioc.pc1.into_push_pull_output();
let pc0_out = gpioc.pc0.into_analog();
let mut adc = Adc::adc1(board_peripherals.ADC1, true, AdcConfig::default());
let mut reader = Gp2y1014au::new(pc1_led, pc0_out, adc);

pub fn read(
    &mut self
) -> Result<Word, Error<PinLed::Error, OneShotReader::Error>>
[src]

Reads the pin state. Returns back Word which varies based on your HAL implementation.

The error types returned back from this will either be Error::LedError or Error::ReadError.

  • Error::ReadError - Implies the OneShot::read function failed for some reason. nb::Error::WouldBlock is already handled in the code as a loop.
  • Error::LedError - Implies the pin for the LED was either failed to be set low or high respectively. This error indicates you should probably discard the result and call the method again.

pub fn split(self) -> (PinLed, PinData, OneShotReader)[src]

Returns back the pins and reader used to construct the sensor. This function consumes self.

Auto Trait Implementations

impl<PinLed, OneShotReader, Adc, Word, PinData> Send for Gp2y1014au<PinLed, OneShotReader, Adc, Word, PinData> where
    Adc: Send,
    OneShotReader: Send,
    PinData: Send,
    PinLed: Send,
    Word: Send

impl<PinLed, OneShotReader, Adc, Word, PinData> Sync for Gp2y1014au<PinLed, OneShotReader, Adc, Word, PinData> where
    Adc: Sync,
    OneShotReader: Sync,
    PinData: Sync,
    PinLed: Sync,
    Word: Sync

impl<PinLed, OneShotReader, Adc, Word, PinData> Unpin for Gp2y1014au<PinLed, OneShotReader, Adc, Word, PinData> where
    Adc: Unpin,
    OneShotReader: Unpin,
    PinData: Unpin,
    PinLed: Unpin,
    Word: Unpin

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.