From 35c2adef929c2c1062cf62c1ae3427331f6f997c Mon Sep 17 00:00:00 2001 From: Denis Nutiu Date: Tue, 27 Feb 2024 22:12:24 +0200 Subject: [PATCH] refactor: fix clippy hints --- src/calculation.rs | 2 +- src/i2c.rs | 11 +++-------- src/lib.rs | 4 ++-- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/src/calculation.rs b/src/calculation.rs index a9fd829..cf698e6 100644 --- a/src/calculation.rs +++ b/src/calculation.rs @@ -39,7 +39,7 @@ impl Calculation { let mut factor: u8 = 0u8; const MILLIS_PER_SEC: u64 = 1_000; const NANOS_PER_MILLI: u64 = 1_000_000; - let mut dur = (duration.as_secs() as u64 * MILLIS_PER_SEC) + let mut dur = (duration.as_secs() * MILLIS_PER_SEC) + (duration.subsec_nanos() as u64 / NANOS_PER_MILLI); if dur as i32 >= 0xfc0i32 { 0xffu8 // Max duration diff --git a/src/i2c.rs b/src/i2c.rs index e317745..9c3078c 100644 --- a/src/i2c.rs +++ b/src/i2c.rs @@ -5,9 +5,10 @@ use embedded_hal::i2c::I2c; /// /// Represents the I2C address of the BME680 Sensor. /// -#[derive(Debug, Clone, Copy)] +#[derive(Debug, Clone, Copy, Default)] pub enum Address { /// Primary Address 0x76 + #[default] Primary, /// Secondary Address 0x77 Secondary, @@ -25,12 +26,6 @@ impl Address { } } -impl Default for Address { - fn default() -> Address { - Address::Primary - } -} - /// I2CUtility is a simple wrapper over the I2c trait to make reading and writing data easier. pub(crate) struct I2CUtility {} @@ -77,7 +72,7 @@ impl I2CUtility { buffer: &[u8], ) -> Result<(), Bme680Error> { i2c_handle - .write(device_address, &buffer) + .write(device_address, buffer) .map_err(|_e| I2CWrite) } } diff --git a/src/lib.rs b/src/lib.rs index 8485189..2f7ee03 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -415,7 +415,7 @@ where /// Sets the sensor registers. fn bme680_set_registers(&mut self, registers: &[(u8, u8)]) -> Result<(), Bme680Error> { - if registers.is_empty() || registers.len() > (BME680_TMP_BUFFER_LENGTH / 2) as usize { + if registers.is_empty() || registers.len() > (BME680_TMP_BUFFER_LENGTH / 2) { return Err(Bme680Error::InvalidLength); } @@ -730,7 +730,7 @@ where duration += sensor_settings .gas_settings .heater_duration - .unwrap_or(Duration::default()); + .unwrap_or_default(); } Ok(duration) }