All Projects → kpeu3i → gods4

kpeu3i / gods4

Licence: MIT license
Golang library to interact with Sony DualShock4

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to gods4

BlueRetro
Multiplayer Bluetooth controllers adapter for retro video game consoles
Stars: ✭ 520 (+1900%)
Mutual labels:  hid, game-controller
GlosSI
Tool for using Steam-Input controller rebinding at a system level alongside a global overlay
Stars: ✭ 1,004 (+3761.54%)
Mutual labels:  dualshock, dualshock4
ControllerBuddy
Highly advanced game controller mapping
Stars: ✭ 47 (+80.77%)
Mutual labels:  game-controller, dualshock4
ES-Timer
A USB timer powered by Digispark ATtiny85 according to 🍅 pomodoro time management technique
Stars: ✭ 45 (+73.08%)
Mutual labels:  hid
mx3000control
Perixx MX-3000 mouse unofficial configuration tool for Linux
Stars: ✭ 20 (-23.08%)
Mutual labels:  hid
cAndroid
cAndroid is tool for control your PC by Android phone
Stars: ✭ 23 (-11.54%)
Mutual labels:  game-controller
veikk-linux-driver
Linux driver for VEIKK-brand digitizers
Stars: ✭ 130 (+400%)
Mutual labels:  hid
python-hid-parser
Typed pure Python library to parse HID report descriptors
Stars: ✭ 31 (+19.23%)
Mutual labels:  hid
windows-touchpad
Make use of touchpad for handwriting in Windows
Stars: ✭ 30 (+15.38%)
Mutual labels:  hid
stadiacontroller
Command line application that emulates an Xbox 360 controller from a wired Stadia controller on Windows.
Stars: ✭ 142 (+446.15%)
Mutual labels:  hid
uC-USBH
Efficient USB host stack for embedded systems equipped with a USB host or OTG controller. Includes many class drivers such as MSC, HID, CDC-ACM, and USB2Ser.
Stars: ✭ 44 (+69.23%)
Mutual labels:  hid
belf
Balika011's PlayStation 4 ELF loader for IDA Pro 7.0/7.1
Stars: ✭ 31 (+19.23%)
Mutual labels:  playstation4
proscene
Processing library for the creation of interactive scenes
Stars: ✭ 45 (+73.08%)
Mutual labels:  hid
ConsolePort
ConsolePort - Game Controller Addon for World of Warcraft
Stars: ✭ 108 (+315.38%)
Mutual labels:  game-controller
joyconpi
An attempt at emulating a Nintendo Switch Joy-Con controller with a Raspberry Pi
Stars: ✭ 24 (-7.69%)
Mutual labels:  hid
ESP32-USB-Soft-Host
An Arduino wrapper to @sdima1357's usb_soft_host esp-idf example
Stars: ✭ 119 (+357.69%)
Mutual labels:  hid
CtrlUI
CtrlUI (Controller User Interface) is a Windows application, game and emulator launcher for your game controller, DirectXInput converts your game controller to a Xbox (XInput) controller, Fps Overlayer is a tool that shows the frames per second and the cpu, gpu and memory information.
Stars: ✭ 39 (+50%)
Mutual labels:  dualshock
authenticator-rs
Rust library to interact with Security Keys, used by Firefox
Stars: ✭ 209 (+703.85%)
Mutual labels:  hid
pi400kb
Raw HID keyboard forwarder to turn the Pi 400 into a USB keyboard
Stars: ✭ 182 (+600%)
Mutual labels:  hid
nxbt
Control your Nintendo Switch through a website, terminal, or macro.
Stars: ✭ 340 (+1207.69%)
Mutual labels:  hid

gods4

A userspace cross-platform driver for Sony DualShock 4 controller over HID. Works for Bluetooth and USB connections.

Features

  • Buttons: x, circle, square, triangle, share, options, touchpad
  • D-pad: up, down, left, right (also intermediate positions)
  • Analog sticks: left, right
  • Analog triggers: L2, R2
  • Touchpad: 2 touches and button
  • Battery
  • Gyroscope (absolute orientation)
  • Accelerometer (relative movement)
  • Activating the motors (rumble)
  • Setting the LED color

Install

Use go get to install the latest version of the library:

go get github.com/kpeu3i/[email protected]

Next, include ds4 in your application:

import "github.com/kpeu3i/gods4"

Usage

First, connect the controller to your computer using a micro-USB cable or Bluetooth.

package main

import (
	"log"
	"os"
	"os/signal"
	"syscall"

	"github.com/kpeu3i/gods4"
	"github.com/kpeu3i/gods4/led"
	"github.com/kpeu3i/gods4/rumble"
)

