Skip to content

Commit ad85efc

Browse files
Update Redragon code, split mouse and keyboard into their own controllers, and get mouse control working
1 parent 7c22141 commit ad85efc

File tree

8 files changed

+381
-150
lines changed

8 files changed

+381
-150
lines changed

Controllers/RedragonController/RedragonControllerDetect.cpp

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
#include "RedragonController.h"
1+
#include "RedragonK556Controller.h"
2+
#include "RedragonM711Controller.h"
23
#include "RGBController.h"
4+
#include "RGBController_RedragonM711.h"
35
#include "RGBController_Dummy.h"
46
#include <vector>
57
#include <hidapi/hidapi.h>
@@ -81,16 +83,28 @@ void DetectRedragonControllers(std::vector<RGBController*>& rgb_controllers)
8183

8284
if( dev )
8385
{
84-
RedragonController* controller = new RedragonController(dev);
86+
switch(device_list[device_idx].type)
87+
{
88+
case DEVICE_TYPE_KEYBOARD:
89+
{
90+
RedragonK556Controller* controller = new RedragonK556Controller(dev);
91+
RGBController_Dummy* rgb_controller = new RGBController_Dummy();
92+
93+
rgb_controller->name = device_list[device_idx].name;
94+
95+
rgb_controllers.push_back(rgb_controller);
96+
}
97+
break;
8598

86-
//if(controller->GetDeviceType() != DEVICE_TYPE_UNKNOWN)
87-
//{
88-
RGBController_Dummy* rgb_controller = new RGBController_Dummy();
99+
case DEVICE_TYPE_MOUSE:
100+
{
101+
RedragonM711Controller* controller = new RedragonM711Controller(dev);
89102

90-
rgb_controller->name = device_list[device_idx].name;
91-
92-
rgb_controllers.push_back(rgb_controller);
93-
//}
103+
RGBController_RedragonM711* rgb_controller = new RGBController_RedragonM711(controller);
104+
rgb_controllers.push_back(rgb_controller);
105+
}
106+
break;
107+
}
94108
}
95109
}
96110
}
Lines changed: 50 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,69 @@
1-
#include "RedragonController.h"
1+
#include "RedragonK556Controller.h"
22

33
#include <cstring>
44

5-
static void send_usb_msg(hid_device* dev, char * data_pkt, unsigned int size)
6-
{
7-
char* usb_pkt = new char[size + 1];
8-
9-
usb_pkt[0] = 0x04;
10-
for(int i = 1; i < size + 1; i++)
11-
{
12-
usb_pkt[i] = data_pkt[i-1];
13-
}
14-
15-
hid_write(dev, (unsigned char *)usb_pkt, size + 1);
16-
17-
delete usb_pkt;
18-
}
19-
20-
static void get_usb_msg(hid_device* dev, char* data_pkt, unsigned int size)
21-
{
22-
char usb_pkt[65];
23-
usb_pkt[0] = 0x00;
24-
for(int i = 1; i < 65; i++)
25-
{
26-
usb_pkt[i] = data_pkt[i-1];
27-
}
28-
int bytes = hid_get_feature_report(dev, (unsigned char*)data_pkt, size);
29-
}
30-
31-
RedragonController::RedragonController(hid_device* dev_handle)
5+
RedragonK556Controller::RedragonK556Controller(hid_device* dev_handle)
326
{
337
dev = dev_handle;
348

35-
//SendMouseMode(REDRAGON_MODE_STATIC, 0x01, 0x00, 0xFF, 0xFF);
36-
//SendMouseApply();
9+
unsigned char color_data[0x36 * 7];
3710

38-
unsigned char color_data[0x36];
11+
SendKeyboardBegin();
12+
SendKeyboardMode(20);
3913

40-
for(int i = 0; i < 0x36; i += 3)
14+
for(int i = 0; i < 0x36 * 7; i += 3)
4115
{
42-
color_data[i] = 0xFF;
43-
color_data[i+1] = 0x00;
16+
color_data[i] = 0x00;
17+
color_data[i+1] = 0xff;
4418
color_data[i+2] = 0x00;
4519
}
46-
47-
color_data[51] = 0xFF;
48-
color_data[52] = 0xFF;
49-
color_data[53] = 0xFF;
50-
51-
SendKeyboardBegin();
52-
SendKeyboardMode(REDRAGON_K556_MODE_CUSTOM);
53-
54-
SendKeyboardData
20+
21+
SetKeyboardColors
5522
(
5623
color_data,
57-
0x36,
58-
0x36 + 0x36 + 0x36 + 0x36 + 0x36 + 0x36
24+
0x36 * 6
5925
);
26+
6027
SendKeyboardEnd();
6128
}
6229

