Add example and modify accordingly

This commit is contained in:
marcelbuesing 2018-05-18 14:57:34 +02:00
parent e17260a5fc
commit bccb2eac61
No known key found for this signature in database
GPG key ID: 03F06F8179D5549D
4 changed files with 621 additions and 85 deletions

444
Cargo.lock generated
View file

@ -1,3 +1,39 @@
[[package]]
name = "backtrace"
version = "0.3.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"backtrace-sys 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)",
"cfg-if 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-demangle 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "backtrace-sys"
version = "0.1.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cc 1.0.15 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "bitflags"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "bitflags"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "bitflags"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]] [[package]]
name = "bitflags" name = "bitflags"
version = "1.0.1" version = "1.0.1"
@ -9,20 +45,144 @@ version = "0.1.0"
dependencies = [ dependencies = [
"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)", "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.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"i2cdev 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
"linux-embedded-hal 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]]
name = "bytecount"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]] [[package]]
name = "byteorder" name = "byteorder"
version = "1.2.2" version = "1.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "bytes"
version = "0.4.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"byteorder 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "cargo_metadata"
version = "0.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"error-chain 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
"semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.55 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.55 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.17 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "cast"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "cc"
version = "1.0.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "cfg-if"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "dtoa"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]] [[package]]
name = "embedded-hal" name = "embedded-hal"
version = "0.1.2" version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"nb 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "nb 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "error-chain"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"backtrace 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "fuchsia-zircon"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "fuchsia-zircon-sys"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "gcc"
version = "0.3.54"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "glob"
version = "0.2.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "i2cdev"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"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)",
"libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)",
"nix 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
"skeptic 0.13.3 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "iovec"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "itoa"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "libc"
version = "0.2.40"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "linux-embedded-hal"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cast 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"embedded-hal 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"i2cdev 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
"spidev 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"sysfs_gpio 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]] [[package]]
@ -30,8 +190,286 @@ name = "nb"
version = "0.1.1" version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "nix"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"bitflags 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"cfg-if 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc_version 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
"semver 0.1.20 (registry+https://github.com/rust-lang/crates.io-index)",
"void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "nix"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"bytes 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)",
"cfg-if 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
"gcc 0.3.54 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)",
"void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "proc-macro2"
version = "0.3.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "pulldown-cmark"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"bitflags 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "quote"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "rand"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "remove_dir_all"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "rustc-demangle"
version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "rustc_version"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"semver 0.1.20 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "same-file"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "semver"
version = "0.1.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "semver"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.55 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "semver-parser"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "serde"
version = "1.0.55"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "serde_derive"
version = "1.0.55"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.13.10 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "serde_json"
version = "1.0.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"dtoa 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
"itoa 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.55 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "skeptic"
version = "0.13.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"bytecount 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"cargo_metadata 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)",
"error-chain 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
"glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
"pulldown-cmark 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.17 (registry+https://github.com/rust-lang/crates.io-index)",
"tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
"walkdir 2.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "spidev"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"bitflags 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)",
"nix 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "syn"
version = "0.13.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "sysfs_gpio"
version = "0.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"nix 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "tempdir"
version = "0.3.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
"remove_dir_all 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "unicode-xid"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "void"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "walkdir"
version = "2.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"same-file 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "winapi"
version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "winapi"
version = "0.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[metadata] [metadata]
"checksum backtrace 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "8ea58cd16fd6c9d120b5bcb01d63883ae4cc7ba2aed35c1841b862a3c7ef6639"
"checksum backtrace-sys 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "44585761d6161b0f57afc49482ab6bd067e4edef48c12a152c237eb0203f7661"
"checksum bitflags 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "32866f4d103c4e438b1db1158aa1b1a80ee078e5d77a59a2f906fd62a577389c"
"checksum bitflags 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8dead7461c1127cf637931a1e50934eb6eee8bff2f74433ac7909e9afcee04a3"
"checksum bitflags 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4efd02e230a02e18f92fc2735f44597385ed02ad8f831e7c1c1156ee5e1ab3a5"
"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 bytecount 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "882585cd7ec84e902472df34a5e01891202db3bf62614e1f0afe459c1afcf744"
"checksum byteorder 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "73b5bdfe7ee3ad0b99c9801d58807a9dbc9e09196365b0203853b99889ab3c87" "checksum byteorder 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "73b5bdfe7ee3ad0b99c9801d58807a9dbc9e09196365b0203853b99889ab3c87"
"checksum embedded-hal 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "684b1fa3196f78342296d04edc2a6e5d053729d1b64a819dcb072810d706e267" "checksum bytes 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)" = "2f1d50c876fb7545f5f289cd8b2aee3f359d073ae819eed5d6373638e2c61e59"
"checksum cargo_metadata 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)" = "6ebd6272a2ca4fd39dbabbd6611eb03df45c2259b3b80b39a9ff8fbdcf42a4b3"
"checksum cast 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "926013f2860c46252efceabb19f4a6b308197505082c609025aa6706c011d427"
"checksum cc 1.0.15 (registry+https://github.com/rust-lang/crates.io-index)" = "0ebb87d1116151416c0cf66a0e3fb6430cccd120fd6300794b4dfaa050ac40ba"
"checksum cfg-if 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "405216fd8fe65f718daa7102ea808a946b6ce40c742998fbfd3463645552de18"
"checksum dtoa 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "09c3753c3db574d215cba4ea76018483895d7bff25a31b49ba45db21c48e50ab"
"checksum embedded-hal 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "26944677e4934eb5fb4025501dc0d6cdbcf6bfabd6200fcfee2e7e8eef8c0362"
"checksum error-chain 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ff511d5dc435d703f4971bc399647c9bc38e20cb41452e3b9feb4765419ed3f3"
"checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82"
"checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7"
"checksum gcc 0.3.54 (registry+https://github.com/rust-lang/crates.io-index)" = "5e33ec290da0d127825013597dbdfc28bee4964690c7ce1166cbc2a7bd08b1bb"
"checksum glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "8be18de09a56b60ed0edf84bc9df007e30040691af7acd1c41874faac5895bfb"
"checksum i2cdev 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "3c10164c76056ea2af0beb6a3f76ed9fb1b941716a53b4319242090d7f26368e"
"checksum iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dbe6e417e7d0975db6512b90796e8ce223145ac4e33c377e4a42882a0e88bb08"
"checksum itoa 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c069bbec61e1ca5a596166e55dfe4773ff745c3d16b700013bcaff9a6df2c682"
"checksum libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)" = "6fd41f331ac7c5b8ac259b8bf82c75c0fb2e469bbf37d2becbba9a6a2221965b"
"checksum linux-embedded-hal 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7ff46245fb2338f6df956f389ccd62ed82d4b71cf778da946a7fce27d9c7e1a3"
"checksum nb 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "69f380b5fe9fab8c0d7a6a99cda23e2cc0463bedb2cbc3aada0813b98496ecdc" "checksum nb 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "69f380b5fe9fab8c0d7a6a99cda23e2cc0463bedb2cbc3aada0813b98496ecdc"
"checksum nix 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b7fd5681d13fda646462cfbd4e5f2051279a89a544d50eb98c365b507246839f"
"checksum nix 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7a7bb1da2be7da3cbffda73fc681d509ffd9e665af478d2bee1907cee0bc64b2"
"checksum proc-macro2 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "1b06e2f335f48d24442b35a19df506a835fb3547bc3c06ef27340da9acf5cae7"
"checksum pulldown-cmark 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d6fdf85cda6cadfae5428a54661d431330b312bc767ddbc57adbedc24da66e32"
"checksum quote 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9949cfe66888ffe1d53e6ec9d9f3b70714083854be20fd5e271b232a017401e8"
"checksum rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "eba5f8cb59cc50ed56be8880a5c7b496bfd9bd26394e176bc67884094145c2c5"
"checksum remove_dir_all 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3488ba1b9a2084d38645c4c08276a1752dcbf2c7130d74f1569681ad5d2799c5"
"checksum rustc-demangle 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "76d7ba1feafada44f2d38eed812bd2489a03c0f5abb975799251518b68848649"
"checksum rustc_version 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "c5f5376ea5e30ce23c03eb77cbe4962b988deead10910c372b226388b594c084"
"checksum same-file 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "cfb6eded0b06a0b512c8ddbcf04089138c9b4362c2f696f3c3d76039d68f3637"
"checksum semver 0.1.20 (registry+https://github.com/rust-lang/crates.io-index)" = "d4f410fedcf71af0345d7607d246e7ad15faaadd49d240ee3b24e5dc21a820ac"
"checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403"
"checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
"checksum serde 1.0.55 (registry+https://github.com/rust-lang/crates.io-index)" = "97f6a6c3caba0cf8f883b53331791036404ce3c1bd895961cf8bb2f8cecfd84b"
"checksum serde_derive 1.0.55 (registry+https://github.com/rust-lang/crates.io-index)" = "f51b0ef935cf8a41a77bce553da1f8751a739b7ad82dd73669475a22e6ecedb0"
"checksum serde_json 1.0.17 (registry+https://github.com/rust-lang/crates.io-index)" = "f3ad6d546e765177cf3dded3c2e424a8040f870083a0e64064746b958ece9cb1"
"checksum skeptic 0.13.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c4474d6da9593171bcb086890fc344a3a12783cb24e5b141f8a5d0e43561f4b6"
"checksum spidev 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1ba01d3ef92a37e898fecac76cd3e1b33c999395e2d70787608d9678c4293e04"
"checksum syn 0.13.10 (registry+https://github.com/rust-lang/crates.io-index)" = "77961dcdac942fa8bc033c16f3a790b311c8a27d00811b878ebd8cf9b7ba39d5"
"checksum sysfs_gpio 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3d68f2cae3c7d39f54ce8a858cc31ffb01974744ee65e5b4999b6037cd691e3f"
"checksum tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "15f2b5fb00ccdf689e0149d1b1b3c03fead81c2b37735d812fa8bddbbf41b6d8"
"checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc"
"checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d"
"checksum walkdir 2.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "63636bd0eb3d00ccb8b9036381b526efac53caf112b7783b730ab3f8e44da369"
"checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a"
"checksum winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "04e3bd221fcbe8a271359c04f21a76db7d0c6028862d1bb5512d85e1e2eb5bb3"
"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"

