2 releases

0.0.2 Feb 29, 2024
0.0.1 Feb 25, 2024

#1157 in Hardware support

MIT license

10KB
84 lines

CoreMotion-rs

Makes CoreMotion API available to Rust

Basic Usage

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));
        }
    }
}

Dependencies

~0.3–2MB
~41K SLoC