sensor

package
v0.0.0-...-ff625c4 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2016 License: BSD-3-Clause Imports: 2 Imported by: 0

Documentation

Overview

Package sensor provides sensor events from various movement sensors.

Index

Constants

View Source
const (
	Accelerometer = Type(0)
	Gyroscope     = Type(1)
	Magnetometer  = Type(2)
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

type Event struct {
	// Sensor is the type of the sensor the event is coming from.
	Sensor Type

	// Timestamp is a device specific event time in nanoseconds.
	// Timestamps are not Unix times, they represent a time that is
	// only valid for the device's default sensor.
	Timestamp int64

	// Data is the event data.
	//
	// If the event source is Accelerometer,
	//  - Data[0]: acceleration force in x axis in m/s^2
	//  - Data[1]: acceleration force in y axis in m/s^2
	//  - Data[2]: acceleration force in z axis in m/s^2
	//
	// If the event source is Gyroscope,
	//  - Data[0]: rate of rotation around the x axis in rad/s
	//  - Data[1]: rate of rotation around the y axis in rad/s
	//  - Data[2]: rate of rotation around the z axis in rad/s
	//
	// If the event source is Magnetometer,
	//  - Data[0]: force of gravity along the x axis in m/s^2
	//  - Data[1]: force of gravity along the y axis in m/s^2
	//  - Data[2]: force of gravity along the z axis in m/s^2
	//
	Data []float64
}

Event represents a sensor event.

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager multiplexes sensor event data from various sensor sources.

func (*Manager) Close

func (m *Manager) Close() error

Close stops the manager and frees the related resources. Once Close is called, Manager becomes invalid to use.

func (*Manager) Disable

func (m *Manager) Disable(t Type) error

Disable disables to feed the manager with the specified sensor.

func (*Manager) Enable

func (m *Manager) Enable(t Type, delay time.Duration) error

Enable enables a sensor with the specified delay rate. If there are multiple sensors of type t on the device, Enable uses the default one. If there is no default sensor of type t on the device, an error returned. Valid sensor types supported by this package are Accelerometer, Gyroscope, Magnetometer and Altimeter.

func (*Manager) Read

func (m *Manager) Read(e []Event) (n int, err error)

Read reads a series of events from the manager. It may read up to len(e) number of events, but will return less events if timeout occurs.

type Type

type Type int

Type represents a sensor type.

func (Type) String

func (t Type) String() string

String returns the string representation of the sensor type.

Jump to

Keyboard shortcuts

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