Struct Sensor

Source
pub struct Sensor<U> { /* private fields */ }
Expand description

A struct representing sensor interface.

Implementations§

Source§

impl<R, W> Sensor<UartWrapper<R, W>>
where R: Read<u8>, W: Write<u8>,

Constructs the Sensor interface from 2 ‘halves’ of UART.

Source

pub fn from_rx_tx(read: R, write: W) -> Sensor<UartWrapper<R, W>>

Source§

impl<U> Sensor<U>
where U: Read<u8> + Write<u8>,

Source

pub fn new(uart: U) -> Sensor<U>

Source

pub fn write_packet_op<'a>( &'a mut self, packet: &'a Packet, ) -> impl FnMut() -> Result<(), <U as Write<u8>>::Error> + 'a

Write a packet to the device.

Returns a closure that sends a packet to the sensor. The result of this function can be used with the block!() macro from nb crate, e.g.:


let mut op = sensor.write_packet_op(commands::READ_CO2);
block!(op()).unwrap();
Source

pub fn read_packet_op<'a>( &'a mut self, packet: &'a mut Packet, ) -> impl FnMut() -> Result<(), <U as Read<u8>>::Error> + 'a

Read a packet from the device.

Returns a closure that reads a response packet from the sensor. The result of this function can be used with the block!() macro from nb crate, e.g.:


let mut packet = Default::default();
let mut op = sensor.read_packet_op(&mut packet);
block!(op()).unwrap();

Auto Trait Implementations§

§

impl<U> Freeze for Sensor<U>
where U: Freeze,

§

impl<U> RefUnwindSafe for Sensor<U>
where U: RefUnwindSafe,

§

impl<U> Send for Sensor<U>
where U: Send,

§

impl<U> Sync for Sensor<U>
where U: Sync,

§

impl<U> Unpin for Sensor<U>
where U: Unpin,

§

impl<U> UnwindSafe for Sensor<U>
where U: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.