Barometer

Struct 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 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
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.

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.

Source

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.

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.

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.

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> Freeze for Barometer<'a, I2C>

§

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 T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

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 T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

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

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.