Skip to content

Commit

Permalink
adds optional serde support, upgrades deps
Browse files Browse the repository at this point in the history
Signed-off-by: Sean Bruton <[email protected]>
  • Loading branch information
sbruton committed Dec 24, 2019
1 parent 6253cf8 commit 65f0d1c
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 9 deletions.
8 changes: 5 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
[package]
name = "bme280"
version = "0.1.2"
version = "0.2.0"
authors = ["Sean Bruton <[email protected]>"]
description = "A rust device driver for the Bosch BME280 temperature, humidity, and atmospheric pressure sensor and the Bosch BMP280 temperature, and atmospheric pressure sensor"
repository = "https://github.com/uber-foo/bme280-rs"
license = "MIT OR Apache-2.0"
keywords = ["bme280", "bmp280", "temperature", "pressure", "humidity"]
categories = ["embedded", "no-std", "hardware-support"]
edition = "2018"

[dependencies]
embedded-hal = "0.2.1"
embedded-hal = "0.2.3"
serde = { version = "1.0.104", optional = true, features = ["derive"] }

[dev-dependencies]
linux-embedded-hal = "0.2.0"
linux-embedded-hal = "0.3.0"
43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,49 @@

A rust device driver for the Bosch BME280 temperature, humidity, and atmospheric pressure sensor and the Bosch BMP280 temperature and atmospheric pressure sensor.

## Usage

[View Complete Documentation Here](https://docs.rs/bme280)

```rust
use linux_embedded_hal as hal;

use linux_embedded_hal::{Delay, I2cdev};
use bme280::BME280;

// using Linux I2C Bus #1 in this example
let i2c_bus = I2cdev::new("/dev/i2c-1").unwrap();

// initialize the BME280 using the primary I2C address 0x76
let mut bme280 = BME280::new_primary(i2c_bus, Delay);

// or, initialize the BME280 using the secondary I2C address 0x77
// let mut bme280 = BME280::new_secondary(i2c_bus, Delay);

// or, initialize the BME280 using a custom I2C address
// let bme280_i2c_addr = 0x88;
// let mut bme280 = BME280::new(i2c_bus, bme280_i2c_addr, Delay);

// initialize the sensor
bme280.init().unwrap();

// measure temperature, pressure, and humidity
let measurements = bme280.measure().unwrap();

println!("Relative Humidity = {}%", measurements.humidity);
println!("Temperature = {} deg C", measurements.temperature);
println!("Pressure = {} pascals", measurements.pressure);
```

## Serde Support

To enable optional serde serialization support for the [measurements struct](https://docs.rs/bme280/0.1.2/bme280/struct.Measurements.html), simply enable the `serde` feature, like so in `Cargo.toml`:

```toml
[dependencies]
bme280 = { version = "0.2", features = ["serde"] }
```

## License

Licensed under either of:
Expand Down
11 changes: 5 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,7 @@
//! ## Usage
//!
//! ```no_run
//! extern crate linux_embedded_hal as hal;
//! extern crate bme280;
//!
//! use hal::{Delay, I2cdev};
//! use linux_embedded_hal::{Delay, I2cdev};
//! use bme280::BME280;
//!
//! // using Linux I2C Bus #1 in this example
Expand All @@ -65,12 +62,13 @@
//! println!("Pressure = {} pascals", measurements.pressure);
//! ```
extern crate embedded_hal;

use core::marker::PhantomData;
use embedded_hal::blocking::delay::DelayMs;
use embedded_hal::blocking::i2c::{Read, Write, WriteRead};

#[cfg(feature = "serde")]
use serde::Serialize;

const BME280_I2C_ADDR_PRIMARY: u8 = 0x76;
const BME280_I2C_ADDR_SECONDARY: u8 = 0x77;

Expand Down Expand Up @@ -188,6 +186,7 @@ struct CalibrationData {
}

/// Measurement data
#[cfg_attr(feature = "serde", derive(Serialize))]
#[derive(Debug)]
pub struct Measurements<E> {
/// temperature in degrees celsius
Expand Down

0 comments on commit 65f0d1c

Please sign in to comment.