gamepad

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2022 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Overview

Package gamepad implements a linux gamepad as an input controller.

Index

Constants

This section is empty.

Variables

View Source
var GamepadMappings = map[string]Mapping{

	"Pro Controller": {
		Axes: map[evdev.AbsoluteType]input.Control{
			0:  input.AbsoluteX,
			1:  input.AbsoluteY,
			3:  input.AbsoluteRX,
			4:  input.AbsoluteRY,
			16: input.AbsoluteHat0X,
			17: input.AbsoluteHat0Y,
		},
		Buttons: map[evdev.KeyType]input.Control{
			304: input.ButtonSouth,
			305: input.ButtonEast,
			306: input.ButtonWest,
			307: input.ButtonNorth,
			308: input.ButtonLT,
			309: input.ButtonRT,
			310: input.ButtonLT2,
			311: input.ButtonRT2,
			312: input.ButtonSelect,
			313: input.ButtonStart,
			314: input.ButtonLThumb,
			315: input.ButtonRThumb,
			316: input.ButtonMenu,
			317: input.ButtonRecord,
		},
	},

	"8BitDo Pro 2": {
		Axes: map[evdev.AbsoluteType]input.Control{
			0:  input.AbsoluteX,
			1:  input.AbsoluteY,
			2:  input.AbsoluteZ,
			3:  input.AbsoluteRX,
			4:  input.AbsoluteRY,
			5:  input.AbsoluteRZ,
			16: input.AbsoluteHat0X,
			17: input.AbsoluteHat0Y,
		},
		Buttons: map[evdev.KeyType]input.Control{
			304: input.ButtonSouth,
			305: input.ButtonEast,
			306: input.ButtonWest,
			307: input.ButtonNorth,
			308: input.ButtonLT,
			309: input.ButtonRT,
			310: input.ButtonSelect,
			311: input.ButtonStart,
			312: input.ButtonLThumb,
			313: input.ButtonRThumb,
			139: input.ButtonMenu,
		},
	},

	"Microsoft X-Box 360 pad": {
		Axes: map[evdev.AbsoluteType]input.Control{
			0:  input.AbsoluteX,
			1:  input.AbsoluteY,
			2:  input.AbsoluteZ,
			3:  input.AbsoluteRX,
			4:  input.AbsoluteRY,
			5:  input.AbsoluteRZ,
			16: input.AbsoluteHat0X,
			17: input.AbsoluteHat0Y,
		},
		Buttons: map[evdev.KeyType]input.Control{
			304: input.ButtonSouth,
			305: input.ButtonEast,
			307: input.ButtonWest,
			308: input.ButtonNorth,
			310: input.ButtonLT,
			311: input.ButtonRT,
			314: input.ButtonSelect,
			315: input.ButtonStart,
			317: input.ButtonLThumb,
			318: input.ButtonRThumb,
			316: input.ButtonMenu,
		},
	},

	"Xbox Wireless Controller": {
		Axes: map[evdev.AbsoluteType]input.Control{
			0:  input.AbsoluteX,
			1:  input.AbsoluteY,
			10: input.AbsoluteZ,
			2:  input.AbsoluteRX,
			5:  input.AbsoluteRY,
			9:  input.AbsoluteRZ,
			16: input.AbsoluteHat0X,
			17: input.AbsoluteHat0Y,
		},
		Buttons: map[evdev.KeyType]input.Control{
			304: input.ButtonSouth,
			305: input.ButtonEast,
			307: input.ButtonWest,
			308: input.ButtonNorth,
			310: input.ButtonLT,
			311: input.ButtonRT,
			314: input.ButtonSelect,
			315: input.ButtonStart,
			317: input.ButtonLThumb,
			318: input.ButtonRThumb,
			316: input.ButtonMenu,
			167: input.ButtonRecord,
		},
	},

	"Microsoft Xbox One X pad": {
		Axes: map[evdev.AbsoluteType]input.Control{
			0:  input.AbsoluteX,
			1:  input.AbsoluteY,
			2:  input.AbsoluteZ,
			3:  input.AbsoluteRX,
			4:  input.AbsoluteRY,
			5:  input.AbsoluteRZ,
			16: input.AbsoluteHat0X,
			17: input.AbsoluteHat0Y,
		},
		Buttons: map[evdev.KeyType]input.Control{
			304: input.ButtonSouth,
			305: input.ButtonEast,
			307: input.ButtonWest,
			308: input.ButtonNorth,
			310: input.ButtonLT,
			311: input.ButtonRT,
			314: input.ButtonSelect,
			315: input.ButtonStart,
			317: input.ButtonLThumb,
			318: input.ButtonRThumb,
			316: input.ButtonMenu,
		},
	},

	"FORT Robotics nVSC Application": {
		Axes: map[evdev.AbsoluteType]input.Control{
			0:  input.AbsoluteX,
			1:  input.AbsoluteY,
			2:  input.AbsoluteZ,
			3:  input.AbsoluteRX,
			4:  input.AbsoluteRY,
			5:  input.AbsoluteRZ,
			16: input.AbsoluteHat0X,
			17: input.AbsoluteHat0Y,
		},
		Buttons: map[evdev.KeyType]input.Control{
			288: input.ButtonSouth,
			289: input.ButtonEast,
			291: input.ButtonWest,
			290: input.ButtonNorth,
			292: input.ButtonEStop,
		},
	},

	"USB Gamepad": {
		Axes: map[evdev.AbsoluteType]input.Control{
			0:  input.AbsoluteX,
			1:  input.AbsoluteY,
			2:  input.AbsoluteRY,
			5:  input.AbsoluteRX,
			16: input.AbsoluteHat0X,
			17: input.AbsoluteHat0Y,
		},
		Buttons: map[evdev.KeyType]input.Control{
			288: input.ButtonNorth,
			289: input.ButtonEast,
			291: input.ButtonWest,
			290: input.ButtonSouth,

			292: input.ButtonLT,
			293: input.ButtonRT,
			294: input.ButtonLT2,
			295: input.ButtonRT2,

			296: input.ButtonSelect,
			297: input.ButtonStart,
		},
	},

	"Wireless Controller": {
		Axes: map[evdev.AbsoluteType]input.Control{
			0:  input.AbsoluteX,
			1:  input.AbsoluteY,
			2:  input.AbsoluteZ,
			3:  input.AbsoluteRX,
			4:  input.AbsoluteRY,
			5:  input.AbsoluteRZ,
			16: input.AbsoluteHat0X,
			17: input.AbsoluteHat0Y,
		},
		Buttons: map[evdev.KeyType]input.Control{
			304: input.ButtonSouth,
			305: input.ButtonEast,
			307: input.ButtonNorth,
			308: input.ButtonWest,
			310: input.ButtonLT,
			311: input.ButtonRT,
			314: input.ButtonSelect,
			315: input.ButtonStart,
			317: input.ButtonLThumb,
			318: input.ButtonRThumb,
			316: input.ButtonMenu,
		},
	},
}

GamepadMappings contains all the axes/button translations for each model. use evtest on linux figure out what maps to what.

Functions

func NewController

func NewController(ctx context.Context, _ registry.Dependencies, config config.Component, logger golog.Logger) (interface{}, error)

NewController creates a new gamepad.

Types

type Config

type Config struct {
	DevFile       string `json:"dev_file"`
	AutoReconnect bool   `json:"auto_reconnect"`
}

Config is used for converting config attributes.

type Mapping

type Mapping struct {
	Buttons map[evdev.KeyType]input.Control
	Axes    map[evdev.AbsoluteType]input.Control
}

Mapping represents the evdev code to input.Control mapping for a given gamepad model.

Jump to

Keyboard shortcuts

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