Crates.io | bsec |
lib.rs | bsec |
version | 0.5.0+1.4.9.2 |
source | src |
created_at | 2021-05-04 19:09:28.607909 |
updated_at | 2023-02-12 17:58:33.007024 |
description | Rust API to the Bosch BSEC library. |
homepage | |
repository | https://github.com/jgosmann/bsec |
max_upload_size | |
id | 393172 |
size | 78,510 |
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.
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.
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.
The crate documentation can be found on docs.rs.
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);
}
}