Documentation
¶
Overview ¶
Package pads is the manager of the gamepads of an app (SPEC §28.2): it takes the pads and the raw reports that a platform backend gives (internal/platform.Gamepads), finds each pad's mapping in the table (internal/gamepaddb), keeps the state of the buttons and axes of the standard layout and tells the listeners, and turns the buttons into key events. The engine owns one manager for the app, so a pad moves the focus of every app, whether it imports package gamepad or not; package gamepad is the public face of it.
A manager belongs to the UI thread, like the rest of the framework: the platform hands its reports over with Post.
Flutter: no counterpart
Index ¶
- func KeyIDs(b gamepaddb.Button) (physical, logical uint64, ok bool)
- func TriggerKeyIDs(i int) (physical, logical uint64)
- type Event
- type EventKind
- type Host
- type Key
- type Manager
- func (m *Manager) AddListener(fn func()) (remove func())
- func (m *Manager) AddMapping(line string) (int, error)
- func (m *Manager) AddMappings(text string) (int, error)
- func (m *Manager) At(i int) *Pad
- func (m *Manager) Available() bool
- func (m *Manager) Count() int
- func (m *Manager) KeyEvents() bool
- func (m *Manager) PadAdded(info platform.PadInfo)
- func (m *Manager) PadBattery(b platform.PadBattery)
- func (m *Manager) PadEvents(events []platform.PadEvent)
- func (m *Manager) PadRemoved(id platform.PadID)
- func (m *Manager) PadSensor(s platform.PadSensor)
- func (m *Manager) PadTouch(t platform.PadTouch)
- func (m *Manager) Pads() []*Pad
- func (m *Manager) SetKeyEvents(on bool)
- func (m *Manager) Start() error
- func (m *Manager) Stop()
- func (m *Manager) Table() *gamepaddb.Table
- type Opts
- type Pad
- func (p *Pad) AddListener(fn func(Event)) (remove func())
- func (p *Pad) AddSensorListener(fn func(SensorReading)) (remove func())
- func (p *Pad) AddTouchListener(fn func(Touch)) (remove func())
- func (p *Pad) AxisChanged(t int64, a gamepaddb.Axis, v int16)
- func (p *Pad) Battery() int
- func (p *Pad) ButtonChanged(t int64, b gamepaddb.Button, down bool)
- func (p *Pad) CanRumble() bool
- func (p *Pad) CanRumbleTriggers() bool
- func (p *Pad) Connected() bool
- func (p *Pad) EnableSensors(on bool) error
- func (p *Pad) FaceStyle() gamepaddb.FaceStyle
- func (p *Pad) GUID() gamepaddb.GUID
- func (p *Pad) HasAxis(a gamepaddb.Axis) bool
- func (p *Pad) HasButton(b gamepaddb.Button) bool
- func (p *Pad) HasLED() bool
- func (p *Pad) HasSensors() bool
- func (p *Pad) ID() platform.PadID
- func (p *Pad) Kind() gamepaddb.Kind
- func (p *Pad) LatestSensor(kind platform.PadSensorKind) (SensorReading, bool)
- func (p *Pad) Mapping() string
- func (p *Pad) Name() string
- func (p *Pad) Path() string
- func (p *Pad) Power() Power
- func (p *Pad) Rumble(low, high uint16, d time.Duration) error
- func (p *Pad) RumbleTriggers(left, right uint16, d time.Duration) error
- func (p *Pad) SensorRate() float32
- func (p *Pad) SensorsEnabled() bool
- func (p *Pad) SetLED(r, g, b uint8) error
- func (p *Pad) State() State
- func (p *Pad) Touches() []Touch
- func (p *Pad) Touchpads() int
- type Power
- type SensorReading
- type State
- type Touch
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func KeyIDs ¶
KeyIDs returns the physical and logical key IDs that the button makes, and whether it makes a key at all.
Flutter: no counterpart
func TriggerKeyIDs ¶
TriggerKeyIDs returns the physical and logical key IDs of the left (0) or right (1) trigger.
Flutter: no counterpart
Types ¶
type Event ¶
type Event struct {
Pad *Pad
Time time.Duration
Kind EventKind
// Button is the button of a ButtonDown or ButtonUp.
Button gamepaddb.Button
// Axis and Value are the axis of an AxisMotion and its new raw value.
Axis gamepaddb.Axis
Value int16
}
Event is a change of the buttons or axes of a pad.
Flutter: no counterpart
type Host ¶
type Host interface {
PadManager() *Manager
}
Host is implemented by the host of the dispatcher (the engine) and found through ui.PlatformDispatcher.HostAs: it gives the manager of the app, or nil when the platform has no gamepads.
Flutter: no counterpart
type Key ¶
type Key struct {
Time time.Duration
Down bool
// Physical and Logical are the IDs of the key (services.PhysicalKeyboardKey and services.LogicalKeyboardKey).
Physical, Logical uint64
// DirectionalPad says that the key is an arrow of the D-pad, and not a game button.
DirectionalPad bool
}
Key is a key event that a pad makes (SPEC §28.2, "Pads as keys").
Flutter: no counterpart
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager keeps the pads of an app.
Flutter: no counterpart
func New ¶
New makes the manager of the gamepad service plat. It does nothing until Start.
Flutter: no counterpart
func (*Manager) AddListener ¶
func (m *Manager) AddListener(fn func()) (remove func())
AddListener adds a function that is called when a pad is connected or removed, and returns the function that removes it.
Flutter: no counterpart
func (*Manager) AddMapping ¶
AddMapping adds one mapping line, like AddMappings, whatever its platform: field says.
Flutter: no counterpart
func (*Manager) AddMappings ¶
AddMappings adds mappings in the community's format (one line each: "GUID,name,a:b0,b:b1,..."; lines with a platform: field for another platform are left out) and gives the pads that had none the chance to take one. It returns the number of mappings that are new. An error tagged GamepadMappingInvalid says the first line that could not be read; the lines before it are added.
Flutter: no counterpart
func (*Manager) At ¶
At returns the i-th connected pad that has a mapping (0 to Count()-1).
Flutter: no counterpart
func (*Manager) Available ¶
Available says whether the platform has a gamepad service at all.
Flutter: no counterpart
func (*Manager) Count ¶
Count is the number of connected pads that have a mapping, and At the pad that came i-th: a loop over them allocates nothing.
Flutter: no counterpart
func (*Manager) KeyEvents ¶
KeyEvents says whether the pads make key events.
Flutter: no counterpart
func (*Manager) PadBattery ¶
func (m *Manager) PadBattery(b platform.PadBattery)
PadBattery implements platform.PadExtrasHandler.
func (*Manager) PadRemoved ¶
PadRemoved implements platform.PadHandler.
func (*Manager) Pads ¶
Pads returns the connected pads that have a mapping, in the order they were connected. The slice is a copy.
Flutter: no counterpart
func (*Manager) SetKeyEvents ¶
SetKeyEvents turns the key events of the pads on or off. They are on at first, when the manager was given a function for them.
Flutter: no counterpart
func (*Manager) Start ¶
Start begins to look for pads. Starting a started manager does nothing.
Flutter: no counterpart
type Opts ¶
type Opts struct {
// Keys receives the key events of the pads; nil turns key events off for good.
Keys func(Key)
// Logger receives the notes of the manager; nil logs nothing.
Logger *slog.Logger
// Getenv is passed to the table of mappings for the hint: fields; nil means os.Getenv.
Getenv func(string) string
// SDKVersion is the version of Android, for the sdk>= fields of the table; 0 elsewhere.
SDKVersion int
}
Opts are the options of a manager.
Flutter: no counterpart
type Pad ¶
type Pad struct {
// Wrapper is a place for the public type that wraps the pad, so that the same pad is the same value for the app.
Wrapper any
// contains filtered or unexported fields
}
Pad is a connected gamepad that has a mapping to the standard layout.
Flutter: no counterpart
func (*Pad) AddListener ¶
AddListener adds a function that is called, on the UI thread, with every change of a button or axis of the pad, and returns the function that removes it. A listener may add and remove listeners.
Flutter: no counterpart
func (*Pad) AddSensorListener ¶
func (p *Pad) AddSensorListener(fn func(SensorReading)) (remove func())
AddSensorListener adds a function that is called, on the UI thread, with every reading of the sensors, and returns the function that removes it. A listener may add and remove listeners.
Flutter: no counterpart
func (*Pad) AddTouchListener ¶
AddTouchListener adds a function that is called, on the UI thread, when a finger goes down, moves or goes up, and returns the function that removes it. A listener may add and remove listeners.
Flutter: no counterpart
func (*Pad) AxisChanged ¶
AxisChanged implements gamepaddb.Sink.
func (*Pad) Battery ¶
Battery is the charge of the pad from 0 to 100, or -1 when it is not known.
Flutter: no counterpart
func (*Pad) ButtonChanged ¶
ButtonChanged implements gamepaddb.Sink.
func (*Pad) CanRumble ¶
CanRumble says whether the pad has motors, as its platform reported.
Flutter: no counterpart
func (*Pad) CanRumbleTriggers ¶
CanRumbleTriggers says whether the pad has motors in its triggers.
Flutter: no counterpart
func (*Pad) EnableSensors ¶
EnableSensors turns the sensors of the pad on or off: a pad reports its sensors only while they are on, which saves its battery. It fails with GamepadSensorsUnavailable when the pad has none or the platform cannot turn them on.
Flutter: no counterpart
func (*Pad) FaceStyle ¶
FaceStyle is how the face buttons of the pad are labelled.
Flutter: no counterpart
func (*Pad) HasLED ¶
HasLED says whether the pad has a light that can be set.
Flutter: no counterpart
func (*Pad) HasSensors ¶
HasSensors says whether the pad has a gyroscope and an accelerometer.
Flutter: no counterpart
func (*Pad) LatestSensor ¶
func (p *Pad) LatestSensor(kind platform.PadSensorKind) (SensorReading, bool)
LatestSensor returns the last reading of the sensor of the kind, if there is one.
Flutter: no counterpart
func (*Pad) Mapping ¶
Mapping is the mapping text of the pad ("a:b0,b:b1,..."), or "" for a pad that reports the standard layout.
Flutter: no counterpart
func (*Pad) Rumble ¶
Rumble turns the pad's motors for d; see platform.Gamepads.Rumble.
Flutter: no counterpart
func (*Pad) RumbleTriggers ¶
RumbleTriggers turns the motors of the pad's triggers for d.
Flutter: no counterpart
func (*Pad) SensorRate ¶
SensorRate is how many readings of each sensor the pad makes in a second, or 0 when it does not say.
Flutter: no counterpart
func (*Pad) SensorsEnabled ¶
SensorsEnabled says whether the sensors are on.
Flutter: no counterpart
type Power ¶
type Power struct {
State platform.PadPowerState
// Percent is from 0 to 100, or -1 when it is not known.
Percent int
}
Power is what a pad says about its battery.
Flutter: no counterpart
type SensorReading ¶
type SensorReading struct {
Pad *Pad
// Time is when the report that held the reading arrived, and SensorTime when the sensor made it, on its own clock.
Time, SensorTime time.Duration
Kind platform.PadSensorKind
// Values are the three components: rad/s for the gyroscope, m/s² (gravity included) for the accelerometer.
Values [3]float32
}
SensorReading is a reading of a motion sensor of a pad (SPEC §28.4, which makes the type public in step 31.7).
Flutter: no counterpart
type State ¶
type State struct {
// Axes are the raw values of the axes, from gamepaddb.AxisMin to gamepaddb.AxisMax (the triggers from 0).
Axes [gamepaddb.AxisCount]int16
// contains filtered or unexported fields
}
State is the buttons and axes of a pad now.
Flutter: no counterpart
type Touch ¶
type Touch struct {
Pad *Pad
// Time is when the pad reported the finger, on the system's monotonic clock.
Time time.Duration
// Touchpad and Finger number the touchpad and the finger, from 0. A PlayStation pad has one touchpad and two fingers.
Touchpad, Finger int
// Down says that the finger is on the touchpad. X and Y are from 0 to 1, from the top left corner, and where the finger
// left when it is not down; Pressure is 1 for a finger that is down and 0 for one that is not.
Down bool
X, Y, Pressure float32
}
Touch is a finger on a touchpad of a pad.
Flutter: no counterpart