asensor

package
v1.17.3 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: BSD-3-Clause Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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 New

func New(opts Options) *Service

New makes a Service. libandroid is not loaded yet.

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

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

Jump to

Keyboard shortcuts

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