30+
void RedragonK556Controller::SetKeyboardColors
31+
(
32+
unsigned char * color_data,
33+
unsigned int size
34+
)
35+
{
36+
unsigned int packet_size = 0;
37+
unsigned int packet_offset = 0;
38+
39+
while(size > 0)
40+
{
41+
if(size >= REDRAGON_K556_MAX_PACKET_SIZE)
42+
{
43+
packet_size = REDRAGON_K556_MAX_PACKET_SIZE;
44+
}
45+
else
46+
{
47+
packet_size = size;
48+
}
49+
50+
SendKeyboardData
51+
(
52+
&color_data[packet_offset],
53+
packet_size,
54+
packet_offset
55+
);
56+
57+
size -= packet_size;
58+
packet_offset += packet_size;
59+
}
60+
}
61+
6362
/*-------------------------------------------------------------------------------------------------*\
6463
| Private packet sending functions. |
6564
\*-------------------------------------------------------------------------------------------------*/
6665

67-
/*-----------------------------------------------------------------------------------------*\
68-
| Keyboard functions |
69-
\*-----------------------------------------------------------------------------------------*/
70-
71-
void RedragonController::SendKeyboardBegin()
66+
void RedragonK556Controller::SendKeyboardBegin()
7267
{
7368
char usb_buf[64];
7469

@@ -92,7 +87,7 @@ void RedragonController::SendKeyboardBegin()
9287
hid_read(dev, (unsigned char *)usb_buf, 64);
9388
}
9489

95-
void RedragonController::SendKeyboardData
90+
void RedragonK556Controller::SendKeyboardData
9691
(
9792
unsigned char * data,
9893
unsigned char data_size,
@@ -129,7 +124,7 @@ void RedragonController::SendKeyboardData
129124
hid_read(dev, (unsigned char *)usb_buf, 64);
130125
}
131126

132-
void RedragonController::SendKeyboardMode
127+
void RedragonK556Controller::SendKeyboardMode
133128
(
134129
unsigned char mode
135130
)
@@ -145,7 +140,7 @@ void RedragonController::SendKeyboardMode
145140
| Set up Keyboard End packet |
146141
\*-----------------------------------------------------*/
147142
usb_buf[0x00] = 0x04;
148-
usb_buf[0x01] = 0x08 + mode;
143+
usb_buf[0x01] = 0x00;
149144
usb_buf[0x02] = 0x00;
150145
usb_buf[0x03] = 0x06;
151146
usb_buf[0x04] = 0x01;
@@ -159,7 +154,7 @@ void RedragonController::SendKeyboardMode
159154
hid_read(dev, (unsigned char *)usb_buf, 64);
160155
}
161156

