-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
expanded with more tests and slightly improved internal code (#9)
* expanded with more tests and slightly improved internal code * fixed tests * fixed alloc issue * added project example * updated documentation * fmt
- Loading branch information
1 parent
4687808
commit e5a4fff
Showing
13 changed files
with
314 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,19 @@ | ||
[package] | ||
name = "sht31" | ||
description = "A library for the SHT31 temperature and humidity sensor" | ||
version = "0.3.1" | ||
version = "0.3.2" | ||
edition = "2021" | ||
license = "MIT" | ||
repository = "https://github.com/FloppyDisck/SHT31-rs" | ||
readme = "README.md" | ||
keywords = ["embedded", "sensor", "temperature", "humidity"] | ||
categories = ["embedded"] | ||
|
||
[features] | ||
thiserror = ["dep:thiserror"] | ||
|
||
[dependencies] | ||
embedded-hal = "1.0.0" | ||
|
||
crc = "3.0.0" | ||
thiserror = { version = "1.0.38", optional = true } | ||
thiserror = { version = "2.0.3", default-features = false } | ||
|
||
[dev-dependencies] | ||
embedded-hal-mock = "0.11.1" | ||
rstest = "0.21.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
[target.xtensa-esp32-none-elf] | ||
runner = "espflash flash --monitor" | ||
|
||
[env] | ||
ESP_LOG="INFO" | ||
|
||
[build] | ||
rustflags = [ | ||
"-C", "link-arg=-nostartfiles", | ||
] | ||
|
||
target = "xtensa-esp32-none-elf" | ||
|
||
[unstable] | ||
build-std = ["core"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
[package] | ||
name = "esp32" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
esp-backtrace = { version = "0.14.1", features = [ | ||
"esp32", | ||
"exception-handler", | ||
"panic-handler", | ||
"println", | ||
]} | ||
|
||
esp-hal = { version = "0.22.0", features = [ | ||
"esp32", | ||
] } | ||
esp-println = { version = "0.12.0", features = ["esp32", "log"] } | ||
log = { version = "0.4.21" } | ||
sht31 = { path = "../../." } | ||
|
||
[profile.dev] | ||
# Rust debug is too slow. | ||
# For debug builds always builds with some optimization | ||
opt-level = "s" | ||
|
||
[profile.release] | ||
codegen-units = 1 # LLVM can perform better optimizations using a single thread | ||
debug = 2 | ||
debug-assertions = false | ||
incremental = false | ||
lto = 'fat' | ||
opt-level = 's' | ||
overflow-checks = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
fn main() { | ||
println!("cargo:rustc-link-arg-bins=-Tlinkall.x"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[toolchain] | ||
channel = "esp" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#![no_std] | ||
#![no_main] | ||
|
||
use esp_backtrace as _; | ||
use esp_hal::delay::Delay; | ||
use esp_hal::i2c::master::{Config, I2c}; | ||
use esp_hal::prelude::*; | ||
use sht31::prelude::*; | ||
use log::info; | ||
|
||
#[entry] | ||
fn main() -> ! { | ||
esp_println::logger::init_logger_from_env(); | ||
let peripherals = esp_hal::init({ | ||
let mut config = esp_hal::Config::default(); | ||
config.cpu_clock = CpuClock::max(); | ||
config | ||
}); | ||
|
||
info!("Initializing SHT31"); | ||
let i2c = I2c::new( | ||
peripherals.I2C0, | ||
Config::default() | ||
); | ||
let delay = Delay::new(); | ||
let mut sht = SHT31::new(i2c, delay); | ||
|
||
loop { | ||
let reading = sht.read().unwrap(); | ||
info!("Temperature: {}\nHumidity: {}", reading.temperature, reading.humidity); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#![no_std] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,37 @@ | ||
use thiserror::Error; | ||
|
||
pub type Result<T> = core::result::Result<T, SHTError>; | ||
#[cfg_attr(feature = "thiserror", derive(thiserror::Error))] | ||
#[derive(Copy, Clone, Debug, Ord, PartialOrd, Eq, PartialEq)] | ||
#[derive(Error, Copy, Clone, Debug, Ord, PartialOrd, Eq, PartialEq)] | ||
pub enum SHTError { | ||
#[cfg_attr(feature = "thiserror", error("Read I2C Error"))] | ||
#[error("Read I2C Error")] | ||
ReadI2CError, | ||
#[cfg_attr(feature = "thiserror", error("Write Read I2C Error"))] | ||
#[error("Write Read I2C Error")] | ||
WriteReadI2CError, | ||
#[cfg_attr(feature = "thiserror", error("Write I2C Error"))] | ||
#[error("Write I2C Error")] | ||
WriteI2CError, | ||
#[cfg_attr(feature = "thiserror", error("Humidity bytes [{bytes_start:#x}, {bytes_end:#x}] expected {expected_checksum:#x} but got the checksum {calculated_checksum:#x}"))] | ||
#[error("Humidity bytes [{bytes_start:#x}, {bytes_end:#x}] expected {expected_checksum:#x} but got the checksum {calculated_checksum:#x}")] | ||
InvalidHumidityChecksumError { | ||
bytes_start: u8, | ||
bytes_end: u8, | ||
expected_checksum: u8, | ||
calculated_checksum: u8, | ||
}, | ||
#[cfg_attr(feature = "thiserror", error("Temperature bytes [{bytes_start:#x}, {bytes_end:#x}] expected {expected_checksum:#x} but got the checksum {calculated_checksum:#x}"))] | ||
#[error("Temperature bytes [{bytes_start:#x}, {bytes_end:#x}] expected {expected_checksum:#x} but got the checksum {calculated_checksum:#x}")] | ||
InvalidTemperatureChecksumError { | ||
bytes_start: u8, | ||
bytes_end: u8, | ||
expected_checksum: u8, | ||
calculated_checksum: u8, | ||
}, | ||
#[cfg_attr(feature = "thiserror", error("Status bytes [{bytes_start:#x}, {bytes_end:#x}] expected {expected_checksum:#x} but got the checksum {calculated_checksum:#x}"))] | ||
#[error("Status bytes [{bytes_start:#x}, {bytes_end:#x}] expected {expected_checksum:#x} but got the checksum {calculated_checksum:#x}")] | ||
InvalidStatusChecksumError { | ||
bytes_start: u8, | ||
bytes_end: u8, | ||
expected_checksum: u8, | ||
calculated_checksum: u8, | ||
}, | ||
#[cfg_attr(feature = "thiserror", error("Single shot reading timeout"))] | ||
#[error("Single shot reading timeout")] | ||
ReadingTimeoutError, | ||
#[cfg_attr(feature = "thiserror", error("This error should not happen"))] | ||
#[error("This error should not happen")] | ||
PlaceholderError, | ||
} |
Oops, something went wrong.