iokit

package
v1.18.2 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2026 License: BSD-3-Clause Imports: 9 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 iokit is the gamepad backend of macOS (SPEC §29.11): the pads that IOKit's HID manager reports, read as raw axes, buttons and hats, and the pads that have a HID driver (package gamepadhid), read through their reports.

Everything that decides something is plain Go with no OS tag, so tables of elements and of values test it on any host: which HID elements make axes, buttons and hats (elements.go), how a value is scaled and a hat decoded, which devices are pads, the GUID and the name of a pad, and the Service that turns what a Manager says into what platform.PadHandler gets (service.go). The calls into IOKit are in the files with the darwin tag (iokit_darwin.go, transport_darwin.go), which make a Manager.

The rules of which elements count, their order, the calibration of an axis and the decoding of a hat are those of SDL 3's src/joystick/darwin/SDL_iokitjoystick.c; the code here is a new Go version of them and is changed.

Flutter: no counterpart

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsPad

func IsPad(page, usage uint32) bool

IsPad says whether a device with the primary usage page and usage is a pad: a joystick, a game pad or a multi-axis controller of the Generic Desktop page. Keyboards, mice and the rest are not.

Flutter: no counterpart

func MatchingPages

func MatchingPages() [][2]uint32

MatchingPages are the (usage page, usage) pairs that the manager is asked to report, the three kinds of pad.

Flutter: no counterpart

Types

type Callbacks

type Callbacks struct {
	// Added is a device that was found; the devices that are there when the manager starts are found first.
	Added func(d Device)
	// Removed is a device that has gone.
	Removed func(d Device)
	// Input is an element of a device that has a new value.
	Input func(d Device, cookie uint32, value int32)
}

Callbacks are the calls that a Manager makes. They run on the UI thread (the manager is on the main run loop), never inside Manager.Start.

Flutter: no counterpart

type Device

type Device interface {
	// Info says what the device is.
	Info() DeviceInfo
	// Elements lists the elements of the device, the ones in collections too.
	Elements() []RawElement
	// Value reads the current value of an element; ok is false when the system has none.
	Value(cookie uint32) (v int32, ok bool)
	// OpenHID opens the device for the reports of a HID driver. The transport belongs to the caller.
	OpenHID() (gamepadhid.Transport, error)
	// Release lets go of the device: the Service has no more use for it.
	Release()
}

Device is a HID device that the manager found.

Flutter: no counterpart

type DeviceInfo

type DeviceInfo struct {
	Vendor, Product, Version uint16
	VendorName, ProductName  string
	// Transport is how the device is connected, as IOKit says it: "USB", "Bluetooth" and the like.
	Transport string
	// UsagePage and Usage are the primary usage of the device.
	UsagePage, Usage uint32
	// Path says where the device is on the system (its location ID), for the app that wants to tell two pads of a model apart.
	Path string
}

DeviceInfo is what a HID device says of itself (the properties of an IOHIDDevice).

Flutter: no counterpart

type Element

type Element struct {
	RawElement
	// contains filtered or unexported fields
}

Element is an element that the pad uses, with the range of the values that it has reported.

Flutter: no counterpart

func (*Element) AxisValue

func (e *Element) AxisValue(v int32) int16

AxisValue scales the value of an axis from what the device reported to the range of -32768 to 32767. The range of what the element has reported so far grows with the value, so a pad that goes beyond its logical limits still fills the range. An element whose range is a single value is passed as it is.

Flutter: no counterpart

func (*Element) ButtonValue

func (e *Element) ButtonValue(v int32) int

ButtonValue says whether the button is down: any value that is not zero is.

Flutter: no counterpart

func (*Element) HatValue

func (e *Element) HatValue(v int32) int

HatValue decodes a hat switch into a mask of the directions. A hat with four positions is read as one with eight (its steps are the even ones), a hat with eight positions is read as it is, and the value of one with another number of positions, or outside of its range (the "null state" of a hat that is released), is centered.

Flutter: no counterpart

type ElementType

type ElementType uint32

ElementType is the type of an element of a HID device (IOHIDElementType).

Flutter: no counterpart

const (
	// ElementInputMisc is an input with a value of any kind.
	//
	// Flutter: no counterpart
	ElementInputMisc ElementType = 1
	// ElementInputButton is a button.
	//
	// Flutter: no counterpart
	ElementInputButton ElementType = 2
	// ElementInputAxis is an axis.
	//
	// Flutter: no counterpart
	ElementInputAxis ElementType = 3
	// ElementCollection groups elements; the manager reads into it and gives the elements it holds.
	//
	// Flutter: no counterpart
	ElementCollection ElementType = 513
)

