Skip to content
Snippets Groups Projects
Commit 11b02b57 authored by andrea.tambani@studenti.unimi.it's avatar andrea.tambani@studenti.unimi.it
Browse files

destroy method added

parent 89fd43db
No related branches found
No related tags found
No related merge requests found
......@@ -52,10 +52,15 @@ pub struct Sht4x<B, T> {
tim: T,
}
pub struct Sht4xI2C<P> {
i2c: P,
address: SevenBitAddress,
}
///
/// The SHT4X driver struct implementation.
///
impl<P, T> Sht4x<sht4x_reg::Sht4xI2C<P>, T>
impl<P, T> Sht4x<Sht4xI2C<P>, T>
where
P: I2c,
T: DelayNs,
......@@ -77,7 +82,7 @@ where
/// * Error: The failure of a bus operation returns Error::Bus(B).
///
pub fn new_i2c(i2c: P, address: I2CAddress, tim: T) -> Result<Self, Error<P::Error>> {
let bus = sht4x_reg::Sht4xI2C::new(i2c, address as SevenBitAddress);
let bus = Sht4xI2C::new(i2c, address as SevenBitAddress);
let mut instance = Self { bus, tim };
instance.tim.delay_ms(1);
instance.soft_reset()?;
......@@ -110,6 +115,13 @@ pub enum I2CAddress {
}
impl<B: BusOperation, T: DelayNs> Sht4x<B, T> {
///
/// This method destroys the driver and returns the bus and timer instances.
///
pub fn destroy(self) -> (B, T) {
(self.bus, self.tim)
}
///
/// This method returns the sensor serial number.
///
......
......@@ -6,18 +6,14 @@ use embedded_hal::{
use generic_bus::BusOperation;
use crate::Error;
pub struct Sht4xI2C<P> {
i2c: P,
address: SevenBitAddress,
}
impl<P: I2c> Sht4xI2C<P> {
impl<P: I2c> super::Sht4xI2C<P> {
pub(super) fn new(i2c: P, address: SevenBitAddress) -> Self {
Self { i2c, address }
}
}
impl<P: I2c> BusOperation for Sht4xI2C<P> {
impl<P: I2c> BusOperation for super::Sht4xI2C<P> {
type Error = P::Error;
#[inline]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment