Skip to content

Commit a20a19e

Browse files
VavooonCalcProgrammer1
authored andcommitted
Add HyperX Origins Core support (direct mode)
Commits squashed and amended for code style by Adam Honse <[email protected]>
1 parent c665c87 commit a20a19e

6 files changed

+455
-2
lines changed
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*------------------------------------------*\
2+
| HyperXAlloyOriginsCoreController.cpp |
3+
| |
4+
| Driver for HyperX Alloy Origins Core |
5+
| RGB Keyboard lighting controller |
6+
| |
7+
| Volodymyr Nazarchuk (Vavooon) 4/28/2021 |
8+
\*------------------------------------------*/
9+
10+
#include "HyperXAlloyOriginsCoreController.h"
11+
12+
#include <cstring>
13+
14+
// Skip these indices in the color output
15+
static unsigned int skip_idx[] = {6, 7, 14, 15, 22, 23, 30, 31, 38, 39, 44, 46, 47, 54, 55, 58, 60, 61, 62, 63, 70, 71, 78, 79, 86, 87, 94, 95, 101, 102, 103, 109, 110, 111, 118, 119};
16+
17+
HyperXAlloyOriginsCoreController::HyperXAlloyOriginsCoreController(hid_device* dev_handle, const char* path)
18+
{
19+
dev = dev_handle;
20+
location = path;
21+
}
22+
23+
HyperXAlloyOriginsCoreController::~HyperXAlloyOriginsCoreController()
24+
{
25+
hid_close(dev);
26+
}
27+
28+
std::string HyperXAlloyOriginsCoreController::GetDeviceLocation()
29+
{
30+
return("HID " + location);
31+
}
32+
33+
void HyperXAlloyOriginsCoreController::SetLEDsDirect(std::vector<RGBColor> colors)
34+
{
35+
for(unsigned int skip_cnt = 0; skip_cnt < (sizeof(skip_idx) / sizeof(skip_idx[0])); skip_cnt++)
36+
{
37+
colors.insert(colors.begin() + skip_idx[skip_cnt], 0x00000000);
38+
}
39+
40+
unsigned char buf[380];
41+
memset(buf, 0x00, sizeof(buf));
42+
43+
int offset = 0;
44+
int rowPos = 0;
45+
46+
for(unsigned int color_idx = 0; color_idx < colors.size(); color_idx++)
47+
{
48+
if (color_idx > 0 && color_idx % 16 == 0)
49+
{
50+
offset += 48;
51+
rowPos = 0;
52+
}
53+
54+
buf[rowPos + offset] = RGBGetGValue(colors[color_idx]);
55+
buf[rowPos + offset + 16] = RGBGetRValue(colors[color_idx]);
56+
buf[rowPos + offset + 32] = RGBGetBValue(colors[color_idx]);
57+
58+
rowPos++;
59+
}
60+
61+
unsigned int sentBytes = 0;
62+
unsigned int bytesToSend = sizeof(buf);
63+
unsigned int payloadSize = 60;
64+
unsigned int seq = 0;
65+
66+
while(sentBytes < bytesToSend)
67+
{
68+
if (bytesToSend - sentBytes < payloadSize)
69+
{
70+
payloadSize = bytesToSend - sentBytes;
71+
}
72+
73+
unsigned char packet[65];
74+
memset(packet, 0x00, sizeof(packet));
75+
76+
packet[0] = 0xA2;
77+
packet[1] = seq++;
78+
packet[3] = payloadSize;
79+
80+
memcpy(&packet[4], &buf[sentBytes], payloadSize);
81+
82+
hid_write(dev, packet, 65);
83+
84+
sentBytes += payloadSize;
85+
}
86+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*------------------------------------------*\
2+
| HyperXAlloyOriginsCoreController.h |
3+
| |
4+
| Definitions and types for HyperX Alloy |
5+
| Origins Core RGB Keyboard lighting |
6+
| controller |
7+
| |
8+
| Volodymyr Nazarchuk (Vavooon) 4/28/2021 |
9+
\*------------------------------------------*/
10+
11+
#include "RGBController.h"
12+
13+
#include <string>
14+
#include <hidapi/hidapi.h>
15+
16+
#pragma once
17+
18+
class HyperXAlloyOriginsCoreController
19+
{
20+
public:
21+
HyperXAlloyOriginsCoreController(hid_device* dev_handle, const char* path);
22+
~HyperXAlloyOriginsCoreController();
23+
24+
std::string GetDeviceLocation();
25+
26+
void SetLEDsDirect(std::vector<RGBColor> colors);
27+
28+
private:
29+
hid_device* dev;
30+
std::string location;
31+
};

Controllers/HyperXKeyboardController/HyperXKeyboardControllerDetect.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
#include "Detector.h"
22
#include "HyperXAlloyElite2Controller.h"
33
#include "HyperXAlloyOriginsController.h"
4+
#include "HyperXAlloyOriginsCoreController.h"
45
#include "HyperXKeyboardController.h"
56
#include "RGBController.h"
67
#include "RGBController_HyperXAlloyElite2.h"
78
#include "RGBController_HyperXAlloyOrigins.h"
9+
#include "RGBController_HyperXAlloyOriginsCore.h"
810
#include "RGBController_HyperXKeyboard.h"
911
#include <hidapi/hidapi.h>
1012

@@ -41,6 +43,19 @@ void DetectHyperXAlloyOrigins(hid_device_info* info, const std::string& name)
4143
ResourceManager::get()->RegisterRGBController(rgb_controller);
4244
}
4345
}
46+
47+
void DetectHyperXAlloyOriginsCore(hid_device_info* info, const std::string& name)
48+
{
49+
hid_device* dev = hid_open_path(info->path);
50+
if( dev )
51+
{
52+
HyperXAlloyOriginsCoreController* controller = new HyperXAlloyOriginsCoreController(dev, info->path);
53+
RGBController_HyperXAlloyOriginsCore* rgb_controller = new RGBController_HyperXAlloyOriginsCore(controller);
54+
rgb_controller->name = name;
55+
ResourceManager::get()->RegisterRGBController(rgb_controller);
56+
}
57+
}
58+
4459
void DetectHyperXAlloyElite2(hid_device_info* info, const std::string& name)
4560
{
4661
hid_device* dev = hid_open_path(info->path);
@@ -57,11 +72,10 @@ REGISTER_HID_DETECTOR_IP("HyperX Alloy Elite RGB", DetectHyperXKeyboards,
5772
REGISTER_HID_DETECTOR_IP("HyperX Alloy FPS RGB", DetectHyperXKeyboards, HYPERX_KEYBOARD_VID, HYPERX_ALLOY_FPS_RGB_PID, 2, 0xFF01);
5873

5974
#ifdef _WIN32
60-
REGISTER_HID_DETECTOR_I("HyperX Alloy Origins Core", DetectHyperXAlloyOrigins, HYPERX_KEYBOARD_VID, HYPERX_ALLOY_ORIGINS_CORE_PID, 3);
6175
REGISTER_HID_DETECTOR_I("HyperX Alloy Origins", DetectHyperXAlloyOrigins, HYPERX_KEYBOARD_VID, HYPERX_ALLOY_ORIGINS_PID, 3);
6276
REGISTER_HID_DETECTOR_IP("HyperX Alloy Elite 2", DetectHyperXAlloyElite2, HYPERX_KEYBOARD_VID, HYPERX_ALLOY_ELITE_2_PID, 3, 0xFF90);
6377
#else
64-
REGISTER_HID_DETECTOR_I("HyperX Alloy Origins Core", DetectHyperXAlloyOrigins, HYPERX_KEYBOARD_VID, HYPERX_ALLOY_ORIGINS_CORE_PID, 0);
6578
REGISTER_HID_DETECTOR_I("HyperX Alloy Origins", DetectHyperXAlloyOrigins, HYPERX_KEYBOARD_VID, HYPERX_ALLOY_ORIGINS_PID, 0);
6679
REGISTER_HID_DETECTOR_I("HyperX Alloy Elite 2", DetectHyperXAlloyElite2, HYPERX_KEYBOARD_VID, HYPERX_ALLOY_ELITE_2_PID, 0);
80+
REGISTER_HID_DETECTOR_I("HyperX Alloy Origins Core", DetectHyperXAlloyOriginsCore, HYPERX_KEYBOARD_VID, HYPERX_ALLOY_ORIGINS_CORE_PID, 2);
6781
#endif

0 commit comments

Comments
 (0)