Help us shape the future of Go! Take the 2026 Go Developer Survey

dualshock

package module
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2019 License: MIT Imports: 2 Imported by: 0

README

go-dualshock

Version Build Status GoDoc Go Report Card

Connect a PS4 DualShock controller with your go program.

Install
go get github.com/kvartborg/go-dualshock
Example
package main

import (
    "fmt"
    "log"
    "github.com/karalabe/hid"
    dualshock "github.com/kvartborg/go-dualshock"
)

func main() {
    vendorID, productID := uint16(1356), uint16(1476)
    devices := hid.Enumerate(vendorID, productID)

    if len(devices) == 0 {
        log.Fatal("no dualshock controller where found")
    }

    device, err := devices[0].Open()

    if err != nil {
        log.Fatal(err)
    }

    controller := dualshock.New(device)

    controller.Listen(func(state dualshock.State) {
        fmt.Println(state.Analog.L2)
    })
}
License

This project is licensed under the MIT License.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Controller

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

Controller describes the reference to the hardware device

func New

func New(reader io.Reader) *Controller

New returns a new controller which transforms input from the device to a valid controller state

func (*Controller) Close

func (c *Controller) Close()

Close the listener

func (*Controller) Errors added in v1.0.1

func (c *Controller) Errors() <-chan error

Errors returns a channel of reader errors

func (*Controller) Listen

func (c *Controller) Listen(handle func(State))

Listen for controller state changes

type DPad

type DPad struct {
	X, Y int
}

DPad is the data structure describing the joysticks on the controller

type Motion

type Motion struct {
	X, Y, Z int16
}

Motion contains information about acceleration in x, y and z axis

type Orientation

type Orientation struct {
	Roll, Yaw, Pitch int16
}

Orientation describes roll, yaw and pith of the controller

type State

type State struct {
	L1, L2, L3                      bool
	R1, R2, R3                      bool
	Up, Down, Left, Right           bool
	Cross, Circle, Square, Triangle bool
	Share, Options, PSHome          bool
	Timestamp, BatteryLevel         int
	LeftDPad                        DPad
	RightDPad                       DPad
	Motion                          Motion
	Orientation                     Orientation

	// TrackPad is true if its pressed
	TrackPad bool

	// TrackPad0 contains info relating to a touch event
	TrackPad0 TrackPad

	// TrackPad1 only register touches if TrackPad0 also does, this enables
	// multi touch functionality
	TrackPad1 TrackPad
	// Analog describes the analog position of buttons, on the PS4 controller its
	// only L2 and R2 which has analog output as well as digital.
	Analog struct{ L2, R2 int }
}

State is the overall state of the controller, the controller will output 254 states within a second.

type TrackPad

type TrackPad struct {
	ID     int
	Active bool
	X, Y   int
}

TrackPad is the touch surface in the middle of the controller

Jump to

Keyboard shortcuts

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