Skip to content

haonothow/mac-lid-angle-sensor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

mac-lid-angle-sensor

A minimal C program to read the physical lid angle of a MacBook using IOKit and CoreFoundation frameworks.

Note

I coded this strictly for practice. It is not intended for any production use.

Credits

Full credit goes to Sam Henri Gold for the original discovery and implementation. Here is the original project in Objective-C & Swift.

Precision Note

Unfortunately, the raw hardware sensor can only output a whole integer of the degree (e.g., 67, 69). In Sam's original project, he uses an Exponential Moving Average to calculate a smoothed value with 2 decimal precision.

smoothedAngle = Self.angleSmoothingFactor * rawAngle + (1 - Self.angleSmoothingFactor) * smoothedAngle

I am too lazy to implement that math here, so this C program will only print out the raw integer value.

Compatibility

The lid angle sensor was first introduced with the 2019 16-inch MacBook Pro.

  • While this code should theoretically work with any MacBook released after that time, there are known issues with some specific models.
  • Since Sam developed the project with a M4 MacBook Pro, so it is guaranteed to work on the M4 MacBook Pro.

Requirements

  • A C99 or newer C compiler (clang or gcc) is strictly required (the code uses the C99 Variable Length Arrays & inline variable declarations)

Compile & Run

clang main.c -framework IOKit -framework CoreFoundation -o main
./main

Example Output:

Current Lid Angle: 67 degrees

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Contributors

Languages