gcadapter

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2023 License: GPL-3.0 Imports: 6 Imported by: 0

README

go-gc-adapter

A Go library for interfacing with the Gamecube controller adapter.

Example

package main

import (
	"fmt"
	"log"
	"time"

	gcadapter "github.com/Gurvan/go-gc-adapter"
)

func main() {
	adapter, err := gcadapter.NewGCAdapter()
	if err != nil {
		log.Fatalf("%v", err)
	}
	defer adapter.Close()
	go adapter.StartPolling()

	go func() {
		for range time.Tick(time.Second / time.Duration(60.)) {
			inputs := adapter.Controllers()
			fmt.Println(inputs[0])
		}
	}()
	time.Sleep(10 * time.Second)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeserializeGCControllers added in v0.1.0

func DeserializeGCControllers(data []byte) map[uint8]*rawGCInput

Types

type Buttons

type Buttons struct {
	UP    bool
	DOWN  bool
	RIGHT bool
	LEFT  bool
	Y     bool
	X     bool
	B     bool
	A     bool
	L     bool
	R     bool
	Z     bool
	START bool
}

Buttons represents the Gamecube controller buttons

type GCAdapter

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

GCAdapter represents a Gamecube controller usb adapter

func NewGCAdapter

func NewGCAdapter() (*GCAdapter, error)

NewGCAdapter connects to a Gamecube controller usb adapter and returns a pointer to it. An adapter should be closed with adapter.Close() once it's not required anymore or when the program closes. The best way of achieving that is calling defer adapter.Close() right after adapter, err := NewGCAdapter()

func (*GCAdapter) AllControllers

func (adapter *GCAdapter) AllControllers() map[uint8]*GCInputs

AllControllers return the current state of the 4 controllers (even unplugged ones)

func (*GCAdapter) Close

func (adapter *GCAdapter) Close() error

Close properly closes the adapter once it's not required anymore

func (*GCAdapter) Controller

func (adapter *GCAdapter) Controller(PORT uint8) *GCInputs

Controller return the current state of the controller on port PORT.

func (*GCAdapter) Controllers

func (adapter *GCAdapter) Controllers() map[uint8]*GCInputs

Controllers return the current state of the plugged in controllers.

func (*GCAdapter) Poll

func (adapter *GCAdapter) Poll() error

Poll polls the Gamecube usb adapter once

func (*GCAdapter) StartPolling

func (adapter *GCAdapter) StartPolling()

StartPolling starts a Gamecube adapter polling loop, where the adapter is polled at its defined polling rate (which is 125Hz by default on the official adapter). The function is meant to be wrapped in a goroutine.

type GCInputs

type GCInputs struct {
	Button    Buttons
	StickX    float32
	StickY    float32
	CX        float32
	CY        float32
	LAnalog   float32
	RAnalog   float32
	PluggedIn bool
}

GCInputs represent the state of the gamecube controller, with sticks values in [-1, 1], triggers values in [0, 1] and buttons as boolean Sticks and triggers values are calibrated, and sticks values are clamped inside the unit circle, but deadzones are not enforced.

type Offsets

type Offsets = rawGCInput

Offsets are the sticks and trigger values read right after plugging the controller or resetting it with X+Y+Start. They are used to calibrate the values returned in GCInputs.

Jump to

Keyboard shortcuts

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