Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

other method to add compatible DS4 usb devices #36

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions JoyShockLibrary/JoyShock.cpp
Original file line number Diff line number Diff line change
@@ -9,6 +9,8 @@
#include <atomic>
#include "tools.cpp"
#include <cstring>
#include "SensorFusion.cpp"


#ifdef __GNUC__
#define _wcsdup wcsdup
57 changes: 56 additions & 1 deletion JoyShockLibrary/JoyShockLibrary.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
// JoyShockLibrary.cpp : Defines the exported functions for the DLL application.
//

#ifdef _WIN32
#include <Windows.h>
#endif

#include "JoyShockLibrary.h"
#include <bitset>
#include "hidapi.h"
@@ -9,7 +13,6 @@
#include <shared_mutex>
#include <unordered_map>
#include <atomic>
#include "SensorFusion.cpp"
#include "JoyShock.cpp"
#include "InputHelpers.cpp"

@@ -175,8 +178,27 @@ void pollIndividualLoop(JoyShock *jc) {
}
}

#ifdef _WIN32
static BOOL UnicodeToMByte(LPCWSTR unicodeStr, LPSTR multiByteStr, DWORD size)
{
// Get the required size of the buffer that receives the multiByte string.
DWORD minSize;
minSize = WideCharToMultiByte(CP_OEMCP, NULL, unicodeStr, -1, NULL, 0, NULL, FALSE);
if (size < minSize)
{
return FALSE;
}
// Convert string from Unicode to multi-byte.
WideCharToMultiByte(CP_OEMCP, NULL, unicodeStr, -1, multiByteStr, size, NULL, FALSE);
return TRUE;
}
#endif


int JslConnectDevices()
{
char tempString[1024];

// for writing to console:
//freopen("CONOUT$", "w", stdout);
if (_joyshocks.size() > 0) {
@@ -256,10 +278,43 @@ int JslConnectDevices()
while (cur_dev) {
// brook usb ds4:
printf("Brook DS4\n");
//doesn't seem super reliable unless u already know all IDs...
if (cur_dev->product_id == BROOK_DS4_USB) {
JoyShock* jc = new JoyShock(cur_dev, GetUniqueHandle());
_joyshocks.emplace(jc->intHandle, jc);
}
else { //unkown product but gamepad based
//Ozzy note: only modified this case, maybe you should do the same for others registration parts??
if (cur_dev->product_string != NULL) {

#ifdef USE_ANY_FILTER
#ifdef _WIN32
UnicodeToMByte(cur_dev->product_string, tempString, 1024);
#else
strcpy(tempString, cur_dev->product_string);
#endif
strlwr(tempString);
if (strstr(tempString, "pad") || strstr(tempString, "ds") || strstr(tempString, "shock"))
#endif
{
//we don't want to add same device multiple times so use product unique ID instead of incremented ID!
std::unordered_map<int, JoyShock*>::const_iterator got = _joyshocks.find(cur_dev->product_id);

if (got == _joyshocks.end()) {
JoyShock* jc = new JoyShock(cur_dev, cur_dev->product_id/*GetUniqueHandle()*/);
_joyshocks.emplace(jc->intHandle, jc);
if (jc != NULL) {
jc->name = std::string("DualShock 4");
jc->left_right = 3; // left and right?
jc->controller_type = ControllerType::s_ds4;
jc->is_usb = true; // this controller is wired
}
}

}
}

}

cur_dev = cur_dev->next;
}
5 changes: 5 additions & 0 deletions JoyShockLibrary/JoyShockLibrary.h
Original file line number Diff line number Diff line change
@@ -2,7 +2,12 @@
#pragma once

#if _MSC_VER // this is defined when compiling with Visual Studio
#ifdef USE_JOYSHOCK_DLL //used when generating a DLL instead of static lib
#define JOY_SHOCK_API __declspec(dllexport) // Visual Studio needs annotating exported functions with this
#else
#define JOY_SHOCK_API
#endif

#else
#define JOY_SHOCK_API // XCode does not need annotating exported functions, so define is empty
#endif