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§
Sourcetype SensorError
type SensorError
Interface error type
Required Methods§
Sourcefn setup(
&mut self,
delay_source: &mut impl DelayMs<u8>,
) -> Result<(), Self::SensorError>
fn setup( &mut self, delay_source: &mut impl DelayMs<u8>, ) -> Result<(), Self::SensorError>
give the sensor interface a chance to set up
Sourcefn write_packet(&mut self, packet: &[u8]) -> Result<(), Self::SensorError>
fn write_packet(&mut self, packet: &[u8]) -> Result<(), Self::SensorError>
Write the whole packet provided
Sourcefn read_packet(
&mut self,
recv_buf: &mut [u8],
) -> Result<usize, Self::SensorError>
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)
Sourcefn read_with_timeout(
&mut self,
recv_buf: &mut [u8],
delay_source: &mut impl DelayMs<u8>,
max_ms: 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>
Wait for sensor to indicate it has data available before reading
max_ms
maximum number of milliseconds to wait for data
Sourcefn send_and_receive_packet(
&mut self,
send_buf: &[u8],
recv_buf: &mut [u8],
) -> Result<usize, Self::SensorError>
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
Sourcefn requires_soft_reset(&self) -> bool
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.