sensor

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 22, 2026 License: MIT Imports: 6 Imported by: 2

Documentation

Rendered for darwin/amd64

Overview

Package sensor reads accelerometer, gyroscope, ambient light, and lid angle from Apple Silicon MacBooks via IOKit HID (AppleSPUHIDDevice, Bosch BMI286 IMU).

Index

Constants

View Source
const (
	PageVendor = 0xFF00 // Apple vendor page
	PageSensor = 0x0020 // HID sensor page
	UsageAccel = 3      // Accelerometer
	UsageGyro  = 9      // Gyroscope
	UsageALS   = 4      // Ambient light sensor
	UsageLid   = 138    // Lid angle sensor
)

HID usage pages and usages for Apple SPU sensors.

View Source
const (
	IMUReportLen     = 22   // Accel/gyro report length in bytes
	IMUDecimation    = 8    // Keep 1 in N samples
	IMUDataOffset    = 6    // XYZ payload start offset
	ALSReportLen     = 122  // ALS report length in bytes
	LidReportLen     = 3    // Lid angle report length in bytes
	ReportBufSize    = 4096 // HID callback buffer size
	ReportIntervalUS = 1000 // Driver report interval in microseconds
)

Report format constants for the Bosch BMI286 IMU.

View Source
const (
	CFStringEncodingUTF8 = 0x08000100
	CFNumberSInt32Type   = 3
	CFNumberSInt64Type   = 4
)

CoreFoundation type IDs.

Variables

This section is empty.

Functions

func ParseIMUReport

func ParseIMUReport(data []byte) (x, y, z int32)

ParseIMUReport extracts 3 int32 XYZ values from a BMI286 IMU report.

func ParseLidAngle

func ParseLidAngle(data []byte) (float32, bool)

ParseLidAngle extracts the lid angle from a lid sensor report.

func Run

func Run(cfg Config) error

Run starts the sensor worker. This function blocks forever, running the CFRunLoop to receive HID callbacks. It must be called from the main thread.

Types

type Config

type Config struct {
	AccelRing *shm.RingBuffer
	GyroRing  *shm.RingBuffer
	ALSSnap   *shm.Snapshot
	LidSnap   *shm.Snapshot
	Restarts  uint32
}

Config holds the shared memory targets for the sensor worker.

type ReportCallback

type ReportCallback func(context uintptr, result int32, sender uintptr, reportType int32, reportID uint32, report []byte)

ReportCallback is the type for HID input report callbacks. Parameters: context, result, sender, reportType, reportID, report data, report length.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL