Skip to main content

Magnetometer

caution

This service is rc and may change in the future.

A 3-axis magnetometer.

import { Magnetometer } from "@devicescript/core"

const magnetometer = new Magnetometer()

Commands

calibrate

Forces a calibration sequence where the user/device might have to rotate to be calibrated.

magnetometer.calibrate(): Promise<void>

Registers

reading

Indicates the current magnetic field on magnetometer. For reference: 1 mgauss is 100 nT (and 1 gauss is 100 000 nT).

  • type: Register<any[]> (packing format i32 i32 i32)

  • track incoming values

import { Magnetometer } from "@devicescript/core"

const magnetometer = new Magnetometer()
// ...
magnetometer.reading.subscribe(async (value) => {
...
})
note

write and read will block until a server is bound to the client.

readingError

Absolute estimated error on the readings.

  • type: Register<number> (packing format i32)

  • optional: this register may not be implemented

  • read only

import { Magnetometer } from "@devicescript/core"

const magnetometer = new Magnetometer()
// ...
const value = await magnetometer.readingError.read()
  • track incoming values
import { Magnetometer } from "@devicescript/core"

const magnetometer = new Magnetometer()
// ...
magnetometer.readingError.subscribe(async (value) => {
...
})
note

write and read will block until a server is bound to the client.