motion

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 motion reads the accelerometer and gyroscope.

nimbus native plugin add motion

go motion.Watch(ctx, 30, func(r motion.Reading) { setTilt(r.Accel.X) })

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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.

func WatchOrientation

func WatchOrientation(ctx context.Context, hz int, f func(Orientation)) error

WatchOrientation is Watch for how the phone is turned, as angles, for a level or a tilt control.

Types

type Orientation

type Orientation struct {
	Pitch float64 `json:"pitch"` // the top raised toward you; 90 is upright
	Roll  float64 `json:"roll"`  // the right edge dipped down; 90 is on its side
	// Yaw is the turn around the screen's axis. On Android it's from
	// north; on iOS it's from wherever it began, so only changes in it mean
	// anything there.
	Yaw float64 `json:"yaw"`
}

Orientation is how the phone is turned, in degrees. Lying flat on its back with the top pointing away from you, Pitch and Roll are about 0.

type Reading

type Reading struct {
	Accel Vector `json:"accel"` // the accelerometer, in g, gravity included
	Gyro  Vector `json:"gyro"`  // the gyroscope, in radians a second
}

Reading is one sample from both sensors.

type Vector

type Vector 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
}

Vector is a reading on each axis, as the phone is held upright.

Jump to

Keyboard shortcuts

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