Trait SensorInterface

Source
pub trait SensorInterface {
    type SensorError;

    // Required methods
    fn setup(
        &mut self,
        delay_source: &mut impl DelayMs<u8>,
    ) -> Result<(), Self::SensorError>;
    fn write_packet(&mut self, packet: &[u8]) -> Result<(), Self::SensorError>;
    fn read_packet(
        &mut self,
        recv_buf: &mut [u8],
    ) -> Result<usize, Self::SensorError>;
    fn read_with_timeout(
        &mut self,
        recv_buf: &mut [u8],
        delay_source: &mut impl DelayMs<u8>,
        max_ms: u8,
    ) -> Result<usize, Self::SensorError>;
    fn send_and_receive_packet(
        &mut self,
        send_buf: &[u8],
        recv_buf: &mut [u8],
    ) -> Result<usize, Self::SensorError>;
    fn requires_soft_reset(&self) -> bool;
}
Expand description

A method of communicating with the sensor

Required Associated Types§

Source

type SensorError

Interface error type

Required Methods§

Source

fn setup( &mut self, delay_source: &mut impl DelayMs<u8>, ) -> Result<(), Self::SensorError>

give the sensor interface a chance to set up

Source

fn write_packet(&mut self, packet: &[u8]) -> Result<(), Self::SensorError>

Write the whole packet provided

Source

fn read_packet( &mut self, recv_buf: &mut [u8], ) -> Result<usize, Self::SensorError>

Read the next packet from the sensor Returns the size of the packet read (up to the size of the slice provided)

Source

fn read_with_timeout( &mut self, recv_buf: &mut [u8], delay_source: &mut impl DelayMs<u8>, max_ms: u8, ) -> Result<usize, Self::SensorError>

Wait for sensor to indicate it has data available before reading

  • max_ms maximum number of milliseconds to wait for data
Source

fn send_and_receive_packet( &mut self, send_buf: &[u8], recv_buf: &mut [u8], ) -> Result<usize, Self::SensorError>

Send a packet and receive the response immediately

Source

fn requires_soft_reset(&self) -> bool

Does this interface require a soft reset after init?

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<I2C, CommE> SensorInterface for I2cInterface<I2C>
where I2C: Write<Error = CommE> + Read<Error = CommE> + WriteRead<Error = CommE>,

Source§

impl<SPI, CSN, IN, RS, CommE, PinE> SensorInterface for SpiInterface<SPI, CSN, IN, RS>
where SPI: Write<u8, Error = CommE> + Transfer<u8, Error = CommE>, CSN: OutputPin<Error = PinE>, IN: InputPin<Error = PinE>, RS: OutputPin<Error = PinE>, CommE: Debug, PinE: Debug,

Source§

type SensorError = Error<CommE, PinE>