pub trait ContinuousSensorSync {
type Error: Debug;
type Measurement: Measurement;
// Required methods
fn start_measuring(&mut self) -> Result<(), Self::Error>;
fn stop_measuring(&mut self) -> Result<(), Self::Error>;
fn measurement_interval_us(&mut self) -> Result<u32, Self::Error>;
fn current_measurement(
&mut self,
) -> Result<Option<Self::Measurement>, Self::Error>;
fn is_measurement_ready(&mut self) -> Result<bool, Self::Error>;
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§
Sourcefn start_measuring(&mut self) -> Result<(), Self::Error>
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.
Sourcefn stop_measuring(&mut self) -> Result<(), Self::Error>
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.
Sourcefn measurement_interval_us(&mut self) -> Result<u32, Self::Error>
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.
Sourcefn current_measurement(
&mut self,
) -> Result<Option<Self::Measurement>, Self::Error>
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.
Sourcefn is_measurement_ready(&mut self) -> Result<bool, Self::Error>
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.
Sourcefn next_measurement(&mut self) -> Result<Self::Measurement, Self::Error>
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.