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 = [
|
||||
"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)",
|
||||
"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)",
|
||||
"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]]
|
||||
name = "cc"
|
||||
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 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 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 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"
|
||||
|
|
|
@ -5,6 +5,7 @@ build = "build.rs"
|
|||
authors = ["marcelbuesing <buesing.marcel@googlemail.com>"]
|
||||
|
||||
[dependencies]
|
||||
byteorder = "1.2"
|
||||
embedded-hal = "0.1"
|
||||
|
||||
[build-dependencies]
|
||||
|
|
44
build.rs
44
build.rs
|
@ -9,26 +9,26 @@ fn main() {
|
|||
// shared library.
|
||||
//println!("cargo:rustc-link-lib=bz2");
|
||||
|
||||
gcc::Config::new()
|
||||
.file("BME680_driver/bme680.c")
|
||||
.include("BME680_driver")
|
||||
.compile("bme680.a");
|
||||
|
||||
// The bindgen::Builder is the main entry point
|
||||
// to bindgen, and lets you build up options for
|
||||
// the resulting bindings.
|
||||
let bindings = bindgen::Builder::default()
|
||||
// The input header we would like to generate
|
||||
// bindings for.
|
||||
.header("wrapper.h")
|
||||
// Finish the builder and generate the bindings.
|
||||
.generate()
|
||||
// Unwrap the Result and panic on failure.
|
||||
.expect("Unable to generate bindings");
|
||||
|
||||
// Write the bindings to the $OUT_DIR/bindings.rs file.
|
||||
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
|
||||
bindings
|
||||
.write_to_file(out_path.join("bindings.rs"))
|
||||
.expect("Couldn't write bindings!");
|
||||
// gcc::Config::new()
|
||||
// .file("BME680_driver/bme680.c")
|
||||
// .include("BME680_driver")
|
||||
// .compile("bme680.a");
|
||||
//
|
||||
// // The bindgen::Builder is the main entry point
|
||||
// // to bindgen, and lets you build up options for
|
||||
// // the resulting bindings.
|
||||
// let bindings = bindgen::Builder::default()
|
||||
// // The input header we would like to generate
|
||||
// // bindings for.
|
||||
// .header("wrapper.h")
|
||||
// // Finish the builder and generate the bindings.
|
||||
// .generate()
|
||||
// // Unwrap the Result and panic on failure.
|
||||
// .expect("Unable to generate bindings");
|
||||
//
|
||||
// // Write the bindings to the $OUT_DIR/bindings.rs file.
|
||||
// let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
|
||||
// bindings
|
||||
// .write_to_file(out_path.join("bindings.rs"))
|
||||
// .expect("Couldn't write bindings!");
|
||||
}
|
||||
|
|
1144
src/bme680.rs
1144
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]
|
||||
extern crate bitflags;
|
||||
|
||||
extern crate byteorder;
|
||||
|
||||
extern crate embedded_hal as hal;
|
||||
|
||||
use std::result;
|
||||
use hal::blocking::delay::{DelayMs, DelayUs};
|
||||
use hal::blocking::i2c::{Read, Write, WriteRead};
|
||||
use std::result;
|
||||
|
||||
#[link(name = "example", kind = "static")]
|
||||
mod consts;
|
||||
mod device_builder;
|
||||
//mod device_builder;
|
||||
mod bme680;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
|
@ -74,37 +78,13 @@ pub enum I2CAddr {
|
|||
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! {
|
||||
pub struct SensorSettings: u16 {
|
||||
/// To set temperature oversampling
|
||||
const OST_SEL = 1;
|
||||
/// To set pressure oversampling.
|
||||
const OSP_SEL = 2;
|
||||
|
||||
/// To set humidity oversampling.
|
||||
const OSH_SEL = 4;
|
||||
/// To set gas measurement setting.
|
||||
|
|
Loading…
Reference in a new issue