Documentation
¶
Overview ¶
Package evdev is the gamepad backend of Linux: it finds the pads among the event devices of /dev/input, reads their buttons, axes and hats, and reports them to the pad manager (internal/pads) through platform.Gamepads. It is plain Go over the standard library's syscall, with no library to load (SPEC §28.2).
The decoding of the kernel's events and the numbering of buttons, axes and hats are translated to Go and changed from src/joystick/linux/SDL_sysjoystick.c of SDL 3 (zlib license, third_party/sdl/LICENSE). They are in files that carry no OS tag, so that tables of events test them on any machine; the files that talk to the kernel carry the linux tag.
Flutter: no counterpart
Index ¶
- type Opts
- type Service
- func (s *Service) MappingPlatform() string
- 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()
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Opts ¶
type Opts struct {
// Post runs a function on the UI thread; it is safe to call from any goroutine.
Post func(func())
// Logger receives the notes of the backend; nil logs nothing.
Logger *slog.Logger
// DevDir is the directory of the event devices ("/dev/input" when empty) and SysDir that of their description in sysfs
// ("/sys/class/input" when empty); tests point them at other places.
DevDir, SysDir string
// PollEvery makes the service look at the directory of the devices that often, instead of asking inotify to tell it. The
// service does so by itself (every 2 seconds) when inotify is not there for it, which happens when the user has used up the
// instances that the system allows; tests use it to try that way.
PollEvery time.Duration
// DisableHID turns the HID drivers off: every pad is read through its event device.
DisableHID bool
// HidDevDir is the directory of the hidraw nodes ("/dev" when empty). OpenHID opens the transport of a HID driver at a path;
// nil opens the hidraw node. Tests use both.
HidDevDir string
OpenHID func(path string) (gamepadhid.Transport, error)
}
Opts are the options of a Service.
Flutter: no counterpart
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service is the gamepad backend of Linux (platform.Gamepads). It finds the pads among the event devices, reads them on a goroutine of its own and hands the reports over to the UI thread with Post.
Flutter: no counterpart
func (*Service) MappingPlatform ¶
MappingPlatform implements platform.Gamepads.
func (*Service) Rumble ¶
Rumble implements platform.Gamepads with force feedback: an effect of type FF_RUMBLE is uploaded with the strengths and the length and then played, and the kernel stops it when the length is over. A duration of 0, or no strength, stops the motors.
func (*Service) RumbleTriggers ¶
RumbleTriggers implements platform.Gamepads.
func (*Service) SetPadSensors ¶
SetPadSensors implements platform.PadSensorControl: the sensors of a pad are on its HID driver.