evdev

package
v1.14.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 10, 2026 License: BSD-3-Clause Imports: 16 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

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 New

func New(opts Opts) *Service

New makes the service. It does nothing until Start.

Flutter: no counterpart

func (*Service) MappingPlatform

func (s *Service) MappingPlatform() string

MappingPlatform implements platform.Gamepads.

func (*Service) Rumble

func (s *Service) Rumble(id platform.PadID, low, high uint16, d time.Duration) error

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

func (s *Service) RumbleTriggers(id platform.PadID, left, right uint16, d time.Duration) error

RumbleTriggers implements platform.Gamepads.

func (*Service) SetLED

func (s *Service) SetLED(id platform.PadID, r, g, b uint8) error

SetLED implements platform.Gamepads.

func (*Service) SetPadSensors

func (s *Service) SetPadSensors(id platform.PadID, on bool) error

SetPadSensors implements platform.PadSensorControl: the sensors of a pad are on its HID driver.

func (*Service) Start

func (s *Service) Start(h platform.PadHandler) error

Start implements platform.Gamepads: it looks at the event devices that are there, watches /dev/input for the ones that come and go, and reads the pads on a goroutine of its own.

func (*Service) Stop

func (s *Service) Stop()

Stop implements platform.Gamepads.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL