pub struct Sgpc3<I2C, D> { /* private fields */ }
Implementations
sourceimpl<I2C, D, E> Sgpc3<I2C, D> where
I2C: Read<Error = E> + Write<Error = E> + WriteRead<Error = E>,
D: DelayMs<u32>,
impl<I2C, D, E> Sgpc3<I2C, D> where
I2C: Read<Error = E> + Write<Error = E> + WriteRead<Error = E>,
D: DelayMs<u32>,
pub fn new(i2c: I2C, address: u8, delay: D) -> Self
sourcepub fn serial(&mut self) -> Result<u64, Error<E>>
pub fn serial(&mut self) -> Result<u64, Error<E>>
Acquires the sensor serial number.
Sensor serial number is only 48-bits long so the remaining 16-bits are zeros.
sourcepub fn get_feature_set(&mut self) -> Result<FeatureSet, Error<E>>
pub fn get_feature_set(&mut self) -> Result<FeatureSet, Error<E>>
Gets the sensor product type and supported feature set.
The sensor uses feature versioning system to indicate the device capabilities. Feature set 5 enables getting TVOC inceptive baseline. Feature set 6 and above enables ultra-low power-save, setting absolute humidity and preheating. The behaviour is undefined when using these functions with sensor not supporting the specific features.
sourcepub fn set_ultra_power_mode(&mut self) -> Result<(), Error<E>>
pub fn set_ultra_power_mode(&mut self) -> Result<(), Error<E>>
Sets sensor into ultra-low power mode.
The SGPC3 offers two operation modes with different power consumptions and sampling intervals. The low-power mode with 1mA average current and 2s sampling interval and the ultra-low power mode with 0.065mA average current and 30s sampling interval. By default, the SGPC3 is using the low-power mode. You want to stick with the sensor sampling internal so you want to take the samples per the internal. The current SW implementation sees ultra low-power mode as one-way street and once entered, one can get only get out of it through resetting the sensor.
sourcepub fn self_test(&mut self) -> Result<&mut Self, Error<E>>
pub fn self_test(&mut self) -> Result<&mut Self, Error<E>>
Sensor self-test.
Performs sensor self-test. This is intended for production line and testing and verification only and shouldn’t be needed for normal use. It should not be used after having issues any init commands.
sourcepub fn init_no_preheat(&mut self) -> Result<&mut Self, Error<E>>
pub fn init_no_preheat(&mut self) -> Result<&mut Self, Error<E>>
Initializes the sensor without preheat.
Initializing without preheat will lead the early samples to be inaccurate. It is the responsibility of the caller to wait the sufficient preheat period.
sourcepub fn init_preheat(&mut self) -> Result<(), Error<E>>
pub fn init_preheat(&mut self) -> Result<(), Error<E>>
Initializes the sensor with preheat.
This is the standard way of initializing the system.
sourcepub fn init_preheat_64s_fs5(&mut self) -> Result<(), Error<E>>
pub fn init_preheat_64s_fs5(&mut self) -> Result<(), Error<E>>
Initializes the sensor with preheat for feature set 5 sensors
This is the standard way of initializing the systems with feature set 5 sensor firmware
sourcepub fn set_absolute_humidity(
&mut self,
abs_hum: u32
) -> Result<&mut Self, Error<E>>
pub fn set_absolute_humidity(
&mut self,
abs_hum: u32
) -> Result<&mut Self, Error<E>>
Sets the absolute humidity for the best accuracy.
The argument must be supplied at fixed-point 8.8bit format.
sourcepub fn set_relative_humidity(
&mut self,
rh: i32,
t_mc: i32
) -> Result<&mut Self, Error<E>>
pub fn set_relative_humidity(
&mut self,
rh: i32,
t_mc: i32
) -> Result<&mut Self, Error<E>>
Sets the relative humidity for the best accuracy.
The arguments are supplied as milli-units. Eg. 20% relative humidity is supplied as 20000 and temperature t_mc as Celsius. 10C is 10000.
sourcepub fn measure_tvoc_and_raw(&mut self) -> Result<(u16, u16), Error<E>>
pub fn measure_tvoc_and_raw(&mut self) -> Result<(u16, u16), Error<E>>
Measures both TVOC and RAW signal.
The measurement should be performed at the configured sampling internal for the best accuracy. The values are returned as tuple (TVOC, RAW)
sourcepub fn measure_tvoc(&mut self) -> Result<u16, Error<E>>
pub fn measure_tvoc(&mut self) -> Result<u16, Error<E>>
Measures TVOC
The measurement should be performed at the configured sampling internal for the best accuracy.
sourcepub fn measure_raw(&mut self) -> Result<u16, Error<E>>
pub fn measure_raw(&mut self) -> Result<u16, Error<E>>
Measures RAW signal
The measurement should be performed at the configured sampling internal for the best accuracy. Typically, the caller shouldn’t need RAW value but should use TVOC instead.
sourcepub fn get_baseline(&mut self) -> Result<u16, Error<E>>
pub fn get_baseline(&mut self) -> Result<u16, Error<E>>
Acquired the baseline for faster accurate sampling.
Baseline can be used to reach faster accurate repeatable samples. Sensor must be supporting feature set 6 for the support. Check sensor application note for the usage as you need ensure that sensor has been operating long-enough for valid baseline.
sourcepub fn get_inceptive_baseline(&mut self) -> Result<u16, Error<E>>
pub fn get_inceptive_baseline(&mut self) -> Result<u16, Error<E>>
Acquired the inceptive baseline for faster accurate sampling.
Baseline can be used to reach faster accurate repeatable samples. This method needs to be used for sensors only supporting feature set 5 instead of using get_tvoc_baseline.
Check sensor application note for the usage as you need ensure that sensor has been operating long-enough for valid baseline.
sourcepub fn set_baseline(&mut self, baseline: u16) -> Result<&mut Self, Error<E>>
pub fn set_baseline(&mut self, baseline: u16) -> Result<&mut Self, Error<E>>
Sets the baseline for faster accurate.
Baseline will ensure that you can start regarding the accuracy where you left it off after powering down or reseting the sensor.
sourcepub fn initialize(
&mut self,
baseline: u16,
baseline_age_s: u32,
ultra_power_save: bool
) -> Result<&mut Self, Error<E>>
pub fn initialize(
&mut self,
baseline: u16,
baseline_age_s: u32,
ultra_power_save: bool
) -> Result<&mut Self, Error<E>>
Initialize sensor for use
Full initialization sequence for common way to initialize the sensor for production use. This code uses the existing functionality making this shortcut to get things going for those who don’t want to learn the internal workings of the sensor. This method can only be used with sensors supporting feature set 6 and above.
It is assumed that [‘baseline’] has been stored in system non-volatile memory with timestamp during the earlier operation. Datasheet says “If no stored baseline is available after initializing the baseline algorithm, the sensor has to run for 12 hours until the baseline can be stored. This will ensure an optimal behavior for subsequent startups. Reading out the baseline prior should be avoided unless a valid baseline is restored first. Once the baseline is properly initialized or restored, the current baseline value should be stored approximately once per hour. While the sensor is off, baseline values are valid for a maximum of seven days.” Baseline age is provided in seconds and set value zero if there is no baseline available.
Initialization can take up to 204s so depending on the application the user may want to run this in own task.
Once the method is complete, the user should immediately take a sample and then continue taking them per the defined power-mode. In ultra power-save, the sampling frequency is 30s and in standard mode 2s.
Trait Implementations
Auto Trait Implementations
impl<I2C, D> RefUnwindSafe for Sgpc3<I2C, D> where
D: RefUnwindSafe,
I2C: RefUnwindSafe,
impl<I2C, D> Send for Sgpc3<I2C, D> where
D: Send,
I2C: Send,
impl<I2C, D> Sync for Sgpc3<I2C, D> where
D: Sync,
I2C: Sync,
impl<I2C, D> Unpin for Sgpc3<I2C, D> where
D: Unpin,
I2C: Unpin,
impl<I2C, D> UnwindSafe for Sgpc3<I2C, D> where
D: UnwindSafe,
I2C: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> CheckedAs for T
impl<T> CheckedAs for T
sourcefn checked_as<Dst>(self) -> Option<Dst> where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst> where
T: CheckedCast<Dst>,
Casts the value.
sourceimpl<Src, Dst> CheckedCastFrom<Src> for Dst where
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dst where
Src: CheckedCast<Dst>,
sourcefn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
Casts the value.
sourceimpl<Src, Dst> LosslessTryInto<Dst> for Src where
Dst: LosslessTryFrom<Src>,
impl<Src, Dst> LosslessTryInto<Dst> for Src where
Dst: LosslessTryFrom<Src>,
sourcefn lossless_try_into(self) -> Option<Dst>
fn lossless_try_into(self) -> Option<Dst>
Performs the conversion.
sourceimpl<Src, Dst> LossyInto<Dst> for Src where
Dst: LossyFrom<Src>,
impl<Src, Dst> LossyInto<Dst> for Src where
Dst: LossyFrom<Src>,
sourcefn lossy_into(self) -> Dst
fn lossy_into(self) -> Dst
Performs the conversion.
sourceimpl<T> OverflowingAs for T
impl<T> OverflowingAs for T
sourcefn overflowing_as<Dst>(self) -> (Dst, bool) where
T: OverflowingCast<Dst>,
fn overflowing_as<Dst>(self) -> (Dst, bool) where
T: OverflowingCast<Dst>,
Casts the value.
sourceimpl<Src, Dst> OverflowingCastFrom<Src> for Dst where
Src: OverflowingCast<Dst>,
impl<Src, Dst> OverflowingCastFrom<Src> for Dst where
Src: OverflowingCast<Dst>,
sourcefn overflowing_cast_from(src: Src) -> (Dst, bool)
fn overflowing_cast_from(src: Src) -> (Dst, bool)
OverflowingCasts the value.
sourceimpl<T> SaturatingAs for T
impl<T> SaturatingAs for T
sourcefn saturating_as<Dst>(self) -> Dst where
T: SaturatingCast<Dst>,
fn saturating_as<Dst>(self) -> Dst where
T: SaturatingCast<Dst>,
Casts the value.
sourceimpl<Src, Dst> SaturatingCastFrom<Src> for Dst where
Src: SaturatingCast<Dst>,
impl<Src, Dst> SaturatingCastFrom<Src> for Dst where
Src: SaturatingCast<Dst>,
sourcefn saturating_cast_from(src: Src) -> Dst
fn saturating_cast_from(src: Src) -> Dst
Casts the value.
sourceimpl<T> UnwrappedAs for T
impl<T> UnwrappedAs for T
sourcefn unwrapped_as<Dst>(self) -> Dst where
T: UnwrappedCast<Dst>,
fn unwrapped_as<Dst>(self) -> Dst where
T: UnwrappedCast<Dst>,
Casts the value.
sourceimpl<Src, Dst> UnwrappedCastFrom<Src> for Dst where
Src: UnwrappedCast<Dst>,
impl<Src, Dst> UnwrappedCastFrom<Src> for Dst where
Src: UnwrappedCast<Dst>,
sourcefn unwrapped_cast_from(src: Src) -> Dst
fn unwrapped_cast_from(src: Src) -> Dst
UnwrappedCasts the value.
sourceimpl<T> WrappingAs for T
impl<T> WrappingAs for T
sourcefn wrapping_as<Dst>(self) -> Dst where
T: WrappingCast<Dst>,
fn wrapping_as<Dst>(self) -> Dst where
T: WrappingCast<Dst>,
Casts the value.
sourceimpl<Src, Dst> WrappingCastFrom<Src> for Dst where
Src: WrappingCast<Dst>,
impl<Src, Dst> WrappingCastFrom<Src> for Dst where
Src: WrappingCast<Dst>,
sourcefn wrapping_cast_from(src: Src) -> Dst
fn wrapping_cast_from(src: Src) -> Dst
WrappingCasts the value.