use embedded_hal::i2c;
use thiserror::Error;
#[derive(Debug, Error, PartialEq)]
pub enum Scd30Error<I2cErr: i2c::Error> {
#[error(transparent)]
DataError(#[from] DataError),
#[error(transparent)]
I2cError(#[from] I2cErr),
#[error("Only 16-bits of data can be send")]
SentDataToBig,
}
#[cfg(feature = "defmt")]
impl<I2cErr: i2c::Error> defmt::Format for Scd30Error<I2cErr> {
fn format(&self, f: defmt::Formatter) {
defmt::write!(f, "{}", self)
}
}
#[derive(Debug, Error, PartialEq)]
pub enum DataError {
#[error("{parameter} must be between {min} and {max} {unit}.")]
ValueOutOfRange {
parameter: &'static str,
min: u16,
max: u16,
unit: &'static str,
},
#[error("Instead of setting the ambient pressure compensation to 0, use AmbientPressureCompensation::DefaultPressure.")]
UseDefaultPressure,
#[error("CRC check failed.")]
CrcFailed,
#[error("Buffer size received to wrong size for expected data.")]
ReceivedBufferWrongSize,
#[error("Unexpected Value for {parameter}: expected {expected} got {actual}")]
UnexpectedValueReceived {
parameter: &'static str,
expected: &'static str,
actual: u16,
},
}
#[cfg(feature = "defmt")]
impl defmt::Format for DataError {
fn format(&self, f: defmt::Formatter) {
defmt::write!(f, "{}", self)
}
}