From 56e4f94be3f7d5a363353a86fa762d9c91340ffa Mon Sep 17 00:00:00 2001 From: Wojciech Lazarski Date: Mon, 23 Jan 2023 22:51:06 +0100 Subject: [PATCH] Added brightness support for HyperX Origin Core --- .../HyperXAlloyOriginsCoreController.cpp | 13 +++++++++++++ .../HyperXAlloyOriginsCoreController.h | 1 + .../RGBController_HyperXAlloyOriginsCore.cpp | 17 ++++++++++++----- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/Controllers/HyperXKeyboardController/HyperXAlloyOriginsCoreController.cpp b/Controllers/HyperXKeyboardController/HyperXAlloyOriginsCoreController.cpp index 9dcfa5f8..48ba75f0 100644 --- a/Controllers/HyperXKeyboardController/HyperXAlloyOriginsCoreController.cpp +++ b/Controllers/HyperXKeyboardController/HyperXAlloyOriginsCoreController.cpp @@ -63,6 +63,19 @@ std::string HyperXAlloyOriginsCoreController::GetFirmwareVersion() return(firmware_version); } +void HyperXAlloyOriginsCoreController::SetBrightness(unsigned int brightness) +{ + unsigned char packet[65]; + memset(packet, 0x00, sizeof(packet)); + + packet[1] = 0xA7; + packet[4] = 0x01; + packet[5] = brightness; + + hid_write(dev, packet, 65); +} + + void HyperXAlloyOriginsCoreController::SetLEDsDirect(std::vector colors) { for(unsigned int skip_cnt = 0; skip_cnt < (sizeof(skip_idx) / sizeof(skip_idx[0])); skip_cnt++) diff --git a/Controllers/HyperXKeyboardController/HyperXAlloyOriginsCoreController.h b/Controllers/HyperXKeyboardController/HyperXAlloyOriginsCoreController.h index 91ba44f6..483088b2 100644 --- a/Controllers/HyperXKeyboardController/HyperXAlloyOriginsCoreController.h +++ b/Controllers/HyperXKeyboardController/HyperXAlloyOriginsCoreController.h @@ -26,6 +26,7 @@ public: std::string GetFirmwareVersion(); void SetLEDsDirect(std::vector colors); + void SetBrightness(unsigned int brightness); private: hid_device* dev; diff --git a/Controllers/HyperXKeyboardController/RGBController_HyperXAlloyOriginsCore.cpp b/Controllers/HyperXKeyboardController/RGBController_HyperXAlloyOriginsCore.cpp index f14b1694..9e076dc7 100644 --- a/Controllers/HyperXKeyboardController/RGBController_HyperXAlloyOriginsCore.cpp +++ b/Controllers/HyperXKeyboardController/RGBController_HyperXAlloyOriginsCore.cpp @@ -12,6 +12,10 @@ using namespace std::chrono_literals; + +#define HYPERX_MIN_BRIGHTNESS 0 +#define HYPERX_MAX_BRIGHTNESS 255 + //0xFFFFFFFF indicates an unused entry in matrix #define NA 0xFFFFFFFF @@ -170,10 +174,13 @@ RGBController_HyperXAlloyOriginsCore::RGBController_HyperXAlloyOriginsCore(Hyper version = controller->GetFirmwareVersion(); mode Direct; - Direct.name = "Direct"; - Direct.value = 0xFFFF; - Direct.flags = MODE_FLAG_HAS_PER_LED_COLOR; - Direct.color_mode = MODE_COLORS_PER_LED; + Direct.name = "Direct"; + Direct.value = 0xFFFF; + Direct.flags = MODE_FLAG_HAS_PER_LED_COLOR | MODE_FLAG_HAS_BRIGHTNESS; + Direct.brightness_min = HYPERX_MIN_BRIGHTNESS; + Direct.brightness_max = HYPERX_MAX_BRIGHTNESS; + Direct.brightness = HYPERX_MAX_BRIGHTNESS; + Direct.color_mode = MODE_COLORS_PER_LED; modes.push_back(Direct); SetupZones(); @@ -271,7 +278,7 @@ void RGBController_HyperXAlloyOriginsCore::UpdateSingleLED(int /*led*/) void RGBController_HyperXAlloyOriginsCore::DeviceUpdateMode() { - + controller->SetBrightness(modes[active_mode].brightness); } void RGBController_HyperXAlloyOriginsCore::KeepaliveThread()