Add support for Sony DualShock 4 (manual merge of !160)
Files pulled in manually and code style changes, Gamepad type addition by Adam Honse <calcprogrammer1@gmail.com>
This commit is contained in:
parent
e52619dbab
commit
791df64f81
13 changed files with 2020 additions and 0 deletions
89
Controllers/SonyDS4Controller/RGBController_SonyDS4.cpp
Normal file
89
Controllers/SonyDS4Controller/RGBController_SonyDS4.cpp
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
/*-----------------------------------------*\
|
||||
| RGBController_SonyDS4.cpp |
|
||||
| |
|
||||
| Controller for Sony Dualshock 4 |
|
||||
| |
|
||||
| Pol Rius (alpemwarrior) 24/09/2020 |
|
||||
\*-----------------------------------------*/
|
||||
|
||||
#include <iostream>
|
||||
#include "RGBController.h"
|
||||
#include "RGBController_SonyDS4.h"
|
||||
|
||||
RGBController_SonyDS4::RGBController_SonyDS4(SonyDS4Controller* dualshock)
|
||||
{
|
||||
this->dualshock = dualshock;
|
||||
|
||||
name = "Sony DualShock 4";
|
||||
type = DEVICE_TYPE_GAMEPAD;
|
||||
description = "Sony DualShock 4 Device";
|
||||
location = dualshock->GetLocation();
|
||||
|
||||
mode Direct;
|
||||
Direct.value = 0;
|
||||
Direct.name = "Direct";
|
||||
Direct.flags = MODE_FLAG_HAS_PER_LED_COLOR;
|
||||
Direct.color_mode = MODE_COLORS_PER_LED;
|
||||
modes.push_back(Direct);
|
||||
|
||||
SetupZones();
|
||||
}
|
||||
|
||||
void RGBController_SonyDS4::SetupZones()
|
||||
{
|
||||
/*---------------------------------------------------------*\
|
||||
| This device only has one LED, so create a single zone and |
|
||||
| LED for it |
|
||||
\*---------------------------------------------------------*/
|
||||
zone* new_zone = new zone();
|
||||
led* new_led = new led();
|
||||
|
||||
new_zone->name = "Controller Zone";
|
||||
new_zone->type = ZONE_TYPE_SINGLE;
|
||||
new_zone->leds_min = 1;
|
||||
new_zone->leds_max = 1;
|
||||
new_zone->leds_count = 1;
|
||||
new_zone->matrix_map = NULL;
|
||||
|
||||
new_led->name = "Controller LED";
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Push the zone and LED on to device vectors |
|
||||
\*---------------------------------------------------------*/
|
||||
leds.push_back(*new_led);
|
||||
zones.push_back(*new_zone);
|
||||
SetupColors();
|
||||
}
|
||||
|
||||
void RGBController_SonyDS4::ResizeZone(int /*zone*/, int /*new_size*/)
|
||||
{
|
||||
/*---------------------------------------------------------*\
|
||||
| This device does not support resizing zones |
|
||||
\*---------------------------------------------------------*/
|
||||
}
|
||||
|
||||
void RGBController_SonyDS4::DeviceUpdateLEDs()
|
||||
{
|
||||
unsigned char red = char(RGBGetRValue(colors[0]));
|
||||
unsigned char green = char(RGBGetGValue(colors[0]));
|
||||
unsigned char blue = char(RGBGetBValue(colors[0]));
|
||||
dualshock->SetColors(red, green, blue);
|
||||
}
|
||||
|
||||
void RGBController_SonyDS4::UpdateZoneLEDs(int /*zone*/)
|
||||
{
|
||||
DeviceUpdateLEDs();
|
||||
}
|
||||
|
||||
void RGBController_SonyDS4::UpdateSingleLED(int /*led*/)
|
||||
{
|
||||
DeviceUpdateLEDs();
|
||||
}
|
||||
|
||||
void RGBController_SonyDS4::SetCustomMode()
|
||||
{
|
||||
}
|
||||
|
||||
void RGBController_SonyDS4::DeviceUpdateMode()
|
||||
{
|
||||
}
|
||||
30
Controllers/SonyDS4Controller/RGBController_SonyDS4.h
Normal file
30
Controllers/SonyDS4Controller/RGBController_SonyDS4.h
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
/*-----------------------------------------*\
|
||||
| RGBController_SonyDS4.h |
|
||||
| |
|
||||
| Controller for Sony Dualshock 4 |
|
||||
| |
|
||||
| Pol Rius (alpemwarrior) 24/09/2020 |
|
||||
\*-----------------------------------------*/
|
||||
|
||||
#include "RGBController.h"
|
||||
#include "SonyDS4Controller.h"
|
||||
|
||||
class RGBController_SonyDS4 : public RGBController
|
||||
{
|
||||
public:
|
||||
RGBController_SonyDS4(SonyDS4Controller* dualshock);
|
||||
|
||||
void SetupZones();
|
||||
|
||||
void ResizeZone(int zone, int new_size);
|
||||
|
||||
void DeviceUpdateLEDs();
|
||||
void UpdateZoneLEDs(int zone);
|
||||
void UpdateSingleLED(int led);
|
||||
|
||||
void SetCustomMode();
|
||||
void DeviceUpdateMode();
|
||||
|
||||
private:
|
||||
SonyDS4Controller* dualshock;
|
||||
};
|
||||
104
Controllers/SonyDS4Controller/SonyDS4Controller.cpp
Normal file
104
Controllers/SonyDS4Controller/SonyDS4Controller.cpp
Normal file
|
|
@ -0,0 +1,104 @@
|
|||
/*-----------------------------------------*\
|
||||
| SonyDS4Controller.cpp |
|
||||
| |
|
||||
| Controller for Sony Dualshock 4 |
|
||||
| |
|
||||
| Pol Rius (alpemwarrior) 24/09/2020 |
|
||||
\*-----------------------------------------*/
|
||||
|
||||
#include <CRC.h>
|
||||
#include <hidapi/hidapi.h>
|
||||
#include "SonyDS4Controller.h"
|
||||
|
||||
SonyDS4Controller::SonyDS4Controller(hid_device * device_handle, const char * device_path)
|
||||
{
|
||||
this->device_handle = device_handle;
|
||||
unsigned char readBuffer[64];
|
||||
unsigned char reportBuffer[64];
|
||||
reportBuffer[0] = 0x02;
|
||||
|
||||
hid_get_feature_report(device_handle, reportBuffer, 64);
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
hid_read(device_handle, readBuffer, 64);
|
||||
if (readBuffer[0] == 17)
|
||||
{
|
||||
is_bluetooth = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
location = device_path;
|
||||
}
|
||||
|
||||
const char * SonyDS4Controller::GetLocation()
|
||||
{
|
||||
return location;
|
||||
}
|
||||
|
||||
void SonyDS4Controller::SetColors(unsigned char red, unsigned char green, unsigned char blue)
|
||||
{
|
||||
if(is_bluetooth)
|
||||
{
|
||||
sendReportBT(red, green, blue);
|
||||
}
|
||||
else
|
||||
{
|
||||
sendReportUSB(red, green, blue);
|
||||
}
|
||||
}
|
||||
|
||||
void SonyDS4Controller::sendReportBT(unsigned char red, unsigned char green, unsigned char blue)
|
||||
{
|
||||
unsigned char buffer[79] =
|
||||
{
|
||||
0xa2, 0x11, 0xC0, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, red, green, blue, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||
};
|
||||
|
||||
uint32_t crc = CRCPP::CRC::Calculate(buffer, 75, CRCPP::CRC::CRC_32());
|
||||
unsigned char outbuffer[78];
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| The report has to be signed with the byte 0xa2. |
|
||||
| However, hidapi already adds 0xa2 to the report, |
|
||||
| so we need to remove it from the buffer. |
|
||||
\*-------------------------------------------------*/
|
||||
for(unsigned int i = 1; i < 79; i++)
|
||||
{
|
||||
outbuffer[i - 1] = buffer[i];
|
||||
}
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Add the crc32 to the end of the buffer |
|
||||
\*-------------------------------------------------*/
|
||||
outbuffer[74] = (0x000000FF & crc);
|
||||
outbuffer[75] = (0x0000FF00 & crc) >> 8;
|
||||
outbuffer[76] = (0x00FF0000 & crc) >> 16;
|
||||
outbuffer[77] = (0xFF000000 & crc) >> 24;
|
||||
|
||||
hid_write(device_handle, outbuffer, 78);
|
||||
}
|
||||
|
||||
void SonyDS4Controller::sendReportUSB(unsigned char red, unsigned char green, unsigned char blue)
|
||||
{
|
||||
uint8_t buffer[11] =
|
||||
{
|
||||
0x05,
|
||||
0x07,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
red,
|
||||
green,
|
||||
blue,
|
||||
0x00,
|
||||
0x00
|
||||
};
|
||||
|
||||
hid_write(device_handle, buffer, 11);
|
||||
}
|
||||
27
Controllers/SonyDS4Controller/SonyDS4Controller.h
Normal file
27
Controllers/SonyDS4Controller/SonyDS4Controller.h
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
/*-----------------------------------------*\
|
||||
| SonyDS4Controller.h |
|
||||
| |
|
||||
| Controller for Sony Dualshock 4 |
|
||||
| |
|
||||
| Pol Rius (alpemwarrior) 24/09/2020 |
|
||||
\*-----------------------------------------*/
|
||||
|
||||
#include <hidapi/hidapi.h>
|
||||
|
||||
class SonyDS4Controller
|
||||
{
|
||||
public:
|
||||
SonyDS4Controller(hid_device * device_handle, const char * device_path);
|
||||
|
||||
const char* GetLocation();
|
||||
|
||||
void SetColors(unsigned char red, unsigned char green, unsigned char blue);
|
||||
|
||||
private:
|
||||
hid_device* device_handle;
|
||||
bool is_bluetooth = false;
|
||||
const char* location;
|
||||
|
||||
void sendReportUSB(unsigned char red, unsigned char green, unsigned char blue);
|
||||
void sendReportBT(unsigned char red, unsigned char green, unsigned char blue);
|
||||
};
|
||||
48
Controllers/SonyDS4Controller/SonyDS4ControllerDetect.cpp
Normal file
48
Controllers/SonyDS4Controller/SonyDS4ControllerDetect.cpp
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
/*-----------------------------------------*\
|
||||
| SonyDS4Controller.h |
|
||||
| |
|
||||
| Detector for Sony Dualshock 4 |
|
||||
| |
|
||||
| Pol Rius (alpemwarrior) 24/09/2020 |
|
||||
\*-----------------------------------------*/
|
||||
|
||||
#include <vector>
|
||||
#include <hidapi/hidapi.h>
|
||||
|
||||
#include "RGBController_SonyDS4.h"
|
||||
#include "Detector.h"
|
||||
|
||||
const unsigned short vendor_id = 0x054C;
|
||||
const unsigned short product_id_v1 = 0x05C4;
|
||||
const unsigned short product_id_v2 = 0x09CC;
|
||||
|
||||
void DetectSonyDS4Controllers(std::vector<RGBController*>& rgb_controllers)
|
||||
{
|
||||
hid_device_info* info;
|
||||
hid_init();
|
||||
|
||||
info = hid_enumerate(0x00, 0x00);
|
||||
|
||||
while (info)
|
||||
{
|
||||
if(info->vendor_id == vendor_id)
|
||||
{
|
||||
if(info->product_id == product_id_v1 || info->product_id == product_id_v2)
|
||||
{
|
||||
hid_device* dev = hid_open_path(info->path);
|
||||
|
||||
if (dev != NULL)
|
||||
{
|
||||
SonyDS4Controller* controller = new SonyDS4Controller(dev, info->path);
|
||||
RGBController_SonyDS4* rgb_controller = new RGBController_SonyDS4(controller);
|
||||
rgb_controllers.push_back(rgb_controller);
|
||||
}
|
||||
}
|
||||
}
|
||||
info = info->next;
|
||||
}
|
||||
|
||||
hid_free_enumeration(info);
|
||||
}
|
||||
|
||||
REGISTER_DETECTOR("Sony DualShock 4", DetectSonyDS4Controllers);
|
||||
|
|
@ -41,6 +41,7 @@ DEFINES +=
|
|||
#-----------------------------------------------------------------------------------------------#
|
||||
INCLUDEPATH += \
|
||||
dependencies/ColorWheel \
|
||||
dependencies/CRCpp/ \
|
||||
dependencies/libe131/src/ \
|
||||
i2c_smbus/ \
|
||||
i2c_tools/ \
|
||||
|
|
@ -94,6 +95,7 @@ INCLUDEPATH +=
|
|||
Controllers/RGBFusionGPUController/ \
|
||||
Controllers/SapphireGPUController/ \
|
||||
Controllers/SinowealthController/ \
|
||||
Controllers/SonyDS4Controller/ \
|
||||
Controllers/SteelSeriesController/ \
|
||||
Controllers/TecknetController/ \
|
||||
Controllers/ThermaltakeRiingController/ \
|
||||
|
|
@ -235,6 +237,8 @@ HEADERS +=
|
|||
Controllers/SapphireGPUController/RGBController_SapphireGPU.h \
|
||||
Controllers/SinowealthController/SinowealthController.h \
|
||||
Controllers/SinowealthController/RGBController_Sinowealth.h \
|
||||
Controllers/SonyDS4Controller/SonyDS4Controller.h \
|
||||
Controllers/SonyDS4Controller/RGBController_SonyDS4.h \
|
||||
Controllers/SteelSeriesController/SteelSeriesApexController.h \
|
||||
Controllers/SteelSeriesController/SteelSeriesRivalController.h \
|
||||
Controllers/SteelSeriesController/SteelSeriesSiberiaController.h \
|
||||
|
|
@ -429,6 +433,9 @@ SOURCES +=
|
|||
Controllers/SinowealthController/SinowealthController.cpp \
|
||||
Controllers/SinowealthController/SinowealthControllerDetect.cpp \
|
||||
Controllers/SinowealthController/RGBController_Sinowealth.cpp \
|
||||
Controllers/SonyDS4Controller/SonyDS4Controller.cpp \
|
||||
Controllers/SonyDS4Controller/SonyDS4ControllerDetect.cpp \
|
||||
Controllers/SonyDS4Controller/RGBController_SonyDS4.cpp \
|
||||
Controllers/SteelSeriesController/SteelSeriesApexController.cpp \
|
||||
Controllers/SteelSeriesController/SteelSeriesRivalController.cpp \
|
||||
Controllers/SteelSeriesController/SteelSeriesSiberiaController.cpp \
|
||||
|
|
|
|||
|
|
@ -1416,6 +1416,8 @@ std::string device_type_to_str(device_type type)
|
|||
return "Headset";
|
||||
case DEVICE_TYPE_HEADSET_STAND:
|
||||
return "Headset Stand";
|
||||
case DEVICE_TYPE_GAMEPAD:
|
||||
return "Gamepad";
|
||||
default:
|
||||
return "Unknown";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -115,6 +115,7 @@ enum
|
|||
DEVICE_TYPE_MOUSEMAT,
|
||||
DEVICE_TYPE_HEADSET,
|
||||
DEVICE_TYPE_HEADSET_STAND,
|
||||
DEVICE_TYPE_GAMEPAD,
|
||||
DEVICE_TYPE_UNKNOWN
|
||||
};
|
||||
|
||||
|
|
|
|||
1707
dependencies/CRCpp/CRC.h
vendored
Normal file
1707
dependencies/CRCpp/CRC.h
vendored
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -50,6 +50,9 @@ static QString GetIconString(device_type type, bool dark)
|
|||
case DEVICE_TYPE_HEADSET_STAND:
|
||||
filename = "headsetstand";
|
||||
break;
|
||||
case DEVICE_TYPE_GAMEPAD:
|
||||
filename = "gamepad";
|
||||
break;
|
||||
default:
|
||||
filename = "unknown";
|
||||
break;
|
||||
|
|
|
|||
BIN
qt/gamepad.png
Normal file
BIN
qt/gamepad.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 144 B |
BIN
qt/gamepad_dark.png
Normal file
BIN
qt/gamepad_dark.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 159 B |
|
|
@ -25,5 +25,7 @@
|
|||
<file>motherboard_dark.png</file>
|
||||
<file>software_dark.png</file>
|
||||
<file>tools_dark.png</file>
|
||||
<file>gamepad.png</file>
|
||||
<file>gamepad_dark.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue