Documentation
¶
Overview ¶
Package sensors gives an app the motion sensors of the device (SPEC §28.4): the accelerometer and the gyroscope of a phone or of a browser on one, and the sensors of a gamepad (package gamepad). Flutter has no such package in its framework (the sensors_plus plugin is the closest); the names here are Glutter's.
A Sensor is opened with System.Open, keeps its latest reading, and calls its listeners with the readings that arrived since the last frame, once a frame, on the UI thread. The axes are SDL's: x to the right, y up and z out of the screen, for a device in its natural orientation.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Feed ¶
type Feed struct {
// contains filtered or unexported fields
}
Feed gives readings to a Sensor that the platform's sensors service does not make: the sensors of a gamepad (package gamepad) are made this way. An app that wants a Sensor of its own (a recording that it plays back, a test) may make one too.
Flutter: no counterpart
func NewFeed ¶
NewFeed makes a Feed whose Sensor is of the kind, with the rate that the source makes (0 when it does not say). onClose, which may be nil, runs when the sensor is closed.
Flutter: no counterpart
type Kind ¶
type Kind uint8
Kind is the kind of a motion sensor.
Flutter: no counterpart
const ( // Accelerometer measures the acceleration of the device with gravity included, in m/s². A device that lies flat on a table, // face up, reads about 9.8 on z. // // Flutter: no counterpart Accelerometer Kind = iota // Gyroscope measures the rate of rotation about the three axes, in rad/s, counterclockwise as seen from the positive end of // an axis. // // Flutter: no counterpart Gyroscope )
type Opts ¶
type Opts struct {
// Rate is the number of readings a second that the app would like. 0 leaves it to the platform (60 a second, or the fastest
// that the sensor can do if that is slower); a browser sends events at its own rate whatever is asked.
Rate float64
}
Opts are the options of Open.
Flutter: no counterpart
type Reading ¶
type Reading struct {
// Timestamp is when the reading was made, on a monotonic clock whose start is not defined: only the difference of two
// readings of the same sensor means something.
Timestamp time.Duration
// Values are x, y and z, in the unit of the kind (m/s² or rad/s).
Values [3]float64
}
Reading is one reading of a sensor.
Flutter: no counterpart
type Sensor ¶
type Sensor struct {
// contains filtered or unexported fields
}
Sensor is an open sensor. It is a platform.SensorHandler: the backend calls it on its own thread.
Flutter: no counterpart
func (*Sensor) AddListener ¶
AddListener adds a function that is called, on the UI thread, once a frame, with the readings that arrived since the last call, oldest first. The slice is valid only during the call. It returns the function that removes the listener. A sensor with no listener schedules no frames.
Flutter: no counterpart
func (*Sensor) Close ¶
Close ends the sensor: no listener is called after it returns. It may be called more than once.
Flutter: no counterpart
func (*Sensor) Dropped ¶
Dropped is how many readings were thrown away because no frame ran to deliver them (see maxPending).
Flutter: no counterpart
func (*Sensor) Latest ¶
Latest returns the last reading and whether there is one yet. It may be called from any goroutine.
Flutter: no counterpart
func (*Sensor) Rate ¶
Rate is the number of readings a second that the sensor was set to, or 0 when the platform does not say (a browser).
Flutter: no counterpart
func (*Sensor) SensorReadings ¶
func (s *Sensor) SensorReadings(in []platform.SensorReading)
SensorReadings implements platform.SensorHandler. It runs on the backend's thread: it keeps the readings and asks the UI thread for a frame to deliver them in.
type System ¶
type System struct {
// contains filtered or unexported fields
}
System is the motion sensors of the app. Get it with Of. It is made when it is first asked for, and closed with the app.
Flutter: no counterpart
func ForBinding ¶
func ForBinding(b *widgets.WidgetsBinding) *System
ForBinding returns the sensors of the binding, for code that has no BuildContext.
Flutter: no counterpart
func Of ¶
func Of(bc widgets.BuildContext) *System
Of returns the sensors of the app (the ones of the binding). An app on a platform that has no sensors service gets a System whose calls fail with SensorUnavailable.
Flutter: no counterpart
func (*System) Available ¶
Available says whether the platform has a sensors service. It does not say that the device has the sensor that the app wants: Has does, and Open fails when it has not.
Flutter: no counterpart
func (*System) Close ¶
func (s *System) Close()
Close closes every sensor that the app left open. The engine does it when the app ends.
Flutter: no counterpart
func (*System) Has ¶
Has says whether the device has a sensor of the kind. A browser cannot know before it sends the first reading, and answers yes where it has the events.
Flutter: no counterpart
func (*System) Open ¶
Open opens a sensor and starts it. It fails with SensorUnavailable when the platform has no sensors service or the device has no such sensor, SensorPermissionDenied when the user refuses it, and SensorOpenFailed for the rest (also when ctx ends first). Where the system asks the user (a browser on some systems) the call waits for the answer, until ctx ends: call it from a goroutine that is not the UI one. At most one Opts may be given.
Flutter: no counterpart