Skip to content

Commit 6928c50

Browse files
773534601CalcProgrammer1
authored andcommitted
Add new device, DRGB LED controller, including multiple versions
1 parent 9284ec7 commit 6928c50

File tree

6 files changed

+618
-0
lines changed

6 files changed

+618
-0
lines changed

Controllers/DRGBController/.gitkeep

Whitespace-only changes.
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/*---------------------------------------------------------*\
2+
| DRGBController.cpp |
3+
| |
4+
| Driver for DRGBmods |
5+
| |
6+
| Zhi Yan 25 Jun 2024 |
7+
| |
8+
| This file is part of the OpenRGB project |
9+
| SPDX-License-Identifier: GPL-2.0-only |
10+
\*---------------------------------------------------------*/
11+
12+
#include <cstring>
13+
#include "DRGBController.h"
14+
15+
using namespace std::chrono_literals;
16+
17+
DRGBController::DRGBController(hid_device* dev_handle, const char* path, unsigned short pid)
18+
{
19+
dev = dev_handle;
20+
location = path;
21+
device_pid = pid;
22+
}
23+
24+
std::string DRGBController::GetLocationString()
25+
{
26+
return("HID: " + location);
27+
}
28+
29+
std::string DRGBController::GetSerialString()
30+
{
31+
wchar_t serial_string[128];
32+
int ret = hid_get_serial_number_string(dev, serial_string, 128);
33+
if(ret != 0)
34+
{
35+
return("");
36+
}
37+
std::wstring return_wstring = serial_string;
38+
std::string return_string(return_wstring.begin(), return_wstring.end());
39+
return(return_string);
40+
}
41+
42+
unsigned short DRGBController::GetDevicePID()
43+
{
44+
return(device_pid);
45+
}
46+
47+
void DRGBController::SendPacket(unsigned char* colors, unsigned int buf_packets , unsigned int Array)
48+
{
49+
unsigned char usb_buf[1025];
50+
unsigned int buf_idx = 0;
51+
memset(usb_buf, 0x00, sizeof(usb_buf));
52+
usb_buf[0x00] = 0x00;
53+
unsigned int HigCount = Array / 256 >= 1 ? 1 : 0;
54+
unsigned int LowCount = Array >= 316 ? 60 : (Array % 256) ;
55+
Array = Array <= 316 ? 0 : (Array-316);
56+
for(unsigned int i = 0; i < buf_packets; i++)
57+
{
58+
usb_buf[1] = i + 100 ;
59+
usb_buf[2] = buf_packets + 99 ;
60+
usb_buf[3] = HigCount;
61+
usb_buf[4] = LowCount;
62+
buf_idx = i*1020;
63+
for(unsigned int k=0;k<1020;k++)
64+
{
65+
usb_buf[k+5] = colors[buf_idx + k];
66+
}
67+
hid_write(dev, usb_buf, 1025);
68+
if(Array)
69+
{
70+
HigCount = Array / 256 >= 1 ? 1 : 0;
71+
LowCount = Array >= 340 ? 84 : (Array % 256) ;
72+
Array = Array <= 340 ? 0 : (Array-316);
73+
}
74+
}
75+
}
76+
77+
void DRGBController::SendPacketFS(unsigned char* colors, unsigned int buf_packets , bool Array)
78+
{
79+
unsigned char usb_buf[65];
80+
unsigned int buf_idx = 0;
81+
memset(usb_buf, 0x00, sizeof(usb_buf));
82+
usb_buf[0x00] = 0x00;
83+
if(Array)
84+
{
85+
for(unsigned int i = 0; i < buf_packets; i++)
86+
{
87+
usb_buf[1] = i == buf_packets - 1 ? 200 + i : 100 + i;
88+
buf_idx = i*63;
89+
for(unsigned int k=0;k<63;k++)
90+
{
91+
usb_buf[k+2] = colors[buf_idx + k];
92+
}
93+
hid_write(dev, usb_buf, 65);
94+
}
95+
}
96+
else
97+
{
98+
for(unsigned int e=0;e<64;e++)
99+
{
100+
usb_buf[e+1] = colors[e];
101+
}
102+
hid_write(dev, usb_buf, 65);
103+
}
104+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*---------------------------------------------------------*\
2+
| DRGBController.h |
3+
| |
4+
| Driver for DRGBmods |
5+
| |
6+
| Zhi Yan 25 Jun 2024 |
7+
| |
8+
| This file is part of the OpenRGB project |
9+
| SPDX-License-Identifier: GPL-2.0-only |
10+
\*---------------------------------------------------------*/
11+
12+
#pragma once
13+
14+
#include <chrono>
15+
#include <vector>
16+
#include <hidapi/hidapi.h>
17+
#include "RGBController.h"
18+
19+
class DRGBController
20+
{
21+
public:
22+
DRGBController(hid_device* dev_handle, const char* path, unsigned short pid);
23+
~DRGBController();
24+
std::string GetLocationString();
25+
std::string GetSerialString();
26+
unsigned short GetDevicePID();
27+
void SetChannelLEDs(unsigned char channel, RGBColor * colors, unsigned int num_colors);
28+
void SendPacket(unsigned char* colors,unsigned int buf_packets ,unsigned int Array);
29+
void SendPacketFS(unsigned char* colors,unsigned int buf_packets ,bool Array);
30+
private:
31+
hid_device* dev;
32+
unsigned short device_pid;
33+
std::string location;
34+
};
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*---------------------------------------------------------*\
2+
| DRGBControllerDetect.cpp |
3+
| |
4+
| Driver for DRGBmods |
5+
| |
6+
| Zhi Yan 25 Jun 2024 |
7+
| |
8+
| This file is part of the OpenRGB project |
9+
| SPDX-License-Identifier: GPL-2.0-only |
10+
\*---------------------------------------------------------*/
11+
12+
#include <vector>
13+
#include <hidapi/hidapi.h>
14+
#include "Detector.h"
15+
#include "DRGBController.h"
16+
#include "RGBController.h"
17+
#include "RGBController_DRGB.h"
18+
19+
void DetectDRGBControllers(hid_device_info* info, const std::string& name)
20+
{
21+
hid_device* dev = hid_open_path(info->path);
22+
if(dev)
23+
{
24+
wchar_t product[128];
25+
hid_get_product_string(dev, product, 128);
26+
std::wstring product_str(product);
27+
DRGBController* controller = new DRGBController(dev, info->path,info->product_id);
28+
RGBController_DRGB* rgb_controller = new RGBController_DRGB(controller);
29+
rgb_controller->name = name;
30+
ResourceManager::get()->RegisterRGBController(rgb_controller);
31+
}
32+
}
33+
34+
REGISTER_HID_DETECTOR("DRGB LED V4", DetectDRGBControllers, DRGBV4_VID, DRGB_LED_V4_PID);
35+
REGISTER_HID_DETECTOR("DRGB ULTRA V4F", DetectDRGBControllers, DRGBV4_VID, DRGB_ULTRA_V4F_PID);
36+
REGISTER_HID_DETECTOR("DRGB CORE V4F", DetectDRGBControllers, DRGBV4_VID, DRGB_CORE_V4F_PID);
37+
REGISTER_HID_DETECTOR("DRGB SIG V4F", DetectDRGBControllers, DRGBV4_VID, DRGB_SIG_V4F_PID);
38+
39+
REGISTER_HID_DETECTOR("DRGB LED", DetectDRGBControllers, DRGBV3_VID, DRGB_LED_V3_PID);
40+
REGISTER_HID_DETECTOR("DRGB Ultra V3", DetectDRGBControllers, DRGBV3_VID, DRGB_Ultra_V3_PID);
41+
REGISTER_HID_DETECTOR("DRGB CORE V3", DetectDRGBControllers, DRGBV3_VID, DRGB_CORE_V3_PID);
42+
43+
REGISTER_HID_DETECTOR("DRGB LED Controller", DetectDRGBControllers, DRGBV2_VID, DRGB_LED_PID);
44+
REGISTER_HID_DETECTOR("DRGB ULTRA", DetectDRGBControllers, DRGBV2_VID, DRGB_ULTRA_PID);
45+
REGISTER_HID_DETECTOR("DRGB SIG AB", DetectDRGBControllers, DRGBV2_VID, DRGB_SIG_AB_PID);
46+
REGISTER_HID_DETECTOR("DRGB SIG CD", DetectDRGBControllers, DRGBV2_VID, DRGB_SIG_CD_PID);
47+
REGISTER_HID_DETECTOR("DRGB Strimer Controller", DetectDRGBControllers, DRGBV2_VID, DRGB_Strimer_PID);

0 commit comments

Comments
 (0)