162-
void RedragonController::SendKeyboardEnd()
157+
void RedragonK556Controller::SendKeyboardEnd()
163158
{
164159
char usb_buf[64];
165160

@@ -181,71 +176,4 @@ void RedragonController::SendKeyboardEnd()
181176
\*-----------------------------------------------------*/
182177
hid_write(dev, (unsigned char *)usb_buf, 64);
183178
hid_read(dev, (unsigned char *)usb_buf, 64);
184-
}
185-
186-
/*-----------------------------------------------------------------------------------------*\
187-
| Mouse functions |
188-
\*-----------------------------------------------------------------------------------------*/
189-
190-
void RedragonController::SendMouseApply()
191-
{
192-
char usb_buf[16];
193-
194-
/*-----------------------------------------------------*\
195-
| Zero out buffer |
196-
\*-----------------------------------------------------*/
197-
memset(usb_buf, 0x00, sizeof(usb_buf));
198-
199-
/*-----------------------------------------------------*\
200-
| Set up Apply packet |
201-
\*-----------------------------------------------------*/
202-
usb_buf[0x00] = 0x02;
203-
usb_buf[0x01] = 0xF1;
204-
usb_buf[0x02] = 0x02;
205-
usb_buf[0x03] = 0x04;
206-
207-
/*-----------------------------------------------------*\
208-
| Send packet |
209-
\*-----------------------------------------------------*/
210-
send_usb_msg(dev, usb_buf, 16);
211-
}
212-
213-
void RedragonController::SendMouseMode
214-
(
215-
unsigned char mode,
216-
unsigned char speed,
217-
unsigned char red,
218-
unsigned char green,
219-
unsigned char blue
220-
)
221-
{
222-
char usb_buf[16];
223-
224-
/*-----------------------------------------------------*\
225-
| Zero out buffer |
226-
\*-----------------------------------------------------*/
227-
memset(usb_buf, 0x00, sizeof(usb_buf));
228-
229-
/*-----------------------------------------------------*\
230-
| Set up Lighting Control packet |
231-
\*-----------------------------------------------------*/
232-
usb_buf[0x00] = 0x02;
233-
usb_buf[0x01] = 0xF3;
234-
usb_buf[0x02] = 0x49;
235-
usb_buf[0x03] = 0x04;
236-
usb_buf[0x04] = 0x06;
237-
238-
usb_buf[0x08] = red;
239-
usb_buf[0x09] = green;
240-
usb_buf[0x0A] = blue;
241-
242-
usb_buf[0x0B] = 0x01; //on
243-
244-
usb_buf[0x0C] = speed;
245-
usb_buf[0x0D] = mode;
246-
247-
/*-----------------------------------------------------*\
248-
| Send packet |
249-
\*-----------------------------------------------------*/
250-
send_usb_msg(dev, usb_buf, 16);
251-
}
179+
}

Controllers/RedragonController/RedragonController.h renamed to Controllers/RedragonController/RedragonK556Controller.h

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
/*-----------------------------------------*\
2-
| RedragonController.h |
2+
| RedragonK556Controller.h |
33
| |
4-
| Definitions and types for Redragon RGB |
5-
| keyboard, mouse, and mousemat lighting |
6-
| controller |
4+
| Definitions and types for Redragon K556 |
5+
| Devarajas keyboard lighting controller |
76
| |
87
| Adam Honse (CalcProgrammer1) 3/15/2020 |
98
\*-----------------------------------------*/
@@ -15,6 +14,9 @@
1514

1615
#pragma once
1716

17+
#define REDRAGON_K556_MAX_PACKET_SIZE ( 0x36 ) /* max packet size for color*/
18+
/* update packets */
19+
1820
enum
1921
{
2022
REDRAGON_K556_MODE_RAINBOW_WAVE_SHORT = 0x01, /* "Go with the stream" */
@@ -37,22 +39,18 @@ enum
3739
REDRAGON_K556_MODE_CUSTOM = 0x14, /* "Coastal" */
3840
};
3941

40-
enum
41-
{
42-
REDRAGON_M117_MODE_WAVE = 0x00,
43-
REDRAGON_M117_MODE_RANDOM_BREATHING = 0x01,
44-
REDRAGON_M117_MODE_STATIC = 0x02,
45-
REDRAGON_M117_MODE_BREATHING = 0x04,
46-
REDRAGON_M117_MODE_RAINBOW = 0x08,
47-
REDRAGON_M117_MODE_FLASHING = 0x10,
48-
};
49-
50-
class RedragonController
42+
class RedragonK556Controller
5143
{
5244
public:
53-
RedragonController(hid_device* dev_handle);
54-
~RedragonController();
45+
RedragonK556Controller(hid_device* dev_handle);
46+
~RedragonK556Controller();
5547

48+
void SetKeyboardColors
49+
(
50+
unsigned char * color_data,
51+
unsigned int size
52+
);
53+
5654
private:
5755
hid_device* dev;
5856

0 commit comments

Comments
 (0)