Struct sgp30::Sgp30

source ·
pub struct Sgp30<I2C, D> { /* private fields */ }
Expand description

Driver for the SGP30

Implementations§

source§

impl<I2C, D, E> Sgp30<I2C, D>
where I2C: Read<Error = E> + Write<Error = E> + WriteRead<Error = E>, D: DelayUs<u16> + DelayMs<u16>,

source

pub fn new(i2c: I2C, address: u8, delay: D) -> Self

Create a new instance of the SGP30 driver.

source

pub fn destroy(self) -> I2C

Destroy driver instance, return I²C bus instance.

source

pub fn serial(&mut self) -> Result<[u8; 6], Error<E>>

Return the 48 bit serial number of the SGP30.

source

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

Run an on-chip self-test. Return a boolean indicating whether the test succeeded.

source

pub fn init(&mut self) -> Result<(), Error<E>>

Initialize the air quality measurement.

The SGP30 uses a dynamic baseline compensation algorithm and on-chip calibration parameters to provide two complementary air quality signals.

Calling this method starts the air quality measurement. After initializing the measurement, the measure() method must be called in regular intervals of 1 s to ensure proper operation of the dynamic baseline compensation algorithm. It is the responsibility of the user of this driver to ensure that these periodic measurements are being done.

For the first 15 s after initializing the air quality measurement, the sensor is in an initialization phase during which it returns fixed values of 400 ppm CO₂eq and 0 ppb TVOC. After 15 s (15 measurements) the values should start to change.

A new init command has to be sent after every power-up or soft reset.

source

pub fn force_init(&mut self) -> Result<(), Error<E>>

Like init(), but without checking whether the sensor is already initialized.

This might be necessary after a sensor soft or hard reset.

source

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

Get an air quality measurement.

Before calling this method, the air quality measurements must have been initialized using the init() method. Otherwise an Error::NotInitialized will be returned.

Once the measurements have been initialized, the measure() method must be called in regular intervals of 1 s to ensure proper operation of the dynamic baseline compensation algorithm. It is the responsibility of the user of this driver to ensure that these periodic measurements are being done.

For the first 15 s after initializing the air quality measurement, the sensor is in an initialization phase during which it returns fixed values of 400 ppm CO₂eq and 0 ppb TVOC. After 15 s (15 measurements) the values should start to change.

source

pub fn measure_raw_signals(&mut self) -> Result<RawSignals, Error<E>>

Return sensor raw signals.

This command is intended for part verification and testing purposes. It returns the raw signals which are used as inputs for the on-chip calibration and baseline compensation algorithm. The command performs a measurement to which the sensor responds with the two signals for H2 and Ethanol.

source

pub fn get_baseline(&mut self) -> Result<Baseline, Error<E>>

Return the baseline values of the baseline correction algorithm.

The SGP30 provides the possibility to read and write the baseline values of the baseline correction algorithm. This feature is used to save the baseline in regular intervals on an external non-volatile memory and restore it after a new power-up or soft reset of the sensor.

This function returns the baseline values for the two air quality signals. These two values should be stored on an external memory. After a power-up or soft reset, the baseline of the baseline correction algorithm can be restored by calling init() followed by set_baseline().

source

pub fn set_baseline(&mut self, baseline: &Baseline) -> Result<(), Error<E>>

Set the baseline values for the baseline correction algorithm.

Before calling this method, the air quality measurements must have been initialized using the init() method. Otherwise an Error::NotInitialized will be returned.

The SGP30 provides the possibility to read and write the baseline values of the baseline correction algorithm. This feature is used to save the baseline in regular intervals on an external non-volatile memory and restore it after a new power-up or soft reset of the sensor.

This function sets the baseline values for the two air quality signals.

source

pub fn set_humidity( &mut self, humidity: Option<&Humidity> ) -> Result<(), Error<E>>

Set the humidity value for the baseline correction algorithm.

The SGP30 features an on-chip humidity compensation for the air quality signals (CO₂eq and TVOC) and sensor raw signals (H2 and Ethanol). To use the on-chip humidity compensation, an absolute humidity value from an external humidity sensor is required.

After setting a new humidity value, this value will be used by the on-chip humidity compensation algorithm until a new humidity value is set. Restarting the sensor (power-on or soft reset) or calling the function with a None value sets the humidity value used for compensation to its default value (11.57 g/m³) until a new humidity value is sent.

Before calling this method, the air quality measurements must have been initialized using the init() method. Otherwise an Error::NotInitialized will be returned.

source

pub fn get_feature_set(&mut self) -> Result<FeatureSet, Error<E>>

Get the feature set.

The SGP30 features a versioning system for the available set of measurement commands and on-chip algorithms. This so called feature set version number can be read out with this method.

Trait Implementations§

source§

impl<I2C: Debug, D: Debug> Debug for Sgp30<I2C, D>

source§

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

Formats the value using the given formatter. Read more
source§

impl<I2C: Default, D: Default> Default for Sgp30<I2C, D>

source§

fn default() -> Sgp30<I2C, D>

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<I2C, D> RefUnwindSafe for Sgp30<I2C, D>

§

impl<I2C, D> Send for Sgp30<I2C, D>
where D: Send, I2C: Send,

§

impl<I2C, D> Sync for Sgp30<I2C, D>
where D: Sync, I2C: Sync,

§

impl<I2C, D> Unpin for Sgp30<I2C, D>
where D: Unpin, I2C: Unpin,

§

impl<I2C, D> UnwindSafe for Sgp30<I2C, D>
where D: UnwindSafe, I2C: UnwindSafe,

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

§

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.