Giter Club home page Giter Club logo

dualsense-windows's Introduction

DualSense on Windows [API]

Windows API for the PS5 DualSense controller. Written in C++ for C++. This API will help you using the DualSense controller in your windows C++ Applications / Projects.

❗ ​Warning: The current release state is still a preview release. The library may not work as intended!

Features

  • Reading all button input from the controller
  • Reading the analog sticks and analog triggers
  • Reading the two finger touch positions
  • Reading the Accelerometer and Gyroscope
  • Using the haptic feedback for default rumbleing
  • Controlling the adaptive triggers (3 Types of effects) and reading back the users force while active
  • Controlling the RGB color of the lightbar
  • Setting the player indication LEDs and the microphone LED

The library is still in active development and will be extended with additional features soon. Consider checking out our Road-map for further information.

Using the API

  1. Download the DualSenseWindows_VX.X.zip file from the latest release found at the Release Page
  2. Unzip the archive to your computer
  3. Read the DualSenseWindows.pdf PDF documentation to get the specific information for your current release

If you don't want to waste time reading the documentation - this is the minimal example on how to use the library:

#include <Windows.h>
#include <ds5w.h>
#include <iostream>

int main(int argc, char** argv){
   	// Array of controller infos
	DS5W::DeviceEnumInfo infos[16];
	
	// Number of controllers found
	unsigned int controllersCount = 0;
	
	// Call enumerate function and switch on return value
	switch(DS5W::enumDevices(infos, 16, &controllersCount)){
		case DS5W_OK:
        // The buffer was not big enough. Ignore for now
		case DS5W_E_INSUFFICIENT_BUFFER:
			break;
			
		// Any other error will terminate the application
		default:
			// Insert your error handling
			return -1;
	}
    
    // Check number of controllers
    if(!controllersCount){
		return -1;
	}

	// Context for controller
	DS5W::DeviceContext con;
	
	// Init controller and close application is failed
	if(DS5W_FAILED(DS5W::initDeviceContext(&infos[0], &con))){
		return -1;
	}
    
   	// Main loop
	while(true){
		// Input state
		DS5W::DS5InputState inState;
	
		// Retrieve data
		if (DS5W_SUCCESS(DS5W::getDeviceInputState(&con, &inState))){
			// Check for the Logo button
			if(inState.buttonsB & DS5W_ISTATE_BTN_B_PLAYSTATION_LOGO){
				// Break from while loop
				break;
			}
		
            // Create struct and zero it
			DS5W::DS5OutputState outState;
			ZeroMemory(&outState, sizeof(DS5W::DS5OutputState));

			// Set output data
			outState.leftRumble = inState.leftTrigger;
			outState.rightRumble = inState.rightTrigger;

			// Send output to the controller
			DS5W::setDeviceOutputState(&con, &outState);
		}
	}
	
	// Shutdown context
	DS5W::freeDeviceContext(&con);
    
    // Return zero
   	return 0;
}

Known issues

  • When the controller being shut down while connected via Bluetooth (Holding the PS button). The lib will encounter a dead lock within getDeviceInputState(...) call. The function will return as soon as the controller is getting reconnected. Not encountering over USB, over USB the expected DS5W_E_DEVICE_REMOVED error is returned.

Special thanks to

I have partially used the following sources to implement the functionality:

Important Informations about Trademarks

dualsense-windows's People

Contributors

16-bit-dog avatar describe19 avatar elliotwoods avatar kitatus avatar leifmessinger avatar ohjurot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dualsense-windows's Issues

Unreal Engine 4 Port

Hey all,
I've created a rudimentary port of the code to Unreal Engine 4 as a plugin. Did you want to include this in the repo somehow or would you rather I fork and place it elsewhere?

It's still a work in progress but it is functional.

Which CRC32 algorithm for PS5 Controller BT package? [Help wanted]

Hi,
i am trying to use the PS5 controller via bluetooth with a microcontroller (ESP32) and the Arduino framework. This library offers the possibility to receive and process the input from the controller without problems. The previous version (for the PS4 controller) also offers the functionality to send an output and for example control the RGB LED of the controller. Unfortunately, this function is not adapted in the library for the PS5 controller, so it does not work. Therefore I try to implement this function based on this repository. I have already posted my current status here.
My question:
Which algorithm must be used to calculate the CRC32 checksum? I have of course looked at the algorithm in DS_CRC32.cpp. However, when I run it on my ESP32 (32bit), it gives a result that I can't find in this online calculator that I use as a reference. Therefore, my question is how I can check whether the ESP32 calculates the checksum correctly.
I would be very happy if someone can help me further. If there are any uncertainties regarding my question, please bring them to my attention.

gyroscope, 3rd axis not working ?

i think one of the axes is missing,
when the controller is layed flat on a table and i turn it to the left and right there is no value chang in
inState.gyroscope.x nor
inState.gyroscope.y nor
inState.gyroscope.z

compile and run the attached file to test what i mean

main.cpp.txt

953fde32-c67b-4505-9a78-18a16c43002f.mp4

Input / Output buffer

Hello, I have a question. Can I "read" previous output data, for example, if my controller has some rumble, can I save it and put it in the output.
I just want to use your API for another application that will change only some output data and the rest will be saved (like led and rumble).
As I understood, evaluateHidInputBuffer gets data from controller buffer and createHidOutputBuffer puts data in controller buffer, but I didn't understand why 0x02 is rightStick.x for input and same pointer is rightRumble for output. But so mysterious thing that I saw that after clearing buffer, filling it in createHidOutputBuffer, writing it to the controller and then reading it, it gets other data. I don't understand how it works. I guess I need read WinAPI documentation. Can you send some documentation which I should read or explain how it works and why these pointers used for buffer?
I'm sorry for this tangled question and my bad English, I hope you understood :)

Question - Haptic feedback

Hi,

I'm currently writing a library for Android which allows it to natively process inputs from Dualshock and Dualsense controller. I would like to use the haptic feedback instead of rumble emulation. I found your project and it seems quite nice :)
The reason why I want to add haptic feedback is that I have a 3rd Party PlayStation Remote Play app and I receive haptic audio feedback data from the PS5 but I don't know what to do with this data. I guess I have to forward the data to the USB audio output endpoint of the Dualsense controller but unfortunately it doesn't do anything. Yesterday I found this interesting topic on reddit

https://www.reddit.com/r/PS5/comments/jnp8tu/heres_how_to_get_audio_haptic_feedback_with/

So it seems it works fine. Do you have any experience in regards to this topic (as you have it mentioned in your roadmap)? Or maybe even somewhere a proof of concept example? Any help would be appreciated, feel free to close this issue.

Gyro callibration

Steam added some time ago gyro (IMU) calibration. It can be launched from big picture mode.

Left rumble is much more intense than right rumble

There's quite a difference between setting outstate.leftRumble = 0xFF and outstate.rightRumble = 0xFF. The left one is much deeper and more intense.

Using USB connection.

edit: The vibration frequencies are about an octave apart, left is B1 and right B2.

Dead project

There has been no commit the past 3 years, and this is the only project currently supporting DualSense features on Windows.
The lead maintainer (Ohjurot) appears to still be active, anyone know whats going on?

Audio Graph (Version 0.2) and Internal Rework (Version 0.3)

Audio

Sorry for the recent inactivity of this project but my EE university studies are currently quit demanding I didn't have much time. However, I have created a "Audio graph" to illustrate the audio flow currently planned.
You can take a look at it here https://github.com/Ohjurot/DualSense-Windows/blob/audio/Doc/Audio/audio_graph.pdf

Feedback is highly appreciated I have not started the implementation yet!

Rework and Additions

