Skip to content

A Rust command-line tool to read and display your MacBook's hidden lid angle sensor in real-time.

License

Notifications You must be signed in to change notification settings

wangfu91/lid-angle-rs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

lid-angle-rs

Crates.io License: MIT

A Rust command-line tool to read and display your MacBook's hidden lid angle sensor in real-time.

Overview

This tool uses the IOKit HID framework to access the MacBook's built-in lid angle sensor and displays the current angle of your laptop's lid in real-time in the terminal.

Features

  • 🔍 Automatic detection of the lid angle sensor
  • 📊 Real-time angle display with visual progress bar
  • 🎯 High precision (0.01 degree resolution)
  • 🚀 Written in Rust for performance and safety

Requirements

  • macOS 11.0+ (Big Sur or later)
  • Compatible MacBook:
    • MacBook Pro 16-inch (2019) or newer
    • MacBook Pro (M1/M2/M3/M4)
    • MacBook Air (M1/M2/M3/M4)
    • Note: Not all models have this sensor; compatibility varies

Installation

From crates.io

cargo install lid-angle

From source

git clone https://github.com/wangfu91/lid-angle-rs.git
cd lid-angle-rs
cargo build --release

The compiled binary will be available at target/release/lid-angle (or run with cargo run --release during development).

Usage

Simply run the tool:

Install once, then run:

lid-angle

The tool will:

  1. Search for the lid angle sensor
  2. Display real-time angle updates as you open/close your MacBook lid
  3. Show a visual progress bar representing the angle (0-180°)

Press Ctrl+C to exit.

Example Output

MacBook Lid Angle Sensor Reader
================================

Searching for lid angle sensor...
✓ Lid angle sensor found and opened

Reading lid angle in real-time (press Ctrl+C to exit)...

Lid Angle: 125.43° [█████████████████████████████████████            ]

How It Works

This tool interfaces with macOS's IOKit HID framework to access the lid angle sensor. The sensor is exposed as a HID device with the following properties:

  • VendorID: 0x05AC (Apple)
  • ProductID: 0x8104
  • Usage Page: 0x0020 (Sensor)
  • Usage: 0x008A (Orientation)

The implementation is based on reverse-engineering work from the LidAngleSensor Objective-C project.

Troubleshooting

"No lid angle sensor found"

If you see this error:

  1. Check device compatibility: Run the diagnostic command:

    hidutil list --matching '{"VendorID":0x05AC,"ProductID":0x8104,"PrimaryUsagePage":32,"PrimaryUsage":138}'

    If this returns no devices, your MacBook may not have the sensor.

  2. Try with elevated privileges:

    sudo lid-angle
  3. Verify your MacBook model: The sensor is typically available on MacBook Pro models from 2019 onwards.

Permission issues

If you encounter permission errors, run the tool with sudo:

sudo lid-angle

Credits

This project was inspired by and based on the research from:

Technical Details

The tool uses the following Rust crates:

  • core-foundation and core-foundation-sys: For CoreFoundation types and bindings
  • Direct FFI bindings to IOKit HID framework

The lid angle sensor reports values as 16-bit integers in units of 0.01 degrees, providing a range from 0° (closed) to ~180° (fully open).

License

MIT License - see LICENSE file for details.

Contributing

Contributions are welcome! Please feel free to submit issues or pull requests.

About

A Rust command-line tool to read and display your MacBook's hidden lid angle sensor in real-time.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •  

Languages