View file

@ -6,4 +6,8 @@ authors = ["marcelbuesing <buesing.marcel@googlemail.com>"]
[dependencies] [dependencies]
bitflags = "1.0" bitflags = "1.0"
byteorder = "1.2" byteorder = "1.2"
embedded-hal = "0.1" embedded-hal = "0.2"
[dev-dependencies]
i2cdev = "0.3"
linux-embedded-hal = "0.2"

View file

@ -0,0 +1,46 @@
//extern crate i2cdev;
extern crate embedded_hal;
extern crate linux_embedded_hal as hal;
extern crate bme680_rs;
//use i2cdev::linux::LinuxI2CDevice;
use bme680_rs::*;
use std::io;
use hal::*;
use std::thread;
use std::result;
use std::time::Duration;
fn main() -> result::Result<(), Bme680Error>{
let i2c = I2cdev::new("/dev/i2c-1").unwrap();
let mut dev = Bme680_dev::init(i2c, Delay{}, 0x76, 25)?;
let mut sensor_settings: SensorSettings = Default::default();
sensor_settings.tph_sett.os_hum = Some(BME680_OS_1X);
sensor_settings.tph_sett.os_pres = Some(BME680_OS_16X);
sensor_settings.tph_sett.os_temp = Some(BME680_OS_2X);
sensor_settings.gas_sett.run_gas = Some(0x01);
sensor_settings.gas_sett.heatr_dur = Some(2000);
let settings_sel =
DesiredSensorSettings::OST_SEL |
DesiredSensorSettings::OSP_SEL |
DesiredSensorSettings::OSH_SEL |
DesiredSensorSettings::GAS_SENSOR_SEL;
let profile_dur = dev.get_profile_dur(&sensor_settings)?;
println!("Duration {}", profile_dur);
dev.set_sensor_settings(settings_sel, &sensor_settings)?;
dev.set_sensor_mode(PowerMode::ForcedMode)?;
thread::sleep(Duration::from_millis(profile_dur as u64));
let data = dev.get_sensor_data()?;
println!("Sensor Data {:?}", data);
Ok(())
}

