https://github.com/badgooooor/silicon-accelerometer-ts
Playing around with mems accelerometer on Apple Silicon Macbooks
https://github.com/badgooooor/silicon-accelerometer-ts
accelerometer apple bun c iokit macbook macos typescript
Last synced: 15 days ago
JSON representation
Playing around with mems accelerometer on Apple Silicon Macbooks
- Host: GitHub
- URL: https://github.com/badgooooor/silicon-accelerometer-ts
- Owner: badgooooor
- Created: 2026-04-15T01:28:23.000Z (2 months ago)
- Default Branch: main
- Last Pushed: 2026-04-15T07:30:05.000Z (2 months ago)
- Last Synced: 2026-04-15T09:31:01.902Z (2 months ago)
- Topics: accelerometer, apple, bun, c, iokit, macbook, macos, typescript
- Language: C
- Homepage:
- Size: 22.5 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# silicon-accelerometer
Read accelerometer data from Apple Silicon Macs via Bun FFI.
A TypeScript wrapper around a C implementation based from [apple-silicon-accelerometer](https://github.com/olvvier/apple-silicon-accelerometer), exposing `x`, `y`, `z`, and `timestamp` readings through a simple class interface.
## Video demo
[silicon-accelerometer-demo.webm](https://github.com/user-attachments/assets/d1dc69a6-458c-45a8-b342-9de3c58ea506)
## Requirements
- macOS, Apple Silicon (arm64)
- [Bun](https://bun.sh)
## Install
```sh
bun add silicon-accelerometer
```
## Usage
```ts
import { Accelerometer } from "silicon-accelerometer";
const accel = new Accelerometer();
accel.start();
const reading = accel.read();
// { x: 0.01, y: -0.03, z: 9.81, timestamp: 1234567890n }
accel.stop();
```
`read()` returns `null` if no valid sample is available. `stop()` is called automatically on process exit.
## API
| Method | Description |
|--------|-------------|
| `start()` | Start the accelerometer. Throws if already started. |
| `stop()` | Stop and release the native library. Safe to call multiple times. |
| `read()` | Return `{ x, y, z, timestamp }` or `null` if no valid sample. |
## Build
To recompile the native dylib:
```sh
bun run build:dylib
```
## License
MIT