Struct PaSpl

Source
pub struct PaSpl<I2C>
where I2C: Read + Write + WriteRead,
{ /* private fields */ }
Expand description

A PA SPL Module on the I2C bus I2C.

Implementations§

Source§

impl<E, I2C> PaSpl<I2C>
where I2C: Read<Error = E> + Write<Error = E> + WriteRead<Error = E>,

Source

pub fn new(i2c: I2C) -> Self

Initializes the PCB Artists SPL Module driver.

§Errors

Returns Error::NoI2cInstance if the I2C instance is empty.

Source

pub fn set_device_addr(&mut self, addr: u8)

Sets a new I2C device address.

The published device address is the default but the vendor’s website states that it is possible to order a device with a custom address.

Source

pub fn get_avg_time(&mut self) -> Result<u16, Error<E>>

Gets the 16-bit averaging time in ms from registers TAVG high and TAVG low (0x07 and 0x08).

§Errors

Returns Error::NoI2cInstance if the I2C instance is empty.

Returns Error::I2c if I2C returns an error.

Source

pub fn get_control_register(&mut self) -> Result<ControlRegister, Error<E>>

Gets the CONTROL register.

§Errors

Returns Error::NoI2cInstance if the I2C instance is empty.

Returns Error::I2c if I2C returns an error.

Source

pub fn get_device_id(&mut self) -> Result<u32, Error<E>>

Gets the 32-bit device ID from registers ID3-ID0.

§Errors

Returns Error::NoI2cInstance if the I2C instance is empty.

Returns Error::I2c if I2C returns an error.

Source

pub fn get_firmware_version(&mut self) -> Result<u8, Error<E>>

Gets the firmware version from the VERSION register.

§Errors

Returns Error::NoI2cInstance if the I2C instance is empty.

Returns Error::I2c if I2C returns an error.

Source

pub fn get_latest_decibel(&mut self) -> Result<u8, Error<E>>

Gets the latest SPL value in decibels from the DECIBEL register.

The SPL value is averaged over the last Tavg time period that is stored in the TAVG high byte register (0x07) and the TAVG low register (x08).

§Errors

Returns Error::NoI2cInstance if the I2C instance is empty.

Returns Error::I2c if I2C returns an error.

Source

pub fn get_max_decibel(&mut self) -> Result<u8, Error<E>>

Gets the max SPL value in decibels from the MAX register.

Maximum value of decibel reading captured since power-up or manual reset of MIN/MAX registers.

§Errors

Returns Error::NoI2cInstance if the I2C instance is empty.

Returns Error::I2c if I2C returns an error.

Source

pub fn get_min_decibel(&mut self) -> Result<u8, Error<E>>

Gets the min SPL value in decibels from the MIN register.

Minimum value of decibel reading captured since power-up or manual reset of MIN/MAX registers.

§Errors

Returns Error::NoI2cInstance if the I2C instance is empty.

Returns Error::I2c if I2C returns an error.

Source

pub fn get_scratch(&mut self) -> Result<u8, Error<E>>

Gets the value stored in the SCRATCH register.

§Errors

Returns Error::NoI2cInstance if the I2C instance is empty.

Returns Error::I2c if I2C returns an error.

Source

pub fn reset(&mut self) -> Result<(), Error<E>>

Soft resets the sensor.

The sensor is soft reset by setting the System Reset bit in the RESET register.

§Errors

Returns Error::NoI2cInstance if the I2C instance is empty.

Returns Error::I2c if I2C returns an error.

Source

pub fn set_avg_time(&mut self, ms: u16) -> Result<(), Error<E>>

Sets the average time in ms for calculating SPL.

§Errors

Returns Error::NoI2cInstance if the I2C instance is empty.

Returns Error::I2c if I2C returns an error.

Source

pub fn set_control_register( &mut self, reg: ControlRegister, ) -> Result<(), Error<E>>

Sets the CONTROL register.

§Errors

Returns Error::NoI2cInstance if the I2C instance is empty.

Returns Error::I2c if I2C returns an error.

Source

pub fn set_scratch(&mut self, value: u8) -> Result<(), Error<E>>

Sets the value stored in the SCRATCH register.

§Errors

Returns Error::NoI2cInstance if the I2C instance is empty.

Returns Error::I2c if I2C returns an error.

Source

pub fn destroy(&mut self) -> I2C

Destroys this driver and releases the I2C bus.

Auto Trait Implementations§

§

impl<I2C> Freeze for PaSpl<I2C>
where I2C: Freeze,

§

impl<I2C> RefUnwindSafe for PaSpl<I2C>
where I2C: RefUnwindSafe,

§

impl<I2C> Send for PaSpl<I2C>
where I2C: Send,

§

impl<I2C> Sync for PaSpl<I2C>
where I2C: Sync,

§

impl<I2C> Unpin for PaSpl<I2C>
where I2C: Unpin,

§

impl<I2C> UnwindSafe for PaSpl<I2C>
where I2C: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.