pub enum AlertLatch {
NotLatched = 0x00,
Latched = 0x01,
}
pub enum AlertMode {
Interrupt = 0x00,
Comparator = 0x01,
}
pub enum ThrxCount {
ConvResult1 = 0x00,
ConvResult2 = 0x01,
ConvResult3 = 0x02,
ConvResult4 = 0x03,
}
pub struct AlertConfig {
config: u16,
}
impl AlertConfig {
pub fn new() -> Self {
let config = 0x00;
AlertConfig { config }
}
pub fn form_u16(config: u16) -> Self {
AlertConfig { config }
}
pub fn to_u16(&self) -> u16 {
self.config
}
pub fn set_alert_latch(mut self, alert_latch: AlertLatch) -> Self {
self.config = self.config & !(0b1 << 13) | ((alert_latch as u16) << 13);
self
}
pub fn set_alert_mode(mut self, alert_mode: AlertMode) -> Self {
self.config = self.config & !(0b1 << 12) | ((alert_mode as u16) << 12);
self
}
pub fn set_status_alrt_enable(mut self, status_alrt_enable: bool) -> Self {
self.config = self.config & !(0b1 << 11) | ((status_alrt_enable as u16) << 11);
self
}
pub fn set_rslt_alrt_enable(mut self, rslt_alrt_enable: bool) -> Self {
self.config = self.config & !(0b1 << 8) | ((rslt_alrt_enable as u16) << 8);
self
}
pub fn set_thrx_count(mut self, thrx_count: ThrxCount) -> Self {
self.config = self.config & !(0b11 << 4) | ((thrx_count as u16) << 4);
self
}
pub fn set_t_thrx_alrt_enable(mut self, t_thrx_alrt_enable: bool) -> Self {
self.config = self.config & !(0b1 << 3) | ((t_thrx_alrt_enable as u16) << 3);
self
}
pub fn set_z_thrx_alrt_enable(mut self, z_thrx_alrt_enable: bool) -> Self {
self.config = self.config & !(0b1 << 2) | ((z_thrx_alrt_enable as u16) << 2);
self
}
pub fn set_y_thrx_alrt_enable(mut self, y_thrx_alrt_enable: bool) -> Self {
self.config = self.config & !(0b1 << 1) | ((y_thrx_alrt_enable as u16) << 1);
self
}
pub fn set_x_thrx_alrt_enable(mut self, x_thrx_alrt_enable: bool) -> Self {
self.config = self.config & !(0b1) | (x_thrx_alrt_enable as u16);
self
}
}
impl Default for AlertConfig {
fn default() -> Self {
AlertConfig::new()
}
}