-
Notifications
You must be signed in to change notification settings - Fork 0
/
motion_interrupt.rs
42 lines (37 loc) · 1.38 KB
/
motion_interrupt.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
use esp_idf_svc::hal::{delay::FreeRtos, i2c::*, prelude::Peripherals, units::Hertz};
use kxtj3_1057::{
config::MotionDetctionConfiguration,
register::{DataRate, Mode, Range, SlaveAddr},
Kxtj3,
};
fn main() {
esp_idf_svc::sys::link_patches();
let peripherals = Peripherals::take().unwrap();
let i2c = peripherals.i2c0;
let sda = peripherals.pins.gpio2;
let scl = peripherals.pins.gpio1;
let config = I2cConfig::new()
.baudrate(Hertz(400_000))
.scl_enable_pullup(true)
.sda_enable_pullup(true);
let i2c = I2cDriver::new(i2c, sda, scl, &config).unwrap();
let device_config = kxtj3_1057::config::Configuration {
mode: Mode::HighResolution,
datarate: DataRate::Hz_6_25,
range: Range::G2,
enable_new_acceleration_interrupt: true,
motion_detection: Some(MotionDetctionConfiguration::default()),
};
let mut kxtj3 = Kxtj3::new_with_config(i2c, SlaveAddr::Default, device_config).unwrap();
loop {
if let Ok(is_motion_detected) = kxtj3.is_motion_detected() {
if is_motion_detected {
if let Ok(motion_detection_axis) = kxtj3.get_motion_detection_axis() {
println!("{:?}", motion_detection_axis);
}
let _ = kxtj3.clear_motion_detection_lathced_info();
}
}
FreeRtos::delay_ms(500);
}
}