sensor

package
v0.0.0-...-8c85b09 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package sensor provides a minimal, cgo-free wrapper around the Android NDK sensor API. It dynamically links against libandroid.so at runtime via purego, exposing just the subset of the API that this program needs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

type Event struct {
	Sensor    int32
	Type      Type
	Timestamp int64 // elapsed realtime nanoseconds
	Data      [16]float32
}

Event is a single sensor reading.

func (*Event) StepCount

func (e *Event) StepCount() uint64

StepCount returns the step counter value for a step counter event.

type Manager

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

Manager wraps a native ASensorManager handle.

func GetInstance

func GetInstance() (*Manager, error)

GetInstance returns the process-wide sensor manager.

func (*Manager) Read

func (m *Manager) Read(s *Sensor, timeout time.Duration) (*Event, error)

Read enables the sensor, waits for a single event, and disables it again. A non-positive timeout waits forever.

func (*Manager) Sensors

func (m *Manager) Sensors() ([]*Sensor, error)

Sensors returns every sensor reported by the manager.

func (*Manager) Watch

func (m *Manager) Watch(s *Sensor, duration time.Duration, fn func(*Event)) error

Watch enables the sensor and streams events to fn until duration elapses. A non-positive duration streams indefinitely.

type ReportingMode

type ReportingMode int32

ReportingMode is a sensor's reporting mode as returned by ASensor_getReportingMode.

const (
	ReportingInvalid        ReportingMode = -1
	ReportingContinuous     ReportingMode = 0
	ReportingOnChange       ReportingMode = 1
	ReportingOneShot        ReportingMode = 2
	ReportingSpecialTrigger ReportingMode = 3
)

func (ReportingMode) String

func (m ReportingMode) String() string

String returns the Android name of the reporting mode.

type Sensor

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

Sensor wraps a native ASensor handle.

func (*Sensor) FifoMaxEventCount

func (s *Sensor) FifoMaxEventCount() int32

FifoMaxEventCount returns the maximum number of events that can be batched.

func (*Sensor) FifoReservedEventCount

func (s *Sensor) FifoReservedEventCount() int32

FifoReservedEventCount returns the number of events reserved in the FIFO.

func (*Sensor) Handle

func (s *Sensor) Handle() int32

Handle returns the sensor's system handle.

func (*Sensor) HighestDirectReportRateLevel

func (s *Sensor) HighestDirectReportRateLevel() int32

HighestDirectReportRateLevel returns the highest direct report rate level supported.

func (*Sensor) IsWakeUp

func (s *Sensor) IsWakeUp() bool

IsWakeUp reports whether this is a wake-up sensor.

func (*Sensor) MinDelay

func (s *Sensor) MinDelay() int32

MinDelay returns the minimum delay between events in microseconds.

func (*Sensor) Name

func (s *Sensor) Name() string

Name returns the sensor's name.

func (*Sensor) ReportingMode

func (s *Sensor) ReportingMode() ReportingMode

ReportingMode returns the sensor's reporting mode.

func (*Sensor) Resolution

func (s *Sensor) Resolution() float32

Resolution returns the sensor's resolution in the sensor's unit.

func (*Sensor) StringType

func (s *Sensor) StringType() string

StringType returns the sensor's Android string type (e.g. android.sensor.accelerometer).

func (*Sensor) Type

func (s *Sensor) Type() Type

Type returns the sensor's type.

func (*Sensor) Vendor

func (s *Sensor) Vendor() string

Vendor returns the sensor's vendor string.

type Type

type Type int32

Type is an Android sensor type as returned by ASensor_getType.

const (
	Invalid                              Type = -1
	Accelerometer                        Type = 1
	MagneticField                        Type = 2
	Orientation                          Type = 3
	Gyroscope                            Type = 4
	Light                                Type = 5
	Pressure                             Type = 6
	Temperature                          Type = 7
	Proximity                            Type = 8
	Gravity                              Type = 9
	LinearAcceleration                   Type = 10
	RotationVector                       Type = 11
	RelativeHumidity                     Type = 12
	AmbientTemperature                   Type = 13
	MagneticFieldUncalibrated            Type = 14
	GameRotationVector                   Type = 15
	GyroscopeUncalibrated                Type = 16
	SignificantMotion                    Type = 17
	StepDetector                         Type = 18
	StepCounter                          Type = 19
	GeomagneticRotationVector            Type = 20
	HeartRate                            Type = 21
	TiltDetector                         Type = 22
	WakeGesture                          Type = 23
	GlanceGesture                        Type = 24
	PickUpGesture                        Type = 25
	WristTiltGesture                     Type = 26
	DeviceOrientation                    Type = 27
	Pose6dof                             Type = 28
	StationaryDetect                     Type = 29
	MotionDetect                         Type = 30
	HeartBeat                            Type = 31
	DynamicSensorMeta                    Type = 32
	AdditionalInfo                       Type = 33
	LowLatencyOffbodyDetect              Type = 34
	AccelerometerUncalibrated            Type = 35
	HingeAngle                           Type = 36
	HeadTracker                          Type = 37
	AccelerometerLimitedAxes             Type = 38
	GyroscopeLimitedAxes                 Type = 39
	AccelerometerLimitedAxesUncalibrated Type = 40
	GyroscopeLimitedAxesUncalibrated     Type = 41
	Heading                              Type = 42
)

func (Type) String

func (t Type) String() string

String returns the Android name of the sensor type.

func (Type) ValueCount

func (t Type) ValueCount() int

ValueCount returns how many leading floats of an event's data are meaningful for this sensor type.

Jump to

Keyboard shortcuts

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