Giter Site home page Giter Site logo

bsec's Introduction

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);
    }
}

bsec's People

Contributors

jgosmann avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.