Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add non-blocking single-shot measurement #8

Merged
merged 1 commit into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "scd4x"
version = "0.2.1"
version = "0.2.2"
authors = ["Hauke Jung <hauke.jung@outlook.de>"]
documentation = "https://docs.rs/scd4x"
repository = "https://github.com/hauju/scd4x-rs.git"
Expand Down
5 changes: 5 additions & 0 deletions src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ pub enum Command {
/// Allows on-demand measurements
#[cfg(feature = "scd41")]
MeasureSingleShot,
/// Allows on-demand, non-blocking measurements
#[cfg(feature = "scd41")]
MeasureSingleShotNonBlocking,
/// On-demand measurement of CO2 concentration, relative humidity and temperature.
MeasureSingleShotRhtOnly,
/// Put the sensor from idle to sleep mode to reduce current consumption.
Expand Down Expand Up @@ -79,6 +82,8 @@ impl Command {
Self::Reinit => (0x3646, 20, false),
#[cfg(feature = "scd41")]
Self::MeasureSingleShot => (0x219D, 5000, false),
#[cfg(feature = "scd41")]
Self::MeasureSingleShotNonBlocking => (0x219D, 1, false),
Self::MeasureSingleShotRhtOnly => (0x2196, 50, false),
Self::PowerDown => (0x36E0, 1, false),
Self::WakeUp => (0x36F6, 20, false),
Expand Down
10 changes: 10 additions & 0 deletions src/scd4x.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,12 +205,22 @@ where

/// On-demand measurement of CO₂ concentration, relative humidity and temperature.
/// The sensor output is read with the measurement method.
/// Takes around 5 seconds to complete
#[cfg(feature = "scd41")]
pub fn measure_single_shot(&mut self) -> Result<(), Error<E>>{
self.write_command(Command::MeasureSingleShot)?;
Ok(())
}

/// On-demand measurement of CO₂ concentration, relative humidity and temperature.
/// The sensor output is read with the measurement method.
/// Completes immediately, but the measurement can only be read after 5 seconds.
#[cfg(feature = "scd41")]
pub fn measure_single_shot_non_blocking(&mut self) -> Result<(), Error<E>> {
self.write_command(Command::MeasureSingleShotNonBlocking)?;
Ok(())
}

/// On-demand measurement of relative humidity and temperature only.
pub fn measure_single_shot_rht(&mut self) ->Result<(), Error<E>> {
self.write_command(Command::MeasureSingleShotRhtOnly)?;
Expand Down
Loading