Documentation
¶
Overview ¶
Package winpad is the gamepad service of Windows without the calls into Windows: it finds the pads that XInput serves and the HID pads that Raw Input lists, reads them, and reports them to the pad manager through platform.Gamepads (SPEC §28.2). What it needs from Windows is behind two interfaces, XInputAPI and HIDSource; the real ones and the window that hears of devices arriving are in package windows (gamepads_windows.go), and the tests drive the service with fakes on any host. The code of the HID pads is translated to Go and changed from src/joystick/windows/SDL_rawinputjoystick.c of SDL 3 and the XInput code from src/joystick/windows/SDL_xinputjoystick.c (zlib license, third_party/sdl/LICENSE).
Flutter: no counterpart
Index ¶
- type HIDDescription
- type HIDDevice
- type HIDSource
- type Layout
- type Opts
- type Service
- func (s *Service) EnableExtras()
- func (s *Service) HIDReports(device uintptr, reports [][]byte, at time.Duration)
- func (s *Service) MappingPlatform() string
- func (s *Service) Rescan()
- func (s *Service) Rumble(id platform.PadID, low, high uint16, d time.Duration) error
- func (s *Service) RumbleTriggers(id platform.PadID, left, right uint16, d time.Duration) error
- func (s *Service) SetLED(id platform.PadID, r, g, b uint8) error
- func (s *Service) SetPadSensors(id platform.PadID, on bool) error
- func (s *Service) Start(h platform.PadHandler) error
- func (s *Service) Stop()
- type XInputAPI
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type HIDDescription ¶
type HIDDescription struct {
// Name is the product name of the device, empty when it has none.
Name string
// Buttons and Values are the capabilities of the input reports, and MaxItems the most items one report has.
Buttons []win32.HidpButtonCaps
Values []win32.HidpValueCaps
MaxItems int
}
HIDDescription is what the parsed report descriptor of a device says.
Flutter: no counterpart
type HIDDevice ¶
type HIDDevice struct {
// Handle is the handle of Raw Input; the reports of the device carry it.
Handle uintptr
// Path is the path of the device.
Path string
// Vendor, Product and Version are the numbers the device reports.
Vendor, Product, Version uint16
// UsagePage and Usage say what the device is (the generic desktop page and the joystick, gamepad or multi-axis usage for a
// pad).
UsagePage, Usage uint16
}
HIDDevice is a HID device that Raw Input lists, with what it says about itself.
Flutter: no counterpart
type HIDSource ¶
type HIDSource interface {
// Devices lists the HID devices that are there.
Devices() ([]HIDDevice, error)
// Describe reads the report descriptor of a device and keeps it for GetData.
Describe(d HIDDevice) (HIDDescription, error)
// GetData reads the items of a report of the device into items and says how many there are.
GetData(d HIDDevice, report []byte, items []win32.HidpData) (int, error)
// Release lets go of what Describe kept for the device.
Release(d HIDDevice)
}
HIDSource is what the service asks of Raw Input and the HID parser; package windows has the real one.
Flutter: no counterpart
type Layout ¶
type Layout struct {
// MaxItems is the most items that a report can have, the size of the buffer that HIDSource.GetData is given.
MaxItems int
// contains filtered or unexported fields
}
Layout is the buttons, axes and hats of a HID device, in the order that numbers them for the mapping.
Flutter: no counterpart
func NewLayout ¶
func NewLayout(buttons []win32.HidpButtonCaps, values []win32.HidpValueCaps, maxItems int) *Layout
NewLayout numbers the inputs of a device from its button and value capabilities. The buttons are those of the button page, in the order of their capabilities, a range counting each of its data indices; the values are sorted by usage (so X comes before Y), the hat switches are the hats and the rest are the axes, and the values that are ranges are left out, as SDL does.
Flutter: no counterpart
type Opts ¶
type Opts struct {
// Post runs a function on the UI thread; it is safe to call from any goroutine.
Post func(func())
// Clock gives the time of an event.
Clock func() time.Duration
// Logger receives the notes of the service; nil logs nothing.
Logger *slog.Logger
// XInput serves the pads of XInput; nil when the library is not there.
XInput XInputAPI
// HID lists and reads the other pads; nil for none.
HID HIDSource
// OpenHID opens the HID device at a path as the transport of a HID driver (SPEC §28.2, step 31.3); nil gives no drivers, and
// every pad is read through Raw Input. DisableDrivers does the same when the transport is there.
OpenHID func(path string) (gamepadhid.Transport, error)
DisableDrivers bool
// Asleep starts the service with its drivers asleep (EnableExtras wakes them): every pad is read through XInput or Raw
// Input, and nothing is written to a pad, until the app uses package gamepad (SPEC §28.2, "Decided in step 36.1").
Asleep bool
// PollEvery is how often the XInput pads are read while there is one (8 ms when zero); ScanEvery how often the empty slots
// are looked at and the HID devices listed when Windows has told of nothing (2 s when zero).
PollEvery, ScanEvery time.Duration
}
Opts are the options of a Service.
Flutter: no counterpart
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service is the gamepad service of Windows (platform.Gamepads). XInput pads are read by polling, the HID pads from the reports that Raw Input delivers (HIDReports), and Rescan says that a device came or went.
Flutter: no counterpart
func (*Service) EnableExtras ¶
func (s *Service) EnableExtras()
EnableExtras implements platform.PadExtras: the HID drivers wake. The pads that Raw Input serves and that have a driver are let go (the handler is told they are removed) and the next look at the devices starts their drivers and adds them. Called before Start, it makes the service start awake.
func (*Service) HIDReports ¶
HIDReports gives the service the reports that Raw Input delivered for a device, as they were read at time at. The reports are kept, so the caller may reuse its buffers. It does not block: when the service is behind, reports are dropped (each carries the whole state of the pad, so the next one repairs it).
Flutter: no counterpart
func (*Service) MappingPlatform ¶
MappingPlatform implements platform.Gamepads.
func (*Service) Rescan ¶
func (s *Service) Rescan()
Rescan says that a device came or went: the service looks at the slots and the HID devices at once. It does not block and may be called from any goroutine.
Flutter: no counterpart
func (*Service) Rumble ¶
Rumble implements platform.Gamepads for the XInput pads: the motors turn at the strengths for d, and a timer stops them. A duration of 0 stops them. The pads of the HID drivers rumble through their driver; a pad read through Raw Input cannot rumble.
func (*Service) RumbleTriggers ¶
RumbleTriggers implements platform.Gamepads: the pads of the HID drivers that have motors in their triggers rumble them; XInput has none.
func (*Service) SetLED ¶
SetLED implements platform.Gamepads: the pads of the HID drivers that have a light set it; neither XInput nor Raw Input can.
func (*Service) SetPadSensors ¶
SetPadSensors implements platform.PadSensorControl: the sensors of a pad are on its HID driver.
type XInputAPI ¶
type XInputAPI interface {
GetState(user uint32, st *win32.XInputState) uint32
SetState(user uint32, v *win32.XInputVibration) uint32
GetCapabilities(user, flags uint32, c *win32.XInputCapabilities) uint32
GetCapabilitiesEx(user uint32) (win32.XInputCapabilitiesEx, bool)
GetBatteryInformation(user uint32) (win32.XInputBatteryInformation, bool)
}
XInputAPI is what the service asks of XInput; *win32.XInput is the real one.
Flutter: no counterpart