diff --git a/Controllers/RedragonController/RedragonController.cpp b/Controllers/RedragonController/RedragonController.cpp new file mode 100644 index 00000000..20b86a85 --- /dev/null +++ b/Controllers/RedragonController/RedragonController.cpp @@ -0,0 +1,251 @@ +#include "RedragonController.h" + +#include + +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) +{ + 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; + + SendKeyboardBegin(); + SendKeyboardMode(REDRAGON_K556_MODE_CUSTOM); + + SendKeyboardData + ( + color_data, + 0x36, + 0x36 + 0x36 + 0x36 + 0x36 + 0x36 + 0x36 + ); + SendKeyboardEnd(); +} + +/*-------------------------------------------------------------------------------------------------*\ +| Private packet sending functions. | +\*-------------------------------------------------------------------------------------------------*/ + +/*-----------------------------------------------------------------------------------------*\ +| Keyboard functions | +\*-----------------------------------------------------------------------------------------*/ + +void RedragonController::SendKeyboardBegin() +{ + char usb_buf[64]; + + /*-----------------------------------------------------*\ + | Zero out buffer | + \*-----------------------------------------------------*/ + memset(usb_buf, 0x00, sizeof(usb_buf)); + + /*-----------------------------------------------------*\ + | Set up Keyboard Begin packet | + \*-----------------------------------------------------*/ + usb_buf[0x00] = 0x04; + usb_buf[0x01] = 0x01; + usb_buf[0x02] = 0x00; + usb_buf[0x03] = 0x01; + + /*-----------------------------------------------------*\ + | Send packet | + \*-----------------------------------------------------*/ + hid_write(dev, (unsigned char *)usb_buf, 64); + hid_read(dev, (unsigned char *)usb_buf, 64); +} + +void RedragonController::SendKeyboardData + ( + unsigned char * data, + unsigned char data_size, + unsigned short data_offset + ) +{ + char usb_buf[64]; + + /*-----------------------------------------------------*\ + | Zero out buffer | + \*-----------------------------------------------------*/ + memset(usb_buf, 0x00, sizeof(usb_buf)); + + /*-----------------------------------------------------*\ + | Set up Keyboard End packet | + \*-----------------------------------------------------*/ + usb_buf[0x00] = 0x04; + usb_buf[0x01] = 0x11 + data_offset; + usb_buf[0x02] = data_size; + usb_buf[0x03] = ( data_size / 3 ) - 1; + usb_buf[0x04] = data_size; + usb_buf[0x05] = data_offset & 0x00FF; + usb_buf[0x06] = data_offset >> 8; + + /*-----------------------------------------------------*\ + | Copy in data bytes | + \*-----------------------------------------------------*/ + memcpy(&usb_buf[0x08], data, data_size); + + /*-----------------------------------------------------*\ + | Send packet | + \*-----------------------------------------------------*/ + hid_write(dev, (unsigned char *)usb_buf, 64); + hid_read(dev, (unsigned char *)usb_buf, 64); +} + +void RedragonController::SendKeyboardMode + ( + unsigned char mode + ) +{ + char usb_buf[64]; + + /*-----------------------------------------------------*\ + | Zero out buffer | + \*-----------------------------------------------------*/ + memset(usb_buf, 0x00, sizeof(usb_buf)); + + /*-----------------------------------------------------*\ + | Set up Keyboard End packet | + \*-----------------------------------------------------*/ + usb_buf[0x00] = 0x04; + usb_buf[0x01] = 0x08 + mode; + usb_buf[0x02] = 0x00; + usb_buf[0x03] = 0x06; + usb_buf[0x04] = 0x01; + + usb_buf[0x08] = mode; + + /*-----------------------------------------------------*\ + | Send packet | + \*-----------------------------------------------------*/ + hid_write(dev, (unsigned char *)usb_buf, 64); + hid_read(dev, (unsigned char *)usb_buf, 64); +} + +void RedragonController::SendKeyboardEnd() +{ + char usb_buf[64]; + + /*-----------------------------------------------------*\ + | Zero out buffer | + \*-----------------------------------------------------*/ + memset(usb_buf, 0x00, sizeof(usb_buf)); + + /*-----------------------------------------------------*\ + | Set up Keyboard End packet | + \*-----------------------------------------------------*/ + usb_buf[0x00] = 0x04; + usb_buf[0x01] = 0x02; + usb_buf[0x02] = 0x00; + usb_buf[0x03] = 0x02; + + /*-----------------------------------------------------*\ + | Send packet | + \*-----------------------------------------------------*/ + 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); +} diff --git a/Controllers/RedragonController/RedragonController.h b/Controllers/RedragonController/RedragonController.h new file mode 100644 index 00000000..53668035 --- /dev/null +++ b/Controllers/RedragonController/RedragonController.h @@ -0,0 +1,85 @@ +/*-----------------------------------------*\ +| RedragonController.h | +| | +| Definitions and types for Redragon RGB | +| keyboard, mouse, and mousemat lighting | +| controller | +| | +| Adam Honse (CalcProgrammer1) 3/15/2020 | +\*-----------------------------------------*/ + +#include "RGBController.h" + +#include +#include + +#pragma once + +enum +{ + REDRAGON_K556_MODE_RAINBOW_WAVE_SHORT = 0x01, /* "Go with the stream" */ + REDRAGON_K556_MODE_RAINBOW_WAVE_LONG = 0x02, /* "Clouds fly" */ + REDRAGON_K556_MODE_COLOR_WHEEL = 0x03, /* "Winding paths" */ + REDRAGON_K556_MODE_SPECTRUM_CYCLE = 0x04, /* "The trial of light" */ + REDRAGON_K556_MODE_BREATHING = 0x05, /* "Breathing" */ + REDRAGON_K556_MODE_STATIC = 0x06, /* "Normally on" */ + REDRAGON_K556_MODE_REACTIVE = 0x07, /* "Pass without trace" */ + REDRAGON_K556_MODE_REACTIVE_RIPPLE = 0x08, /* "Ripple graff" */ + REDRAGON_K556_MODE_REACTIVE_LINE = 0x09, /* "Fast run without trace" */ + REDRAGON_K556_MODE_STARLIGHT_FAST = 0x0A, /* "Swift action" */ + REDRAGON_K556_MODE_BLOOMING = 0x0B, /* "Flowers blooming" */ + REDRAGON_K556_MODE_RAINBOW_WAVE_VERTICAL = 0x0C, /* "Snow winter jasmine" */ + REDRAGON_K556_MODE_HURRICANE = 0x0D, /* "Hurricane" */ + REDRAGON_K556_MODE_ACCUMULATE = 0x0E, /* "Accumulate" */ + REDRAGON_K556_MODE_STARLIGHT_SLOW = 0x0F, /* "Digital times" */ + REDRAGON_K556_MODE_VISOR = 0x10, /* "Both ways" */ + REDRAGON_K556_MODE_RAINBOW_WAVE_CIRCLE = 0x12, /* "Fast and the Furious" */ + 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 +{ +public: + RedragonController(hid_device* dev_handle); + ~RedragonController(); + +private: + hid_device* dev; + + void SendKeyboardBegin(); + + void SendKeyboardMode + ( + unsigned char mode + ); + + void SendKeyboardData + ( + unsigned char * data, + unsigned char data_size, + unsigned short data_offset + ); + + void SendKeyboardEnd(); + + void SendMouseApply(); + + void SendMouseMode + ( + unsigned char mode, + unsigned char speed, + unsigned char red, + unsigned char green, + unsigned char blue + ); +}; diff --git a/Controllers/RedragonController/RedragonControllerDetect.cpp b/Controllers/RedragonController/RedragonControllerDetect.cpp new file mode 100644 index 00000000..abe2d8d7 --- /dev/null +++ b/Controllers/RedragonController/RedragonControllerDetect.cpp @@ -0,0 +1,96 @@ +#include "RedragonController.h" +#include "RGBController.h" +#include "RGBController_Dummy.h" +#include +#include + +/*-----------------------------------------------------*\ +| Keyboard product IDs | +\*-----------------------------------------------------*/ +#define REDRAGON_K556_VID 0x0C45 +#define REDRAGON_K556_PID 0x5004 + +/*-----------------------------------------------------*\ +| Mouse product IDs | +\*-----------------------------------------------------*/ +#define REDRAGON_M711_VID 0x04D9 +#define REDRAGON_M711_PID 0xFC30 + +typedef struct +{ + unsigned short usb_vid; + unsigned short usb_pid; + unsigned char usb_interface; + device_type type; + const char * name; +} redragon_device; + +#define REDRAGON_NUM_DEVICES (sizeof(device_list) / sizeof(device_list[ 0 ])) + +static const redragon_device device_list[] = +{ + /*-----------------------------------------------------------------------------------------------------*\ + | Keyboards | + \*-----------------------------------------------------------------------------------------------------*/ + { REDRAGON_K556_VID, REDRAGON_K556_PID, 1, DEVICE_TYPE_KEYBOARD, "Redragon K556 Devarajas" }, + /*-----------------------------------------------------------------------------------------------------*\ + | Mice | + \*-----------------------------------------------------------------------------------------------------*/ + { REDRAGON_M711_VID, REDRAGON_M711_PID, 2, DEVICE_TYPE_MOUSE, "Redragon M711 Cobra" }, + /*-----------------------------------------------------------------------------------------------------*\ + | Mousemats | + \*-----------------------------------------------------------------------------------------------------*/ +}; + +/******************************************************************************************\ +* * +* DetectRedragonControllers * +* * +* Tests the USB address to see if a Redragon RGB Keyboard controller exists there. * +* * +\******************************************************************************************/ + +void DetectRedragonControllers(std::vector& rgb_controllers) +{ + hid_device_info* info; + hid_device* dev; + + hid_init(); + + for(int device_idx = 0; device_idx < REDRAGON_NUM_DEVICES; device_idx++) + { + dev = NULL; + + info = hid_enumerate(device_list[device_idx].usb_vid, device_list[device_idx].usb_pid); + + //Look for Redragon RGB Peripheral + while(info) + { + if((info->vendor_id == device_list[device_idx].usb_vid) + &&(info->product_id == device_list[device_idx].usb_pid) + &&(info->interface_number == device_list[device_idx].usb_interface)) + { + dev = hid_open_path(info->path); + break; + } + else + { + info = info->next; + } + } + + if( dev ) + { + RedragonController* controller = new RedragonController(dev); + + //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); + //} + } + } +} diff --git a/OpenRGB.cpp b/OpenRGB.cpp index b26b4f31..27d4810d 100644 --- a/OpenRGB.cpp +++ b/OpenRGB.cpp @@ -304,6 +304,7 @@ void DetectFaustusControllers(std::vector &rgb_controllers); void DetectHyperXKeyboardControllers(std::vector& rgb_controllers); void DetectThermaltakeRiingControllers(std::vector& rgb_controllers); void DetectRGBFusion2USBControllers(std::vector &rgb_controllers); +void DetectRedragonControllers(std::vector& rgb_controllers); /******************************************************************************************\ * * @@ -342,7 +343,8 @@ void DetectRGBControllers(void) DetectCorsairLightingNodeControllers(rgb_controllers); DetectThermaltakeRiingControllers(rgb_controllers); DetectRGBFusion2USBControllers(rgb_controllers); - + DetectRedragonControllers(rgb_controllers); + DetectE131Controllers(rgb_controllers); DetectOpenRazerControllers(rgb_controllers); diff --git a/OpenRGB.pro b/OpenRGB.pro index 5ab8a7d0..22767e35 100644 --- a/OpenRGB.pro +++ b/OpenRGB.pro @@ -47,6 +47,7 @@ INCLUDEPATH += \ Controllers/PatriotViperController/ \ Controllers/PolychromeController/ \ Controllers/PoseidonZRGBController/ \ + Controllers/RedragonController/ \ Controllers/RGBFusionController/ \ Controllers/RGBFusion2USBController/ \ Controllers/RGBFusionGPUController/ \ @@ -117,6 +118,8 @@ SOURCES += \ Controllers/RGBFusion2USBController/RGBFusion2USBControllerDetect.cpp \ Controllers/RGBFusionGPUController/RGBFusionGPUController.cpp \ Controllers/RGBFusionGPUController/RGBFusionGPUControllerDetect.cpp \ + Controllers/RedragonController/RedragonController.cpp \ + Controllers/RedragonController/RedragonControllerDetect.cpp \ Controllers/ThermaltakeRiingController/ThermaltakeRiingController.cpp \ Controllers/ThermaltakeRiingController/ThermaltakeRiingControllerDetect.cpp \ RGBController/RGBController.cpp \ @@ -183,6 +186,7 @@ HEADERS += \ Controllers/RGBFusionController/RGBFusionController.h \ Controllers/RGBFusion2USBController/RGBFusion2USBController.h \ Controllers/RGBFusionGPUController/RGBFusionGPUController.h \ + Controllers/RedragonController/RedragonController.h \ Controllers/ThermaltakeRiingController/ThermaltakeRiingController.h \ RGBController/RGBController.h \ RGBController/RGBController_AMDWraithPrism.h \ diff --git a/dependencies/hidapi/hidapi.c b/dependencies/hidapi/hidapi.c index 5f3e2c65..44d986ad 100644 --- a/dependencies/hidapi/hidapi.c +++ b/dependencies/hidapi/hidapi.c @@ -946,7 +946,7 @@ int HID_API_EXPORT hid_read_timeout(hid_device *dev, unsigned char *data, size_t { int bytes_read = -1; -#if 0 +#if 1 int transferred; int res = libusb_interrupt_transfer(dev->device_handle, dev->input_endpoint, data, length, &transferred, 5000); LOG("transferred: %d\n", transferred);