Since audio and some planed features require a more sophisticated allocation and background worker concept I’m planning to rework the internal flow of memory allocation and I/O calls to be more advanced and fully customisable (when things are done you will be able to integrate the API in your Engine's job system; But don’t worry there will be an easy to use DefaultInit() function)
Currently I can't tell you much about the concrete plans because I have not started working on it. But there will be a class IMemoryAllocator and struct API_FLOW_DESC to optionally configure the behaviour of the API.

Bluetooth sound clues

I randomly stumbled upon an issue in ViGemBus pointing a russian post where a guy reverse engineered bluetooth audio for ds4.
He successfully determined that DS4 uses standard SBC codec and actually sent an audio stream through bluetooth.
I don't know how well this will word for DualSense since it has quadraphonic audio instead of simple stereo, but nevertheless it's something worth investigating in my opinion.

nefarius/ViGEmBus#61

If you need help understanding original post hit me up, I'm a native russian speaker.

export

can you please add feature to send data to external application like JSON file or screaming by someway to use it by external or managed DLL.

Is the Section trigger effect set up properly?

In processTrigger(), the code for the Continuous trigger effect looks like this:

case DS5W::TriggerEffectType::ContinuousResitance:
// Mode
buffer[0x00] = 0x01;
// Parameters
buffer[0x01] = ptrEffect->Continuous.startPosition;
buffer[0x02] = ptrEffect->Continuous.force;
break;

And the code for the Section trigger effect looks like this:

case DS5W::TriggerEffectType::SectionResitance:
// Mode
buffer[0x00] = 0x02;
// Parameters
buffer[0x01] = ptrEffect->Continuous.startPosition;
buffer[0x02] = ptrEffect->Continuous.force;
break;

The Section trigger effect sets the first part of the array to a different value, which probably makes it do the Section effect rather than the Continuous effect, but the rest of that code actually uses the values from the Continuous effect.

The value for the end position should be put somewhere, correct?

Also, shouldn't the struct for the Section effect contain a value for the force to be used?

Problems with run code (can you provide help please?)

Hi, i've wrote a code and now i want to run it to see if it work. I've downloaded Mincrosoft Visual Studio from the official site and i've installed it correctly. So I've created a new project in visual studio (following the quick start guide in the PDF) and debugged.
i've copied and pasted the "ds5w.h" code text because it cannot open that file, but at the end of the operation it tells me this error: "error LNK2019: unresolved external symbol main referenced in function "int __cdecl invoke_main(void)" (?invoke_main@@yahxz)".
How i can bypass this problem?
And how can I run it with my Dualsense?
Can you answer me please?
Thank you at this splendid community

Accelerometer and gyroscope seem to be swapped

Hello!

Awesome implementation! Thank you so much for making it available at github!
I've tested your code (commit 0b869f4). My impression is accelerometer and gyroscope readings are swapped. I.e. accelerometer shows angular velocity and gyroscope shows acceleration.

For example, this code
builder << "gyro x: " << (int)inState.gyroscope.x << std::endl;
builder << "gyro y: " << (int)inState.gyroscope.y << std::endl;
builder << "gyro z: " << (int)inState.gyroscope.z << std::endl;
builder << "acc x: " << (int)inState.accelerometer.x << std::endl;
builder << "acc y: " << (int)inState.accelerometer.y << std::endl;
builder << "acc z: " << (int)inState.accelerometer.z << std::endl;

provides this output (controller is 100% stationary)
gyro x: -243
gyro y: 8187
gyro z: 1453
acc x: -5
acc y: 11
acc z: 2

.NET support or Raspberrypi

I am using a project using Raspberry pi to control devices I need to use PlayStation5 new buttons and touch sensor, feedback and other features in my project , do you have example or sln file for .NET
Thank you

BT gyro info reading with another program

There was a link from the other issue's form, it had a link to some other software.
Darn link didn't show up
I think the "Input reports" correspond to the 78 bytes in the buffer.
0-9 seems to be the same as what we get
11 is 1 when the ps button is clicked
11 is 2 when the touchpad is clicked
11 is 4 (third bit) when the mute button is clicked
17-28 seem to be the gyro
34-37 seem to be the touchpad
39-41 seem to be the second finger on the touchpad
38 and 42 are wildin, but seem to be connected to the touchpad data
52 counts up each poll, then overflows to 53, which I assume overflows to 54,55, and 56
29 to 32 seem to be more precise time, note how 52-53 and 31-32 are the same thing

Considering that "Headphones connected" is a single bit out of 78 bytes, that's basically a needle in a haystack. The only question is why does this program get more detailed info than this one...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.