pub trait ContinuousSensorAsync {
type Error: Debug;
type Measurement: Measurement;
// Required methods
async fn start_measuring(&mut self) -> Result<(), Self::Error>;
async fn stop_measuring(&mut self) -> Result<(), Self::Error>;
async fn measurement_interval_us(&mut self) -> Result<u32, Self::Error>;
async fn current_measurement(
&mut self,
) -> Result<Option<Self::Measurement>, Self::Error>;
async fn is_measurement_ready(&mut self) -> Result<bool, Self::Error>;
async fn next_measurement(
&mut self,
) -> Result<Self::Measurement, Self::Error>;
}Expand description
A sensor supporting continuous measurement mode.
If the hardware device itself doesn’t support continuous measurements but they can be meaningfully emulated by using a one-shot mode without drawbacks, it may also implement this trait.
Required Associated Types§
Sourcetype Measurement: Measurement
type Measurement: Measurement
A type holding the measurements obtained by this sensor
Required Methods§
Sourceasync fn start_measuring(&mut self) -> Result<(), Self::Error>
async fn start_measuring(&mut self) -> Result<(), Self::Error>
Starts continuous measurement.
If the device supports several measurement modes, this function attempts to switch to continuous mode on best effort.
Sourceasync fn stop_measuring(&mut self) -> Result<(), Self::Error>
async fn stop_measuring(&mut self) -> Result<(), Self::Error>
Stops continuous measurement.
The mode in which the device is left afterwards is not specified further, but if possible, a sleep mode or equivalent mode should be preferred.
Sourceasync fn measurement_interval_us(&mut self) -> Result<u32, Self::Error>
async fn measurement_interval_us(&mut self) -> Result<u32, Self::Error>
Expected amount of time between measurements in microseconds. This may need to communicate with the device to determine the interval based on device settings.
Sourceasync fn current_measurement(
&mut self,
) -> Result<Option<Self::Measurement>, Self::Error>
async fn current_measurement( &mut self, ) -> Result<Option<Self::Measurement>, Self::Error>
Returns the most recent measurement. If the sensor cannot provide the measurement
current/last measurement at any time (e.g. the register is cleared after it is read), this
should return None when there is no new data available.
Sourceasync fn is_measurement_ready(&mut self) -> Result<bool, Self::Error>
async fn is_measurement_ready(&mut self) -> Result<bool, Self::Error>
Check if new measurements are available. If the device does not support checking for
availability of new measurements (e.g. via some form of data ready indicator), this method
should always return true.
Sourceasync fn next_measurement(&mut self) -> Result<Self::Measurement, Self::Error>
async fn next_measurement(&mut self) -> Result<Self::Measurement, Self::Error>
Wait indefinitely until new measurements are available and return them. If the device does
not support checking for new measurements (e.g. via some form of data ready indicator),
this method should wait for Self::measurement_interval_us and read the measurement
opportunistically.
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.