func main() {
	// Find all controllers connected to your machine via USB or Bluetooth
	controllers := gods4.Find()
	if len(controllers) == 0 {
		panic("No connected DS4 controllers found")
	}

	// Select first controller from the list
	controller := controllers[0]

	// Connect to the controller
	err := controller.Connect()
	if err != nil {
		panic(err)
	}

	log.Printf("* Controller #1 | %-10s | name: %s, connection: %s\n", "Connect", controller, controller.ConnectionType())

	// Disconnect controller when a program is terminated
	signals := make(chan os.Signal, 1)
	signal.Notify(signals, syscall.SIGINT, syscall.SIGTERM)
	go func() {
		<-signals
		err := controller.Disconnect()
		if err != nil {
			panic(err)
		}
		log.Printf("* Controller #1 | %-10s | bye!\n", "Disconnect")
	}()

	// Register callback for "BatteryUpdate" event
	controller.On(gods4.EventBatteryUpdate, func(data interface{}) error {
		battery := data.(gods4.Battery)
		log.Printf("* Controller #1 | %-10s | capacity: %v%%, charging: %v, cable: %v\n",
			"Battery",
			battery.Capacity,
			battery.IsCharging,
			battery.IsCableConnected,
		)

		return nil
	})

	// Register callback for "CrossPress" event
	controller.On(gods4.EventCrossPress, func(data interface{}) error {
		log.Printf("* Controller #1 | %-10s | state: press\n", "Cross")

		return nil
	})

	// Register callback for "CrossRelease" event
	controller.On(gods4.EventCrossRelease, func(data interface{}) error {
		log.Printf("* Controller #1 | %-10s | state: release\n", "Cross")

		return nil
	})

	// Register callback for "RightStickMove" event
	controller.On(gods4.EventRightStickMove, func(data interface{}) error {
		stick := data.(gods4.Stick)
		log.Printf("* Controller #1 | %-10s | x: %v, y: %v\n", "RightStick", stick.X, stick.Y)

		return nil
	})

	// Enable left and right rumble motors
	err = controller.Rumble(rumble.Both())
	if err != nil {
		panic(err)
	}

	// Enable LED (yellow) with flash
	err = controller.Led(led.Yellow().Flash(50, 50))
	if err != nil {
		panic(err)
	}

	// Start listening for controller events
	err = controller.Listen()
	if err != nil {
		panic(err)
	}

	// Output:
	// 2019/02/16 17:00:23 * Controller #1 | Connect    | name: Wireless Controller (vendor: 1356, product: 2508), connection: BT
	// 2019/02/16 17:00:23 * Controller #1 | Battery    | capacity: 77%, charging: false, cable: false
	// 2019/02/16 17:00:34 * Controller #1 | Cross      | state: press
	// 2019/02/16 17:00:34 * Controller #1 | Cross      | state: release
	// 2019/02/16 17:00:39 * Controller #1 | RightStick | x: 187, y: 98
	// 2019/02/16 17:00:39 * Controller #1 | RightStick | x: 191, y: 94
	// 2019/02/16 17:00:39 * Controller #1 | RightStick | x: 196, y: 93
	// 2019/02/16 17:00:39 * Controller #1 | RightStick | x: 212, y: 88
	// 2019/02/16 17:00:39 * Controller #1 | RightStick | x: 228, y: 79
	// 2019/02/16 17:02:52 * Controller #1 | Disconnect | bye!
}

Events

Events on which you can subscribe are listed below:

Name Data
EventCrossPress nil
EventCrossRelease nil
EventCirclePress nil
EventCircleRelease nil
EventSquarePress nil
EventSquareRelease nil
EventTrianglePress nil
EventTriangleRelease nil
EventL1Press nil
EventL1Release nil
EventL2Press byte
EventL2Release byte
EventL3Press nil
EventL3Release nil
EventR1Press nil
EventR1Release nil
EventR2Press byte
EventR2Release byte
EventR3Press nil
EventR3Release nil
EventDPadUpPress nil
EventDPadUpRelease nil
EventDPadDownPress nil
EventDPadDownRelease nil
EventDPadLeftPress nil
EventDPadLeftRelease nil
EventDPadRightPress nil
EventDPadRightRelease nil
EventSharePress nil
EventShareRelease nil
EventOptionsPress nil
EventOptionsRelease nil
EventTouchpadSwipe Touchpad
EventTouchpadPress Touchpad
EventTouchpadRelease Touchpad
EventPSPress nil
EventPSRelease nil
EventLeftStickMove Stick
EventRightStickMove Stick
EventAccelerometerUpdate Accelerometer
EventGyroscopeUpdate Gyroscope
EventBatteryUpdate Battery

TODO

  • Microphone/speaker
  • Tests

References

The DualShock 4 report format is not open and these resources have been very helpful when creating gods4:

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].