Skip to main content

Accelerometer

The startAccelerometer function starts a accelerometer server on the device and returns a client.

The accelerometer IMU chip will be auto-detected if it is supported.

import { startAccelerometer } from "@devicescript/servers"
const acc = startAccelerometer({})

Coordinate transforms

You can specify transform for X, Y, Z axis of the accelerometer to compensate for the physical placement of the IMU chip. See service spec for info about what XYZ values should be returned, depending on device position.

For each output axis (trX, trY, trZ) you specify input axis 1, 2, 3 or negated input axis -1, -2, -3. The default is { trX: 1, trY: 2, trZ: 3 }, which is no transform. The following would work for accelerometer mounted upside down and rotated, it transforms (x1, y2, z3) into (y2, -x1, -z3).

import { startAccelerometer } from "@devicescript/servers"
const acc = startAccelerometer({
trX: 2,
trY: -1,
trZ: -3,
})