Skip to content

Commit

Permalink
Bumped all dependencies to the HAL 1.0 version
Browse files Browse the repository at this point in the history
  • Loading branch information
FloppyDisck committed Jun 25, 2024
1 parent cd881eb commit 68d3ae4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 20 deletions.
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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"
embedded-hal-mock = "0.11.1"
rstest = "0.21.0"
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -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()?;
Expand Down
25 changes: 13 additions & 12 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -30,23 +30,23 @@ pub struct SoilSensor<I2C: 'static + Send + Sync, D> {
// 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<I2C, D> SoilSensor<I2C, D>
where
I2C: 'static + Send + Sync,
D: DelayUs<u16>,
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,
}
}
Expand Down Expand Up @@ -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
Expand All @@ -83,8 +84,8 @@ where

impl<I2C, D> SoilSensor<I2C, D>
where
I2C: i2c::Write + i2c::Read + Send + Sync,
D: DelayUs<u16>,
I2C: I2c + Send + Sync,
D: DelayNs,
{
pub fn temperature(&mut self) -> Result<f32, SoilMoistureSensorError> {
let mut buffer = [0; 4];
Expand All @@ -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)
Expand Down

0 comments on commit 68d3ae4

Please sign in to comment.