Publish LumaOps source

This commit is contained in:
LumaOps release export
2026-09-03 01:18:36 +02:00
commit 7f1c0e5f71
2363 changed files with 501543 additions and 0 deletions
@@ -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()
{
}
@@ -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;
};
@@ -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;
};