Proceed on translation
This commit is contained in:
parent
29913014f6
commit
a2e0687cba
5 changed files with 716 additions and 844 deletions
7
Cargo.lock
generated
7
Cargo.lock
generated
|
@ -53,10 +53,16 @@ version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bindgen 0.35.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"bindgen 0.35.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"byteorder 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"embedded-hal 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"embedded-hal 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"gcc 0.3.54 (registry+https://github.com/rust-lang/crates.io-index)",
|
"gcc 0.3.54 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "byteorder"
|
||||||
|
version = "1.2.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cc"
|
name = "cc"
|
||||||
version = "1.0.9"
|
version = "1.0.9"
|
||||||
|
@ -355,6 +361,7 @@ dependencies = [
|
||||||
"checksum atty 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "af80143d6f7608d746df1520709e5d141c96f240b0e62b0aa41bdfb53374d9d4"
|
"checksum atty 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "af80143d6f7608d746df1520709e5d141c96f240b0e62b0aa41bdfb53374d9d4"
|
||||||
"checksum bindgen 0.35.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b023955126e7909ab9fc1d1973965b8b004f1f388afb5c589640ab483b3b0ad2"
|
"checksum bindgen 0.35.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b023955126e7909ab9fc1d1973965b8b004f1f388afb5c589640ab483b3b0ad2"
|
||||||
"checksum bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b3c30d3802dfb7281680d6285f2ccdaa8c2d8fee41f93805dba5c4cf50dc23cf"
|
"checksum bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b3c30d3802dfb7281680d6285f2ccdaa8c2d8fee41f93805dba5c4cf50dc23cf"
|
||||||
|
"checksum byteorder 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "73b5bdfe7ee3ad0b99c9801d58807a9dbc9e09196365b0203853b99889ab3c87"
|
||||||
"checksum cc 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)" = "2b4911e4bdcb4100c7680e7e854ff38e23f1b34d4d9e079efae3da2801341ffc"
|
"checksum cc 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)" = "2b4911e4bdcb4100c7680e7e854ff38e23f1b34d4d9e079efae3da2801341ffc"
|
||||||
"checksum cexpr 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "42aac45e9567d97474a834efdee3081b3c942b2205be932092f53354ce503d6c"
|
"checksum cexpr 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "42aac45e9567d97474a834efdee3081b3c942b2205be932092f53354ce503d6c"
|
||||||
"checksum cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d4c819a1287eb618df47cc647173c5c4c66ba19d888a6e50d605672aed3140de"
|
"checksum cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d4c819a1287eb618df47cc647173c5c4c66ba19d888a6e50d605672aed3140de"
|
||||||
|
|
|
@ -5,6 +5,7 @@ build = "build.rs"
|
||||||
authors = ["marcelbuesing <buesing.marcel@googlemail.com>"]
|
authors = ["marcelbuesing <buesing.marcel@googlemail.com>"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
byteorder = "1.2"
|
||||||
embedded-hal = "0.1"
|
embedded-hal = "0.1"
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
|
|
44
build.rs
44
build.rs
|
@ -9,26 +9,26 @@ fn main() {
|
||||||
// shared library.
|
// shared library.
|
||||||
//println!("cargo:rustc-link-lib=bz2");
|
//println!("cargo:rustc-link-lib=bz2");
|
||||||
|
|
||||||
gcc::Config::new()
|
// gcc::Config::new()
|
||||||
.file("BME680_driver/bme680.c")
|
// .file("BME680_driver/bme680.c")
|
||||||
.include("BME680_driver")
|
// .include("BME680_driver")
|
||||||
.compile("bme680.a");
|
// .compile("bme680.a");
|
||||||
|
//
|
||||||
// The bindgen::Builder is the main entry point
|
// // The bindgen::Builder is the main entry point
|
||||||
// to bindgen, and lets you build up options for
|
// // to bindgen, and lets you build up options for
|
||||||
// the resulting bindings.
|
// // the resulting bindings.
|
||||||
let bindings = bindgen::Builder::default()
|
// let bindings = bindgen::Builder::default()
|
||||||
// The input header we would like to generate
|
// // The input header we would like to generate
|
||||||
// bindings for.
|
// // bindings for.
|
||||||
.header("wrapper.h")
|
// .header("wrapper.h")
|
||||||
// Finish the builder and generate the bindings.
|
// // Finish the builder and generate the bindings.
|
||||||
.generate()
|
// .generate()
|
||||||
// Unwrap the Result and panic on failure.
|
// // Unwrap the Result and panic on failure.
|
||||||
.expect("Unable to generate bindings");
|
// .expect("Unable to generate bindings");
|
||||||
|
//
|
||||||
// Write the bindings to the $OUT_DIR/bindings.rs file.
|
// // Write the bindings to the $OUT_DIR/bindings.rs file.
|
||||||
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
|
// let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
|
||||||
bindings
|
// bindings
|
||||||
.write_to_file(out_path.join("bindings.rs"))
|
// .write_to_file(out_path.join("bindings.rs"))
|
||||||
.expect("Couldn't write bindings!");
|
// .expect("Couldn't write bindings!");
|
||||||
}
|
}
|
||||||
|
|
1474
src/bme680.rs
1474
src/bme680.rs
File diff suppressed because it is too large
Load diff
34
src/lib.rs
34
src/lib.rs
|
@ -7,15 +7,19 @@ include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate bitflags;
|
extern crate bitflags;
|
||||||
|
|
||||||
|
extern crate byteorder;
|
||||||
|
|
||||||
extern crate embedded_hal as hal;
|
extern crate embedded_hal as hal;
|
||||||
|
|
||||||
use std::result;
|
|
||||||
use hal::blocking::delay::{DelayMs, DelayUs};
|
use hal::blocking::delay::{DelayMs, DelayUs};
|
||||||
use hal::blocking::i2c::{Read, Write, WriteRead};
|
use hal::blocking::i2c::{Read, Write, WriteRead};
|
||||||
|
use std::result;
|
||||||
|
|
||||||
#[link(name = "example", kind = "static")]
|
#[link(name = "example", kind = "static")]
|
||||||
mod consts;
|
mod consts;
|
||||||
mod device_builder;
|
//mod device_builder;
|
||||||
|
mod bme680;
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
@ -74,37 +78,13 @@ pub enum I2CAddr {
|
||||||
Secondary,
|
Secondary,
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
|
||||||
/// Power mode settings
|
|
||||||
///
|
|
||||||
pub enum PowerMode {
|
|
||||||
SleepMode,
|
|
||||||
ForcedMode,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl PowerMode {
|
|
||||||
fn from(power_mode: u8) -> Self {
|
|
||||||
match power_mode {
|
|
||||||
consts::BME680_SLEEP_MODE => PowerMode::SleepMode,
|
|
||||||
consts::BME680_FORCED_MODE => PowerMode::ForcedMode,
|
|
||||||
_ => panic!("Unknown power mode: {}", power_mode),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn value(&self) -> u8 {
|
|
||||||
match self {
|
|
||||||
PowerMode::SleepMode => consts::BME680_SLEEP_MODE,
|
|
||||||
PowerMode::ForcedMode => consts::BME680_FORCED_MODE,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bitflags! {
|
bitflags! {
|
||||||
pub struct SensorSettings: u16 {
|
pub struct SensorSettings: u16 {
|
||||||
/// To set temperature oversampling
|
/// To set temperature oversampling
|
||||||
const OST_SEL = 1;
|
const OST_SEL = 1;
|
||||||
/// To set pressure oversampling.
|
/// To set pressure oversampling.
|
||||||
const OSP_SEL = 2;
|
const OSP_SEL = 2;
|
||||||
|
|
||||||
/// To set humidity oversampling.
|
/// To set humidity oversampling.
|
||||||
const OSH_SEL = 4;
|
const OSH_SEL = 4;
|
||||||
/// To set gas measurement setting.
|
/// To set gas measurement setting.
|
||||||
|
|
Loading…
Reference in a new issue