Documentation
¶
Overview ¶
Package pad reads game controllers through SDL3 and turns them into the few actions the big picture interface understands (move, confirm, back, menu, …), with key repeat for held directions. It also drives rumble and the DualSense lightbar. SDL runs on a thread of its own and is only ever touched from there.
Index ¶
- Constants
- Variables
- type Kind
- type Manager
- func (m *Manager) InMode() (Mode, bool)
- func (m *Manager) Mode() Mode
- func (m *Manager) PlugVirtual(kind Kind) error
- func (m *Manager) Rumble(effect string)
- func (m *Manager) SetLight(hex string) error
- func (m *Manager) SetMode(mode Mode)
- func (m *Manager) SetRawListener(fn func(Raw))
- func (m *Manager) State() State
- func (m *Manager) Stop()
- func (m *Manager) UnplugVirtual() error
- func (m *Manager) VirtualAxis(axis int, value int16) error
- func (m *Manager) VirtualButton(button int, down bool) error
- type Mode
- type Raw
- type State
Constants ¶
const ( Up = "up" Down = "down" Left = "left" Right = "right" Confirm = "confirm" // ✕ / A Back = "back" // ○ / B Action = "action" // □ / X Info = "info" // △ / Y Menu = "menu" // Options / Menu View = "view" // Create / View Home = "home" // PS / Xbox button LB = "lb" RB = "rb" LT = "lt" RT = "rt" )
Actions sent to the interface.
Variables ¶
var VirtualAxes = map[string]int{"lx": 0, "ly": 1, "rx": 2, "ry": 3, "lt": 4, "rt": 5}
VirtualAxes names its axes (values -32768 to 32767; a trigger rests at -32768, which the gamepad reports as 0).
var VirtualButtons = map[string]int{
"south": 0, "east": 1, "west": 2, "north": 3, "back": 4, "guide": 5, "start": 6,
"leftstick": 7, "rightstick": 8, "lb": 9, "rb": 10,
"up": 11, "down": 12, "left": 13, "right": 14, "misc": 15, "touchpad": 20,
}
VirtualButtons names the SDL gamepad buttons a virtual controller has.
Functions ¶
This section is empty.
Types ¶
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager owns the SDL thread.
func Start ¶
Start loads SDL and begins reading controllers. onAction gets every action (repeat=true for auto-repeat of a held direction); onState gets controller changes. Both are called from the SDL thread.
func (*Manager) InMode ¶ added in v1.10.0
InMode returns the mode the SDL thread last brought SDL to, and whether SDL is running (false when that mode is Off or SDL didn't start).
func (*Manager) PlugVirtual ¶
PlugVirtual plugs in a virtual controller that looks like a DualSense (kind PlayStation) or an Xbox controller. It stays plugged in when the mode changes (SDL starts over then, and it is made again).
func (*Manager) Rumble ¶
Rumble plays a short effect: "tick" (moving), "bump" (at an edge), "confirm", "error" or "launch". A new effect replaces one still playing.
func (*Manager) SetRawListener ¶
SetRawListener sends every change of the controller's buttons and axes to fn (nil stops it), for testing a controller.
func (*Manager) UnplugVirtual ¶
UnplugVirtual removes the virtual controller.
func (*Manager) VirtualAxis ¶
VirtualAxis moves a virtual controller axis.
type Mode ¶
type Mode int
Mode is how much of the controller Seaglass uses.
const ( // Active is the full layer: input, rumble, lightbar. Active Mode = iota // Passive only listens, for while a game runs. Controllers are read // without SDL's HIDAPI drivers, so Seaglass never writes to one; // the game gets the controller exactly as it expects. Actions // keep coming (the PS button opens the overlay). Passive // Off releases controllers completely. Off )
type Raw ¶
Raw is the whole state of the controller in use: which SDL gamepad buttons are down (bit n is button n) and its axes (left stick x, y, right stick x, y, left and right trigger; -32768 to 32767, triggers from 0).
type State ¶
type State struct {
Connected bool `json:"connected"`
Name string `json:"name"`
Kind Kind `json:"kind"`
DualSense bool `json:"dualSense"`
Battery int `json:"battery"` // percent, -1 unknown
Wireless bool `json:"wireless"`
Error string `json:"error,omitempty"`
}
State describes the controller in use.