bsec

Crates.iobsec
lib.rsbsec
version0.5.0+1.4.9.2
sourcesrc
created_at2021-05-04 19:09:28.607909
updated_at2023-02-12 17:58:33.007024
descriptionRust API to the Bosch BSEC library.
homepage
repositoryhttps://github.com/jgosmann/bsec
max_upload_size
id393172
size78,510
Jan Gosmann (jgosmann)

documentation

README

bsec crate

Rust API to the Bosch BSEC library.

This readme will use bsec to refer to this crate, while Bosch BSEC is used to refer to the original BSEC library provided by Bosch.

Important license information

The Bosch BSEC library is proprietary. Thus, the Bosch BSEC library and its documentation cannot be included in the bsec Rust crate and need to be obtained separately.

While the bsec documentation covers the Rust crate itself, you will likely have to refer to the Bosch BSEC documentation at some points to get a full understanding.

You are responsible for adhering to the Bosch BSEC lincese terms in your products, despite the Rust API in this crate being published under a permissive license.

Features

  • Safe Rust API bindings to the Bosch BSEC library.

  • Implementation to use it with the BME680 sensor.

  • Extensible to other sensors.

  • Rudimentary fake sensor implementation to use in unit tests.

Documentation

The crate documentation can be found on docs.rs.

Getting started

See the crate documentation.

Usage example

use bsec::{Bsec, Input, InputKind, OutputKind, clock::Clock, SampleRate, SubscriptionRequest};
use nb::block;
use std::time::Duration;

// Acquire handle to the BSEC library.
// Only one such handle can be acquired at any time.
let mut bsec: Bsec<_, TimePassed, _> = Bsec::init(sensor, &clock)?;

// Configure the outputs you want to subscribe to.
bsec.update_subscription(&[
    SubscriptionRequest {
        sample_rate: SampleRate::Lp,
        sensor: OutputKind::Iaq,
    },
])?;

// We need to feed BSEC regularly with new measurements.
loop {
    // Wait for when the next measurement is due.
    sleep_for(Duration::from_nanos((bsec.next_measurement() - clock.timestamp_ns()) as u64));

    // Start the measurement.
    let wait_duration = block!(bsec.start_next_measurement())?;
    sleep_for(wait_duration);
    # clock.advance_by(wait_duration);

    // Process the measurement when ready and print the BSEC outputs.
    let outputs = block!(bsec.process_last_measurement())?;
    for output in &outputs {
        println!("{:?}: {}", output.sensor, output.signal);
    }
}
Commit count: 32

cargo fmt