pub enum DiagSel {
AllData = 0x00,
EnabledData = 0x01,
AllDataInSeq = 0x02,
EnabledDataInSeq = 0x03,
}
#[allow(non_camel_case_types)]
pub enum TriggerMode {
Spi = 0x00,
Cs = 0x01,
Alert = 0x02,
}
#[allow(non_camel_case_types)]
pub enum DataType {
Default = 0x00,
XY = 0x01,
XZ = 0x02,
ZY = 0x03,
XT = 0x04,
YT = 0x05,
ZT = 0x06,
AM = 0x07,
}
pub struct SystemConfig {
config: u16,
}
impl SystemConfig {
pub fn new() -> Self {
let config = 0x00;
SystemConfig { config }
}
pub fn form_u16(config: u16) -> Self {
SystemConfig { config }
}
pub fn to_u16(&self) -> u16 {
self.config
}
pub fn set_diag_sel(mut self, diag_sel: DiagSel) -> Self {
self.config = self.config & !(0b11 << 12) | ((diag_sel as u16) << 12);
self
}
pub fn set_trigger_mode(mut self, trigger_mode: TriggerMode) -> Self {
self.config = self.config & !(0b11 << 9) | ((trigger_mode as u16) << 9);
self
}
pub fn set_data_type(mut self, data_type: DataType) -> Self {
self.config = self.config & !(0b111 << 6) | ((data_type as u16) << 6);
self
}
pub fn set_diag_en(mut self, diag_en: bool) -> Self {
self.config = self.config & !(0b1 << 5) | ((diag_en as u16) << 5);
self
}
pub fn set_t_z_limit_check(mut self, z_limit_check: bool) -> Self {
self.config = self.config & !(0b1 << 2) | ((z_limit_check as u16) << 2);
self
}
pub fn set_t_y_limit_check(mut self, y_limit_check: bool) -> Self {
self.config = self.config & !(0b1 << 1) | ((y_limit_check as u16) << 1);
self
}
pub fn set_t_x_limit_check(mut self, x_limit_check: bool) -> Self {
self.config = self.config & !(0b1) | (x_limit_check as u16);
self
}
}
impl Default for SystemConfig {
fn default() -> Self {
SystemConfig::new()
}
}