Struct bmp390::Bmp390

source ·
pub struct Bmp390<I> { /* private fields */ }
Expand description

A driver for the BMP390 pressure sensor over any I2c implementation.

This driver utilizes uom to provide automatic, type-safe, and zero-cost units of measurement. Measurements can be retrieved with Bmp390::measure, which returns a Measurement struct containing the pressure, temperature, and altitude. The altitude is calculated based on the current pressure, standard atmospheric pressure at sea level, and a reference altitude, which can be set with Bmp390::set_reference_altitude. The reference altitude defaults to zero, so the default altitude is measured from sea level.

§Example

use bmp390::Bmp390;
let config = bmp390::Configuration::default();
let mut sensor = Bmp390::try_new(i2c, bmp390::Address::Up, delay, &config).await?;
let measurement = sensor.measure().await?;
defmt::info!("Measurement: {}", measurement);

A reference altitude can be set to calculate the altitude relative to a different reference point:

let measurement = sensor.measure().await?;
sensor.set_reference_altitude(measurement.altitude);

// Some time later...
let measurement = sensor.measure().await?;
defmt::info!("Altitude: {}", measurement.altitude.get::<uom::si::length::meter>());

Implementations§

source§

impl<I, E> Bmp390<I>
where I: I2c<Error = E>,

source

pub async fn try_new<D: DelayNs>( i2c: I, address: Address, delay: D, config: &Configuration ) -> Result<Self, Error<E>>

Creates a new BMP390 driver. This will initialize the barometer with the provided configuration. It will additionally delay for 2 ms to allow the barometer to start up and read the calibration coefficients for temperature and pressure measuring.

source

pub async fn temperature( &mut self ) -> Result<ThermodynamicTemperature, Error<E>>

Reads the temperature from the barometer.

source

pub async fn pressure(&mut self) -> Result<Pressure, Error<E>>

Reads the pressure from the barometer.

source

pub async fn measure(&mut self) -> Result<Measurement, Error<E>>

Measures the pressure and temperature from the barometer.

source

pub fn set_reference_altitude(&mut self, altitude: Length)

Set the reference altitude for altitude calculations.

Following this, the altitude can be calculated using Bmp390::altitude. If the current pressure matches the pressure when the reference altitude is set, the altitude will be 0.

source

pub async fn altitude(&mut self) -> Result<Length, Error<E>>

Retrieve the latest pressure measurement and calculate the altitude based on this and the reference pressure.

The altitude is calculating following the NOAA formula.

Auto Trait Implementations§

§

impl<I> Freeze for Bmp390<I>
where I: Freeze,

§

impl<I> !RefUnwindSafe for Bmp390<I>

§

impl<I> Send for Bmp390<I>
where I: Send,

§

impl<I> Sync for Bmp390<I>
where I: Sync,

§

impl<I> Unpin for Bmp390<I>
where I: Unpin,

§

impl<I> !UnwindSafe for Bmp390<I>

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> Same for T

§

type Output = T

Should always be Self
source§

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

§

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

§

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.