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 ¶
- type Event
- type Manager
- type ReportingMode
- type Sensor
- func (s *Sensor) FifoMaxEventCount() int32
- func (s *Sensor) FifoReservedEventCount() int32
- func (s *Sensor) Handle() int32
- func (s *Sensor) HighestDirectReportRateLevel() int32
- func (s *Sensor) IsWakeUp() bool
- func (s *Sensor) MinDelay() int32
- func (s *Sensor) Name() string
- func (s *Sensor) ReportingMode() ReportingMode
- func (s *Sensor) Resolution() float32
- func (s *Sensor) StringType() string
- func (s *Sensor) Type() Type
- func (s *Sensor) Vendor() string
- type Type
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.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager wraps a native ASensorManager handle.
func GetInstance ¶
GetInstance returns the process-wide sensor manager.
func (*Manager) Read ¶
Read enables the sensor, waits for a single event, and disables it again. A non-positive timeout waits forever.
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 ¶
FifoMaxEventCount returns the maximum number of events that can be batched.
func (*Sensor) FifoReservedEventCount ¶
FifoReservedEventCount returns the number of events reserved in the FIFO.
func (*Sensor) HighestDirectReportRateLevel ¶
HighestDirectReportRateLevel returns the highest direct report rate level supported.
func (*Sensor) ReportingMode ¶
func (s *Sensor) ReportingMode() ReportingMode
ReportingMode returns the sensor's reporting mode.
func (*Sensor) Resolution ¶
Resolution returns the sensor's resolution in the sensor's unit.
func (*Sensor) StringType ¶
StringType returns the sensor's Android string type (e.g. android.sensor.accelerometer).
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) ValueCount ¶
ValueCount returns how many leading floats of an event's data are meaningful for this sensor type.