mobile: golang.org/x/mobile/exp/sensor Index | Files

package sensor

import "golang.org/x/mobile/exp/sensor"

Package sensor provides sensor events from various movement sensors.

Index

Package Files

notmobile.go sensor.go

Constants

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

func Disable

func Disable(t Type) error

Disable disables to feed the manager with the specified sensor. Disable is not safe for concurrent use.

func Enable

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

Enable enables the specified sensor type with the given delay rate. Users must set a non-nil Sender via Notify before enabling a sensor, otherwise an error will be returned.

func Notify

func Notify(s Sender)

Notify registers a Sender and sensor events will be sent to s. A typical example of Sender implementations is app.App. Once you call Notify, you are not allowed to call it again. You cannot call Notify with a nil Sender.

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 Sender

type Sender interface {
    Send(event interface{})
}

Sender sends an event.

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.

Package sensor imports 3 packages (graph). Updated 4 days ago. Refresh now. Tools for package owners.