Crates.io | coremotion-rs |
lib.rs | coremotion-rs |
version | 0.0.2 |
source | src |
created_at | 2024-02-25 15:24:34.969351 |
updated_at | 2024-02-29 22:09:53.496957 |
description | CoreMotion bindings for iOS |
homepage | |
repository | https://github.com/jpedrick/coremotion-rs |
max_upload_size | |
id | 1152518 |
size | 27,102 |
Makes CoreMotion API available to Rust
Cargo.toml
[dependencies]
coremotion = { git = "https://github.com/jpedrick/coremotion-rs.git" }
Your code:
use coremotion::{CMMotionManager, ICMAccelerometerData, ICMMotionManager, INSObject};
fn sample_accelerometer() {
let manager = CMMotionManager::alloc();
unsafe {
manager.init();
let available = manager.isAccelerometerAvailable();
println!("Accelerometer {available}");
manager.setAccelerometerUpdateInterval_(1.0/60.0); //60Hz
manager.startAccelerometerUpdates();
for i in 1..1000 {
let data = manager.accelerometerData();
let acceleration = data.acceleration();
println!("Sample {i} - {acceleration:?}");
std::thread::sleep(std::time::Duration::from_millis(10));
}
}
}