pub struct Barometer<'a, I2C>{ /* private fields */ }Expand description
The SPL06-007 barometer.
This struct is generic over the I2C bus type. See method documentation for details.
Implementations§
Source§impl<'a, I2C, E> Barometer<'a, I2C>
impl<'a, I2C, E> Barometer<'a, I2C>
Sourcepub fn new(i2c: &'a mut I2C) -> Result<Self, E>
pub fn new(i2c: &'a mut I2C) -> Result<Self, E>
Create a new instance of the barometer.
This method will initialise the sensor with the following default settings:
- Pressure sample rate: 1
- Pressure oversample rate: 8
- Temperature oversample rate: 1
- Temperature sample rate: 8
- Mode: Continuous pressure and temperature
- FIFO disabled
- Interrupts disabled
Sourcepub fn sensor_id(&mut self) -> Result<u8, E>
pub fn sensor_id(&mut self) -> Result<u8, E>
First four bits: Product ID Last four bits: Revision ID
Sourcepub fn get_temperature(&mut self) -> Result<f32, E>
pub fn get_temperature(&mut self) -> Result<f32, E>
Read and calculate the temperature in degrees celsius.
When the sensor is in standby mode or continuous pressure mode, this method will block until a new temperature reading is available. When the sensor is in continuous temperature mode, this method will return the latest temperature reading. In continuous mode you can check if a new temperature reading is available using Barometer::new_data_is_available.
Sourcepub fn get_pressure(&mut self) -> Result<f32, E>
pub fn get_pressure(&mut self) -> Result<f32, E>
Read and calculate the pressure in millibars
When the sensor is in standby mode or continuous temperature mode, this method will block until a new temperature reading is available. When the sensor is in continuous pressure mode, this method will return the latest pressure reading. In continuous mode you can check if a new temperature reading is available using Barometer::new_data_is_available.
Sourcepub fn altitude(&mut self, sea_level_hpa: f32) -> Result<f32, E>
pub fn altitude(&mut self, sea_level_hpa: f32) -> Result<f32, E>
Read and calculate the altitude in metres
Sourcepub fn sensor_data_is_ready(&mut self) -> Result<bool, E>
pub fn sensor_data_is_ready(&mut self) -> Result<bool, E>
Sensor data might not be available after the sensor is powered on or settings changed. Note that you should use Barometer::new_data_is_available for checking if new data is available.
Sourcepub fn new_data_is_available(&mut self) -> Result<(bool, bool), E>
pub fn new_data_is_available(&mut self) -> Result<(bool, bool), E>
Returns a tuple of (temperature, pressure). true if new data is available
Sourcepub fn soft_reset(&mut self) -> Result<(), E>
pub fn soft_reset(&mut self) -> Result<(), E>
Reset the sensor. This will reset all configuration registers to their default values.
Sourcepub fn set_temperature_config(
&mut self,
sample: SampleRate,
oversample: SampleRate,
) -> Result<(), E>
pub fn set_temperature_config( &mut self, sample: SampleRate, oversample: SampleRate, ) -> Result<(), E>
The sample rate is the number of measurements available per second. The oversample rate is the number of individual measurements used to calculate the final value for each final measurement. Higher oversample rates will give more accurate results.
Sourcepub fn set_pressure_config(
&mut self,
sample: SampleRate,
oversample: SampleRate,
) -> Result<(), E>
pub fn set_pressure_config( &mut self, sample: SampleRate, oversample: SampleRate, ) -> Result<(), E>
The sample rate is the number of measurements available per second. The oversample rate is the number of individual measurements used to calculate the final value for each final measurement. Higher oversample rates will give more accurate results.
Note that the pressure readings are dependent on temperature readings, so the temperature oversample rate should be equal or higher than the pressure oversample rate.