Skip to content

Commit 35aad36

Browse files
Add Direct mode support for AOC GK500 keyboard
1 parent c23b98d commit 35aad36

File tree

3 files changed

+286
-83
lines changed

3 files changed

+286
-83
lines changed

Controllers/AOCKeyboardController/AOCKeyboardController.cpp

Lines changed: 106 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -47,24 +47,121 @@ std::string AOCKeyboardController::GetSerialString()
4747
return(return_string);
4848
}
4949

50+
void AOCKeyboardController::SetLightingConfig
51+
(
52+
unsigned char mode,
53+
unsigned char random,
54+
unsigned char brightness,
55+
unsigned char speed,
56+
unsigned char direction,
57+
RGBColor* color_data
58+
)
59+
{
60+
SendStartPacket();
61+
std::this_thread::sleep_for(5ms);
62+
63+
SendLightingConfigPacket(mode, random, brightness, speed, direction, color_data);
64+
std::this_thread::sleep_for(5ms);
65+
66+
SendEndPacket();
67+
std::this_thread::sleep_for(10ms);
68+
}
69+
70+
void AOCKeyboardController::SetCustom
71+
(
72+
RGBColor* color_data
73+
)
74+
{
75+
SendStartPacket();
76+
std::this_thread::sleep_for(5ms);
77+
78+
SendCustomPacket(color_data);
79+
std::this_thread::sleep_for(5ms);
80+
81+
SendEndPacket();
82+
std::this_thread::sleep_for(5ms);
83+
}
84+
5085
/*-------------------------------------------------------------------------------------------------*\
5186
| Private packet sending functions. |
5287
\*-------------------------------------------------------------------------------------------------*/
5388

54-
void AOCKeyboardController::SendDirect
89+
void AOCKeyboardController::SendStartPacket()
90+
{
91+
unsigned char buf[64];
92+
93+
/*-----------------------------------------------------*\
94+
| Zero out buffer |
95+
\*-----------------------------------------------------*/
96+
memset(buf, 0x00, sizeof(buf));
97+
98+
/*-----------------------------------------------------*\
99+
| Set up start packet |
100+
\*-----------------------------------------------------*/
101+
buf[0x00] = 0x09;
102+
buf[0x01] = 0x21;
103+
104+
/*-----------------------------------------------------*\
105+
| Send packet |
106+
\*-----------------------------------------------------*/
107+
hid_write(dev, buf, sizeof(buf));
108+
}
109+
110+
void AOCKeyboardController::SendEndPacket()
111+
{
112+
unsigned char buf[64];
113+
114+
/*-----------------------------------------------------*\
115+
| Zero out buffer |
116+
\*-----------------------------------------------------*/
117+
memset(buf, 0x00, sizeof(buf));
118+
119+
/*-----------------------------------------------------*\
120+
| Set up end packet |
121+
\*-----------------------------------------------------*/
122+
buf[0x00] = 0x09;
123+
buf[0x01] = 0x22;
124+
125+
/*-----------------------------------------------------*\
126+
| Send packet |
127+
\*-----------------------------------------------------*/
128+
hid_write(dev, buf, sizeof(buf));
129+
}
130+
131+
void AOCKeyboardController::SendCustomPacket
55132
(
56133
RGBColor* color_data
57134
)
58135
{
59-
SendPacket(AOC_KEYBOARD_MODE_STATIC,
60-
AOC_KEYBOARD_SINGLE_COLOR,
61-
AOC_KEYBOARD_BRIGHTNESS_HIGH,
62-
AOC_KEYBOARD_SPEED_MEDIUM,
63-
AOC_KEYBOARD_DIRECTION_CLOCKWISE,
64-
color_data);
136+
unsigned char buf[361];
137+
138+
/*-----------------------------------------------------*\
139+
| Zero out buffer |
140+
\*-----------------------------------------------------*/
141+
memset(buf, 0x00, sizeof(buf));
142+
143+
/*-----------------------------------------------------*\
144+
| Set up custom lighting packet |
145+
\*-----------------------------------------------------*/
146+
buf[0x00] = 0x20;
147+
148+
/*-----------------------------------------------------*\
149+
| Copy in color data |
150+
\*-----------------------------------------------------*/
151+
for(unsigned int color_idx = 0; color_idx < 120; color_idx++)
152+
{
153+
buf[color_idx + 1] = RGBGetRValue(color_data[color_idx]);
154+
buf[color_idx + 121] = RGBGetGValue(color_data[color_idx]);
155+
buf[color_idx + 241] = RGBGetBValue(color_data[color_idx]);
156+
}
157+
158+
/*-----------------------------------------------------*\
159+
| Send packet |
160+
\*-----------------------------------------------------*/
161+
hid_send_feature_report(dev, buf, sizeof(buf));
65162
}
66163

67-
void AOCKeyboardController::SendPacket
164+
void AOCKeyboardController::SendLightingConfigPacket
68165
(
69166
unsigned char mode,
70167
unsigned char random,
@@ -82,7 +179,7 @@ void AOCKeyboardController::SendPacket
82179
memset(buf, 0x00, sizeof(buf));
83180

84181
/*-----------------------------------------------------*\
85-
| Set up RGB configuration packet |
182+
| Set up lighting configuration packet |
86183
\*-----------------------------------------------------*/
87184
buf[0x00] = 0x14;
88185
buf[0x01] = 0x01;
@@ -107,34 +204,8 @@ void AOCKeyboardController::SendPacket
107204
buf[115] = checksum & 0xFF;
108205
buf[116] = checksum >> 8;
109206

110-
111-
unsigned char buf3[] =
112-
{
113-
0x09, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
114-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
115-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
116-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
117-
0x00, 0x00, 0x00, 0x00,
118-
};
119-
hid_write(dev, buf3, 64);
120-
121-
122-
std::this_thread::sleep_for(10ms);
123-
124207
/*-----------------------------------------------------*\
125208
| Send packet |
126209
\*-----------------------------------------------------*/
127210
hid_send_feature_report(dev, buf, 117);
128-
129-
std::this_thread::sleep_for(10ms);
130-
131-
unsigned char buf2[] =
132-
{
133-
0x09, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
134-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
135-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
136-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
137-
0x00, 0x00, 0x00, 0x00,
138-
};
139-
hid_write(dev, buf2, 64);
140211
}

Controllers/AOCKeyboardController/AOCKeyboardController.h

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,7 @@ class AOCKeyboardController
6868
std::string GetDeviceLocation();
6969
std::string GetSerialString();
7070

71-
void SendDirect
72-
(
73-
RGBColor* color_data
74-
);
75-
76-
void SendPacket
71+
void SetLightingConfig
7772
(
7873
unsigned char mode,
7974
unsigned char random,
@@ -83,8 +78,30 @@ class AOCKeyboardController
8378
RGBColor* color_data
8479
);
8580

81+
void SetCustom
82+
(
83+
RGBColor* color_data
84+
);
8685

8786
private:
8887
hid_device* dev;
8988
std::string location;
89+
90+
void SendStartPacket();
91+
void SendEndPacket();
92+
93+
void SendCustomPacket
94+
(
95+
RGBColor* color_data
96+
);
97+
98+
void SendLightingConfigPacket
99+
(
100+
unsigned char mode,
101+
unsigned char random,
102+
unsigned char brightness,
103+
unsigned char speed,
104+
unsigned char direction,
105+
RGBColor* color_data
106+
);
90107
};

0 commit comments

Comments
 (0)