pub struct PaSpl<I2C>{ /* private fields */ }
Expand description
A PA SPL Module on the I2C bus I2C
.
Implementations§
Source§impl<E, I2C> PaSpl<I2C>
impl<E, I2C> PaSpl<I2C>
Sourcepub fn new(i2c: I2C) -> Self
pub fn new(i2c: I2C) -> Self
Initializes the PCB Artists SPL Module driver.
§Errors
Returns Error::NoI2cInstance
if the I2C instance is empty.
Sourcepub fn set_device_addr(&mut self, addr: u8)
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.
Sourcepub fn get_avg_time(&mut self) -> Result<u16, Error<E>>
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.
Sourcepub fn get_control_register(&mut self) -> Result<ControlRegister, Error<E>>
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.
Sourcepub fn get_device_id(&mut self) -> Result<u32, Error<E>>
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.
Sourcepub fn get_firmware_version(&mut self) -> Result<u8, Error<E>>
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.
Sourcepub fn get_latest_decibel(&mut self) -> Result<u8, Error<E>>
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.
Sourcepub fn get_max_decibel(&mut self) -> Result<u8, Error<E>>
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.
Sourcepub fn get_min_decibel(&mut self) -> Result<u8, Error<E>>
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.
Sourcepub fn get_scratch(&mut self) -> Result<u8, Error<E>>
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.
Sourcepub fn reset(&mut self) -> Result<(), Error<E>>
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.
Sourcepub fn set_avg_time(&mut self, ms: u16) -> Result<(), Error<E>>
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.
Sourcepub fn set_control_register(
&mut self,
reg: ControlRegister,
) -> Result<(), Error<E>>
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.
Sourcepub fn set_scratch(&mut self, value: u8) -> Result<(), Error<E>>
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.