Update Redragon code, split mouse and keyboard into their own controllers, and get mouse control working
This commit is contained in:
parent
7c221416cc
commit
ad85efcb14
8 changed files with 383 additions and 152 deletions
|
|
@ -1,5 +1,7 @@
|
|||
#include "RedragonController.h"
|
||||
#include "RedragonK556Controller.h"
|
||||
#include "RedragonM711Controller.h"
|
||||
#include "RGBController.h"
|
||||
#include "RGBController_RedragonM711.h"
|
||||
#include "RGBController_Dummy.h"
|
||||
#include <vector>
|
||||
#include <hidapi/hidapi.h>
|
||||
|
|
@ -81,16 +83,28 @@ void DetectRedragonControllers(std::vector<RGBController*>& rgb_controllers)
|
|||
|
||||
if( dev )
|
||||
{
|
||||
RedragonController* controller = new RedragonController(dev);
|
||||
switch(device_list[device_idx].type)
|
||||
{
|
||||
case DEVICE_TYPE_KEYBOARD:
|
||||
{
|
||||
RedragonK556Controller* controller = new RedragonK556Controller(dev);
|
||||
RGBController_Dummy* rgb_controller = new RGBController_Dummy();
|
||||
|
||||
//if(controller->GetDeviceType() != DEVICE_TYPE_UNKNOWN)
|
||||
//{
|
||||
RGBController_Dummy* rgb_controller = new RGBController_Dummy();
|
||||
rgb_controller->name = device_list[device_idx].name;
|
||||
|
||||
rgb_controllers.push_back(rgb_controller);
|
||||
}
|
||||
break;
|
||||
|
||||
rgb_controller->name = device_list[device_idx].name;
|
||||
|
||||
rgb_controllers.push_back(rgb_controller);
|
||||
//}
|
||||
case DEVICE_TYPE_MOUSE:
|
||||
{
|
||||
RedragonM711Controller* controller = new RedragonM711Controller(dev);
|
||||
|
||||
RGBController_RedragonM711* rgb_controller = new RGBController_RedragonM711(controller);
|
||||
rgb_controllers.push_back(rgb_controller);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,74 +1,69 @@
|
|||
#include "RedragonController.h"
|
||||
#include "RedragonK556Controller.h"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
static void send_usb_msg(hid_device* dev, char * data_pkt, unsigned int size)
|
||||
{
|
||||
char* usb_pkt = new char[size + 1];
|
||||
|
||||
usb_pkt[0] = 0x04;
|
||||
for(int i = 1; i < size + 1; i++)
|
||||
{
|
||||
usb_pkt[i] = data_pkt[i-1];
|
||||
}
|
||||
|
||||
hid_write(dev, (unsigned char *)usb_pkt, size + 1);
|
||||
|
||||
delete usb_pkt;
|
||||
}
|
||||
|
||||
static void get_usb_msg(hid_device* dev, char* data_pkt, unsigned int size)
|
||||
{
|
||||
char usb_pkt[65];
|
||||
usb_pkt[0] = 0x00;
|
||||
for(int i = 1; i < 65; i++)
|
||||
{
|
||||
usb_pkt[i] = data_pkt[i-1];
|
||||
}
|
||||
int bytes = hid_get_feature_report(dev, (unsigned char*)data_pkt, size);
|
||||
}
|
||||
|
||||
RedragonController::RedragonController(hid_device* dev_handle)
|
||||
RedragonK556Controller::RedragonK556Controller(hid_device* dev_handle)
|
||||
{
|
||||
dev = dev_handle;
|
||||
|
||||
//SendMouseMode(REDRAGON_MODE_STATIC, 0x01, 0x00, 0xFF, 0xFF);
|
||||
//SendMouseApply();
|
||||
|
||||
unsigned char color_data[0x36];
|
||||
|
||||
for(int i = 0; i < 0x36; i += 3)
|
||||
{
|
||||
color_data[i] = 0xFF;
|
||||
color_data[i+1] = 0x00;
|
||||
color_data[i+2] = 0x00;
|
||||
}
|
||||
|
||||
color_data[51] = 0xFF;
|
||||
color_data[52] = 0xFF;
|
||||
color_data[53] = 0xFF;
|
||||
unsigned char color_data[0x36 * 7];
|
||||
|
||||
SendKeyboardBegin();
|
||||
SendKeyboardMode(REDRAGON_K556_MODE_CUSTOM);
|
||||
SendKeyboardMode(20);
|
||||
|
||||
SendKeyboardData
|
||||
for(int i = 0; i < 0x36 * 7; i += 3)
|
||||
{
|
||||
color_data[i] = 0x00;
|
||||
color_data[i+1] = 0xff;
|
||||
color_data[i+2] = 0x00;
|
||||
}
|
||||
|
||||
SetKeyboardColors
|
||||
(
|
||||
color_data,
|
||||
0x36,
|
||||
0x36 + 0x36 + 0x36 + 0x36 + 0x36 + 0x36
|
||||
0x36 * 6
|
||||
);
|
||||
|
||||
SendKeyboardEnd();
|
||||
}
|
||||
|
||||
void RedragonK556Controller::SetKeyboardColors
|
||||
(
|
||||
unsigned char * color_data,
|
||||
unsigned int size
|
||||
)
|
||||
{
|
||||
unsigned int packet_size = 0;
|
||||
unsigned int packet_offset = 0;
|
||||
|
||||
while(size > 0)
|
||||
{
|
||||
if(size >= REDRAGON_K556_MAX_PACKET_SIZE)
|
||||
{
|
||||
packet_size = REDRAGON_K556_MAX_PACKET_SIZE;
|
||||
}
|
||||
else
|
||||
{
|
||||
packet_size = size;
|
||||
}
|
||||
|
||||
SendKeyboardData
|
||||
(
|
||||
&color_data[packet_offset],
|
||||
packet_size,
|
||||
packet_offset
|
||||
);
|
||||
|
||||
size -= packet_size;
|
||||
packet_offset += packet_size;
|
||||
}
|
||||
}
|
||||
|
||||
/*-------------------------------------------------------------------------------------------------*\
|
||||
| Private packet sending functions. |
|
||||
\*-------------------------------------------------------------------------------------------------*/
|
||||
|
||||
/*-----------------------------------------------------------------------------------------*\
|
||||
| Keyboard functions |
|
||||
\*-----------------------------------------------------------------------------------------*/
|
||||
|
||||
void RedragonController::SendKeyboardBegin()
|
||||
void RedragonK556Controller::SendKeyboardBegin()
|
||||
{
|
||||
char usb_buf[64];
|
||||
|
||||
|
|
@ -92,7 +87,7 @@ void RedragonController::SendKeyboardBegin()
|
|||
hid_read(dev, (unsigned char *)usb_buf, 64);
|
||||
}
|
||||
|
||||
void RedragonController::SendKeyboardData
|
||||
void RedragonK556Controller::SendKeyboardData
|
||||
(
|
||||
unsigned char * data,
|
||||
unsigned char data_size,
|
||||
|
|
@ -129,7 +124,7 @@ void RedragonController::SendKeyboardData
|
|||
hid_read(dev, (unsigned char *)usb_buf, 64);
|
||||
}
|
||||
|
||||
void RedragonController::SendKeyboardMode
|
||||
void RedragonK556Controller::SendKeyboardMode
|
||||
(
|
||||
unsigned char mode
|
||||
)
|
||||
|
|
@ -145,7 +140,7 @@ void RedragonController::SendKeyboardMode
|
|||
| Set up Keyboard End packet |
|
||||
\*-----------------------------------------------------*/
|
||||
usb_buf[0x00] = 0x04;
|
||||
usb_buf[0x01] = 0x08 + mode;
|
||||
usb_buf[0x01] = 0x00;
|
||||
usb_buf[0x02] = 0x00;
|
||||
usb_buf[0x03] = 0x06;
|
||||
usb_buf[0x04] = 0x01;
|
||||
|
|
@ -159,7 +154,7 @@ void RedragonController::SendKeyboardMode
|
|||
hid_read(dev, (unsigned char *)usb_buf, 64);
|
||||
}
|
||||
|
||||
void RedragonController::SendKeyboardEnd()
|
||||
void RedragonK556Controller::SendKeyboardEnd()
|
||||
{
|
||||
char usb_buf[64];
|
||||
|
||||
|
|
@ -181,71 +176,4 @@ void RedragonController::SendKeyboardEnd()
|
|||
\*-----------------------------------------------------*/
|
||||
hid_write(dev, (unsigned char *)usb_buf, 64);
|
||||
hid_read(dev, (unsigned char *)usb_buf, 64);
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------------------*\
|
||||
| Mouse functions |
|
||||
\*-----------------------------------------------------------------------------------------*/
|
||||
|
||||
void RedragonController::SendMouseApply()
|
||||
{
|
||||
char usb_buf[16];
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Zero out buffer |
|
||||
\*-----------------------------------------------------*/
|
||||
memset(usb_buf, 0x00, sizeof(usb_buf));
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set up Apply packet |
|
||||
\*-----------------------------------------------------*/
|
||||
usb_buf[0x00] = 0x02;
|
||||
usb_buf[0x01] = 0xF1;
|
||||
usb_buf[0x02] = 0x02;
|
||||
usb_buf[0x03] = 0x04;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send packet |
|
||||
\*-----------------------------------------------------*/
|
||||
send_usb_msg(dev, usb_buf, 16);
|
||||
}
|
||||
|
||||
void RedragonController::SendMouseMode
|
||||
(
|
||||
unsigned char mode,
|
||||
unsigned char speed,
|
||||
unsigned char red,
|
||||
unsigned char green,
|
||||
unsigned char blue
|
||||
)
|
||||
{
|
||||
char usb_buf[16];
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Zero out buffer |
|
||||
\*-----------------------------------------------------*/
|
||||
memset(usb_buf, 0x00, sizeof(usb_buf));
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set up Lighting Control packet |
|
||||
\*-----------------------------------------------------*/
|
||||
usb_buf[0x00] = 0x02;
|
||||
usb_buf[0x01] = 0xF3;
|
||||
usb_buf[0x02] = 0x49;
|
||||
usb_buf[0x03] = 0x04;
|
||||
usb_buf[0x04] = 0x06;
|
||||
|
||||
usb_buf[0x08] = red;
|
||||
usb_buf[0x09] = green;
|
||||
usb_buf[0x0A] = blue;
|
||||
|
||||
usb_buf[0x0B] = 0x01; //on
|
||||
|
||||
usb_buf[0x0C] = speed;
|
||||
usb_buf[0x0D] = mode;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send packet |
|
||||
\*-----------------------------------------------------*/
|
||||
send_usb_msg(dev, usb_buf, 16);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,9 +1,8 @@
|
|||
/*-----------------------------------------*\
|
||||
| RedragonController.h |
|
||||
| RedragonK556Controller.h |
|
||||
| |
|
||||
| Definitions and types for Redragon RGB |
|
||||
| keyboard, mouse, and mousemat lighting |
|
||||
| controller |
|
||||
| Definitions and types for Redragon K556 |
|
||||
| Devarajas keyboard lighting controller |
|
||||
| |
|
||||
| Adam Honse (CalcProgrammer1) 3/15/2020 |
|
||||
\*-----------------------------------------*/
|
||||
|
|
@ -15,6 +14,9 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#define REDRAGON_K556_MAX_PACKET_SIZE ( 0x36 ) /* max packet size for color*/
|
||||
/* update packets */
|
||||
|
||||
enum
|
||||
{
|
||||
REDRAGON_K556_MODE_RAINBOW_WAVE_SHORT = 0x01, /* "Go with the stream" */
|
||||
|
|
@ -37,22 +39,18 @@ enum
|
|||
REDRAGON_K556_MODE_CUSTOM = 0x14, /* "Coastal" */
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
REDRAGON_M117_MODE_WAVE = 0x00,
|
||||
REDRAGON_M117_MODE_RANDOM_BREATHING = 0x01,
|
||||
REDRAGON_M117_MODE_STATIC = 0x02,
|
||||
REDRAGON_M117_MODE_BREATHING = 0x04,
|
||||
REDRAGON_M117_MODE_RAINBOW = 0x08,
|
||||
REDRAGON_M117_MODE_FLASHING = 0x10,
|
||||
};
|
||||
|
||||
class RedragonController
|
||||
class RedragonK556Controller
|
||||
{
|
||||
public:
|
||||
RedragonController(hid_device* dev_handle);
|
||||
~RedragonController();
|
||||
RedragonK556Controller(hid_device* dev_handle);
|
||||
~RedragonK556Controller();
|
||||
|
||||
void SetKeyboardColors
|
||||
(
|
||||
unsigned char * color_data,
|
||||
unsigned int size
|
||||
);
|
||||
|
||||
private:
|
||||
hid_device* dev;
|
||||
|
||||
90
Controllers/RedragonController/RedragonM711Controller.cpp
Normal file
90
Controllers/RedragonController/RedragonM711Controller.cpp
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
#include "RedragonM711Controller.h"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
static void send_usb_msg(hid_device* dev, char * data_pkt, unsigned int size)
|
||||
{
|
||||
char* usb_pkt = new char[size + 1];
|
||||
|
||||
usb_pkt[0] = 0x00;
|
||||
for(int i = 1; i < size + 1; i++)
|
||||
{
|
||||
usb_pkt[i] = data_pkt[i-1];
|
||||
}
|
||||
|
||||
hid_send_feature_report(dev, (unsigned char *)usb_pkt, size + 1);
|
||||
|
||||
delete usb_pkt;
|
||||
}
|
||||
|
||||
RedragonM711Controller::RedragonM711Controller(hid_device* dev_handle)
|
||||
{
|
||||
dev = dev_handle;
|
||||
}
|
||||
|
||||
/*-------------------------------------------------------------------------------------------------*\
|
||||
| Private packet sending functions. |
|
||||
\*-------------------------------------------------------------------------------------------------*/
|
||||
|
||||
void RedragonM711Controller::SendMouseApply()
|
||||
{
|
||||
char usb_buf[16];
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Zero out buffer |
|
||||
\*-----------------------------------------------------*/
|
||||
memset(usb_buf, 0x00, sizeof(usb_buf));
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set up Apply packet |
|
||||
\*-----------------------------------------------------*/
|
||||
usb_buf[0x00] = 0x02;
|
||||
usb_buf[0x01] = 0xF1;
|
||||
usb_buf[0x02] = 0x02;
|
||||
usb_buf[0x03] = 0x04;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send packet |
|
||||
\*-----------------------------------------------------*/
|
||||
send_usb_msg(dev, usb_buf, 16);
|
||||
}
|
||||
|
||||
void RedragonM711Controller::SendMouseMode
|
||||
(
|
||||
unsigned char mode,
|
||||
unsigned char speed,
|
||||
unsigned char red,
|
||||
unsigned char green,
|
||||
unsigned char blue
|
||||
)
|
||||
{
|
||||
char usb_buf[16];
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Zero out buffer |
|
||||
\*-----------------------------------------------------*/
|
||||
memset(usb_buf, 0x00, sizeof(usb_buf));
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set up Lighting Control packet |
|
||||
\*-----------------------------------------------------*/
|
||||
usb_buf[0x00] = 0x02;
|
||||
usb_buf[0x01] = 0xF3;
|
||||
usb_buf[0x02] = 0x49;
|
||||
usb_buf[0x03] = 0x04;
|
||||
usb_buf[0x04] = 0x06;
|
||||
|
||||
usb_buf[0x08] = red;
|
||||
usb_buf[0x09] = green;
|
||||
usb_buf[0x0A] = blue;
|
||||
|
||||
usb_buf[0x0B] = 0x01; //on
|
||||
|
||||
usb_buf[0x0C] = speed;
|
||||
usb_buf[0x0D] = mode;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send packet |
|
||||
\*-----------------------------------------------------*/
|
||||
send_usb_msg(dev, usb_buf, 16);
|
||||
}
|
||||
46
Controllers/RedragonController/RedragonM711Controller.h
Normal file
46
Controllers/RedragonController/RedragonM711Controller.h
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
/*-----------------------------------------*\
|
||||
| RedragonM711Controller.h |
|
||||
| |
|
||||
| Definitions and types for Redragon M711 |
|
||||
| Cobra mouse lighting controller |
|
||||
| |
|
||||
| Adam Honse (CalcProgrammer1) 3/15/2020 |
|
||||
\*-----------------------------------------*/
|
||||
|
||||
#include "RGBController.h"
|
||||
|
||||
#include <string>
|
||||
#include <hidapi/hidapi.h>
|
||||
|
||||
#pragma once
|
||||
|
||||
enum
|
||||
{
|
||||
REDRAGON_M711_MODE_WAVE = 0x00,
|
||||
REDRAGON_M711_MODE_RANDOM_BREATHING = 0x01,
|
||||
REDRAGON_M711_MODE_STATIC = 0x02,
|
||||
REDRAGON_M711_MODE_BREATHING = 0x04,
|
||||
REDRAGON_M711_MODE_RAINBOW = 0x08,
|
||||
REDRAGON_M711_MODE_FLASHING = 0x10,
|
||||
};
|
||||
|
||||
class RedragonM711Controller
|
||||
{
|
||||
public:
|
||||
RedragonM711Controller(hid_device* dev_handle);
|
||||
~RedragonM711Controller();
|
||||
|
||||
void SendMouseApply();
|
||||
|
||||
void SendMouseMode
|
||||
(
|
||||
unsigned char mode,
|
||||
unsigned char speed,
|
||||
unsigned char red,
|
||||
unsigned char green,
|
||||
unsigned char blue
|
||||
);
|
||||
|
||||
private:
|
||||
hid_device* dev;
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue