pub struct Barometer<'a, I2C>where
I2C: Read + Write + WriteRead,{ /* 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>where
I2C: Read<Error = E> + Write<Error = E> + WriteRead<Error = E>,
impl<'a, I2C, E> Barometer<'a, I2C>where I2C: Read<Error = E> + Write<Error = E> + WriteRead<Error = E>,
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 read the calibration data from the sensor and store it in the struct, so it is important that the I2C bus is initialised before calling this method. This method will also set the sensor to standby mode - use Barometer::init to initialise the sensor to default values.
sourcepub fn init(&mut self) -> Result<(), E>
pub fn init(&mut self) -> Result<(), E>
Initialise the sensor to default values:
- 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
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
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. You will need to reinitialse the sensor after this.
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.
sourcepub fn set_mode(&mut self, mode: Mode) -> Result<(), E>
pub fn set_mode(&mut self, mode: Mode) -> Result<(), E>
Set the mode of the sensor. See the Mode enum for more details.
sourcepub fn request_temperature_reading(&mut self) -> Result<(), E>
pub fn request_temperature_reading(&mut self) -> Result<(), E>
Request a temperature reading. This function is intended to be used when the sensor is in standby mode. It will take a new temperature reading, and then return to standby mode. If the sensor is in continuous mode, this function leaves the sensor in standby mode.
This will not block until the reading is complete. You can check if the reading is complete using Barometer::new_data_is_available. You can then read the temperature using Barometer::get_temperature.
For a more straightforward interface when in standby mode, see Barometer::get_temperature_blocking.
sourcepub fn request_pressure_reading(&mut self) -> Result<(), E>
pub fn request_pressure_reading(&mut self) -> Result<(), E>
Request a pressure reading. This function is intended to be used when the sensor is in standby mode. It will take a new temperature reading, and then return to standby mode. If the sensor is in continuous mode, this function leaves the sensor in standby mode.
This will not block until the reading is complete. You can check if the reading is complete using Barometer::new_data_is_available. You can then read the pressure using Barometer::get_pressure.
Because the pressure reading is dependent on the temperature reading, it is recommended that you request a temperature reading first, and then a pressure reading. This will ensure that the temperature reading is recent. If you have recently requested a temperature reading and do not expect the temperature to have changed significantly, you can skip the temperature reading.
For a more straightforward interface when in standby mode, see Barometer::get_pressure_blocking.
sourcepub fn get_temperature_blocking(&mut self) -> Result<f32, E>
pub fn get_temperature_blocking(&mut self) -> Result<f32, E>
Request a temperature reading. This function is intended to be used when the sensor is in standby mode. It will take a new temperature reading, and then return to standby mode. If the sensor is in continuous mode, this function leaves the sensor in standby mode.
This will block until the reading is complete, and then return the result.
sourcepub fn get_pressure_blocking(&mut self) -> Result<f32, E>
pub fn get_pressure_blocking(&mut self) -> Result<f32, E>
Request a pressure reading. This function is intended to be used when the sensor is in standby mode. It will take a new temperature reading, and then return to standby mode. If the sensor is in continuous mode, this function leaves the sensor in standby mode.
Unlike Barometer::request_pressure_reading, this function will also request a temperature reading first, so there is no need to do this manually. If you want both a temperature and pressure reading, it is recommended that you use this function first and then call Barometer::get_temperature to get the saved temperature reading rather than requesting a new one with Barometer::get_temperature_blocking.
This function will block until the reading is complete, and then return the result.