#[derive(Debug)]
pub enum Error<BusError>
where
BusError: embedded_hal_async::i2c::Error
{
BusError(BusError),
IllegalValue { value: i32, min: i32, max: i32},
NotReady,
}
impl <BusError> core::error::Error for Error<BusError>
where
BusError: embedded_hal_async::i2c::Error + core::fmt::Display
{
}
#[cfg(feature = "defmt")]
impl <BusError> defmt::Format for Error<BusError>
where
BusError: embedded_hal_async::i2c::Error + defmt::Format
{
fn format(&self, f: defmt::Formatter) {
match self {
Error::BusError(cause) => defmt::write!(f, "A bus error occurred: {}", cause),
Error::IllegalValue { value, min, max} => defmt::write!(f, "The measured value '{}' exceeds the valid bounds: {} ≤ {} ≤ {}", value, min, value, max),
Error::NotReady => defmt::write!(f, "No new data available"),
}
}
}
impl <BusError> core::fmt::Display for Error<BusError>
where
BusError: embedded_hal_async::i2c::Error + core::fmt::Display
{
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Error::BusError(cause) => core::write!(f, "A bus error occurred: {}", cause),
Error::IllegalValue { value, min, max} => core::write!(f, "The measured value '{}' exceeds the valid bounds: {} ≤ {} ≤ {}", value, min, value, max),
Error::NotReady => core::write!(f, "No new data available"),
}
}
}
impl <BusError> From<BusError> for Error<BusError>
where
BusError: embedded_hal_async::i2c::Error
{
fn from(error: BusError) -> Self {
Error::BusError(error)
}
}