Publish LumaOps source
This commit is contained in:
@@ -0,0 +1,105 @@
|
||||
/*---------------------------------------------------------*\
|
||||
| RGBController_SonyDS4.cpp |
|
||||
| |
|
||||
| RGBController for Sony Dualshock 4 |
|
||||
| |
|
||||
| Pol Rius (alpemwarrior) 24 Sep 2020 |
|
||||
| |
|
||||
| This file is part of the OpenRGB project |
|
||||
| SPDX-License-Identifier: GPL-2.0-or-later |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#include "RGBController.h"
|
||||
#include "RGBController_SonyDS4.h"
|
||||
|
||||
/**------------------------------------------------------------------*\
|
||||
@name Sony Dual Shock 4 controller
|
||||
@category Gamepad
|
||||
@type USB
|
||||
@save :x:
|
||||
@direct :white_check_mark:
|
||||
@effects :x:
|
||||
@detectors DetectSonyDS4Controllers
|
||||
@comment
|
||||
\*-------------------------------------------------------------------*/
|
||||
|
||||
RGBController_SonyDS4::RGBController_SonyDS4(SonyDS4Controller* controller_ptr)
|
||||
{
|
||||
controller = controller_ptr;
|
||||
|
||||
name = "Sony DualShock 4";
|
||||
vendor = "Sony";
|
||||
type = DEVICE_TYPE_GAMEPAD;
|
||||
description = "Sony DualShock 4 Device";
|
||||
location = controller->GetLocation();
|
||||
serial = controller->GetSerialString();
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
RGBController_SonyDS4::~RGBController_SonyDS4()
|
||||
{
|
||||
delete controller;
|
||||
}
|
||||
|
||||
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]));
|
||||
controller->SetColors(red, green, blue);
|
||||
}
|
||||
|
||||
void RGBController_SonyDS4::UpdateZoneLEDs(int /*zone*/)
|
||||
{
|
||||
DeviceUpdateLEDs();
|
||||
}
|
||||
|
||||
void RGBController_SonyDS4::UpdateSingleLED(int /*led*/)
|
||||
{
|
||||
DeviceUpdateLEDs();
|
||||
}
|
||||
|
||||
void RGBController_SonyDS4::DeviceUpdateMode()
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*---------------------------------------------------------*\
|
||||
| RGBController_SonyDS4.h |
|
||||
| |
|
||||
| RGBController for Sony Dualshock 4 |
|
||||
| |
|
||||
| Pol Rius (alpemwarrior) 24 Sep 2020 |
|
||||
| |
|
||||
| This file is part of the OpenRGB project |
|
||||
| SPDX-License-Identifier: GPL-2.0-or-later |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "RGBController.h"
|
||||
#include "SonyDS4Controller.h"
|
||||
|
||||
class RGBController_SonyDS4 : public RGBController
|
||||
{
|
||||
public:
|
||||
RGBController_SonyDS4(SonyDS4Controller* controller_ptr);
|
||||
~RGBController_SonyDS4();
|
||||
|
||||
void SetupZones();
|
||||
void ResizeZone(int zone, int new_size);
|
||||
|
||||
void DeviceUpdateLEDs();
|
||||
void UpdateZoneLEDs(int zone);
|
||||
void UpdateSingleLED(int led);
|
||||
|
||||
void DeviceUpdateMode();
|
||||
|
||||
private:
|
||||
SonyDS4Controller* controller;
|
||||
};
|
||||
@@ -0,0 +1,126 @@
|
||||
/*---------------------------------------------------------*\
|
||||
| SonyDS4Controller.cpp |
|
||||
| |
|
||||
| Driver for Sony Dualshock 4 |
|
||||
| |
|
||||
| Pol Rius (alpemwarrior) 24 Sep 2020 |
|
||||
| |
|
||||
| This file is part of the OpenRGB project |
|
||||
| SPDX-License-Identifier: GPL-2.0-or-later |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#include <CRC.h>
|
||||
#include <hidapi.h>
|
||||
#include "SonyDS4Controller.h"
|
||||
#include "StringUtils.h"
|
||||
|
||||
SonyDS4Controller::SonyDS4Controller(hid_device * device_handle, const char * device_path)
|
||||
{
|
||||
this->dev = device_handle;
|
||||
unsigned char readBuffer[64];
|
||||
unsigned char reportBuffer[64];
|
||||
reportBuffer[0] = 0x02;
|
||||
|
||||
hid_get_feature_report(dev, reportBuffer, 64);
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
hid_read(dev, readBuffer, 64);
|
||||
if (readBuffer[0] == 17)
|
||||
{
|
||||
is_bluetooth = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
location = device_path;
|
||||
}
|
||||
|
||||
SonyDS4Controller::~SonyDS4Controller()
|
||||
{
|
||||
hid_close(dev);
|
||||
}
|
||||
|
||||
std::string SonyDS4Controller::GetLocation()
|
||||
{
|
||||
return("HID: " + location);
|
||||
}
|
||||
|
||||
std::string SonyDS4Controller::GetSerialString()
|
||||
{
|
||||
wchar_t serial_string[128];
|
||||
int ret = hid_get_serial_number_string(dev, serial_string, 128);
|
||||
|
||||
if(ret != 0)
|
||||
{
|
||||
return("");
|
||||
}
|
||||
|
||||
return(StringUtils::wstring_to_string(serial_string));
|
||||
}
|
||||
|
||||
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(dev, 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(dev, buffer, 11);
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/*---------------------------------------------------------*\
|
||||
| SonyDS4Controller.h |
|
||||
| |
|
||||
| Driver for Sony Dualshock 4 |
|
||||
| |
|
||||
| Pol Rius (alpemwarrior) 24 Sep 2020 |
|
||||
| |
|
||||
| This file is part of the OpenRGB project |
|
||||
| SPDX-License-Identifier: GPL-2.0-or-later |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <hidapi.h>
|
||||
|
||||
class SonyDS4Controller
|
||||
{
|
||||
public:
|
||||
SonyDS4Controller(hid_device * device_handle, const char * device_path);
|
||||
~SonyDS4Controller();
|
||||
|
||||
std::string GetLocation();
|
||||
std::string GetSerialString();
|
||||
|
||||
void SetColors(unsigned char red, unsigned char green, unsigned char blue);
|
||||
|
||||
private:
|
||||
hid_device* dev;
|
||||
bool is_bluetooth = false;
|
||||
std::string location;
|
||||
|
||||
void sendReportUSB(unsigned char red, unsigned char green, unsigned char blue);
|
||||
void sendReportBT(unsigned char red, unsigned char green, unsigned char blue);
|
||||
};
|
||||
+141
@@ -0,0 +1,141 @@
|
||||
/*---------------------------------------------------------*\
|
||||
| RGBController_SonyDualSense.cpp |
|
||||
| |
|
||||
| RGBController for Sony DualSense |
|
||||
| |
|
||||
| Flora Aubry 01 Jul 2022 |
|
||||
| |
|
||||
| This file is part of the OpenRGB project |
|
||||
| SPDX-License-Identifier: GPL-2.0-or-later |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#include <iostream>
|
||||
#include "RGBController_SonyDualSense.h"
|
||||
|
||||
/**------------------------------------------------------------------*\
|
||||
@name Sony Dual Sense controller
|
||||
@category Gamepad
|
||||
@type USB
|
||||
@save :x:
|
||||
@direct :white_check_mark:
|
||||
@effects :x:
|
||||
@detectors DetectSonyDualSenseControllers
|
||||
@comment
|
||||
\*-------------------------------------------------------------------*/
|
||||
|
||||
RGBController_SonyDualSense::RGBController_SonyDualSense(SonyDualSenseController* controller_ptr)
|
||||
{
|
||||
controller = controller_ptr;
|
||||
|
||||
name = controller->GetName();
|
||||
|
||||
if(controller->IsBluetooth())
|
||||
{
|
||||
name.append(" (BT)");
|
||||
}
|
||||
|
||||
vendor = "Sony";
|
||||
type = DEVICE_TYPE_GAMEPAD;
|
||||
description = "Sony DualSense Device";
|
||||
location = controller->GetLocation();
|
||||
serial = controller->GetSerialString();
|
||||
|
||||
mode Direct;
|
||||
Direct.value = SONY_DUALSENSE_DIRECT_MODE_VALUE;
|
||||
Direct.name = "Direct";
|
||||
Direct.flags = MODE_FLAG_HAS_PER_LED_COLOR | MODE_FLAG_HAS_BRIGHTNESS;
|
||||
Direct.color_mode = MODE_COLORS_PER_LED;
|
||||
Direct.brightness_min = SONY_DUALSENSE_BRIGHTNESS_MIN;
|
||||
Direct.brightness_max = SONY_DUALSENSE_BRIGHTNESS_MAX;
|
||||
Direct.brightness = SONY_DUALSENSE_DEFAULT_BRIGHTNESS;
|
||||
modes.push_back(Direct);
|
||||
|
||||
mode Micoff;
|
||||
Micoff.value = SONY_DUALSENSE_MIC_OFF_MODE_VALUE;
|
||||
Micoff.name = "Mic Off (Direct)";
|
||||
Micoff.flags = MODE_FLAG_HAS_PER_LED_COLOR | MODE_FLAG_HAS_BRIGHTNESS;
|
||||
Micoff.color_mode = MODE_COLORS_PER_LED;
|
||||
Micoff.brightness_min = SONY_DUALSENSE_BRIGHTNESS_MIN;
|
||||
Micoff.brightness_max = SONY_DUALSENSE_BRIGHTNESS_MAX;
|
||||
Micoff.brightness = SONY_DUALSENSE_DEFAULT_BRIGHTNESS;
|
||||
modes.push_back(Micoff);
|
||||
|
||||
mode Micpulse;
|
||||
Micpulse.value = SONY_DUALSENSE_MIC_PULSE_MODE_VALUE;
|
||||
Micpulse.name = "Mic Pulse (Direct)";
|
||||
Micpulse.flags = MODE_FLAG_HAS_PER_LED_COLOR | MODE_FLAG_HAS_BRIGHTNESS;
|
||||
Micpulse.color_mode = MODE_COLORS_PER_LED;
|
||||
Micpulse.brightness_min = SONY_DUALSENSE_BRIGHTNESS_MIN;
|
||||
Micpulse.brightness_max = SONY_DUALSENSE_BRIGHTNESS_MAX;
|
||||
Micpulse.brightness = SONY_DUALSENSE_DEFAULT_BRIGHTNESS;
|
||||
modes.push_back(Micpulse);
|
||||
|
||||
SetupZones();
|
||||
}
|
||||
|
||||
RGBController_SonyDualSense::~RGBController_SonyDualSense()
|
||||
{
|
||||
delete controller;
|
||||
}
|
||||
|
||||
void RGBController_SonyDualSense::SetupZones()
|
||||
{
|
||||
/*---------------------------------------------------------*\
|
||||
| This device only has one LED, so create a single zone and |
|
||||
| LED for it |
|
||||
\*---------------------------------------------------------*/
|
||||
zone lightbar;
|
||||
lightbar.name = "Lightbar";
|
||||
lightbar.type = ZONE_TYPE_SINGLE;
|
||||
lightbar.leds_min = SONY_DUALSENSE_LIGHTBAR_LED_COUNT;
|
||||
lightbar.leds_max = SONY_DUALSENSE_LIGHTBAR_LED_COUNT;
|
||||
lightbar.leds_count = SONY_DUALSENSE_LIGHTBAR_LED_COUNT;
|
||||
lightbar.matrix_map = NULL;
|
||||
zones.push_back(lightbar);
|
||||
|
||||
zone playerleds;
|
||||
playerleds.name = "Player LEDs";
|
||||
playerleds.type = ZONE_TYPE_LINEAR;
|
||||
playerleds.leds_min = SONY_DUALSENSE_PLAYER_LED_COUNT;
|
||||
playerleds.leds_max = SONY_DUALSENSE_PLAYER_LED_COUNT;
|
||||
playerleds.leds_count = SONY_DUALSENSE_PLAYER_LED_COUNT;
|
||||
playerleds.matrix_map = NULL;
|
||||
zones.push_back(playerleds);
|
||||
|
||||
leds.resize(SONY_DUALSENSE_LIGHTBAR_LED_COUNT + SONY_DUALSENSE_PLAYER_LED_COUNT);
|
||||
|
||||
leds[0].name = "LED 1";
|
||||
|
||||
for(unsigned int i = 0 ; i < SONY_DUALSENSE_PLAYER_LED_COUNT; i++)
|
||||
{
|
||||
leds[i + 1].name = "Player " + std::to_string(i + 1);
|
||||
}
|
||||
|
||||
SetupColors();
|
||||
}
|
||||
|
||||
void RGBController_SonyDualSense::ResizeZone(int /*zone*/, int /*new_size*/)
|
||||
{
|
||||
/*---------------------------------------------------------*\
|
||||
| This device does not support resizing zones |
|
||||
\*---------------------------------------------------------*/
|
||||
}
|
||||
|
||||
void RGBController_SonyDualSense::DeviceUpdateLEDs()
|
||||
{
|
||||
controller->SetColors(colors, modes[active_mode].brightness, modes[active_mode].value);
|
||||
}
|
||||
|
||||
void RGBController_SonyDualSense::UpdateZoneLEDs(int /*zone*/)
|
||||
{
|
||||
DeviceUpdateLEDs();
|
||||
}
|
||||
|
||||
void RGBController_SonyDualSense::UpdateSingleLED(int /*led*/)
|
||||
{
|
||||
DeviceUpdateLEDs();
|
||||
}
|
||||
|
||||
void RGBController_SonyDualSense::DeviceUpdateMode()
|
||||
{
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
/*---------------------------------------------------------*\
|
||||
| RGBController_SonyDualSense.h |
|
||||
| |
|
||||
| RGBController for Sony DualSense |
|
||||
| |
|
||||
| Flora Aubry 01 Jul 2022 |
|
||||
| |
|
||||
| This file is part of the OpenRGB project |
|
||||
| SPDX-License-Identifier: GPL-2.0-or-later |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "RGBController.h"
|
||||
#include "SonyDualSenseController.h"
|
||||
|
||||
class RGBController_SonyDualSense : public RGBController
|
||||
{
|
||||
public:
|
||||
RGBController_SonyDualSense(SonyDualSenseController* controller_ptr);
|
||||
~RGBController_SonyDualSense();
|
||||
|
||||
void SetupZones();
|
||||
void ResizeZone(int zone, int new_size);
|
||||
|
||||
void DeviceUpdateLEDs();
|
||||
void UpdateZoneLEDs(int zone);
|
||||
void UpdateSingleLED(int led);
|
||||
|
||||
void DeviceUpdateMode();
|
||||
|
||||
private:
|
||||
SonyDualSenseController* controller;
|
||||
};
|
||||
+134
@@ -0,0 +1,134 @@
|
||||
/*---------------------------------------------------------*\
|
||||
| SonyDualSenseController.cpp |
|
||||
| |
|
||||
| Driver for Sony DualSense |
|
||||
| |
|
||||
| Flora Aubry 01 Jul 2022 |
|
||||
| |
|
||||
| This file is part of the OpenRGB project |
|
||||
| SPDX-License-Identifier: GPL-2.0-or-later |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#include <cstring>
|
||||
#include <CRC.h>
|
||||
#include <hidapi.h>
|
||||
#include "SonyDualSenseController.h"
|
||||
#include "StringUtils.h"
|
||||
|
||||
SonyDualSenseController::SonyDualSenseController(hid_device * device_handle, const char * device_path, bool is_bluetooth, std::string dev_name)
|
||||
{
|
||||
dev = device_handle;
|
||||
location = device_path;
|
||||
name = dev_name;
|
||||
this->is_bluetooth = is_bluetooth;
|
||||
}
|
||||
|
||||
SonyDualSenseController::~SonyDualSenseController()
|
||||
{
|
||||
hid_close(dev);
|
||||
}
|
||||
|
||||
std::string SonyDualSenseController::GetLocation()
|
||||
{
|
||||
return("HID: " + location);
|
||||
}
|
||||
|
||||
std::string SonyDualSenseController::GetName()
|
||||
{
|
||||
return(name);
|
||||
}
|
||||
|
||||
std::string SonyDualSenseController::GetSerialString()
|
||||
{
|
||||
wchar_t serial_string[128];
|
||||
int ret = hid_get_serial_number_string(dev, serial_string, 128);
|
||||
|
||||
if(ret != 0)
|
||||
{
|
||||
return("");
|
||||
}
|
||||
|
||||
return(StringUtils::wstring_to_string(serial_string));
|
||||
}
|
||||
|
||||
void SonyDualSenseController::SetColors(std::vector<RGBColor> colors, unsigned char brightness, unsigned char mode_value)
|
||||
{
|
||||
if(is_bluetooth)
|
||||
{
|
||||
unsigned char buffer[SONY_DUALSENSE_BT_PACKET_SIZE + 1];
|
||||
memset(buffer, 0x00, SONY_DUALSENSE_BT_PACKET_SIZE + 1);
|
||||
|
||||
buffer[0] = 0xA2;
|
||||
buffer[1] = 0x31;
|
||||
buffer[2] = 0x02;
|
||||
buffer[3] = 0x0F;
|
||||
buffer[4] = 0x55;
|
||||
|
||||
buffer[11] = mode_value;
|
||||
buffer[41] = 0xFF; // Must be > 0x00 to control birghtness
|
||||
buffer[44] = 0x02; // bypass default blue color when connected to bluetooth
|
||||
buffer[45] = 0x02 - brightness;
|
||||
buffer[46] = 0x20
|
||||
+ ((colors[1] > 0) )
|
||||
+ ((colors[2] > 0) << 1)
|
||||
+ ((colors[3] > 0) << 2)
|
||||
+ ((colors[4] > 0) << 3)
|
||||
+ ((colors[5] > 0) << 4);
|
||||
|
||||
buffer[47] = RGBGetRValue(colors[0]);
|
||||
buffer[48] = RGBGetGValue(colors[0]);
|
||||
buffer[49] = RGBGetBValue(colors[0]);
|
||||
|
||||
uint32_t crc = CRCPP::CRC::Calculate(buffer, SONY_DUALSENSE_BT_PACKET_SIZE - 3, CRCPP::CRC::CRC_32());
|
||||
unsigned char outbuffer[SONY_DUALSENSE_BT_PACKET_SIZE];
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| 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 < SONY_DUALSENSE_BT_PACKET_SIZE + 1; 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(dev, outbuffer, SONY_DUALSENSE_BT_PACKET_SIZE);
|
||||
}
|
||||
else
|
||||
{
|
||||
unsigned char usb_buf[SONY_DUALSENSE_USB_PACKET_SIZE];
|
||||
memset(usb_buf, 0x00, SONY_DUALSENSE_USB_PACKET_SIZE);
|
||||
|
||||
usb_buf[0] = 0x02;
|
||||
usb_buf[1] = 0x0F;
|
||||
usb_buf[2] = 0x55;
|
||||
usb_buf[9] = mode_value;
|
||||
usb_buf[39] = 0xFF; // Must be > 0x00 to control birghtness
|
||||
usb_buf[43] = 0x02 - brightness;
|
||||
usb_buf[44] = 0x20
|
||||
+ ((colors[1] > 0) )
|
||||
+ ((colors[2] > 0) << 1)
|
||||
+ ((colors[3] > 0) << 2)
|
||||
+ ((colors[4] > 0) << 3)
|
||||
+ ((colors[5] > 0) << 4);
|
||||
|
||||
usb_buf[45] = RGBGetRValue(colors[0]);
|
||||
usb_buf[46] = RGBGetGValue(colors[0]);
|
||||
usb_buf[47] = RGBGetBValue(colors[0]);
|
||||
|
||||
hid_write(dev, usb_buf, SONY_DUALSENSE_USB_PACKET_SIZE);
|
||||
}
|
||||
}
|
||||
|
||||
bool SonyDualSenseController::IsBluetooth()
|
||||
{
|
||||
return(is_bluetooth);
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/*---------------------------------------------------------*\
|
||||
| SonyDualSenseController.h |
|
||||
| |
|
||||
| Driver for Sony DualSense |
|
||||
| |
|
||||
| Flora Aubry 01 Jul 2022 |
|
||||
| |
|
||||
| This file is part of the OpenRGB project |
|
||||
| SPDX-License-Identifier: GPL-2.0-or-later |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <hidapi.h>
|
||||
#include "RGBController.h"
|
||||
|
||||
#define SONY_DUALSENSE_LIGHTBAR_LED_COUNT 1
|
||||
#define SONY_DUALSENSE_PLAYER_LED_COUNT 5
|
||||
#define SONY_DUALSENSE_BT_PACKET_SIZE 78
|
||||
#define SONY_DUALSENSE_USB_PACKET_SIZE 48
|
||||
|
||||
enum
|
||||
{
|
||||
SONY_DUALSENSE_DIRECT_MODE_VALUE = 0x01,
|
||||
SONY_DUALSENSE_MIC_OFF_MODE_VALUE = 0x00,
|
||||
SONY_DUALSENSE_MIC_PULSE_MODE_VALUE = 0x02,
|
||||
SONY_DUALSENSE_BRIGHTNESS_MIN = 0x00,
|
||||
SONY_DUALSENSE_BRIGHTNESS_MAX = 0x02,
|
||||
SONY_DUALSENSE_DEFAULT_BRIGHTNESS = 0x01
|
||||
};
|
||||
|
||||
class SonyDualSenseController
|
||||
{
|
||||
public:
|
||||
SonyDualSenseController(hid_device * device_handle, const char * device_path, bool is_bluetooth, std::string dev_name);
|
||||
~SonyDualSenseController();
|
||||
|
||||
std::string GetLocation();
|
||||
std::string GetName();
|
||||
std::string GetSerialString();
|
||||
|
||||
void SetColors(std::vector<RGBColor> colors, unsigned char brightness, unsigned char mode_value);
|
||||
bool IsBluetooth();
|
||||
|
||||
private:
|
||||
hid_device* dev;
|
||||
std::string location;
|
||||
std::string name;
|
||||
bool is_bluetooth;
|
||||
};
|
||||
@@ -0,0 +1,59 @@
|
||||
/*---------------------------------------------------------*\
|
||||
| SonyGamepadControllerDetect.cpp |
|
||||
| |
|
||||
| Detector for Sony Gamepads |
|
||||
| |
|
||||
| Pol Rius (alpemwarrior) 24 Sep 2020 |
|
||||
| Flora Aubry 01 Jul 2022 |
|
||||
| Yoan Berthelot 06 Mar 2025 |
|
||||
| |
|
||||
| This file is part of the OpenRGB project |
|
||||
| SPDX-License-Identifier: GPL-2.0-or-later |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#include <vector>
|
||||
#include <hidapi.h>
|
||||
#include "RGBController_SonyDS4.h"
|
||||
#include "RGBController_SonyDualSense.h"
|
||||
#include "Detector.h"
|
||||
|
||||
#define SONY_VID 0x054C
|
||||
|
||||
#define SONY_DS4_V1_PID 0x05C4
|
||||
#define SONY_DS4_V2_PID 0x09CC
|
||||
#define SONY_DS4_RECEIVER_PID 0x0BA0
|
||||
#define SONY_DUALSENSE_PID 0x0CE6
|
||||
#define SONY_DUALSENSE_EDGE_PID 0x0DF2
|
||||
|
||||
void DetectSonyDS4Controllers(hid_device_info* info, const std::string&)
|
||||
{
|
||||
hid_device* dev = hid_open_path(info->path);
|
||||
|
||||
if(dev)
|
||||
{
|
||||
SonyDS4Controller* controller = new SonyDS4Controller(dev, info->path);
|
||||
RGBController_SonyDS4* rgb_controller = new RGBController_SonyDS4(controller);
|
||||
|
||||
ResourceManager::get()->RegisterRGBController(rgb_controller);
|
||||
}
|
||||
}
|
||||
|
||||
void DetectSonyDualSenseControllers(hid_device_info* info, const std::string& name)
|
||||
{
|
||||
hid_device* dev = hid_open_path(info->path);
|
||||
|
||||
if(dev)
|
||||
{
|
||||
bool is_bluetooth = info->interface_number == -1;
|
||||
SonyDualSenseController* controller = new SonyDualSenseController(dev, info->path, is_bluetooth, name);
|
||||
RGBController_SonyDualSense* rgb_controller = new RGBController_SonyDualSense(controller);
|
||||
|
||||
ResourceManager::get()->RegisterRGBController(rgb_controller);
|
||||
}
|
||||
}
|
||||
|
||||
REGISTER_HID_DETECTOR("Sony DualShock 4", DetectSonyDS4Controllers, SONY_VID, SONY_DS4_V1_PID);
|
||||
REGISTER_HID_DETECTOR("Sony DualShock 4", DetectSonyDS4Controllers, SONY_VID, SONY_DS4_V2_PID);
|
||||
REGISTER_HID_DETECTOR("Sony DualShock 4", DetectSonyDS4Controllers, SONY_VID, SONY_DS4_RECEIVER_PID);
|
||||
REGISTER_HID_DETECTOR("Sony DualSense", DetectSonyDualSenseControllers, SONY_VID, SONY_DUALSENSE_PID);
|
||||
REGISTER_HID_DETECTOR("Sony DualSense Edge", DetectSonyDualSenseControllers, SONY_VID, SONY_DUALSENSE_EDGE_PID);
|
||||
Reference in New Issue
Block a user