hinge-angle 0.1.0

A crate for accessing hinge angle sensors on various platforms
Documentation
  • Coverage
  • 100%
    7 out of 7 items documented1 out of 5 items with examples
  • Size
  • Source code size: 15.66 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.09 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 20s Average build duration of successful builds.
  • all releases: 20s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • maxwase/hinge-angle
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • maxwase

hinge-angle

crates doc

A Rust library for accessing hinge angle sensors on various platforms.

Overview

This library provides a unified interface to access hinge angle sensors found in modern devices. It abstracts the platform-specific implementations behind a common HingeAngle trait.

Supported Platforms

macOS

Provides access to the MacBook's internal lid angle sensor.

  • Compatibility: Introduced with the 2019 16-inch MacBook Pro. Works on newer MacBooks and iMacs.
  • Known Issues: Does not work on M1/M2 devices.

Android

Support for Android devices (implementation pending).

Other platforms

There are plans to investigate support for Windows and Linux in the future. It's harder to find devices with hinge angle sensors on these platforms. There's also a possibility to support WASM targets with Posture API, but it's still experimental and doesn't output angles directly.

It's also worth investigating asynchronous APIs for platforms that support it.

Example

To find out whether your platform is supported just run:

cargo r --example=readloop

Alternatively, build the executable and copy to the test machine, for example:

cargo b --release --target=aarch64-apple-darwin --example=readloop
ls target/aarch64-apple-darwin/release/examples/readloop

Usage

use hinge_angle::HingeAngle;
use std::{error::Error, thread, time::Duration};

fn main() -> Result<(), Box<dyn Error>> {
    #[cfg(target_os = "macos")]
    {
        use hinge_angle::macos::Hinge;

        let hinge = Hinge::new()?;
        loop {
            let angle = hinge.angle()?;
            println!("Hinge angle: {angle} degrees");
            thread::sleep(Duration::from_secs(1));
        }
    }
    // Add a platform-specific branch for Android when an implementation is available.
    Ok(())
}

Related Projects

Contributing

Contributions are welcome! Please feel free to submit issues and pull requests. Add a new platform, a new sensor ID or just make something better :)