ns2pro

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2026 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Overview

Package ns2pro provides a Nintendo Switch 2 Pro Controller compatible HID device.

Index

Constants

View Source
const (
	DefaultVID                 = 0x057E
	DefaultPID                 = 0x2069
	DefaultSerialEnding        = "00"
	DefaultSerial              = "VIIPER-NS2PRO-" + DefaultSerialEnding
	DefaultBatteryVolts uint16 = 3800
)
View Source
const (
	EndpointHIDIn   = 0x81
	EndpointHIDOut  = 0x01
	EndpointBulkOut = 0x02
	EndpointBulkIn  = 0x82
)
View Source
const (
	ReportIDCommon = 0x05
	ReportIDPro    = 0x09
	ReportIDOutput = 0x02
)
View Source
const (
	InputReportSize  = 64
	OutputReportSize = 64
	InputWireSize    = 24
	OutputRumbleSize = 32
	OutputWireSize   = 34
)
View Source
const (
	OutputFlagRumble = 0x01
	OutputFlagLED    = 0x02
)
View Source
const (
	StickMin    uint16 = 0
	StickCenter uint16 = 0x0800
	StickMax    uint16 = 0x0FFF
	BatteryMax  uint8  = 9
)
View Source
const (
	FeatureButtons = 0x01
	FeatureSticks  = 0x02
	FeatureIMU     = 0x04
	FeatureMouse   = 0x10
	FeatureRumble  = 0x20
)
View Source
const (
	ButtonB uint32 = 1 << iota
	ButtonA
	ButtonY
	ButtonX
	ButtonR
	ButtonZR
	ButtonPlus
	ButtonRightStick
	ButtonDown
	ButtonRight
	ButtonLeft
	ButtonUp
	ButtonL
	ButtonZL
	ButtonMinus
	ButtonLeftStick
	ButtonHome
	ButtonCapture
	ButtonGR
	ButtonGL
	ButtonC
	ButtonHeadset
)

Variables

This section is empty.

Functions

func MakeDescriptor

func MakeDescriptor() usb.Descriptor

Types

type InputState

type InputState struct {
	Buttons uint32

	LX, LY uint16
	RX, RY uint16

	AccelX, AccelY, AccelZ int16
	GyroX, GyroY, GyroZ    int16
}

nolint viiper:wire ns2pro c2s buttons:u32 lx:u16 ly:u16 rx:u16 ry:u16 accelX:i16 accelY:i16 accelZ:i16 gyroX:i16 gyroY:i16 gyroZ:i16

func (*InputState) MarshalBinary

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

func (*InputState) UnmarshalBinary

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

type MetaState

type MetaState struct {
	SerialNumber  string `json:"serial_number"`
	BatteryLevel  uint8  `json:"battery_level"`
	Charging      bool   `json:"charging"`
	ExternalPower bool   `json:"external_power"`
	BatteryVolts  uint16 `json:"battery_volts"`
}

type NS2Pro

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

func New

func New(o *device.CreateOptions) (*NS2Pro, error)

func (*NS2Pro) GetDescriptor

func (d *NS2Pro) GetDescriptor() *usb.Descriptor

func (*NS2Pro) GetDeviceSpecificArgs

func (d *NS2Pro) GetDeviceSpecificArgs() map[string]any

func (*NS2Pro) HandleControl

func (d *NS2Pro) HandleControl(bmRequestType, bRequest uint8, wValue, wIndex uint16, wLength uint16, data []byte) ([]byte, bool)

func (*NS2Pro) HandleTransfer

func (d *NS2Pro) HandleTransfer(ep uint32, dir uint32, out []byte) []byte

func (*NS2Pro) SetMetaState

func (d *NS2Pro) SetMetaState(meta MetaState)

func (*NS2Pro) SetOutputCallback

func (d *NS2Pro) SetOutputCallback(f func(OutputState)) func()

func (*NS2Pro) UpdateInputState

func (d *NS2Pro) UpdateInputState(state InputState)

type OutputState

type OutputState struct {
	LeftRumble    [16]byte
	RightRumble   [16]byte
	Flags         uint8
	PlayerLedMask uint8
}

nolint viiper:wire ns2pro s2c leftRumble:u8*16 rightRumble:u8*16 flags:u8 playerLedMask:u8

func (*OutputState) MarshalBinary

func (o *OutputState) MarshalBinary() ([]byte, error)

func (*OutputState) UnmarshalBinary

func (o *OutputState) UnmarshalBinary(data []byte) error

Jump to

Keyboard shortcuts

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