#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Diagnostics {
raw: u16,
}
impl Diagnostics {
#[must_use]
pub const fn new(raw: u16) -> Self {
Self { raw }
}
#[must_use]
pub const fn raw(&self) -> u16 {
self.raw
}
#[must_use]
pub const fn comp_high(&self) -> bool {
self.raw & 0x2000 != 0
}
#[must_use]
pub const fn comp_low(&self) -> bool {
self.raw & 0x1000 != 0
}
#[must_use]
pub const fn cordic_overflow(&self) -> bool {
self.raw & 0x0800 != 0
}
#[must_use]
pub const fn offset_comp_finished(&self) -> bool {
self.raw & 0x0400 != 0
}
#[must_use]
pub const fn agc_value(&self) -> u8 {
(self.raw & 0x00FF) as u8
}
#[must_use]
pub const fn magnetic_field_ok(&self) -> bool {
!self.comp_high() && !self.comp_low()
}
#[must_use]
pub const fn is_valid(&self) -> bool {
!self.cordic_overflow() && self.magnetic_field_ok()
}
}
impl From<u16> for Diagnostics {
fn from(raw: u16) -> Self {
Self::new(raw)
}
}