Skip to content

Commit

Permalink
Update to embedded hal v.1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
hauju committed Jan 18, 2024
1 parent 17f9740 commit 51b02e5
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 90 deletions.
22 changes: 11 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "scd4x"
version = "0.2.2"
version = "0.3.0"
authors = ["Hauke Jung <hauke.jung@outlook.de>"]
documentation = "https://docs.rs/scd4x"
repository = "https://github.com/hauju/scd4x-rs.git"
Expand All @@ -18,22 +18,22 @@ util = [ "structopt", "simplelog", "humantime", "linux-embedded-hal", "anyhow" ]
default = [ "util" ]

[dependencies]
sensirion-i2c = "0.1"
embedded-hal = "0.2"
sensirion-i2c = "0.2"
embedded-hal = "1.0"

log = { version = "0.4.16", default_features = false }
defmt = { version = "0.3.0", optional = true }
anyhow = { version = "1.0.56", optional=true, default_features = false }
log = { version = "0.4.20", default_features = false }
defmt = { version = "0.3.5", optional = true }
anyhow = { version = "1.0.79", optional=true, default_features = false }

structopt = { version = "0.3.26", optional = true }
linux-embedded-hal = { version = "0.3.2", optional = true }
simplelog = { version = "0.12.0", optional = true }
linux-embedded-hal = { version = "0.4", optional = true }
simplelog = { version = "0.12.1", optional = true }
humantime = { version = "2.1.0", optional = true }


[dev-dependencies]
linux-embedded-hal = "0.3"
embedded-hal-mock = "0.8"
linux-embedded-hal = "0.4"
embedded-hal-mock = "0.10"


[[bin]]
name = "scd4x-util"
Expand Down
17 changes: 8 additions & 9 deletions bin/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use embedded_hal::blocking::delay::DelayMs;
use hal::{Delay, I2cdev, i2cdev::linux::LinuxI2CError};
use linux_embedded_hal as hal;

use embedded_hal::delay::DelayNs;
use linux_embedded_hal::{Delay, I2cdev, i2cdev::linux::LinuxI2CError};

use log::{debug, info, error};

Expand Down Expand Up @@ -35,7 +35,6 @@ pub struct Options {


fn main() -> Result<(), Error<LinuxI2CError>> {

// Load options
let opts = Options::from_args();

Expand All @@ -62,19 +61,19 @@ fn main() -> Result<(), Error<LinuxI2CError>> {

#[cfg(feature = "scd41")]
sensor.wake_up();
sensor.stop_periodic_measurement()?;
sensor.reinit()?;
sensor.stop_periodic_measurement().unwrap();
sensor.reinit().unwrap();

let serial = sensor.serial_number()?;
let serial = sensor.serial_number().unwrap();
info!("Serial: {:#04x}", serial);

debug!("Starting periodic measurement");
sensor.start_periodic_measurement()?;
sensor.start_periodic_measurement().unwrap();

debug!("Waiting for first measurement... (5 sec)");

loop {
hal::Delay.delay_ms(5000u16);
Delay.delay_ms(5000);

debug!("Waiting for data ready");
loop {
Expand Down
8 changes: 4 additions & 4 deletions examples/linux.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use embedded_hal::blocking::delay::DelayMs;
use hal::{Delay, I2cdev};
use linux_embedded_hal as hal;

use embedded_hal::delay::DelayNs;
use linux_embedded_hal::{Delay, I2cdev};

use scd4x::Scd4x;

Expand All @@ -19,7 +19,7 @@ fn main() {
sensor.start_periodic_measurement().unwrap();
println!("Waiting for first measurement... (5 sec)");
loop {
hal::Delay.delay_ms(5000u16);
Delay.delay_ms(5000);

let data = sensor.measurement().unwrap();

Expand Down
17 changes: 0 additions & 17 deletions src/error.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
use embedded_hal as hal;
use hal::blocking::i2c::{Read, Write};
use sensirion_i2c::i2c;

/// SCD4X errors
#[derive(Debug, PartialEq)]
Expand All @@ -22,17 +19,3 @@ pub enum Error<E> {
/// Internal fail
Internal
}

impl<E, I2cWrite, I2cRead> From<i2c::Error<I2cWrite, I2cRead>> for Error<E>
where
I2cWrite: Write<Error = E>,
I2cRead: Read<Error = E>,
{
fn from(err: i2c::Error<I2cWrite, I2cRead>) -> Self {
match err {
i2c::Error::Crc => Error::Crc,
i2c::Error::I2cWrite(e) => Error::I2c(e),
i2c::Error::I2cRead(e) => Error::I2c(e),
}
}
}
4 changes: 0 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@

/// Log functions for internal use, use `crate::log::*`
mod log {
// Default to logging with log
#[cfg(not(feature = "defmt"))]
pub use log::{trace, debug, info, warn, error};

// Replace with defmt if enabled
#[cfg(feature = "defmt")]
pub use defmt::{trace, debug, info, warn, error};
Expand Down

0 comments on commit 51b02e5

Please sign in to comment.