magnetometer

package
v0.0.14 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package magnetometer reads the magnetic field around the phone: for a metal detector, say, or a compass of your own.

nimbus native plugin add magnetometer

go magnetometer.Watch(ctx, 10, func(r magnetometer.Reading) { setField(r.Strength()) })

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Available

func Available(ctx context.Context) bool

Available reports whether this phone has the sensor.

func Watch

func Watch(ctx context.Context, hz int, f func(Reading)) error

Watch calls f about hz times a second until ctx ends. It blocks, so run it from a goroutine in an effect. Where there's no sensor, as on the iOS simulator, it fails with plugin.Unavailable.

Types

type Reading

type Reading struct {
	X float64 `json:"x"` // across the screen, positive to the right
	Y float64 `json:"y"` // up the screen, positive to the top
	Z float64 `json:"z"` // out of the screen, positive toward you
}

Reading is the field on each axis, in microteslas, as the phone is held upright.

func (Reading) Strength

func (r Reading) Strength() float64

Strength is the field's total size, in microteslas. The Earth's is about 25 to 65.

Jump to

Keyboard shortcuts

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