View file

@ -49,6 +49,15 @@ pub const BME680_ADDR_GAS_CONF_START: u8 = 0x64;
pub const BME680_SOFT_RESET_ADDR: u8 = 0xe0; pub const BME680_SOFT_RESET_ADDR: u8 = 0xe0;
/** Over-sampling settings */
// TODO replace with enum/flags
pub const BME680_OS_NONE: u8 = 0;
pub const BME680_OS_1X: u8 = 1;
pub const BME680_OS_2X: u8 = 2;
pub const BME680_OS_4X: u8 = 3;
pub const BME680_OS_8X: u8 = 4;
pub const BME680_OS_16X: u8 = 5;
/** Field settings */ /** Field settings */
pub const BME680_FIELD0_ADDR: u8 = 0x1d; pub const BME680_FIELD0_ADDR: u8 = 0x1d;
@ -124,6 +133,7 @@ pub const BME680_RUN_GAS_SEL: u16 = 64;
pub const BME680_NBCONV_SEL: u16 = 128; pub const BME680_NBCONV_SEL: u16 = 128;
pub const BME680_GAS_SENSOR_SEL: u16 = BME680_GAS_MEAS_SEL | BME680_RUN_GAS_SEL | BME680_NBCONV_SEL; pub const BME680_GAS_SENSOR_SEL: u16 = BME680_GAS_MEAS_SEL | BME680_RUN_GAS_SEL | BME680_NBCONV_SEL;
#[derive(Debug)]
pub enum Bme680Error { pub enum Bme680Error {
/// ///
/// aka BME680_E_NULL_PTR /// aka BME680_E_NULL_PTR
@ -252,7 +262,7 @@ impl Clone for GasSett {
} }
} }
#[derive(Default, Copy)] #[derive(Debug, Default, Copy)]
#[repr(C)] #[repr(C)]
pub struct FieldData { pub struct FieldData {
pub status: u8, pub status: u8,
@ -273,6 +283,7 @@ impl Clone for FieldData {
/// TODO - replace naming of "State" with something better /// TODO - replace naming of "State" with something better
/// aka new_fields - BME680_NEW_DATA_MSK /// aka new_fields - BME680_NEW_DATA_MSK
/// ///
#[derive(Debug)]
pub enum FieldDataState { pub enum FieldDataState {
NewData, NewData,
// TODO find better naming to no new data // TODO find better naming to no new data
@ -290,8 +301,8 @@ bitflags! {
#[derive(Default)] #[derive(Default)]
pub struct SensorSettings { pub struct SensorSettings {
gas_sett: GasSett, pub gas_sett: GasSett,
tph_sett: TphSett, pub tph_sett: TphSett,
} }
bitflags! { bitflags! {
@ -318,19 +329,45 @@ bitflags! {
} }
} }
pub struct I2CUtil {}
impl I2CUtil
{
pub fn get_regs_u8<I2C>(i2c: &mut I2C, reg_addr: u8) -> Result<u8>
where I2C: Read {
let mut buf = [0; 1];
match i2c.read(reg_addr, &mut buf) {
Ok(()) => Ok(buf[0]),
Err(_) => Err(Bme680Error::CommunicationFailure),
}
}
pub fn get_regs_i8<I2C>(i2c: &mut I2C, reg_addr: u8) -> Result<i8>
where I2C: Read {
let mut buf = [0; 1];
match i2c.read(reg_addr, &mut buf) {
Ok(()) => Ok(i8::try_from(buf[0]).expect("U8 overflow when reading register")),
Err(_) => Err(Bme680Error::CommunicationFailure),
}
}
}
#[repr(C)] #[repr(C)]
pub struct Bme680_dev<I2C, D> { pub struct Bme680_dev<I2C, D> {
pub i2c: I2C, i2c: I2C,
pub delay: D, delay: D,
pub dev_id: u8, dev_id: u8,
pub mem_page: u8, // pub mem_page: u8,
pub amb_temp: i8, amb_temp: i8,
pub calib: CalibData, calib: CalibData,
pub tph_sett: TphSett, // TODO remove ? as it may not reflect the state of the device
pub gas_sett: GasSett, tph_sett: TphSett,
pub power_mode: PowerMode, // TODO remove ? as it may not reflect the state of the device
pub new_fields: u8, gas_sett: GasSett,
pub info_msg: u8, // TODO remove ? as it may not reflect the state of the device
power_mode: PowerMode,
// pub new_fields: u8,
// pub info_msg: u8,
} }
fn boundary_check(value: Option<u8>, min: u8, max: u8) -> Result<u8> { fn boundary_check(value: Option<u8>, min: u8, max: u8) -> Result<u8> {
@ -358,35 +395,47 @@ where
D: DelayMs<u8>, D: DelayMs<u8>,
I2C: Read + Write, I2C: Read + Write,
{ {
pub fn init(&mut self) -> Result<()> { pub fn soft_reset(i2c: &mut I2C, delay: &mut D, dev_id: u8) -> Result<()> {
self.soft_reset()?; // TODO do we we really need TMP_BUFFER_LENGTH ?
let mut tmp_buff = Vec::with_capacity(BME680_TMP_BUFFER_LENGTH);
tmp_buff.push(BME680_SOFT_RESET_ADDR);
tmp_buff.push(BME680_SOFT_RESET_CMD);
/* Soft reset to restore it to default values*/ i2c.write(dev_id, tmp_buff.as_slice())
let chip_id = self.get_regs_u8(BME680_CHIP_ID_ADDR)?; .map_err(|_| Bme680Error::CommunicationFailure)?;
if chip_id == BME680_CHIP_ID {
self.calib = self.get_calib_data()?; delay.delay_ms(BME680_RESET_PERIOD);
Ok(()) Ok(())
}
pub fn init(mut i2c: I2C, mut delay: D, dev_id: u8, ambient_temperature: i8) -> Result<Bme680_dev<I2C, D>> {
Bme680_dev::soft_reset(&mut i2c, &mut delay, dev_id)?;
let mut buf = [0; 1];
/* Soft reset to restore it to default values*/
let chip_id = i2c.read(BME680_CHIP_ID_ADDR, &mut buf)
.map_err(|_| Bme680Error::CommunicationFailure)
.map(move |_| buf[0])?;
//let chip_id = dev.get_regs_u8(BME680_CHIP_ID_ADDR)?;
if chip_id == BME680_CHIP_ID {
let calib = Bme680_dev::<I2C, D>::get_calib_data::<I2C>(&mut i2c)?;
let dev = Bme680_dev {
i2c: i2c,
delay: delay,
dev_id: dev_id,
calib: calib,
amb_temp: ambient_temperature,
power_mode: PowerMode::ForcedMode,
tph_sett: Default::default(),
gas_sett: Default::default(),
};
Ok(dev)
} else { } else {
Err(Bme680Error::DeviceNotFound) Err(Bme680Error::DeviceNotFound)
} }
} }
pub fn get_regs_u8(&mut self, reg_addr: u8) -> Result<u8> {
let mut buf = [0; 1];
match self.i2c.read(reg_addr, &mut buf) {
Ok(()) => Ok(buf[0]),
Err(_) => Err(Bme680Error::CommunicationFailure),
}
}
pub fn get_regs_i8(&mut self, reg_addr: u8) -> Result<i8> {
let mut buf = [0; 1];
match self.i2c.read(reg_addr, &mut buf) {
Ok(()) => Ok(i8::try_from(buf[0]).expect("U8 overflow when reading register")),
Err(_) => Err(Bme680Error::CommunicationFailure),
}
}
pub fn bme680_set_regs(&mut self, reg: &[(u8, u8)]) -> Result<()> { pub fn bme680_set_regs(&mut self, reg: &[(u8, u8)]) -> Result<()> {
if reg.is_empty() || reg.len() > (BME680_TMP_BUFFER_LENGTH / 2) as usize { if reg.is_empty() || reg.len() > (BME680_TMP_BUFFER_LENGTH / 2) as usize {
return Err(Bme680Error::InvalidLength); return Err(Bme680Error::InvalidLength);
@ -404,35 +453,33 @@ where
.map_err(|_| Bme680Error::CommunicationFailure) .map_err(|_| Bme680Error::CommunicationFailure)
} }
pub fn soft_reset(&mut self) -> Result<()> {
self.bme680_set_regs(&[(BME680_SOFT_RESET_ADDR, BME680_SOFT_RESET_CMD)])?;
self.delay.delay_ms(BME680_RESET_PERIOD);
Ok(())
}
// TODO replace parameter desired_settings with safe flags // TODO replace parameter desired_settings with safe flags
pub fn bme680_set_sensor_settings( // TODO replace all the NullPtr mess and split this into separate methods
pub fn set_sensor_settings(
&mut self, &mut self,
desired_settings: DesiredSensorSettings, desired_settings: DesiredSensorSettings,
gas_sett: Option<GasSett>, sensor_settings: &SensorSettings,
) -> Result<()> { ) -> Result<()> {
let tph_sett = sensor_settings.tph_sett;
let gas_sett = sensor_settings.gas_sett;
let mut reg_addr: u8; let mut reg_addr: u8;
let mut reg = Vec::with_capacity(BME680_REG_BUFFER_LENGTH); let mut reg = Vec::with_capacity(BME680_REG_BUFFER_LENGTH);
let intended_power_mode = self.power_mode; let intended_power_mode = self.power_mode;
if desired_settings.contains(DesiredSensorSettings::GAS_MEAS_SEL) { if desired_settings.contains(DesiredSensorSettings::GAS_MEAS_SEL) {
self.set_gas_config(gas_sett.unwrap())?; self.set_gas_config(gas_sett)?;
} }
let power_mode = self.power_mode; let power_mode = self.power_mode;
self.bme680_set_sensor_mode(power_mode)?; self.set_sensor_mode(power_mode)?;
/* Selecting the filter */ /* Selecting the filter */
if desired_settings.contains(DesiredSensorSettings::FILTER_SEL) { if desired_settings.contains(DesiredSensorSettings::FILTER_SEL) {
let tph_sett_filter = boundary_check(self.tph_sett.filter, 0, 7)?; let tph_sett_filter = boundary_check(tph_sett.filter, 0, 7)?;
reg_addr = 0x75u8; reg_addr = 0x75u8;
let mut data = self.get_regs_u8(reg_addr)?; let mut data = I2CUtil::get_regs_u8(&mut self.i2c, reg_addr)?;
// TODO duplicate check of condition ? // TODO duplicate check of condition ?
if desired_settings.contains(DesiredSensorSettings::FILTER_SEL) { if desired_settings.contains(DesiredSensorSettings::FILTER_SEL) {
@ -443,10 +490,9 @@ where
} }
if desired_settings.contains(DesiredSensorSettings::HCNTRL_SEL) { if desired_settings.contains(DesiredSensorSettings::HCNTRL_SEL) {
let gas_sett_heatr_ctrl = boundary_check(gas_sett.heatr_ctrl, 0x0u8, 0x8u8)?;
let gas_sett_heatr_ctrl = boundary_check(self.gas_sett.heatr_ctrl, 0x0u8, 0x8u8)?;
reg_addr = 0x70u8; reg_addr = 0x70u8;
let mut data = self.get_regs_u8(reg_addr)?; let mut data = I2CUtil::get_regs_u8(&mut self.i2c, reg_addr)?;
data = (data as (i32) & !0x8i32 | gas_sett_heatr_ctrl as (i32) & 0x8) as (u8) ; data = (data as (i32) & !0x8i32 | gas_sett_heatr_ctrl as (i32) & 0x8) as (u8) ;
reg.push((reg_addr, data)); reg.push((reg_addr, data));
} }
@ -456,16 +502,16 @@ where
.contains(DesiredSensorSettings::OST_SEL | DesiredSensorSettings::OSP_SEL) .contains(DesiredSensorSettings::OST_SEL | DesiredSensorSettings::OSP_SEL)
{ {
reg_addr = 0x74u8; reg_addr = 0x74u8;
let mut data = self.get_regs_u8(reg_addr)?; let mut data = I2CUtil::get_regs_u8(&mut self.i2c, reg_addr)?;
if desired_settings.contains(DesiredSensorSettings::OST_SEL) { if desired_settings.contains(DesiredSensorSettings::OST_SEL) {
let tph_sett_os_temp = boundary_check(self.tph_sett.os_temp, 0, 5)?; let tph_sett_os_temp = boundary_check(tph_sett.os_temp, 0, 5)?;
data = (data as (i32) & !0xe0i32 | tph_sett_os_temp as (i32) << 5i32 & 0xe0i32) data = (data as (i32) & !0xe0i32 | tph_sett_os_temp as (i32) << 5i32 & 0xe0i32)
as (u8); as (u8);
} }
if desired_settings.contains(DesiredSensorSettings::OSP_SEL) { if desired_settings.contains(DesiredSensorSettings::OSP_SEL) {
let tph_sett_os_pres = self.tph_sett.os_temp.ok_or(Bme680Error::NulltPtr)?; let tph_sett_os_pres = tph_sett.os_temp.ok_or(Bme680Error::NulltPtr)?;
data = (data as (i32) & !0x1ci32 | tph_sett_os_pres as (i32) << 2i32 & 0x1ci32) data = (data as (i32) & !0x1ci32 | tph_sett_os_pres as (i32) << 2i32 & 0x1ci32)
as (u8); as (u8);
} }
@ -477,7 +523,7 @@ where
if desired_settings.contains(DesiredSensorSettings::OSH_SEL) { if desired_settings.contains(DesiredSensorSettings::OSH_SEL) {
let tph_sett_os_hum = boundary_check(self.tph_sett.os_hum, 0, 5)?; let tph_sett_os_hum = boundary_check(self.tph_sett.os_hum, 0, 5)?;
reg_addr = 0x72u8; reg_addr = 0x72u8;
let mut data = self.get_regs_u8(reg_addr)?; let mut data = I2CUtil::get_regs_u8(&mut self.i2c, reg_addr)?;
data = (data as (i32) & !0x7i32 | tph_sett_os_hum as (i32) & 0x7i32) as (u8); data = (data as (i32) & !0x7i32 | tph_sett_os_hum as (i32) & 0x7i32) as (u8);
reg.push((reg_addr, data)); reg.push((reg_addr, data));
} }
@ -487,16 +533,16 @@ where
.contains(DesiredSensorSettings::RUN_GAS_SEL | DesiredSensorSettings::NBCONV_SEL) .contains(DesiredSensorSettings::RUN_GAS_SEL | DesiredSensorSettings::NBCONV_SEL)
{ {
reg_addr = 0x71u8; reg_addr = 0x71u8;
let mut data = self.get_regs_u8(reg_addr)?; let mut data = I2CUtil::get_regs_u8(&mut self.i2c, reg_addr)?;
if desired_settings.contains(DesiredSensorSettings::RUN_GAS_SEL) { if desired_settings.contains(DesiredSensorSettings::RUN_GAS_SEL) {
let gas_sett_run_gas = boundary_check(self.gas_sett.run_gas, 0, 1)?; let gas_sett_run_gas = boundary_check(gas_sett.run_gas, 0, 1)?;
data = (data as (i32) & !0x10i32 | gas_sett_run_gas as (i32) << 4i32 & 0x10i32) data = (data as (i32) & !0x10i32 | gas_sett_run_gas as (i32) << 4i32 & 0x10i32)
as (u8); as (u8);
} }
if desired_settings.contains(DesiredSensorSettings::NBCONV_SEL) { if desired_settings.contains(DesiredSensorSettings::NBCONV_SEL) {
let gas_sett_nb_conv = boundary_check(self.gas_sett.nb_conv, 0, 10)?; let gas_sett_nb_conv = boundary_check(gas_sett.nb_conv, 0, 10)?;
data = (data as (i32) & !0xfi32 | gas_sett_nb_conv as (i32) & 0xfi32) as (u8); data = (data as (i32) & !0xfi32 | gas_sett_nb_conv as (i32) & 0xfi32) as (u8);
} }
@ -511,38 +557,38 @@ where
} }
// TODO replace desired_settings with proper flags type see lib.rs // TODO replace desired_settings with proper flags type see lib.rs
pub fn get_sensor_settings(&mut self, desired_settings: u16) -> Result<SensorSettings> { pub fn get_sensor_settings(&mut self, desired_settings: DesiredSensorSettings) -> Result<SensorSettings> {
let reg_addr: u8 = 0x70u8; let reg_addr: u8 = 0x70u8;
let mut data_array: [u8; BME680_REG_BUFFER_LENGTH] = [0; BME680_REG_BUFFER_LENGTH]; let mut data_array: [u8; BME680_REG_BUFFER_LENGTH] = [0; BME680_REG_BUFFER_LENGTH];
let mut sensor_settings: SensorSettings = Default::default(); let mut sensor_settings: SensorSettings = Default::default();
self.i2c.read(reg_addr, &mut data_array).map_err(|_| Bme680Error::CommunicationFailure)?; self.i2c.read(reg_addr, &mut data_array).map_err(|_| Bme680Error::CommunicationFailure)?;
if desired_settings & BME680_GAS_MEAS_SEL != 0 { if desired_settings.contains(DesiredSensorSettings::GAS_MEAS_SEL){
sensor_settings.gas_sett = self.get_gas_config()?; sensor_settings.gas_sett = self.get_gas_config()?;
} }
if desired_settings & BME680_FILTER_SEL != 0 { if desired_settings.contains(DesiredSensorSettings::FILTER_SEL) {
sensor_settings.tph_sett.filter = sensor_settings.tph_sett.filter =
Some(((data_array[5usize] as (i32) & 0x1ci32) >> 2i32) as (u8)); Some(((data_array[5usize] as (i32) & 0x1ci32) >> 2i32) as (u8));
} }
if desired_settings & (BME680_OST_SEL | BME680_OSP_SEL) != 0 { if desired_settings.contains(DesiredSensorSettings::OST_SEL | DesiredSensorSettings::OSP_SEL) {
sensor_settings.tph_sett.os_temp = sensor_settings.tph_sett.os_temp =
Some(((data_array[4usize] as (i32) & 0xe0i32) >> 5i32) as (u8)); Some(((data_array[4usize] as (i32) & 0xe0i32) >> 5i32) as (u8));
sensor_settings.tph_sett.os_pres = sensor_settings.tph_sett.os_pres =
Some(((data_array[4usize] as (i32) & 0x1ci32) >> 2i32) as (u8)); Some(((data_array[4usize] as (i32) & 0x1ci32) >> 2i32) as (u8));
} }
if desired_settings & BME680_OSH_SEL != 0 { if desired_settings.contains(DesiredSensorSettings::OSH_SEL) {
sensor_settings.tph_sett.os_hum = Some((data_array[2usize] as (i32) & 0x7i32) as (u8)); sensor_settings.tph_sett.os_hum = Some((data_array[2usize] as (i32) & 0x7i32) as (u8));
} }
if desired_settings & BME680_HCNTRL_SEL != 0 { if desired_settings.contains(DesiredSensorSettings::HCNTRL_SEL) {
sensor_settings.gas_sett.heatr_ctrl = Some((data_array[0usize] as (i32) & 0x8i32) as (u8)); sensor_settings.gas_sett.heatr_ctrl = Some((data_array[0usize] as (i32) & 0x8i32) as (u8));
} }
if desired_settings & (BME680_RUN_GAS_SEL | BME680_NBCONV_SEL) != 0 { if desired_settings.contains(DesiredSensorSettings::RUN_GAS_SEL | DesiredSensorSettings::NBCONV_SEL) {
sensor_settings.gas_sett.nb_conv = Some((data_array[1usize] as (i32) & 0xfi32) as (u8)); sensor_settings.gas_sett.nb_conv = Some((data_array[1usize] as (i32) & 0xfi32) as (u8));
sensor_settings.gas_sett.run_gas = sensor_settings.gas_sett.run_gas =
Some(((data_array[1usize] as (i32) & 0x10i32) >> 4i32) as (u8)); Some(((data_array[1usize] as (i32) & 0x10i32) >> 4i32) as (u8));
@ -551,14 +597,14 @@ where
Ok(sensor_settings) Ok(sensor_settings)
} }
pub fn bme680_set_sensor_mode(&mut self, target_power_mode: PowerMode) -> Result<()> { pub fn set_sensor_mode(&mut self, target_power_mode: PowerMode) -> Result<()> {
let mut tmp_pow_mode: u8; let mut tmp_pow_mode: u8;
let mut current_power_mode: PowerMode; let mut current_power_mode: PowerMode;
let reg_addr: u8 = 0x74u8; let reg_addr: u8 = 0x74u8;
/* Call repeatedly until in sleep */ /* Call repeatedly until in sleep */
loop { loop {
tmp_pow_mode = self.get_regs_u8(BME680_CONF_T_P_MODE_ADDR)?; tmp_pow_mode = I2CUtil::get_regs_u8(&mut self.i2c, BME680_CONF_T_P_MODE_ADDR)?;
/* Put to sleep before changing mode */ /* Put to sleep before changing mode */
current_power_mode = PowerMode::from(tmp_pow_mode & BME680_MODE_MSK); current_power_mode = PowerMode::from(tmp_pow_mode & BME680_MODE_MSK);
@ -583,7 +629,7 @@ where
} }
pub fn get_sensor_mode(&mut self) -> Result<PowerMode> { pub fn get_sensor_mode(&mut self) -> Result<PowerMode> {
let regs = self.get_regs_u8(BME680_CONF_T_P_MODE_ADDR)?; let regs = I2CUtil::get_regs_u8(&mut self.i2c, BME680_CONF_T_P_MODE_ADDR)?;
let mode = regs & BME680_MODE_MSK; let mode = regs & BME680_MODE_MSK;
Ok(PowerMode::from(mode)) Ok(PowerMode::from(mode))
} }
@ -605,14 +651,14 @@ where
self.gas_sett.heatr_dur = Some((duration as (i32) - tph_dur as (u16) as (i32)) as (u16)); self.gas_sett.heatr_dur = Some((duration as (i32) - tph_dur as (u16) as (i32)) as (u16));
} }
pub fn get_profile_dur(&self, tph_sett: TphSett, gas_sett: GasSett) -> Result<u16> { pub fn get_profile_dur(&self, sensor_settings: &SensorSettings) -> Result<u16> {
let os_to_meas_cycles: [u8; 6] = [0u8, 1u8, 2u8, 4u8, 8u8, 16u8]; let os_to_meas_cycles: [u8; 6] = [0u8, 1u8, 2u8, 4u8, 8u8, 16u8];
// TODO check if the following unwrap_ors do not change behaviour // TODO check if the following unwrap_ors do not change behaviour
let mut meas_cycles = os_to_meas_cycles[tph_sett.os_temp.unwrap_or(0) as (usize)] as (u32); let mut meas_cycles = os_to_meas_cycles[sensor_settings.tph_sett.os_temp.unwrap_or(0) as (usize)] as (u32);
meas_cycles = meas_cycles =
meas_cycles.wrapping_add(os_to_meas_cycles[tph_sett.os_pres.unwrap_or(0) as (usize)] as (u32)); meas_cycles.wrapping_add(os_to_meas_cycles[sensor_settings.tph_sett.os_pres.unwrap_or(0) as (usize)] as (u32));
meas_cycles = meas_cycles =
meas_cycles.wrapping_add(os_to_meas_cycles[tph_sett.os_hum.unwrap_or(0) as (usize)] as (u32)); meas_cycles.wrapping_add(os_to_meas_cycles[sensor_settings.tph_sett.os_hum.unwrap_or(0) as (usize)] as (u32));
let mut tph_dur = meas_cycles.wrapping_mul(1963u32); let mut tph_dur = meas_cycles.wrapping_mul(1963u32);
tph_dur = tph_dur.wrapping_add(477u32.wrapping_mul(4u32)); tph_dur = tph_dur.wrapping_add(477u32.wrapping_mul(4u32));
tph_dur = tph_dur.wrapping_add(477u32.wrapping_mul(5u32)); tph_dur = tph_dur.wrapping_add(477u32.wrapping_mul(5u32));
@ -620,8 +666,8 @@ where
tph_dur = tph_dur.wrapping_div(1000u32); tph_dur = tph_dur.wrapping_div(1000u32);
tph_dur = tph_dur.wrapping_add(1u32); tph_dur = tph_dur.wrapping_add(1u32);
let mut duration = tph_dur as (u16); let mut duration = tph_dur as (u16);
if gas_sett.run_gas.unwrap_or(0) != 0 { if sensor_settings.gas_sett.run_gas.unwrap_or(0) != 0 {
duration = duration + gas_sett.heatr_dur.ok_or(Bme680Error::NulltPtr)?; duration = duration + sensor_settings.gas_sett.heatr_dur.ok_or(Bme680Error::NulltPtr)?;
} }
Ok(duration) Ok(duration)
} }
@ -637,16 +683,18 @@ where
} }
} }
fn get_calib_data(&mut self) -> Result<CalibData> { fn get_calib_data<I2CX>(i2c:&mut I2CX) -> Result<CalibData>
where I2CX: Read
{
let mut calib: CalibData = Default::default(); let mut calib: CalibData = Default::default();
let mut coeff_array: [u8; BME680_COEFF_SIZE] = [0; BME680_COEFF_SIZE]; let mut coeff_array: [u8; BME680_COEFF_SIZE] = [0; BME680_COEFF_SIZE];
self.i2c.read( i2c.read(
BME680_COEFF_ADDR1, BME680_COEFF_ADDR1,
&mut coeff_array, &mut coeff_array,
).map_err(|_| Bme680Error::CommunicationFailure)?; ).map_err(|_| Bme680Error::CommunicationFailure)?;
self.i2c.read( i2c.read(
BME680_COEFF_ADDR2, BME680_COEFF_ADDR2,
&mut coeff_array, &mut coeff_array,
).map_err(|_| Bme680Error::CommunicationFailure)?; ).map_err(|_| Bme680Error::CommunicationFailure)?;
@ -686,11 +734,11 @@ where
| coeff_array[35usize] as (u16) as (i32)) as (i16); | coeff_array[35usize] as (u16) as (i32)) as (i16);
calib.par_gh3 = coeff_array[38usize] as (i8); calib.par_gh3 = coeff_array[38usize] as (i8);
calib.res_heat_range = (self.get_regs_u8(BME680_ADDR_RES_HEAT_RANGE_ADDR)? & 0x30) / 16; calib.res_heat_range = (I2CUtil::get_regs_u8::<I2CX>(i2c, BME680_ADDR_RES_HEAT_RANGE_ADDR)? & 0x30) / 16;
calib.res_heat_val = self.get_regs_i8(BME680_ADDR_RES_HEAT_VAL_ADDR)?; calib.res_heat_val = I2CUtil::get_regs_i8::<I2CX>(i2c, BME680_ADDR_RES_HEAT_VAL_ADDR)?;
calib.range_sw_err = (self.get_regs_u8(BME680_ADDR_RANGE_SW_ERR_ADDR)? & BME680_RSERROR_MSK) / 16; calib.range_sw_err = (I2CUtil::get_regs_u8::<I2CX>(i2c, BME680_ADDR_RANGE_SW_ERR_ADDR)? & BME680_RSERROR_MSK) / 16;
Ok(calib) Ok(calib)
} }
@ -714,8 +762,8 @@ where
// TODO move both GasSett fields to new struct // TODO move both GasSett fields to new struct
let mut gas_sett: GasSett = Default::default(); let mut gas_sett: GasSett = Default::default();
// TODO figure out if heat_temp and dur can be u8 // TODO figure out if heat_temp and dur can be u8
gas_sett.heatr_temp = Some(self.get_regs_u8(BME680_ADDR_SENS_CONF_START)? as u16); gas_sett.heatr_temp = Some(I2CUtil::get_regs_u8(&mut self.i2c, BME680_ADDR_SENS_CONF_START)? as u16);
gas_sett.heatr_dur = Some(self.get_regs_u8(BME680_ADDR_GAS_CONF_START)? as u16); gas_sett.heatr_dur = Some(I2CUtil::get_regs_u8(&mut self.i2c, BME680_ADDR_GAS_CONF_START)? as u16);
Ok(gas_sett) Ok(gas_sett)
} }