xbox360

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2026 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package xbox360 provides an Xbox 360 controller device implementation.

Index

Constants

View Source
const (
	ButtonDPadUp    = 0x0001
	ButtonDPadDown  = 0x0002
	ButtonDPadLeft  = 0x0004
	ButtonDPadRight = 0x0008
	ButtonStart     = 0x0010
	ButtonBack      = 0x0020
	ButtonLThumb    = 0x0040 // Left stick button
	ButtonRThumb    = 0x0080 // Right stick button
	ButtonLShoulder = 0x0100 // Left bumper (LB)
	ButtonRShoulder = 0x0200 // Right bumper (RB)
	ButtonGuide     = 0x0400 // Xbox/Guide button (center logo)
	ButtonA         = 0x1000
	ButtonB         = 0x2000
	ButtonX         = 0x4000
	ButtonY         = 0x8000
)

Button bitmasks for Xbox 360 controller (XInput compatible)

Variables

This section is empty.

Functions

This section is empty.

Types

type InputState

type InputState struct {
	// Button bitfield (lower 16 bits used typically), higher bits reserved
	Buttons uint32
	// Triggers: 0-255
	LT, RT uint8
	// Sticks: signed 16-bit little endian values
	LX, LY int16
	RX, RY int16
}

InputState represents the controller state used to build a report. Values are more or less XInput's C API viiper:wire xbox360 c2s buttons:u32 lt:u8 rt:u8 lx:i16 ly:i16 rx:i16 ry:i16

func (*InputState) BuildReport

func (x *InputState) BuildReport() []byte

BuildReport encodes an InputState into the 20-byte Xbox 360 wired USB input report. Layout (indices in the returned slice):

 0: 0x00              - Report ID
 1: 0x14              - Payload size (20 bytes)
 2: Buttons (low byte)
 3: Buttons (high byte)
 4: LT (0-255)
 5: RT (0-255)
 6-7: LX (little-endian int16)
 8-9: LY (little-endian int16)
10-11: RX (little-endian int16)
12-13: RY (little-endian int16)
14-19: Reserved / zero

func (*InputState) MarshalBinary

func (x *InputState) MarshalBinary() ([]byte, error)

MarshalBinary encodes InputState to 14 bytes.

func (*InputState) UnmarshalBinary

func (x *InputState) UnmarshalBinary(data []byte) error

UnmarshalBinary decodes 14 bytes into InputState.

type XRumbleState

type XRumbleState struct {
	LeftMotor  uint8
	RightMotor uint8
}

XRumbleState is the wire format for rumble/motor commands sent from device to client. Total size: 2 bytes (fixed). Layout:

LeftMotor: 1 byte (0-255)
RightMotor: 1 byte (0-255)

viiper:wire xbox360 s2c left:u8 right:u8

func (*XRumbleState) MarshalBinary

func (r *XRumbleState) MarshalBinary() ([]byte, error)

MarshalBinary encodes XRumbleState to 2 bytes.

func (*XRumbleState) UnmarshalBinary

func (r *XRumbleState) UnmarshalBinary(data []byte) error

UnmarshalBinary decodes 2 bytes into XRumbleState.

type Xbox360

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

func New

func New(o *device.CreateOptions) *Xbox360

New returns a new Xbox360 device.

func (*Xbox360) GetDescriptor

func (x *Xbox360) GetDescriptor() *usb.Descriptor

func (*Xbox360) HandleTransfer

func (x *Xbox360) HandleTransfer(ep uint32, dir uint32, out []byte) []byte

HandleTransfer implements interrupt IN/OUT for Xbox360.

func (*Xbox360) SetRumbleCallback

func (x *Xbox360) SetRumbleCallback(f func(XRumbleState))

SetRumbleCallback sets a callback that will be invoked when rumble commands arrive.

func (*Xbox360) UpdateInputState

func (x *Xbox360) UpdateInputState(state InputState)

UpdateInputState updates the device's current input state (thread-safe).

Jump to

Keyboard shortcuts

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