coremotion-rs

Crates.iocoremotion-rs
lib.rscoremotion-rs
version0.0.2
sourcesrc
created_at2024-02-25 15:24:34.969351
updated_at2024-02-29 22:09:53.496957
descriptionCoreMotion bindings for iOS
homepage
repositoryhttps://github.com/jpedrick/coremotion-rs
max_upload_size
id1152518
size27,102
Joshua Pedrick (jpedrick)

documentation

https://jpedrick.github.io/coremotion

README

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));
        }
    }
}
Commit count: 0

cargo fmt