Documentation
¶
Overview ¶
Package asensor is the motion sensors backend of Android (SPEC §28.4, step 31.7): the accelerometer and the gyroscope through the sensor manager of the NDK (libandroid.so, Android 8, API 26), called through purego, with the events of every open sensor read on a looper that lives on an OS thread of its own. The design follows the Android sensor driver of SDL 3 (src/sensor/android/SDL_androidsensor.c; zlib license, third_party/sdl/LICENSE), translated to Go and changed: the default rate is 60 readings a second or the sensor's slowest allowed, the app may ask for another, the thread starts at the first open and ends with the service, the readings of an event queue are handed over in batches with their own timestamps (SDL stamps them with the time at which the thread woke up), and a sensor that is closed is never called again.
The package has only the tag of the Linux kernel (Android has it too), so that its tests run on the desktop with a scripted library, as the tests of the AAudio backend do; it is used on Android only.
Flutter: no counterpart
Index ¶
Constants ¶
const LibraryEnv = "GLUTTER_ANDROID_LIBRARY"
LibraryEnv names the environment variable that overrides the path of libandroid (SPEC §8.1).
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Options ¶
type Options struct {
// Package is the package name of the app, which the sensor manager of the NDK wants (it checks the app's permission to read
// the sensors fast against it). Empty means the name of the process, which on Android is the package.
Package string
// Log gets what cannot be returned (nil discards it).
Log *slog.Logger
}
Options are what New is given.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service is the sensors backend: it implements platform.Sensors.
Flutter: no counterpart
func (*Service) Available ¶
func (s *Service) Available(kind platform.SensorKind) bool
Available says whether the device has a default sensor of the kind.
Flutter: no counterpart
func (*Service) Close ¶
func (s *Service) Close()
Close closes every sensor that is open and ends the thread of the looper.
Flutter: no counterpart
func (*Service) Open ¶
func (s *Service) Open(ctx context.Context, kind platform.SensorKind, opts platform.SensorOpenOptions, h platform.SensorHandler) (platform.SensorDevice, error)
Open opens the default sensor of the kind and starts it. It fails with SensorUnavailable when libandroid is not there or the device has no such sensor, and SensorOpenFailed for the rest.
Flutter: no counterpart