From 68d3ae4b3bca63faadef5506a5385f6f6ddf18c5 Mon Sep 17 00:00:00 2001 From: Guy Garcia Date: Tue, 25 Jun 2024 00:35:50 -0400 Subject: [PATCH] Bumped all dependencies to the HAL 1.0 version --- Cargo.toml | 8 ++++---- README.md | 9 +++++---- src/lib.rs | 25 +++++++++++++------------ 3 files changed, 22 insertions(+), 20 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 17ce120..522964e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "stemma_soil_moisture_sensor" description = "A pure generic I2C crate for the Adafruit STEMMA soil moisture sensor " -version = "0.1.1" +version = "0.2.0" edition = "2021" license = "MIT" repository = "https://github.com/FloppyDisck/STEMMA_soil_moisture_sensor" @@ -13,10 +13,10 @@ categories = ["embedded"] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -embedded-hal = "0.2.7" +embedded-hal = "1.0.0" crc = "3.0.0" thiserror-no-std = "2.0.2" [dev-dependencies] -embedded-hal-mock = "0.9.0" -rstest = "0.16.0" \ No newline at end of file +embedded-hal-mock = "0.11.1" +rstest = "0.21.0" \ No newline at end of file diff --git a/README.md b/README.md index ff11f60..b043144 100644 --- a/README.md +++ b/README.md @@ -1,18 +1,19 @@ -# Adafruit STEMMA soil moisture sensor   [![Build Status]][actions] [![Latest Version]][crates.io] -[Build Status]: https://img.shields.io/github/actions/workflow/status/FloppyDisck/STEMMA_soil_moisture_sensor/rust.yml?branch=main -[actions]: https://github.com/FloppyDisck/STEMMA_soil_moisture_sensor/actions?query=branch%3Amain +# Adafruit STEMMA soil moisture sensor   [![Latest Version]][crates.io] + [Latest Version]: https://img.shields.io/crates/v/STEMMA_soil_moisture_sensor.svg + [crates.io]: https://crates.io/crates/STEMMA_soil_moisture_sensor A pure generic I2C crate for the Adafruit STEMMA soil moisture sensor ## Usage + ```rust use stemma_soil_moisture_sensor::prelude::*; fn main() -> Result<(), SoilMoistureSensorError> { // Setup your I2C and import relevant delay let i2c = ...; - + let moisture = SoilSensor::new(i2c, Delay).with_units(TemperatureUnit::Fahrenheit); let temp = moisture.temperature()?; let moist = moisture.moisture()?; diff --git a/src/lib.rs b/src/lib.rs index 3288234..c86f1f5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,7 +1,7 @@ #![no_std] -use embedded_hal::blocking::delay::DelayUs; -use embedded_hal::blocking::i2c; +use embedded_hal::delay::DelayNs; +use embedded_hal::i2c::I2c; pub mod error; use crate::error::SoilMoistureSensorError; @@ -30,23 +30,23 @@ pub struct SoilSensor { // https://github.com/adafruit/Adafruit_Seesaw/blob/8728936a5d1a0a7bf2887a82adb0828b70556a45/Adafruit_seesaw.cpp#L737 delay: D, unit: TemperatureUnit, - temp_delay: u16, - moisture_delay: u16, + temp_delay: u32, + moisture_delay: u32, address: u8, } impl SoilSensor where I2C: 'static + Send + Sync, - D: DelayUs, + D: DelayNs, { pub fn new(i2c: I2C, delay: D) -> Self { Self { i2c, delay, unit: TemperatureUnit::Fahrenheit, - temp_delay: 125, - moisture_delay: 5000, + temp_delay: 125000, + moisture_delay: 5000000, address: 0x36, } } @@ -74,7 +74,8 @@ where self } - pub fn with_delay(mut self, temp: u16, moisture: u16) -> Self { + /// Sets the reading delay in nanoseconds + pub fn with_delay(mut self, temp: u32, moisture: u32) -> Self { self.temp_delay = temp; self.moisture_delay = moisture; self @@ -83,8 +84,8 @@ where impl SoilSensor where - I2C: i2c::Write + i2c::Read + Send + Sync, - D: DelayUs, + I2C: I2c + Send + Sync, + D: DelayNs, { pub fn temperature(&mut self) -> Result { let mut buffer = [0; 4]; @@ -106,12 +107,12 @@ where &mut self, bytes: &[u8], buffer: &mut [u8], - delay: u16, + delay_ns: u32, ) -> Result<(), SoilMoistureSensorError> { self.i2c .write(self.address, bytes) .map_err(|_| SoilMoistureSensorError::WriteI2CError)?; - self.delay.delay_us(delay); + self.delay.delay_ns(delay_ns); self.i2c .read(self.address, buffer) .map_err(|_| SoilMoistureSensorError::ReadI2CError)