The types of elements that matter here.

type ForceFeedback

type ForceFeedback interface {
	// Play turns the motors at the strengths for d; a duration of 0 or no strength stops them. The two motors of the standard
	// layout are one actuator here, which turns at the mean of the two strengths (SDL's choice).
	Play(low, high uint16, d time.Duration) error
	// Close lets go of the effect and the device.
	Close()
}

ForceFeedback is the rumble of one pad.

Flutter: no counterpart

type ForceFeedbacker

type ForceFeedbacker interface {
	// HasForceFeedback says whether the device has force feedback (FFIsForceFeedback of its IOService).
	HasForceFeedback() bool
	// OpenForceFeedback makes the device's rumble: the device is created, reset and its actuators are turned on. The caller closes it.
	OpenForceFeedback() (ForceFeedback, error)
}

ForceFeedbacker is implemented by a Device that the system may give force feedback to.

Flutter: no counterpart

type Kind

type Kind uint8

Kind says what an element is to the pad.

Flutter: no counterpart

const (
	// KindNone is an element that the pad does not use.
	//
	// Flutter: no counterpart
	KindNone Kind = iota
	// KindAxis is a raw axis.
	//
	// Flutter: no counterpart
	KindAxis
	// KindButton is a raw button.
	//
	// Flutter: no counterpart
	KindButton
	// KindHat is a raw hat.
	//
	// Flutter: no counterpart
	KindHat
)

The kinds of elements.

func Classify

func Classify(t ElementType, page, usage uint32) Kind

Classify says what an input element of the given type, usage page and usage is: a wheel, a throttle or a stick axis is an axis, a hat switch is a hat, and the buttons of the Button and Consumer pages (the pause button of some pads is a consumer control), the d-pad usages, Start, Select and the main menu are buttons.

Flutter: no counterpart

type Layout

type Layout struct {
	Axes, Buttons, Hats []*Element
	// contains filtered or unexported fields
}

Layout is the buttons, axes and hats of a device in the order of the raw indices that the app sees: each list is sorted by usage (elements with the same usage keep the order in which the device listed them).

Flutter: no counterpart

func BuildLayout

func BuildLayout(raw []RawElement) *Layout

BuildLayout makes the layout of a device from its elements, in the order in which the manager listed them. An element that the pad does not use is left out, and so is one whose cookie was seen already.

Flutter: no counterpart

func (*Layout) Count

func (l *Layout) Count() int

Count returns the number of elements of the layout.

Flutter: no counterpart

type Manager

type Manager interface {
	// Start begins to report. It may be called again after Stop.
	Start(cb Callbacks) error
	// Stop ends the reports and lets go of what the manager holds; no callback is made after it returns.
	Stop()
}

Manager finds the HID devices of the system that may be pads and reports what they do.

Flutter: no counterpart

type Options

type Options struct {
	// Manager finds the devices.
	Manager Manager
	// Post runs a function on the UI thread; it is safe to call from any goroutine.
	Post func(func())
	// Clock is the monotonic clock that stamps the events; the default is the time since the service was made.
	Clock func() time.Duration
	// Logger receives the notes of the backend; nil logs nothing.
	Logger *slog.Logger
	// DisableHID turns the HID drivers off: every pad is read through its elements.
	DisableHID bool
}

Options are the options of a Service.

Flutter: no counterpart

type RawElement

type RawElement struct {
	// Cookie names the element in its device.
	Cookie uint32
	Type   ElementType
	Page   uint32
	Usage  uint32
	// Min and Max are the logical minimum and maximum of the element.
	Min, Max int32
}

RawElement is an element of a HID device as the manager lists it.

Flutter: no counterpart

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service is the gamepad backend of macOS (platform.Gamepads). A pad is read through its HID elements, or, when package gamepadhid has a driver for its model, through its HID reports, which gives the light, the touchpad, the motion sensors and the trigger motors that the elements do not. Its methods and the callbacks of the manager all run on the UI thread.

The rumble of a pad read through its elements is the Force Feedback framework's (step 37.3, after SDL's iokit joystick): one sine effect that the two motors' strengths set; the pads that a HID driver serves rumble through it.

Flutter: no counterpart

func New

func New(o Options) *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: the mappings of "Mac OS X".

func (*Service) Rumble

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

Rumble implements platform.Gamepads.

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.

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