From 0c30c3192915c59e4120bc63a2c8675f85c1611e Mon Sep 17 00:00:00 2001 From: Nielk1 Date: Mon, 7 Sep 2020 20:04:04 -0500 Subject: [PATCH 1/3] Implemented basic DS4 dongle support. Dongle acts like USB except for a bit set high when no controller is attached. This bit was used to ignore reports when no controller is attached to avoid various errors caused by the repeated identical data. Note that when a controller is removed mid-use with this code JSM will continue the inputs for a short time (for example joystick input will remain fixed) until it realizes no data is coming. For this reason, this implementaiton might need some work. --- JoyShockLibrary/InputHelpers.cpp | 4 ++++ JoyShockLibrary/JoyShock.cpp | 2 ++ JoyShockLibrary/JoyShockLibrary.cpp | 1 + 3 files changed, 7 insertions(+) diff --git a/JoyShockLibrary/InputHelpers.cpp b/JoyShockLibrary/InputHelpers.cpp index 5c8e33e..33907d2 100644 --- a/JoyShockLibrary/InputHelpers.cpp +++ b/JoyShockLibrary/InputHelpers.cpp @@ -30,7 +30,11 @@ bool handle_input(JoyShock *jc, uint8_t *packet, int len, bool &hasIMU) { } else { isValid = packet[0] == 0x01; + if (isValid) // ignore packets from Dongle with no connected controller + if ((packet[31] & 0x04) == 0x04) return false; } + + if (isValid) { // Gyroscope: // Gyroscope data is relative (degrees/s) diff --git a/JoyShockLibrary/JoyShock.cpp b/JoyShockLibrary/JoyShock.cpp index bb5564a..2e553a3 100644 --- a/JoyShockLibrary/JoyShock.cpp +++ b/JoyShockLibrary/JoyShock.cpp @@ -22,6 +22,7 @@ #define DS4_VENDOR 0x054C #define DS4_USB 0x05C4 #define DS4_USB_V2 0x09CC +#define DS4_USB_DONGLE 0x0BA0 #define DS4_BT 0x081F // Joycon and Pro conroller stuff is mostly from @@ -305,6 +306,7 @@ class JoyShock { if (dev->product_id == DS4_BT || dev->product_id == DS4_USB || + dev->product_id == DS4_USB_DONGLE || dev->product_id == DS4_USB_V2) { this->name = std::string("DualShock 4"); this->left_right = 3; // left and right? diff --git a/JoyShockLibrary/JoyShockLibrary.cpp b/JoyShockLibrary/JoyShockLibrary.cpp index c156494..d5d2cc1 100644 --- a/JoyShockLibrary/JoyShockLibrary.cpp +++ b/JoyShockLibrary/JoyShockLibrary.cpp @@ -224,6 +224,7 @@ int JslConnectDevices() printf("DS4\n"); if (cur_dev->product_id == DS4_USB || cur_dev->product_id == DS4_USB_V2 || + cur_dev->product_id == DS4_USB_DONGLE || cur_dev->product_id == DS4_BT) { JoyShock* jc = new JoyShock(cur_dev, GetUniqueHandle()); _joyshocks.emplace(jc->intHandle, jc); From 53a5e3cbf7e0b82913bc20eb404aa5380d842580 Mon Sep 17 00:00:00 2001 From: Nielk1 Date: Mon, 7 Sep 2020 20:10:58 -0500 Subject: [PATCH 2/3] remove some extra spaces --- JoyShockLibrary/InputHelpers.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/JoyShockLibrary/InputHelpers.cpp b/JoyShockLibrary/InputHelpers.cpp index 33907d2..4e80aaf 100644 --- a/JoyShockLibrary/InputHelpers.cpp +++ b/JoyShockLibrary/InputHelpers.cpp @@ -33,8 +33,6 @@ bool handle_input(JoyShock *jc, uint8_t *packet, int len, bool &hasIMU) { if (isValid) // ignore packets from Dongle with no connected controller if ((packet[31] & 0x04) == 0x04) return false; } - - if (isValid) { // Gyroscope: // Gyroscope data is relative (degrees/s) From ef777c24e5700f48f96c23ac34b437baf8f6830c Mon Sep 17 00:00:00 2001 From: Nielk1 Date: Mon, 7 Sep 2020 20:21:02 -0500 Subject: [PATCH 3/3] combine the valid check and bit check ifs, because why not --- JoyShockLibrary/InputHelpers.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/JoyShockLibrary/InputHelpers.cpp b/JoyShockLibrary/InputHelpers.cpp index 4e80aaf..a54944d 100644 --- a/JoyShockLibrary/InputHelpers.cpp +++ b/JoyShockLibrary/InputHelpers.cpp @@ -30,8 +30,8 @@ bool handle_input(JoyShock *jc, uint8_t *packet, int len, bool &hasIMU) { } else { isValid = packet[0] == 0x01; - if (isValid) // ignore packets from Dongle with no connected controller - if ((packet[31] & 0x04) == 0x04) return false; + if (isValid && (packet[31] & 0x04) == 0x04) + return false; // ignore packets from Dongle with no connected controller } if (isValid) { // Gyroscope: