From 8d0915de6e66962f1429945163ff83ca9a6b3b1b Mon Sep 17 00:00:00 2001 From: Adam Honse Date: Tue, 18 Feb 2020 10:21:23 -0600 Subject: [PATCH] Add support for mode specific colors in HyperX keyboard breathing mode --- .../HyperXKeyboardController.cpp | 75 ++++++++++++++++++- .../HyperXKeyboardController.h | 20 ++++- .../RGBController_HyperXKeyboard.cpp | 17 ++++- 3 files changed, 104 insertions(+), 8 deletions(-) diff --git a/Controllers/HyperXKeyboardController/HyperXKeyboardController.cpp b/Controllers/HyperXKeyboardController/HyperXKeyboardController.cpp index 2a3f9295..c135aeea 100644 --- a/Controllers/HyperXKeyboardController/HyperXKeyboardController.cpp +++ b/Controllers/HyperXKeyboardController/HyperXKeyboardController.cpp @@ -46,12 +46,48 @@ HyperXKeyboardController::~HyperXKeyboardController() } -void HyperXKeyboardController::SetMode(unsigned char mode, unsigned char direction, unsigned char speed) +void HyperXKeyboardController::SetMode + ( + unsigned char mode, + unsigned char direction, + unsigned char speed, + std::vector colors + ) { + unsigned char color_mode; + unsigned char mode_colors[9]; + active_mode = mode; active_direction = direction; active_speed = speed; + memset(mode_colors, 0x00, sizeof(mode_colors)); + + switch(colors.size()) + { + default: + case 0: + color_mode = HYPERX_COLOR_MODE_SPECTRUM; + break; + + case 1: + color_mode = HYPERX_COLOR_MODE_SINGLE; + mode_colors[0] = RGBGetRValue(colors[0]); + mode_colors[1] = RGBGetGValue(colors[0]); + mode_colors[2] = RGBGetBValue(colors[0]); + break; + + case 2: + color_mode = HYPERX_COLOR_MODE_DUAL; + mode_colors[3] = RGBGetRValue(colors[0]); + mode_colors[4] = RGBGetGValue(colors[0]); + mode_colors[5] = RGBGetBValue(colors[0]); + mode_colors[6] = RGBGetRValue(colors[1]); + mode_colors[7] = RGBGetGValue(colors[1]); + mode_colors[8] = RGBGetBValue(colors[1]); + break; + } + SendEffect ( 0x01, @@ -59,8 +95,19 @@ void HyperXKeyboardController::SetMode(unsigned char mode, unsigned char directi active_direction, HYPERX_REACTIVE_MODE_NONE, active_speed, - HYPERX_COLOR_MODE_SPECTRUM + color_mode, + mode_colors[0], + mode_colors[1], + mode_colors[2], + mode_colors[3], + mode_colors[4], + mode_colors[5], + mode_colors[6], + mode_colors[7], + mode_colors[8] ); + + Sleep(100); } void HyperXKeyboardController::SetLEDsDirect(std::vector colors) @@ -202,7 +249,16 @@ void HyperXKeyboardController::SendEffect unsigned char direction, unsigned char reactive_mode, unsigned char speed, - unsigned char color_mode + unsigned char color_mode, + unsigned char red_single, + unsigned char grn_single, + unsigned char blu_single, + unsigned char red_dual_1, + unsigned char grn_dual_1, + unsigned char blu_dual_1, + unsigned char red_dual_2, + unsigned char grn_dual_2, + unsigned char blu_dual_2 ) { unsigned char buf[264]; @@ -243,6 +299,19 @@ void HyperXKeyboardController::SendEffect buf[0x21] = reactive_mode; buf[0x22] = reactive_mode; + /*-----------------------------------------------------*\ + | Set mode-specific colors | + \*-----------------------------------------------------*/ + buf[0x29] = red_single; + buf[0x41] = grn_single; + buf[0x59] = blu_single; + buf[0x2A] = red_dual_1; + buf[0x42] = grn_dual_1; + buf[0x5A] = blu_dual_1; + buf[0x2B] = red_dual_2; + buf[0x43] = grn_dual_2; + buf[0x5B] = blu_dual_2; + buf[0x6B] = 0x09; buf[0x6C] = 0x09; buf[0x6D] = 0x05; diff --git a/Controllers/HyperXKeyboardController/HyperXKeyboardController.h b/Controllers/HyperXKeyboardController/HyperXKeyboardController.h index 96b3add2..0176a2ea 100644 --- a/Controllers/HyperXKeyboardController/HyperXKeyboardController.h +++ b/Controllers/HyperXKeyboardController/HyperXKeyboardController.h @@ -68,7 +68,14 @@ public: HyperXKeyboardController(hid_device* dev_handle); ~HyperXKeyboardController(); - void SetMode(unsigned char mode, unsigned char direction, unsigned char speed); + void SetMode + ( + unsigned char mode, + unsigned char direction, + unsigned char speed, + std::vector colors + ); + void SetLEDsDirect(std::vector colors); void SetLEDs(std::vector colors); @@ -90,7 +97,16 @@ private: unsigned char direction, unsigned char reactive_mode, unsigned char speed, - unsigned char color_mode + unsigned char color_mode, + unsigned char red_single, + unsigned char grn_single, + unsigned char blu_single, + unsigned char red_dual_1, + unsigned char grn_dual_1, + unsigned char blu_dual_1, + unsigned char red_dual_2, + unsigned char grn_dual_2, + unsigned char blu_dual_2 ); void SendColor diff --git a/RGBController/RGBController_HyperXKeyboard.cpp b/RGBController/RGBController_HyperXKeyboard.cpp index 7c405bf8..e1204683 100644 --- a/RGBController/RGBController_HyperXKeyboard.cpp +++ b/RGBController/RGBController_HyperXKeyboard.cpp @@ -188,11 +188,14 @@ RGBController_HyperXKeyboard::RGBController_HyperXKeyboard(HyperXKeyboardControl mode Breathing; Breathing.name = "Breathing"; Breathing.value = HYPERX_MODE_BREATHING; - Breathing.flags = MODE_FLAG_HAS_SPEED; + Breathing.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_RANDOM_COLOR; Breathing.speed_min = 0x00; Breathing.speed_max = 0x09; - Breathing.color_mode = MODE_COLORS_NONE; + Breathing.colors_min = 1; + Breathing.colors_max = 2; + Breathing.color_mode = MODE_COLORS_MODE_SPECIFIC; Breathing.speed = 0x09; + Breathing.colors.resize(2); modes.push_back(Breathing); colors.resize(126); @@ -256,5 +259,13 @@ void RGBController_HyperXKeyboard::SetCustomMode() void RGBController_HyperXKeyboard::UpdateMode() { - hyperx->SetMode(modes[active_mode].value, modes[active_mode].direction, modes[active_mode].speed); + if(modes[active_mode].color_mode == MODE_COLORS_MODE_SPECIFIC) + { + hyperx->SetMode(modes[active_mode].value, modes[active_mode].direction, modes[active_mode].speed, modes[active_mode].colors); + } + else + { + std::vector temp_colors; + hyperx->SetMode(modes[active_mode].value, modes[active_mode].direction, modes[active_mode].speed, temp_colors); + } }