-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Implemented reading controller state
- Loading branch information
Ludwig Füchsl
committed
Nov 14, 2020
1 parent
6f97154
commit aad64c0
Showing
17 changed files
with
1,767 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
**/VS19_Solution/bin/ | ||
**.exe | ||
|
||
# Visual studio files | ||
.vs/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,29 @@ | ||
# DualSense-Windows | ||
Windows API for the PS5 DualSense controller | ||
# DualSense / PS5 Controller on Windows [API] | ||
Windows API for the PS5 DualSense controller. Written in C++ for C++ | ||
|
||
First Release coming soon! | ||
|
||
#### Road map to first preview release: | ||
|
||
- ~~Reading the input state from the controller using USB~~. DONE! | ||
- Writing Output state to the controller using USB. *Work In Progress* | ||
- Documenting the API | ||
- Documenting the raw protocol | ||
|
||
First preview should be released before 28.11.2020 (The hard work is done - The USB protocol is, at least partially, reverse engineered) | ||
|
||
#### Features of the first preview | ||
|
||
- Reading **all** buttons and analog values (triggers and sticks) which are on the controller | ||
- Reading the two finger touch positions | ||
- Reading the accelerometer | ||
- Reading the gyroscope (Currently only raw / uncalibrated values) | ||
- Reading the connection state of the headphone jack | ||
- Setting the rumble motors speed | ||
- Setting various effects to the force feedback triggers | ||
- controlling the RGB-Leds, Microphone Led and User Leds | ||
|
||
#### Feature planed for the future | ||
|
||
- Calibrating the gyroscope | ||
- Writing / Reading over bluetooth (If you know something about the wireless protocol - especial writing data to the controller - please let me know by creating an issue!) |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<ShowAllFiles>true</ShowAllFiles> | ||
</PropertyGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
#include <Windows.h> | ||
|
||
#include <string> | ||
#include <sstream> | ||
|
||
#include <DualSenseWindows/IO.h> | ||
#include <DualSenseWindows/Device.h> | ||
|
||
typedef std::wstringstream wstrBuilder; | ||
|
||
class Console { | ||
public: | ||
Console() { | ||
AllocConsole(); | ||
consoleHandle = GetStdHandle(STD_OUTPUT_HANDLE); | ||
} | ||
|
||
~Console() { | ||
FreeConsole(); | ||
} | ||
|
||
void writeLine(LPCWSTR text) { | ||
write(text); | ||
write(L"\n"); | ||
} | ||
|
||
void writeLine(wstrBuilder& builder) { | ||
writeLine(builder.str().c_str()); | ||
builder.str(L""); | ||
} | ||
|
||
void write(LPCWSTR text) { | ||
WriteConsoleW(consoleHandle, text, wcslen(text), NULL, NULL); | ||
} | ||
|
||
void write(wstrBuilder& builder) { | ||
write(builder.str().c_str()); | ||
builder.str(L""); | ||
} | ||
|
||
private: | ||
HANDLE consoleHandle; | ||
}; | ||
|
||
INT WINAPI wWinMain(HINSTANCE _In_ hInstance, HINSTANCE _In_opt_ hPrevInstance, LPWSTR _In_ cmdLine, INT _In_ nCmdShow) { | ||
// Console | ||
Console console; | ||
wstrBuilder builder; | ||
console.writeLine(L"DualShock 5 Windows Test\n========================\n"); | ||
|
||
// Enum all controlers presentf | ||
DS5W::DeviceEnumInfo infos[16]; | ||
unsigned int controlersCount = 0; | ||
DS5W_ReturnValue rv = DS5W::enumDevices(infos, 16, true, &controlersCount); | ||
|
||
// check size | ||
if (controlersCount == 0) { | ||
console.writeLine(L"No PS5 controler found!"); | ||
system("pause"); | ||
return -1; | ||
} | ||
|
||
// Print all controler | ||
builder << L"Found " << controlersCount << L" PS5 Controler(s):"; | ||
console.writeLine(builder); | ||
|
||
// Iterate controlers | ||
for (unsigned int i = 0; i < controlersCount; i++) { | ||
if (infos[i]._internal.connection == DS5W::DeviceConnection::BT) { | ||
builder << L"Wireless (Blotooth) controler ("; | ||
} | ||
else { | ||
builder << L"Wired (USB) controler ("; | ||
} | ||
|
||
builder << infos[i]._internal.path << L")"; | ||
console.writeLine(builder); | ||
} | ||
|
||
// Create first controler | ||
DS5W::DeviceContext con; | ||
if (DS5W_SUCCESS(DS5W::initDeviceContext(&infos[0], &con))) { | ||
console.writeLine(L"DualSense 5 controller connected"); | ||
|
||
// State object | ||
DS5W::DS5InputState inState; | ||
|
||
// Application infinity loop | ||
bool keepRunning = true; | ||
while (keepRunning) { | ||
// Get input state | ||
if (DS5W_SUCCESS(DS5W::getDeviceInputState(&con, &inState))) { | ||
if (inState.headPhoneConnected) { | ||
console.writeLine(L"Connected"); | ||
} | ||
else { | ||
console.writeLine(L"Not Connected"); | ||
} | ||
} | ||
else { | ||
// Device disconnected show error and try to reconnect | ||
console.writeLine(L"Device removed!"); | ||
DS5W::reconnectDevice(&con); | ||
} | ||
} | ||
|
||
// Free state | ||
DS5W::freeDeviceContext(&con); | ||
} | ||
else { | ||
console.writeLine(L"Failed to connect to controler!"); | ||
system("pause"); | ||
return -1; | ||
} | ||
|
||
return 0; | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
// Microsoft Visual C++ generated resource script. | ||
// | ||
#include "resource.h" | ||
|
||
#define APSTUDIO_READONLY_SYMBOLS | ||
///////////////////////////////////////////////////////////////////////////// | ||
// | ||
// Generated from the TEXTINCLUDE 2 resource. | ||
// | ||
#include "winres.h" | ||
|
||
///////////////////////////////////////////////////////////////////////////// | ||
#undef APSTUDIO_READONLY_SYMBOLS | ||
|
||
///////////////////////////////////////////////////////////////////////////// | ||
// Deutsch (Deutschland) resources | ||
|
||
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_DEU) | ||
LANGUAGE LANG_GERMAN, SUBLANG_GERMAN | ||
#pragma code_page(1252) | ||
|
||
#ifdef APSTUDIO_INVOKED | ||
///////////////////////////////////////////////////////////////////////////// | ||
// | ||
// TEXTINCLUDE | ||
// | ||
|
||
1 TEXTINCLUDE | ||
BEGIN | ||
"resource.h\0" | ||
END | ||
|
||
2 TEXTINCLUDE | ||
BEGIN | ||
"#include ""winres.h""\r\n" | ||
"\0" | ||
END | ||
|
||
3 TEXTINCLUDE | ||
BEGIN | ||
"\r\n" | ||
"\0" | ||
END | ||
|
||
#endif // APSTUDIO_INVOKED | ||
|
||
|
||
///////////////////////////////////////////////////////////////////////////// | ||
// | ||
// Version | ||
// | ||
|
||
VS_VERSION_INFO VERSIONINFO | ||
FILEVERSION 0,1,0,0 | ||
PRODUCTVERSION 0,1,0,0 | ||
FILEFLAGSMASK 0x3fL | ||
#ifdef _DEBUG | ||
FILEFLAGS 0x1L | ||
#else | ||
FILEFLAGS 0x0L | ||
#endif | ||
FILEOS 0x40004L | ||
FILETYPE 0x2L | ||
FILESUBTYPE 0x0L | ||
BEGIN | ||
BLOCK "StringFileInfo" | ||
BEGIN | ||
BLOCK "000004b0" | ||
BEGIN | ||
VALUE "CompanyName", "Ludwig F�chsl" | ||
VALUE "FileDescription", "DualSense5 API" | ||
VALUE "FileVersion", "0.1.0.0" | ||
VALUE "InternalName", "ds5w_x64/_x86.dll" | ||
VALUE "LegalCopyright", "Ludwig F�chsl (MIT License)" | ||
VALUE "OriginalFilename", "ds5w_x64/_x86.dll" | ||
VALUE "ProductName", "DualSenseWindows" | ||
VALUE "ProductVersion", "0.1.0.0" | ||
END | ||
END | ||
BLOCK "VarFileInfo" | ||
BEGIN | ||
VALUE "Translation", 0x0, 1200 | ||
END | ||
END | ||
|
||
#endif // Deutsch (Deutschland) resources | ||
///////////////////////////////////////////////////////////////////////////// | ||
|
||
|
||
|
||
#ifndef APSTUDIO_INVOKED | ||
///////////////////////////////////////////////////////////////////////////// | ||
// | ||
// Generated from the TEXTINCLUDE 3 resource. | ||
// | ||
|
||
|
||
///////////////////////////////////////////////////////////////////////////// | ||
#endif // not APSTUDIO_INVOKED | ||
|
Oops, something went wrong.