Skip to content

Commit f0a1ed2

Browse files
carlosjordaoCalcProgrammer1
authored andcommitted
Refactor HyperX Alloy Origins Core to use KLM
1 parent 665069d commit f0a1ed2

File tree

5 files changed

+120
-180
lines changed

5 files changed

+120
-180
lines changed

Controllers/HyperXKeyboardController/HyperXAlloyOriginsCoreController/HyperXAlloyOriginsCoreController.cpp

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ unsigned int HyperXAlloyOriginsCoreController::GetVariant()
9393
if(actual > 0)
9494
variant = packet[56];
9595
else
96-
variant = 0x09;
96+
variant = 0;
9797

9898
LOG_DEBUG("[HyperX Alloy Origins Core] variant: 0x%02X", variant);
9999
return variant;
@@ -112,8 +112,7 @@ void HyperXAlloyOriginsCoreController::SetBrightness(unsigned int brightness)
112112
hid_write(dev, packet, 65);
113113
}
114114

115-
116-
void HyperXAlloyOriginsCoreController::SetLEDsDirect(std::vector<RGBColor> colors)
115+
void HyperXAlloyOriginsCoreController::SetLEDsDirect(std::vector<led> leds, std::vector<RGBColor> colors)
117116
{
118117
/*------------------------------------------------------------------------------*\
119118
| * Always send 380 bytes to the keyboard and a total of 94 led indexes. |
@@ -132,8 +131,7 @@ void HyperXAlloyOriginsCoreController::SetLEDsDirect(std::vector<RGBColor> color
132131
\*------------------------------------------------------------------------------*/
133132
unsigned int segment = 0, sector = 0, sequence = 0;
134133
unsigned int total_colors = 0;
135-
unsigned char buf[380];
136-
memset(buf, 0x00, sizeof(buf));
134+
memset(color_buf, 0x00, sizeof(color_buf));
137135

138136
/*---------------------------------------------------------------------------*\
139137
| transfer the colors to the buffer. Max 94 colors to avoid buffer overflow. |
@@ -147,22 +145,27 @@ void HyperXAlloyOriginsCoreController::SetLEDsDirect(std::vector<RGBColor> color
147145
total_colors = (unsigned int)colors.size();
148146
}
149147

150-
for(unsigned int color_idx = 0; color_idx < total_colors; color_idx++)
148+
unsigned int pos = 0, color_idx = 0;
149+
for(unsigned int i = 0; i < total_colors; i++)
151150
{
152-
unsigned int pos = 0;
153-
segment = (color_idx / 12) * 48;
154-
sector = ((color_idx / 6) & 1) * 8;
155-
sequence = color_idx % 6;
151+
color_idx = leds[i].value;
152+
segment = (color_idx / 12) * 48;
153+
sector = ((color_idx / 6) & 1) * 8;
154+
sequence = color_idx % 6;
156155

157-
pos = segment + sector + sequence;
156+
pos = segment + sector + sequence;
158157

159-
buf[pos ] = RGBGetGValue(colors[color_idx]);
160-
buf[pos + 16] = RGBGetRValue(colors[color_idx]);
161-
buf[pos + 32] = RGBGetBValue(colors[color_idx]);
158+
color_buf[pos ] = RGBGetGValue(colors[i]);
159+
color_buf[pos + 16] = RGBGetRValue(colors[i]);
160+
color_buf[pos + 32] = RGBGetBValue(colors[i]);
162161
}
162+
}
163163

164+
165+
void HyperXAlloyOriginsCoreController::SendRGBToDevice()
166+
{
164167
unsigned int sentBytes = 0;
165-
unsigned int bytesToSend = sizeof(buf);
168+
unsigned int bytesToSend = sizeof(color_buf);
166169
unsigned int payloadSize = 60;
167170
unsigned int seq = 0;
168171

@@ -180,7 +183,7 @@ void HyperXAlloyOriginsCoreController::SetLEDsDirect(std::vector<RGBColor> color
180183
packet[2] = seq++;
181184
packet[4] = payloadSize;
182185

183-
memcpy(&packet[5], &buf[sentBytes], payloadSize);
186+
memcpy(&packet[5], &color_buf[sentBytes], payloadSize);
184187
hid_write(dev, packet, payloadSize + 5);
185188

186189
sentBytes += payloadSize;

Controllers/HyperXKeyboardController/HyperXAlloyOriginsCoreController/HyperXAlloyOriginsCoreController.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
#include <hidapi.h>
1616
#include "RGBController.h"
1717

18+
#define HYPERX_ALLOY_ORIGINS_CORE_ANSI 0x09
19+
#define HYPERX_ALLOY_ORIGINS_CORE_ABNT2 0x10
20+
1821
class HyperXAlloyOriginsCoreController
1922
{
2023
public:
@@ -27,12 +30,14 @@ class HyperXAlloyOriginsCoreController
2730
std::string GetFirmwareVersion();
2831
unsigned int GetVariant();
2932

30-
void SetLEDsDirect(std::vector<RGBColor> colors);
33+
void SetLEDsDirect(std::vector<led> leds, std::vector<RGBColor> colors);
34+
void SendRGBToDevice();
3135
void SetBrightness(unsigned int brightness);
3236

3337
private:
3438
hid_device* dev;
3539
std::string location;
3640
std::string firmware_version;
3741
std::string name;
42+
unsigned char color_buf[380];
3843
};

0 commit comments

Comments
 (0)