From 12116c70ee2e48cc318821f157c8da6ebb65eba3 Mon Sep 17 00:00:00 2001 From: Adam Honse Date: Tue, 4 Feb 2020 20:17:09 -0600 Subject: [PATCH] Big Keyboard Update! HyperX Alloy Elite support, Poseidon Z RGB modes, and Corsair K70 RGB --- .../CorsairKeyboardController.cpp | 136 ++++++ .../CorsairKeyboardController.h | 28 ++ .../CorsairKeyboardControllerDetect.cpp | 52 +++ .../HyperXKeyboardController.cpp | 412 ++++++++++++++++++ .../HyperXKeyboardController.h | 119 +++++ .../HyperXKeyboardControllerDetect.cpp | 51 +++ .../PoseidonZRGBController.cpp | 247 +++++++---- .../PoseidonZRGBController.h | 76 +++- .../PoseidonZRGBControllerDetect.cpp | 24 +- OpenRGB.cpp | 4 + OpenRGB.pro | 11 + .../RGBController_CorsairKeyboard.cpp | 53 +++ RGBController/RGBController_CorsairKeyboard.h | 29 ++ .../RGBController_HyperXKeyboard.cpp | 95 ++++ RGBController/RGBController_HyperXKeyboard.h | 28 ++ RGBController/RGBController_PoseidonZRGB.cpp | 58 ++- 16 files changed, 1317 insertions(+), 106 deletions(-) create mode 100644 Controllers/CorsairKeyboardController/CorsairKeyboardController.cpp create mode 100644 Controllers/CorsairKeyboardController/CorsairKeyboardController.h create mode 100644 Controllers/CorsairKeyboardController/CorsairKeyboardControllerDetect.cpp create mode 100644 Controllers/HyperXKeyboardController/HyperXKeyboardController.cpp create mode 100644 Controllers/HyperXKeyboardController/HyperXKeyboardController.h create mode 100644 Controllers/HyperXKeyboardController/HyperXKeyboardControllerDetect.cpp create mode 100644 RGBController/RGBController_CorsairKeyboard.cpp create mode 100644 RGBController/RGBController_CorsairKeyboard.h create mode 100644 RGBController/RGBController_HyperXKeyboard.cpp create mode 100644 RGBController/RGBController_HyperXKeyboard.h diff --git a/Controllers/CorsairKeyboardController/CorsairKeyboardController.cpp b/Controllers/CorsairKeyboardController/CorsairKeyboardController.cpp new file mode 100644 index 00000000..e7acd486 --- /dev/null +++ b/Controllers/CorsairKeyboardController/CorsairKeyboardController.cpp @@ -0,0 +1,136 @@ +/*-----------------------------------------*\ +| CorsairKeyboardController.cpp | +| | +| Driver for Corsair RGB keyboard lighting | +| controller | +| | +| Adam Honse (CalcProgrammer1) 1/9/2020 | +\*-----------------------------------------*/ + +#include "CorsairKeyboardController.h" + +static void send_usb_msg(hid_device* dev, char * data_pkt) +{ + 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_send_feature_report(dev, (unsigned char *)usb_pkt, 65); + bytes++; +} + +CorsairKeyboardController::CorsairKeyboardController(hid_device* dev_handle) +{ + dev = dev_handle; + + char data_pkt[64] = { 0 }; + + data_pkt[0] = 0x07; + data_pkt[1] = 0x05; + data_pkt[2] = 0x02; + data_pkt[3] = 0x00; + data_pkt[4] = 0x03; + + send_usb_msg(dev, data_pkt); +} + +CorsairKeyboardController::~CorsairKeyboardController() +{ + +} + +void CorsairKeyboardController::SetLEDs(std::vector colors) +{ + char data_pkt[5][64] = { 0 }; + char red_val[144]; + char grn_val[144]; + char blu_val[144]; + + for(int color_idx = 0; color_idx < colors.size(); color_idx++) + { + RGBColor color = colors[color_idx]; + unsigned char red = RGBGetRValue(color); + unsigned char grn = RGBGetGValue(color); + unsigned char blu = RGBGetBValue(color); + + if( red > 7 ) red = 7; + if( grn > 7 ) grn = 7; + if( blu > 7 ) blu = 7; + + red = 7 - red; + grn = 7 - grn; + blu = 7 - blu; + + red_val[color_idx] = red; + grn_val[color_idx] = grn; + blu_val[color_idx] = blu; + } + + // Perform USB control message to keyboard + // + // Request Type: 0x21 + // Request: 0x09 + // Value 0x0300 + // Index: 0x03 + // Size: 64 + + data_pkt[0][0] = 0x7F; + data_pkt[0][1] = 0x01; + data_pkt[0][2] = 0x3C; + + data_pkt[1][0] = 0x7F; + data_pkt[1][1] = 0x02; + data_pkt[1][2] = 0x3C; + + data_pkt[2][0] = 0x7F; + data_pkt[2][1] = 0x03; + data_pkt[2][2] = 0x3C; + + data_pkt[3][0] = 0x7F; + data_pkt[3][1] = 0x04; + data_pkt[3][2] = 0x24; + + data_pkt[4][0] = 0x07; + data_pkt[4][1] = 0x27; + data_pkt[4][2] = 0x00; + data_pkt[4][2] = 0x00; + data_pkt[4][4] = 0xD8; //Number of payload bytes + + for(int i = 0; i < 60; i++) + { + data_pkt[0][i+4] = red_val[i*2+1] << 4 | red_val[i*2]; + } + + for(int i = 0; i < 12; i++) + { + data_pkt[1][i+4] = red_val[i*2+121] << 4 | red_val[i*2+120]; + } + + for(int i = 0; i < 48; i++) + { + data_pkt[1][i+16] = grn_val[i*2+1] << 4 | grn_val[i*2]; + } + + for(int i = 0; i < 24; i++) + { + data_pkt[2][i+4] = grn_val[i*2+97] << 4 | grn_val[i*2+96]; + } + + for(int i = 0; i < 36; i++) + { + data_pkt[2][i+28] = blu_val[i*2+1] << 4 | blu_val[i*2]; + } + + for(int i = 0; i < 36; i++) + { + data_pkt[3][i+4] = blu_val[i*2+73] << 4 | blu_val[i*2+72]; + } + + send_usb_msg(dev, data_pkt[0]); + send_usb_msg(dev, data_pkt[1]); + send_usb_msg(dev, data_pkt[2]); + send_usb_msg(dev, data_pkt[3]); + send_usb_msg(dev, data_pkt[4]); +} diff --git a/Controllers/CorsairKeyboardController/CorsairKeyboardController.h b/Controllers/CorsairKeyboardController/CorsairKeyboardController.h new file mode 100644 index 00000000..b697b0f8 --- /dev/null +++ b/Controllers/CorsairKeyboardController/CorsairKeyboardController.h @@ -0,0 +1,28 @@ +/*-----------------------------------------*\ +| CorsairKeyboardController.h | +| | +| Definitions and types for Corsair RGB | +| keyboard lighting controller | +| | +| Adam Honse (CalcProgrammer1) 1/9/2020 | +\*-----------------------------------------*/ + +#include "RGBController.h" + +#include +#include + +#pragma once + +class CorsairKeyboardController +{ +public: + CorsairKeyboardController(hid_device* dev_handle); + ~CorsairKeyboardController(); + + void SetLEDsDirect(std::vector colors); + void SetLEDs(std::vector colors); + +private: + hid_device* dev; +}; diff --git a/Controllers/CorsairKeyboardController/CorsairKeyboardControllerDetect.cpp b/Controllers/CorsairKeyboardController/CorsairKeyboardControllerDetect.cpp new file mode 100644 index 00000000..2fab1e75 --- /dev/null +++ b/Controllers/CorsairKeyboardController/CorsairKeyboardControllerDetect.cpp @@ -0,0 +1,52 @@ +#include "CorsairKeyboardController.h" +#include "RGBController.h" +#include "RGBController_CorsairKeyboard.h" +#include +#include + +#define CORSAIR_RGB_KEYBOARD_VID 0x1B1C +#define CORSAIR_RGB_KEYBOARD_K70_PID 0x1B13 +#define CORSAIR_RGB_KEYBOARD_K95_PID 0x1B11 + +/******************************************************************************************\ +* * +* DetectCorsairKeyboardControllers * +* * +* Tests the USB address to see if a Corsair RGB Keyboard controller exists there. * +* * +\******************************************************************************************/ + +void DetectCorsairKeyboardControllers(std::vector& rgb_controllers) +{ + hid_device_info* info; + hid_device* dev; + + hid_init(); + + info = hid_enumerate(CORSAIR_RGB_KEYBOARD_VID, CORSAIR_RGB_KEYBOARD_K70_PID); + + //Look for Corsair RGB Keyboard, interface 1 + while(info) + { + if((info->vendor_id == CORSAIR_RGB_KEYBOARD_VID) + &&(info->product_id == CORSAIR_RGB_KEYBOARD_K70_PID) + &&(info->interface_number == 1)) + { + dev = hid_open_path(info->path); + break; + } + else + { + info = info->next; + } + } + + if( dev ) + { + CorsairKeyboardController* controller = new CorsairKeyboardController(dev); + + RGBController_CorsairKeyboard* rgb_controller = new RGBController_CorsairKeyboard(controller); + + rgb_controllers.push_back(rgb_controller); + } +} diff --git a/Controllers/HyperXKeyboardController/HyperXKeyboardController.cpp b/Controllers/HyperXKeyboardController/HyperXKeyboardController.cpp new file mode 100644 index 00000000..fd99c740 --- /dev/null +++ b/Controllers/HyperXKeyboardController/HyperXKeyboardController.cpp @@ -0,0 +1,412 @@ +/*-----------------------------------------*\ +| HyperXKeyboardController.cpp | +| | +| Driver for HyperX RGB Keyboard lighting | +| controller | +| | +| Adam Honse (CalcProgrammer1) 1/30/2020 | +\*-----------------------------------------*/ + +#include "HyperXKeyboardController.h" + +#ifdef WIN32 +#include +#else +#include + +static void Sleep(unsigned int milliseconds) +{ + usleep(1000 * milliseconds); +} +#endif + + +static unsigned int keys[] = {0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, + 0x15, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1D, 0x1E, 0x20, 0x21, 0x22, 0x23, 0x24, + 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32, + 0x33, 0x34, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3E, 0x3F, 0x41, 0x44, 0x45, + 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x51, 0x54, 0x55, 0x58, 0x59, + 0x5A, 0x5B, 0x5C, 0x5E, 0x5F, 0x61, 0x64, 0x65, 0x68, 0x69, 0x6A, 0x6B, 0x6C, + 0x6E, 0x6F, 0x74, 0x75, 0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7F, 0x81, + 0x84, 0x85, 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F, 0x91, 0x94, 0x95 }; + +static unsigned int extended_red[] = {0x08, 0x48, 0x88, 0x09, 0x89, 0x0A, 0x8A, 0x0B, 0x8B, 0x0C, 0x8C, 0x0D, 0x8D, 0x0E, 0x8F, 0x8E, 0x0F, 0x4F, 0x92, 0x13, 0x93, 0x12 }; +static unsigned int extended_grn[] = {0x29, 0x28, 0x78, 0x19, 0x79, 0x1A, 0x7A, 0x1B, 0x7B, 0x1C, 0x7C, 0x1D, 0x7D, 0x1E, 0x6E, 0x7E, 0x1F, 0x6F, 0x82, 0x23, 0x83, 0x22 }; +static unsigned int extended_blu[] = {0x39, 0x38, 0x68, 0x3A, 0x69, 0x2A, 0x6A, 0x2B, 0x6B, 0x2C, 0x6C, 0x2D, 0x6D, 0x2E, 0x5E, 0x5D, 0x2F, 0x5F, 0x72, 0x33, 0x73, 0x32 }; + +HyperXKeyboardController::HyperXKeyboardController(hid_device* dev_handle) +{ + dev = dev_handle; +} + +HyperXKeyboardController::~HyperXKeyboardController() +{ + +} + +void HyperXKeyboardController::SetMode(unsigned char mode, unsigned char direction, unsigned char speed) +{ + active_mode = mode; + active_direction = direction; + active_speed = speed; + + SendEffect + ( + 0x01, + active_mode, + active_direction, + HYPERX_REACTIVE_MODE_NONE, + active_speed, + HYPERX_COLOR_MODE_SPECTRUM + ); +} + +void HyperXKeyboardController::SetLEDsDirect(std::vector colors) +{ + unsigned char red_color_data[104]; + unsigned char grn_color_data[104]; + unsigned char blu_color_data[104]; + unsigned char ext_color_data[150]; + + for(std::size_t i = 0; i < 104; i++) + { + red_color_data[i] = RGBGetRValue(colors[i]); + grn_color_data[i] = RGBGetGValue(colors[i]); + blu_color_data[i] = RGBGetBValue(colors[i]); + } + + for(std::size_t i = 0; i < 22; i++) + { + ext_color_data[extended_red[i]] = RGBGetRValue(colors[i + 104]); + ext_color_data[extended_grn[i]] = RGBGetGValue(colors[i + 104]); + ext_color_data[extended_blu[i]] = RGBGetBValue(colors[i + 104]); + } + + SendDirect + ( + HYPERX_COLOR_CHANNEL_RED, + red_color_data + ); + + Sleep(2); + + SendDirect + ( + HYPERX_COLOR_CHANNEL_GREEN, + grn_color_data + ); + + Sleep(2); + + SendDirect + ( + HYPERX_COLOR_CHANNEL_BLUE, + blu_color_data + ); + + Sleep(2); + + SendDirectExtended + ( + ext_color_data + ); +} + +void HyperXKeyboardController::SetLEDs(std::vector colors) +{ + unsigned char red_color_data[104]; + unsigned char grn_color_data[104]; + unsigned char blu_color_data[104]; + unsigned char ext_color_data[150]; + + for(std::size_t i = 0; i < 104; i++) + { + red_color_data[i] = RGBGetRValue(colors[i]); + grn_color_data[i] = RGBGetGValue(colors[i]); + blu_color_data[i] = RGBGetBValue(colors[i]); + } + + for(std::size_t i = 0; i < 22; i++) + { + ext_color_data[extended_red[i]] = RGBGetRValue(colors[i + 104]); + ext_color_data[extended_grn[i]] = RGBGetGValue(colors[i + 104]); + ext_color_data[extended_blu[i]] = RGBGetBValue(colors[i + 104]); + } + + SendColor + ( + 0x01, + HYPERX_COLOR_CHANNEL_RED, + red_color_data + ); + + SendColor + ( + 0x01, + HYPERX_COLOR_CHANNEL_GREEN, + grn_color_data + ); + + SendColor + ( + 0x01, + HYPERX_COLOR_CHANNEL_BLUE, + blu_color_data + ); + + SendExtendedColor + ( + 0x01, + ext_color_data + ); +} + +/*-------------------------------------------------------------------------------------------------*\ +| Private packet sending functions. | +\*-------------------------------------------------------------------------------------------------*/ + +void HyperXKeyboardController::SelectProfile + ( + unsigned char profile + ) +{ + unsigned char buf[264]; + + /*-----------------------------------------------------*\ + | Zero out buffer | + \*-----------------------------------------------------*/ + memset(buf, 0x00, sizeof(buf)); + + /*-----------------------------------------------------*\ + | Set up Select Profile packet | + \*-----------------------------------------------------*/ + buf[0x00] = 0x07; + buf[0x01] = 0x01; + buf[0x02] = profile; + + buf[0x06] = 0x03; + buf[0x07] = 0x01; + + /*-----------------------------------------------------*\ + | Send packet | + \*-----------------------------------------------------*/ + hid_send_feature_report(dev, buf, 264); +} + +void HyperXKeyboardController::SendEffect + ( + unsigned char profile, + unsigned char mode, + unsigned char direction, + unsigned char reactive_mode, + unsigned char speed, + unsigned char color_mode + ) +{ + unsigned char buf[264]; + + /*-----------------------------------------------------*\ + | Zero out buffer | + \*-----------------------------------------------------*/ + memset(buf, 0x00, sizeof(buf)); + + /*-----------------------------------------------------*\ + | Set up Effect packet | + \*-----------------------------------------------------*/ + buf[0x00] = 0x07; + buf[0x01] = HYPERX_PACKET_ID_SET_EFFECT; + buf[0x02] = profile; + + /*-----------------------------------------------------*\ + | Set mode | + \*-----------------------------------------------------*/ + buf[0x09] = 0x01; + buf[0x0A] = mode; + + /*-----------------------------------------------------*\ + | Set direction | + \*-----------------------------------------------------*/ + buf[0x0D] = direction; + buf[0x0E] = direction; + + /*-----------------------------------------------------*\ + | Set reactive mode | + \*-----------------------------------------------------*/ + buf[0x1B] = reactive_mode; + buf[0x1C] = reactive_mode; + buf[0x1D] = reactive_mode; + buf[0x1E] = reactive_mode; + buf[0x1F] = reactive_mode; + buf[0x20] = reactive_mode; + buf[0x21] = reactive_mode; + buf[0x22] = reactive_mode; + + buf[0x6B] = 0x09; + buf[0x6C] = 0x09; + buf[0x6D] = 0x05; + buf[0x6E] = 0x05; + buf[0x6F] = 0x06; + buf[0x70] = 0x05; + + /*-----------------------------------------------------*\ + | Set speed | + \*-----------------------------------------------------*/ + buf[0x71] = speed; + + buf[0x72] = 0x09; + + /*-----------------------------------------------------*\ + | Set color mode | + \*-----------------------------------------------------*/ + buf[0x73] = color_mode; + buf[0x74] = color_mode; + buf[0x75] = color_mode; + buf[0x76] = color_mode; + buf[0x77] = color_mode; + buf[0x78] = color_mode; + buf[0x79] = color_mode; + buf[0x7A] = color_mode; + + /*-----------------------------------------------------*\ + | Send packet | + \*-----------------------------------------------------*/ + hid_send_feature_report(dev, buf, 264); +} + +void HyperXKeyboardController::SendColor + ( + unsigned char profile, + unsigned char color_channel, + unsigned char* color_data + ) +{ + unsigned char buf[264]; + + /*-----------------------------------------------------*\ + | Zero out buffer | + \*-----------------------------------------------------*/ + memset(buf, 0x00, sizeof(buf)); + + /*-----------------------------------------------------*\ + | Set up Color packet | + \*-----------------------------------------------------*/ + buf[0x00] = 0x07; + buf[0x01] = HYPERX_PACKET_ID_SET_COLOR; + buf[0x02] = profile; + buf[0x03] = color_channel; + + /*-----------------------------------------------------*\ + | Fill in color data | + \*-----------------------------------------------------*/ + for(int i = 0; i < 104; i++) + { + buf[keys[i]] = color_data[i]; + } + + /*-----------------------------------------------------*\ + | Send packet | + \*-----------------------------------------------------*/ + hid_send_feature_report(dev, buf, 264); +} + +void HyperXKeyboardController::SendExtendedColor + ( + unsigned char profile, + unsigned char* color_data + ) +{ + unsigned char buf[264]; + + /*-----------------------------------------------------*\ + | Zero out buffer | + \*-----------------------------------------------------*/ + memset(buf, 0x00, sizeof(buf)); + + /*-----------------------------------------------------*\ + | Set up Color packet | + \*-----------------------------------------------------*/ + buf[0x00] = 0x07; + buf[0x01] = HYPERX_PACKET_ID_SET_COLOR; + buf[0x02] = profile; + buf[0x03] = HYPERX_COLOR_CHANNEL_EXTENDED; + + /*-----------------------------------------------------*\ + | Fill in color data | + \*-----------------------------------------------------*/ + for(int i = 0x08; i <= 0x93; i++) + { + buf[i] = color_data[i]; + } + + /*-----------------------------------------------------*\ + | Send packet | + \*-----------------------------------------------------*/ + hid_send_feature_report(dev, buf, 264); +} + +void HyperXKeyboardController::SendDirect + ( + unsigned char color_channel, + unsigned char* color_data + ) +{ + unsigned char buf[264]; + + /*-----------------------------------------------------*\ + | Zero out buffer | + \*-----------------------------------------------------*/ + memset(buf, 0x00, sizeof(buf)); + + /*-----------------------------------------------------*\ + | Set up Direct packet | + \*-----------------------------------------------------*/ + buf[0x00] = 0x07; + buf[0x01] = HYPERX_PACKET_ID_DIRECT; + buf[0x02] = color_channel; + + /*-----------------------------------------------------*\ + | Fill in color data | + \*-----------------------------------------------------*/ + for(int i = 0; i < 104; i++) + { + buf[keys[i]] = color_data[i]; + } + + /*-----------------------------------------------------*\ + | Send packet | + \*-----------------------------------------------------*/ + hid_send_feature_report(dev, buf, 264); +} + +void HyperXKeyboardController::SendDirectExtended + ( + unsigned char* color_data + ) +{ + unsigned char buf[264]; + + /*-----------------------------------------------------*\ + | Zero out buffer | + \*-----------------------------------------------------*/ + memset(buf, 0x00, sizeof(buf)); + + /*-----------------------------------------------------*\ + | Set up Direct packet | + \*-----------------------------------------------------*/ + buf[0x00] = 0x07; + buf[0x01] = HYPERX_PACKET_ID_DIRECT; + buf[0x02] = HYPERX_COLOR_CHANNEL_EXTENDED; + + /*-----------------------------------------------------*\ + | Fill in color data | + \*-----------------------------------------------------*/ + for(int i = 0x08; i <= 0x93; i++) + { + buf[i] = color_data[i]; + } + + /*-----------------------------------------------------*\ + | Send packet | + \*-----------------------------------------------------*/ + hid_send_feature_report(dev, buf, 264); +} diff --git a/Controllers/HyperXKeyboardController/HyperXKeyboardController.h b/Controllers/HyperXKeyboardController/HyperXKeyboardController.h new file mode 100644 index 00000000..96b3add2 --- /dev/null +++ b/Controllers/HyperXKeyboardController/HyperXKeyboardController.h @@ -0,0 +1,119 @@ +/*-----------------------------------------*\ +| HyperXKeyboardController.h | +| | +| Definitions and types for HyperX RGB | +| Keyboard lighting controller | +| | +| Adam Honse (CalcProgrammer1) 1/30/2020 | +\*-----------------------------------------*/ + +#include "RGBController.h" + +#include +#include + +#pragma once + +enum +{ + HYPERX_PACKET_ID_SET_EFFECT = 0x02, /* Set profile effect packet */ + HYPERX_PACKET_ID_SET_COLOR = 0x06, /* Set profile color packet */ + HYPERX_PACKET_ID_DIRECT = 0x16, /* Direct control packet */ +}; + + +enum +{ + HYPERX_DIRECTION_RIGHT = 0x00, + HYPERX_DIRECTION_LEFT = 0x01, + HYPERX_DIRECTION_UP = 0x02, + HYPERX_DIRECTION_DOWN = 0x03, + HYPERX_DIRECTION_IN = 0x04, + HYPERX_DIRECTION_OUT = 0x05 +}; + +enum +{ + HYPERX_MODE_WAVE = 0x00, + HYPERX_MODE_STATIC = 0x01, + HYPERX_MODE_BREATHING = 0x02, +}; + +enum +{ + HYPERX_REACTIVE_MODE_TRIGGER = 0x03, + HYPERX_REACTIVE_MODE_EXPLOSION = 0x04, + HYPERX_REACTIVE_MODE_HYPERX_FLAME = 0x05, + HYPERX_REACTIVE_MODE_NONE = 0xFF +}; + +enum +{ + HYPERX_COLOR_MODE_SINGLE = 0x00, + HYPERX_COLOR_MODE_DUAL = 0x01, + HYPERX_COLOR_MODE_SPECTRUM = 0x02 +}; + +enum +{ + HYPERX_COLOR_CHANNEL_RED = 0x01, + HYPERX_COLOR_CHANNEL_GREEN = 0x02, + HYPERX_COLOR_CHANNEL_BLUE = 0x03, + HYPERX_COLOR_CHANNEL_EXTENDED = 0x04 +}; + +class HyperXKeyboardController +{ +public: + HyperXKeyboardController(hid_device* dev_handle); + ~HyperXKeyboardController(); + + void SetMode(unsigned char mode, unsigned char direction, unsigned char speed); + void SetLEDsDirect(std::vector colors); + void SetLEDs(std::vector colors); + +private: + hid_device* dev; + unsigned char active_mode; + unsigned char active_direction; + unsigned char active_speed; + + void SelectProfile + ( + unsigned char profile + ); + + void SendEffect + ( + unsigned char profile, + unsigned char mode, + unsigned char direction, + unsigned char reactive_mode, + unsigned char speed, + unsigned char color_mode + ); + + void SendColor + ( + unsigned char profile, + unsigned char color_channel, + unsigned char* color_data + ); + + void SendExtendedColor + ( + unsigned char profile, + unsigned char* color_data + ); + + void SendDirect + ( + unsigned char color_channel, + unsigned char* color_data + ); + + void SendDirectExtended + ( + unsigned char* color_data + ); +}; diff --git a/Controllers/HyperXKeyboardController/HyperXKeyboardControllerDetect.cpp b/Controllers/HyperXKeyboardController/HyperXKeyboardControllerDetect.cpp new file mode 100644 index 00000000..71fe1b50 --- /dev/null +++ b/Controllers/HyperXKeyboardController/HyperXKeyboardControllerDetect.cpp @@ -0,0 +1,51 @@ +#include "HyperXKeyboardController.h" +#include "RGBController.h" +#include "RGBController_HyperXKeyboard.h" +#include +#include + +#define HYPERX_KEYBOARD_VID 0x0951 +#define HYPERX_ALLOY_ELITE_PID 0x16BE + +/******************************************************************************************\ +* * +* DetectHyperXKeyboardControllers * +* * +* Tests the USB address to see if a HyperX Keyboard controller exists there. * +* * +\******************************************************************************************/ + +void DetectHyperXKeyboardControllers(std::vector& rgb_controllers) +{ + hid_device_info* info; + hid_device* dev; + + hid_init(); + + info = hid_enumerate(HYPERX_KEYBOARD_VID, HYPERX_ALLOY_ELITE_PID); + + //Look for HyperX Keyboard, Interface 2 + while(info) + { + if((info->vendor_id == HYPERX_KEYBOARD_VID) + &&(info->product_id == HYPERX_ALLOY_ELITE_PID) + &&(info->interface_number == 2)) + { + dev = hid_open_path(info->path); + break; + } + else + { + info = info->next; + } + } + + if( dev ) + { + HyperXKeyboardController* controller = new HyperXKeyboardController(dev); + + RGBController_HyperXKeyboard* rgb_controller = new RGBController_HyperXKeyboard(controller); + + rgb_controllers.push_back(rgb_controller); + } +} diff --git a/Controllers/PoseidonZRGBController/PoseidonZRGBController.cpp b/Controllers/PoseidonZRGBController/PoseidonZRGBController.cpp index 17cdf8b7..d241bd11 100644 --- a/Controllers/PoseidonZRGBController/PoseidonZRGBController.cpp +++ b/Controllers/PoseidonZRGBController/PoseidonZRGBController.cpp @@ -9,6 +9,8 @@ #include "PoseidonZRGBController.h" +#include + #ifdef WIN32 #include #else @@ -20,15 +22,14 @@ static void Sleep(unsigned int milliseconds) } #endif -static unsigned int keys[] = {8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 21, - 22, 23, 24, 25, 26, 27, 29, 30, 31, 32, 33, 34, 35, - 36, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, - 50, 51, 52, 54, 55, 56, 57, 58, 59, 60, 62, 63, 64, - 65, 66, 67, 68, 70, 71, 72, 73, 74, 75, 76, 78, 79, - 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, - 93, 94, 95, 96, 97, 98, 99, 100, 102, 103, 104, 105, - 106, 108, 109, 111, 112, 114, 115, 117, 118, 119, 120, - 124, 128, 129 }; +static unsigned int keys[] = {0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x15, + 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, + 0x24, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x30, 0x31, + 0x32, 0x33, 0x34, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3E, 0x3F, 0x40, + 0x41, 0x42, 0x43, 0x44, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4E, 0x4F, + 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x5B, 0x5C, + 0x5D, 0x5E, 0x5F, 0x60, 0x61, 0x62, 0x63, 0x64, 0x66, 0x67, 0x68, 0x69, 0x6A, + 0x6C, 0x6D, 0x6F, 0x70, 0x72, 0x73, 0x75, 0x76, 0x77, 0x78, 0x7C, 0x80, 0x81 }; PoseidonZRGBController::PoseidonZRGBController(hid_device* dev_handle) { @@ -40,9 +41,21 @@ PoseidonZRGBController::~PoseidonZRGBController() } -char* PoseidonZRGBController::GetDeviceName() +void PoseidonZRGBController::SetMode(unsigned char mode, unsigned char direction, unsigned char speed) { - return device_name; + active_mode = mode; + active_direction = direction; + active_speed = speed; + + SendControl + ( + POSEIDONZ_PROFILE_P1, + POSEIDONZ_PROFILE_P1, + active_direction, + active_mode, + POSEIDONZ_BRIGHTNESS_MAX, + active_speed + ); } void PoseidonZRGBController::SetLEDsDirect(std::vector colors) @@ -50,124 +63,174 @@ void PoseidonZRGBController::SetLEDsDirect(std::vector colors) unsigned char red_grn_buf[264]; unsigned char blu_buf[264]; - for(int i = 0; i < 264; i++) - { - red_grn_buf[i] = 0x00; - blu_buf[i] = 0x00; - } + /*-----------------------------------------------------*\ + | Zero out buffers | + \*-----------------------------------------------------*/ + memset(red_grn_buf, 0x00, sizeof(red_grn_buf)); + memset(blu_buf, 0x00, sizeof(blu_buf)); - red_grn_buf[0] = POSEIDONZ_START; - red_grn_buf[1] = POSEIDONZ_LED_CMD; - red_grn_buf[2] = POSEIDONZ_PROFILE; - red_grn_buf[3] = POSEIDONZ_RED_GRN_CH; + /*-----------------------------------------------------*\ + | Set up Direct packets | + \*-----------------------------------------------------*/ + red_grn_buf[0] = 0x07; + red_grn_buf[1] = POSEIDONZ_PACKET_ID_SET_DIRECT; + red_grn_buf[2] = POSEIDONZ_PROFILE_P1; + red_grn_buf[3] = POSEIDONZ_DIRECT_RED_GREEN; red_grn_buf[4] = 0x00; red_grn_buf[5] = 0x00; red_grn_buf[6] = 0x00; red_grn_buf[7] = 0x00; - blu_buf[0] = POSEIDONZ_START; - blu_buf[1] = POSEIDONZ_LED_CMD; - blu_buf[2] = POSEIDONZ_PROFILE; - blu_buf[3] = POSEIDONZ_BLU_CH; + blu_buf[0] = 0x07; + blu_buf[1] = POSEIDONZ_PACKET_ID_SET_DIRECT; + blu_buf[2] = POSEIDONZ_PROFILE_P1; + blu_buf[3] = POSEIDONZ_DIRECT_BLUE; blu_buf[4] = 0x00; blu_buf[5] = 0x00; blu_buf[6] = 0x00; blu_buf[7] = 0x00; - for(int i = 0; i < 104; i++) + /*-----------------------------------------------------*\ + | Fill in color data | + \*-----------------------------------------------------*/ + for(std::size_t i = 0; i < 104; i++) { red_grn_buf[keys[i] ] = RGBGetRValue(colors[i]); red_grn_buf[keys[i] + 128] = RGBGetGValue(colors[i]); blu_buf[ keys[i] ] = RGBGetBValue(colors[i]); } + /*-----------------------------------------------------*\ + | Send packets | + \*-----------------------------------------------------*/ hid_send_feature_report(dev, red_grn_buf, 264); - - Sleep(1); - hid_send_feature_report(dev, blu_buf, 264); - } void PoseidonZRGBController::SetLEDs(std::vector colors) { - unsigned char buf[264] = {0}; + unsigned char red_color_data[104]; + unsigned char grn_color_data[104]; + unsigned char blu_color_data[104]; - //Send Red Packet - for(int i = 0; i < 264; i++) + for(std::size_t i = 0; i < 104; i++) { - buf[i] = 0xFF; + red_color_data[i] = RGBGetRValue(colors[i]); + grn_color_data[i] = RGBGetGValue(colors[i]); + blu_color_data[i] = RGBGetBValue(colors[i]); } - buf[0] = 0x07; - buf[1] = 0x09; - buf[2] = 0x01; - buf[3] = 0x01; - - for(int i = 0; i < 104; i++) - { - buf[keys[i]] = RGBGetRValue(colors[i]); - } - - hid_send_feature_report(dev, buf, 264); + SendColor + ( + POSEIDONZ_PROFILE_P1, + POSEIDONZ_COLOR_RED, + red_color_data + ); Sleep(10); - - //Send Green Packet - for(int i = 0; i < 264; i++) - { - buf[i] = 0x00; - } - buf[0] = 0x07; - buf[1] = 0x09; - buf[2] = 0x01; - buf[3] = 0x02; - - buf[8] = 0xFF; - - for(int i = 0; i < 104; i++) - { - buf[keys[i]] = RGBGetGValue(colors[i]); - } - - hid_send_feature_report(dev, buf, 264); + SendColor + ( + POSEIDONZ_PROFILE_P1, + POSEIDONZ_COLOR_GREEN, + grn_color_data + ); Sleep(10); - - //Send Blue Packet - for(int i = 0; i < 264; i++) - { - buf[i] = 0x11; - } - buf[0] = 0x07; - buf[1] = 0x09; - buf[2] = 0x01; - buf[3] = 0x03; - - for(int i = 0; i < 104; i++) - { - buf[keys[i]] = RGBGetBValue(colors[i]); - } - - hid_send_feature_report(dev, buf, 264); + SendColor + ( + POSEIDONZ_PROFILE_P1, + POSEIDONZ_COLOR_BLUE, + blu_color_data + ); Sleep(10); - - //Send Update Packet - for(int i = 0; i < 264; i++) + + SendControl + ( + POSEIDONZ_PROFILE_P1, + POSEIDONZ_PROFILE_P1, + active_direction, + active_mode, + POSEIDONZ_BRIGHTNESS_MAX, + active_speed + ); +} + +/*-------------------------------------------------------------------------------------------------*\ +| Private packet sending functions. | +\*-------------------------------------------------------------------------------------------------*/ + +void PoseidonZRGBController::SendColor + ( + unsigned char profile_to_edit, + unsigned char color_channel, + unsigned char* color_data + ) +{ + unsigned char buf[264]; + + /*-----------------------------------------------------*\ + | Zero out buffer | + \*-----------------------------------------------------*/ + memset(buf, 0x00, sizeof(buf)); + + /*-----------------------------------------------------*\ + | Set up Color packet | + \*-----------------------------------------------------*/ + buf[0x00] = 0x07; + buf[0x01] = POSEIDONZ_PACKET_ID_SET_COLOR; + buf[0x02] = profile_to_edit; + buf[0x03] = color_channel; + + /*-----------------------------------------------------*\ + | Fill in color data | + \*-----------------------------------------------------*/ + for(int i = 0; i < 104; i++) { - buf[i] = 0x00; + buf[keys[i]] = color_data[i]; } - buf[0] = 0x07; - buf[1] = 0x02; - buf[2] = 0x01; - buf[8] = 0x01; //Preset to save - buf[13] = 0x04; //Brightness? - buf[16] = 0x08; - buf[22] = 0x03; - + /*-----------------------------------------------------*\ + | Send packet | + \*-----------------------------------------------------*/ + hid_send_feature_report(dev, buf, 264); +} + +void PoseidonZRGBController::SendControl + ( + unsigned char profile_to_activate, + unsigned char profile_to_edit, + unsigned char direction, + unsigned char mode, + unsigned char brightness, + unsigned char speed + ) +{ + unsigned char buf[264]; + + /*-----------------------------------------------------*\ + | Zero out buffer | + \*-----------------------------------------------------*/ + memset(buf, 0x00, sizeof(buf)); + + /*-----------------------------------------------------*\ + | Set up Effect packet | + \*-----------------------------------------------------*/ + buf[0x00] = 0x07; + buf[0x01] = POSEIDONZ_PACKET_ID_SET_EFFECT; + buf[0x02] = profile_to_activate; + buf[0x08] = profile_to_edit; + buf[0x0A] = direction; + buf[0x0C] = mode; + buf[0x0D] = brightness; + buf[0x10] = 0x08; + buf[0x12] = speed; + buf[0x13] = 0x50; + + /*-----------------------------------------------------*\ + | Send packet | + \*-----------------------------------------------------*/ hid_send_feature_report(dev, buf, 264); } diff --git a/Controllers/PoseidonZRGBController/PoseidonZRGBController.h b/Controllers/PoseidonZRGBController/PoseidonZRGBController.h index c4bea0ff..0a49c6bf 100644 --- a/Controllers/PoseidonZRGBController/PoseidonZRGBController.h +++ b/Controllers/PoseidonZRGBController/PoseidonZRGBController.h @@ -11,7 +11,7 @@ #include "RGBController.h" #include -#include +#include "hidapi.h" #pragma once @@ -21,18 +21,86 @@ #define POSEIDONZ_RED_GRN_CH 0x01 #define POSEIDONZ_BLU_CH 0x02 +enum +{ + POSEIDONZ_PACKET_ID_SET_EFFECT = 0x02, /* Set profile effect packet */ + POSEIDONZ_PACKET_ID_SET_COLOR = 0x09, /* Set profile color packet */ + POSEIDONZ_PACKET_ID_SET_DIRECT = 0x0E, /* Set direct color packet */ +}; + +enum +{ + POSEIDONZ_MODE_STATIC = 0x00, + POSEIDONZ_MODE_REACTIVE = 0x01, + POSEIDONZ_MODE_ARROW_FLOW = 0x02, + POSEIDONZ_MODE_WAVE = 0x03, + POSEIDONZ_MODE_RIPPLE = 0x04 +}; + +enum +{ + POSEIDONZ_PROFILE_P1 = 0x01, + POSEIDONZ_PROFILE_P2 = 0x02, + POSEIDONZ_PROFILE_P3 = 0x03, + POSEIDONZ_PROFILE_P4 = 0x04, + POSEIDONZ_PROFILE_P5 = 0x05 +}; + +enum +{ + POSEIDONZ_BRIGHTNESS_MIN = 0x00, + POSEIDONZ_BRIGHTNESS_MAX = 0x04 +}; + +enum +{ + POSEIDONZ_COLOR_RED = 0x01, + POSEIDONZ_COLOR_GREEN = 0x02, + POSEIDONZ_COLOR_BLUE = 0x03 +}; + +enum +{ + POSEIDONZ_DIRECT_RED_GREEN = 0x01, + POSEIDONZ_DIRECT_BLUE = 0x02 +}; + +enum +{ + POSEIDONZ_SPEED_SLOW = 0x10, + POSEIDONZ_SPEED_FAST = 0x05 +}; + class PoseidonZRGBController { public: PoseidonZRGBController(hid_device* dev_handle); ~PoseidonZRGBController(); - char* GetDeviceName(); - + void SetMode(unsigned char mode, unsigned char direction, unsigned char speed); void SetLEDsDirect(std::vector colors); void SetLEDs(std::vector colors); private: - char device_name[32]; hid_device* dev; + unsigned char active_mode; + unsigned char active_direction; + unsigned char active_speed; + + void SendControl + ( + unsigned char profile_to_activate, + unsigned char profile_to_edit, + unsigned char direction, + unsigned char mode, + unsigned char brightness, + unsigned char speed + ); + + void SendColor + ( + unsigned char profile_to_edit, + unsigned char color_channel, + unsigned char* color_data + ); }; diff --git a/Controllers/PoseidonZRGBController/PoseidonZRGBControllerDetect.cpp b/Controllers/PoseidonZRGBController/PoseidonZRGBControllerDetect.cpp index cb1234e7..6d6bb464 100644 --- a/Controllers/PoseidonZRGBController/PoseidonZRGBControllerDetect.cpp +++ b/Controllers/PoseidonZRGBController/PoseidonZRGBControllerDetect.cpp @@ -2,7 +2,7 @@ #include "RGBController.h" #include "RGBController_PoseidonZRGB.h" #include -#include +#include "hidapi.h" #define TT_POSEIDON_Z_RGB_VID 0x264A #define TT_POSEIDON_Z_RGB_PID 0x3006 @@ -18,12 +18,28 @@ void DetectPoseidonZRGBControllers(std::vector& rgb_controllers) { - hid_device* dev; + hid_device_info* info; + hid_device* dev = NULL; - //Look for Thermaltake Poseidon Z RGB Keyboard hid_init(); - dev = hid_open(TT_POSEIDON_Z_RGB_VID, TT_POSEIDON_Z_RGB_PID, 0); + info = hid_enumerate(TT_POSEIDON_Z_RGB_VID, TT_POSEIDON_Z_RGB_PID); + + //Look for Thermaltake Poseidon Z RGB, Interface 2 + while(info) + { + if((info->vendor_id == TT_POSEIDON_Z_RGB_VID) + &&(info->product_id == TT_POSEIDON_Z_RGB_PID) + &&(info->interface_number == 2)) + { + dev = hid_open_path(info->path); + break; + } + else + { + info = info->next; + } + } if( dev ) { diff --git a/OpenRGB.cpp b/OpenRGB.cpp index dc8bb782..23e187b8 100644 --- a/OpenRGB.cpp +++ b/OpenRGB.cpp @@ -335,8 +335,10 @@ void DetectAorusGPUControllers(std::vector &rgb_controllers); void DetectMSI3ZoneControllers(std::vector& rgb_controllers); void DetectPoseidonZRGBControllers(std::vector& rgb_controllers); void DetectCorsairCmdrProControllers(std::vector &rgb_controllers); +void DetectCorsairKeyboardControllers(std::vector& rgb_controllers); void DetectCorsairNodeProControllers(std::vector &rgb_controllers); void DetectFaustusControllers(std::vector &rgb_controllers); +void DetectHyperXKeyboardControllers(std::vector& rgb_controllers); /******************************************************************************************\ * * @@ -365,7 +367,9 @@ void DetectRGBControllers(void) DetectAMDWraithPrismControllers(rgb_controllers); DetectMSI3ZoneControllers(rgb_controllers); DetectPoseidonZRGBControllers(rgb_controllers); + DetectHyperXKeyboardControllers(rgb_controllers); DetectCorsairCmdrProControllers(rgb_controllers); + DetectCorsairKeyboardControllers(rgb_controllers); DetectCorsairNodeProControllers(rgb_controllers); DetectE131Controllers(rgb_controllers); diff --git a/OpenRGB.pro b/OpenRGB.pro index 096b0bd5..6bbf2ba6 100644 --- a/OpenRGB.pro +++ b/OpenRGB.pro @@ -15,11 +15,13 @@ INCLUDEPATH += \ Controllers/AuraController/ \ Controllers/CorsairController/ \ Controllers/CorsairCmdrProController/ \ + Controllers/CorsairKeyboardController/ \ Controllers/CorsairNodeProController/ \ Controllers/CorsairProController/ \ Controllers/Hue2Controller/ \ Controllers/HuePlusController/ \ Controllers/HyperXController/ \ + Controllers/HyperXKeyboardController/ \ Controllers/LEDStripController/ \ Controllers/MSI3ZoneController/ \ Controllers/PatriotViperController/ \ @@ -51,6 +53,8 @@ SOURCES += \ Controllers/CorsairController/CorsairControllerDetect.cpp \ Controllers/CorsairCmdrProController/CorsairCmdrProController.cpp \ Controllers/CorsairCmdrProController/CorsairCmdrProControllerDetect.cpp \ + Controllers/CorsairKeyboardController/CorsairKeyboardController.cpp \ + Controllers/CorsairKeyboardController/CorsairKeyboardControllerDetect.cpp \ Controllers/CorsairNodeProController/CorsairNodeProController.cpp \ Controllers/CorsairNodeProController/CorsairNodeProControllerDetect.cpp \ Controllers/CorsairProController/CorsairProController.cpp \ @@ -61,6 +65,8 @@ SOURCES += \ Controllers/HuePlusController/HuePlusControllerDetect.cpp \ Controllers/HyperXController/HyperXController.cpp \ Controllers/HyperXController/HyperXControllerDetect.cpp \ + Controllers/HyperXKeyboardController/HyperXKeyboardController.cpp \ + Controllers/HyperXKeyboardController/HyperXKeyboardControllerDetect.cpp \ Controllers/LEDStripController/LEDStripController.cpp \ Controllers/LEDStripController/LEDStripControllerDetect.cpp \ Controllers/MSI3ZoneController/MSI3ZoneController.cpp \ @@ -79,11 +85,13 @@ SOURCES += \ RGBController/RGBController_Aura.cpp \ RGBController/RGBController_Corsair.cpp \ RGBController/RGBController_CorsairCmdrPro.cpp \ + RGBController/RGBController_CorsairKeyboard.cpp \ RGBController/RGBController_CorsairNodePro.cpp \ RGBController/RGBController_CorsairPro.cpp \ RGBController/RGBController_Hue2.cpp \ RGBController/RGBController_HuePlus.cpp \ RGBController/RGBController_HyperX.cpp \ + RGBController/RGBController_HyperXKeyboard.cpp \ RGBController/RGBController_E131.cpp \ RGBController/RGBController_LEDStrip.cpp \ RGBController/RGBController_MSI3Zone.cpp \ @@ -107,11 +115,13 @@ HEADERS += \ Controllers/AuraController/AuraController.h \ Controllers/CorsairController/CorsairController.h \ Controllers/CorsairCmdrProController/CorsairCmdrProController.h \ + Controllers/CorsairKeyboardController/CorsairKeyboardController.h \ Controllers/CorsairNodeProController/CorsairNodeProController.h \ Controllers/CorsairProController/CorsairProController.h \ Controllers/Hue2Controller/Hue2Controller.h \ Controllers/HuePlusController/HuePlusController.h \ Controllers/HyperXController/HyperXController.h \ + Controllers/HyperXKeyboardController/HyperXKeyboardController.h \ Controllers/LEDStripController/LEDStripController.h \ Controllers/MSI3ZoneController/MSI3ZoneController.h \ Controllers/PatriotViperController/PatriotViperController.h \ @@ -129,6 +139,7 @@ HEADERS += \ RGBController/RGBController_Hue2.h \ RGBController/RGBController_HuePlus.h \ RGBController/RGBController_HyperX.h \ + RGBController/RGBController_HyperXKeyboard.h \ RGBController/RGBController_LEDStrip.h \ RGBController/RGBController_MSI3Zone.h \ RGBController/RGBController_PatriotViper.h \ diff --git a/RGBController/RGBController_CorsairKeyboard.cpp b/RGBController/RGBController_CorsairKeyboard.cpp new file mode 100644 index 00000000..775333ea --- /dev/null +++ b/RGBController/RGBController_CorsairKeyboard.cpp @@ -0,0 +1,53 @@ +/*-----------------------------------------*\ +| RGBController_CorsairKeyboard.cpp | +| | +| Generic RGB Interface for Corsair RGB | +| keyboards | +| | +| Adam Honse (CalcProgrammer1) 1/9/2020 | +\*-----------------------------------------*/ + +#include "RGBController_CorsairKeyboard.h" + +RGBController_CorsairKeyboard::RGBController_CorsairKeyboard(CorsairKeyboardController* corsair_ptr) +{ + corsair = corsair_ptr; + + name = "Corsair RGB Keyboard"; + type = DEVICE_TYPE_KEYBOARD; + + for(int i = 0; i < 144; i++) + { + colors.push_back(0x00000000); + } +} + +RGBController_CorsairKeyboard::~RGBController_CorsairKeyboard() +{ + +} + +void RGBController_CorsairKeyboard::UpdateLEDs() +{ + corsair->SetLEDs(colors); +} + +void RGBController_CorsairKeyboard::UpdateZoneLEDs(int zone) +{ + corsair->SetLEDs(colors); +} + +void RGBController_CorsairKeyboard::UpdateSingleLED(int led) +{ + corsair->SetLEDs(colors); +} + +void RGBController_CorsairKeyboard::SetCustomMode() +{ + +} + +void RGBController_CorsairKeyboard::UpdateMode() +{ + +} diff --git a/RGBController/RGBController_CorsairKeyboard.h b/RGBController/RGBController_CorsairKeyboard.h new file mode 100644 index 00000000..5266f79b --- /dev/null +++ b/RGBController/RGBController_CorsairKeyboard.h @@ -0,0 +1,29 @@ +/*-----------------------------------------*\ +| RGBController_CorsairKeyboard.h | +| | +| Generic RGB Interface for Corsair RGB | +| keyboards | +| | +| Adam Honse (CalcProgrammer1) 1/9/2020 | +\*-----------------------------------------*/ + +#pragma once +#include "RGBController.h" +#include "CorsairKeyboardController.h" + +class RGBController_CorsairKeyboard : public RGBController +{ +public: + RGBController_CorsairKeyboard(CorsairKeyboardController* corsair_ptr); + ~RGBController_CorsairKeyboard(); + + void UpdateLEDs(); + void UpdateZoneLEDs(int zone); + void UpdateSingleLED(int led); + + void SetCustomMode(); + void UpdateMode(); + +private: + CorsairKeyboardController* corsair; +}; diff --git a/RGBController/RGBController_HyperXKeyboard.cpp b/RGBController/RGBController_HyperXKeyboard.cpp new file mode 100644 index 00000000..7df1d612 --- /dev/null +++ b/RGBController/RGBController_HyperXKeyboard.cpp @@ -0,0 +1,95 @@ +/*-----------------------------------------*\ +| RGBController_HyperXKeyboard.cpp | +| | +| Generic RGB Interface for HyperX RGB | +| Keyboard | +| | +| Adam Honse (CalcProgrammer1) 2/2/2020 | +\*-----------------------------------------*/ + +#include "RGBController_HyperXKeyboard.h" + +RGBController_HyperXKeyboard::RGBController_HyperXKeyboard(HyperXKeyboardController* hyperx_ptr) +{ + hyperx = hyperx_ptr; + + name = "HyperX RGB Keyboard"; + type = DEVICE_TYPE_KEYBOARD; + + mode Direct; + Direct.name = "Direct"; + Direct.value = HYPERX_MODE_STATIC; + Direct.flags = MODE_FLAG_HAS_COLOR | MODE_FLAG_PER_LED_COLOR; + Direct.random = false; + modes.push_back(Direct); + + mode Static; + Static.name = "Static"; + Static.value = HYPERX_MODE_STATIC; + Static.flags = MODE_FLAG_HAS_COLOR | MODE_FLAG_PER_LED_COLOR; + Static.random = false; + modes.push_back(Static); + + mode Wave; + Wave.name = "Wave"; + Wave.value = HYPERX_MODE_WAVE; + Wave.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_DIRECTION_LR; + Wave.speed_min = 0x00; + Wave.speed_max = 0x09; + Wave.random = false; + Wave.speed = 0x09; + Wave.direction = MODE_DIRECTION_LEFT; + modes.push_back(Wave); + + mode Breathing; + Breathing.name = "Breathing"; + Breathing.value = HYPERX_MODE_BREATHING; + Breathing.flags = MODE_FLAG_HAS_SPEED; + Breathing.speed_min = 0x00; + Breathing.speed_max = 0x09; + Breathing.random = false; + Breathing.speed = 0x09; + modes.push_back(Breathing); + + for(int i = 0; i < 126; i++) + { + colors.push_back(0x00000000); + } +} + +RGBController_HyperXKeyboard::~RGBController_HyperXKeyboard() +{ + +} + +void RGBController_HyperXKeyboard::UpdateLEDs() +{ + if(active_mode == 0) + { + hyperx->SetLEDsDirect(colors); + } + else + { + hyperx->SetLEDs(colors); + } +} + +void RGBController_HyperXKeyboard::UpdateZoneLEDs(int zone) +{ + UpdateLEDs(); +} + +void RGBController_HyperXKeyboard::UpdateSingleLED(int led) +{ + UpdateLEDs(); +} + +void RGBController_HyperXKeyboard::SetCustomMode() +{ + SetMode(0); +} + +void RGBController_HyperXKeyboard::UpdateMode() +{ + hyperx->SetMode(modes[active_mode].value, modes[active_mode].direction, modes[active_mode].speed); +} diff --git a/RGBController/RGBController_HyperXKeyboard.h b/RGBController/RGBController_HyperXKeyboard.h new file mode 100644 index 00000000..7837d8ca --- /dev/null +++ b/RGBController/RGBController_HyperXKeyboard.h @@ -0,0 +1,28 @@ +/*-----------------------------------------*\ +| RGBController_HyperXKeyboard.h | +| | +| Generic RGB Interface for HyperX RGB | +| Keyboard | +| | +| Adam Honse (CalcProgrammer1) 2/2/2020 | +\*-----------------------------------------*/ + +#pragma once +#include "RGBController.h" +#include "HyperXKeyboardController.h" + +class RGBController_HyperXKeyboard : public RGBController +{ +public: + RGBController_HyperXKeyboard(HyperXKeyboardController* hyperx_ptr); + ~RGBController_HyperXKeyboard(); + void UpdateLEDs(); + void UpdateZoneLEDs(int zone); + void UpdateSingleLED(int led); + + void SetCustomMode(); + void UpdateMode(); + +private: + HyperXKeyboardController* hyperx; +}; diff --git a/RGBController/RGBController_PoseidonZRGB.cpp b/RGBController/RGBController_PoseidonZRGB.cpp index c09af5e7..872006fb 100644 --- a/RGBController/RGBController_PoseidonZRGB.cpp +++ b/RGBController/RGBController_PoseidonZRGB.cpp @@ -16,6 +16,45 @@ RGBController_PoseidonZRGB::RGBController_PoseidonZRGB(PoseidonZRGBController* p name = "Thermaltake Poseidon Z RGB"; type = DEVICE_TYPE_KEYBOARD; + mode Direct; + Direct.name = "Direct"; + Direct.value = POSEIDONZ_MODE_STATIC; + Direct.flags = MODE_FLAG_HAS_COLOR | MODE_FLAG_PER_LED_COLOR; + Direct.random = false; + modes.push_back(Direct); + + mode Static; + Static.name = "Static"; + Static.value = POSEIDONZ_MODE_STATIC; + Static.flags = MODE_FLAG_HAS_COLOR | MODE_FLAG_PER_LED_COLOR; + Static.random = false; + modes.push_back(Static); + + mode Wave; + Wave.name = "Wave"; + Wave.value = POSEIDONZ_MODE_WAVE; + Wave.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_DIRECTION_LR; + Wave.speed_min = POSEIDONZ_SPEED_SLOW; + Wave.speed_max = POSEIDONZ_SPEED_FAST; + Wave.random = false; + Wave.speed = POSEIDONZ_SPEED_FAST; + Wave.direction = MODE_DIRECTION_LEFT; + modes.push_back(Wave); + + mode Ripple; + Ripple.name = "Ripple"; + Ripple.value = POSEIDONZ_MODE_RIPPLE; + Ripple.flags = 0; + Ripple.random = false; + modes.push_back(Ripple); + + mode Reactive; + Reactive.name = "Reactive"; + Reactive.value = POSEIDONZ_MODE_REACTIVE; + Reactive.flags = 0; + Reactive.random = false; + modes.push_back(Reactive); + for(int i = 0; i < 104; i++) { colors.push_back(0x00000000); @@ -29,25 +68,32 @@ RGBController_PoseidonZRGB::~RGBController_PoseidonZRGB() void RGBController_PoseidonZRGB::UpdateLEDs() { - poseidon->SetLEDs(colors); + if(active_mode == 0) + { + poseidon->SetLEDsDirect(colors); + } + else + { + poseidon->SetLEDs(colors); + } } void RGBController_PoseidonZRGB::UpdateZoneLEDs(int zone) { - poseidon->SetLEDs(colors); + UpdateLEDs(); } void RGBController_PoseidonZRGB::UpdateSingleLED(int led) { - poseidon->SetLEDs(colors); + UpdateLEDs(); } void RGBController_PoseidonZRGB::SetCustomMode() { - + SetMode(0); } void RGBController_PoseidonZRGB::UpdateMode() { - -} \ No newline at end of file + poseidon->SetMode(modes[active_mode].value, modes[active_mode].direction, modes[active_mode].speed); +}