Skip to content

badgooooor/silicon-accelerometer-ts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

silicon-accelerometer

Read accelerometer data from Apple Silicon Macs via Bun FFI.

A TypeScript wrapper around a C implementation based from apple-silicon-accelerometer, exposing x, y, z, and timestamp readings through a simple class interface.

Requirements

  • macOS, Apple Silicon (arm64)
  • Bun

Install

bun add silicon-accelerometer

Usage

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:

bun run build:dylib

License

MIT

About

Playing around with mems accelerometer on Apple Silicon Macbooks

Topics

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors