Struct spl06_007::Barometer

source ·
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>,

source

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.

source

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
source

pub fn sensor_id(&mut self) -> Result<u8, E>

First four bits: Product ID Last four bits: Revision ID

source

pub fn get_temperature(&mut self) -> Result<f32, E>

Read and calculate the temperature in degrees celsius

source

pub fn get_pressure(&mut self) -> Result<f32, E>

Read and calculate the pressure in millibars

source

pub fn altitude(&mut self, sea_level_hpa: f32) -> Result<f32, E>

Read and calculate the altitude in metres

source

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.

source

pub fn new_data_is_available(&mut self) -> Result<(bool, bool), E>

Returns a tuple of (temperature, pressure). true if new data is available

source

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.

source

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.

source

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.

source

pub fn set_mode(&mut self, mode: Mode) -> Result<(), E>

Set the mode of the sensor. See the Mode enum for more details.

source

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.

source

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.

source

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.

source

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.

Trait Implementations§

source§

impl<'a, I2C> Debug for Barometer<'a, I2C>where I2C: Read + Write + WriteRead + Debug,

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a, I2C> RefUnwindSafe for Barometer<'a, I2C>where I2C: RefUnwindSafe,

§

impl<'a, I2C> Send for Barometer<'a, I2C>where I2C: Send,

§

impl<'a, I2C> Sync for Barometer<'a, I2C>where I2C: Sync,

§

impl<'a, I2C> Unpin for Barometer<'a, I2C>

§

impl<'a, I2C> !UnwindSafe for Barometer<'a, I2C>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.