Skip to content

Commit ec1cb11

Browse files
Mola19CalcProgrammer1
authored andcommitted
Add layout, version, save, brightness to AsusTufKeyboard
Commits squashed and amended for code style by Adam Honse <calcprogrammer1@gmail.com>
1 parent 33e15cf commit ec1cb11

File tree

6 files changed

+677
-329
lines changed

6 files changed

+677
-329
lines changed

Controllers/AsusAuraUSBController/AsusAuraTUFKeyboardController.cpp

Lines changed: 86 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#include <math.h>
1616
#include <stdio.h>
1717
#include <string.h>
18-
#include <iostream>
18+
#include <cmath>
1919

2020
AuraTUFKeyboardController::AuraTUFKeyboardController(hid_device* dev_handle, const char* path)
2121
{
@@ -36,14 +36,66 @@ std::string AuraTUFKeyboardController::GetDeviceLocation()
3636
std::string AuraTUFKeyboardController::GetSerialString()
3737
{
3838
wchar_t serial_string[128];
39-
hid_get_serial_number_string(dev, serial_string, 128);
39+
int ret = hid_get_serial_number_string(dev, serial_string, 128);
40+
41+
if(ret != 0)
42+
{
43+
return("");
44+
}
4045

4146
std::wstring return_wstring = serial_string;
4247
std::string return_string(return_wstring.begin(), return_wstring.end());
4348

4449
return(return_string);
4550
}
4651

52+
std::string AuraTUFKeyboardController::GetVersion()
53+
{
54+
unsigned char usb_buf[65];
55+
memset(usb_buf, 0x00, sizeof(usb_buf));
56+
usb_buf[0x00] = 0x00;
57+
usb_buf[0x01] = 0x12;
58+
usb_buf[0x02] = 0x00;
59+
60+
hid_write(dev, usb_buf, 65);
61+
62+
unsigned char usb_buf_out[65];
63+
hid_read(dev, usb_buf_out, 65);
64+
65+
char version[9];
66+
snprintf(version, 9, "%02X.%02X.%02X", usb_buf_out[5], usb_buf_out[6], usb_buf_out[7]);
67+
return std::string(version);
68+
}
69+
70+
int AuraTUFKeyboardController::GetLayout()
71+
{
72+
unsigned char usb_buf[65];
73+
memset(usb_buf, 0x00, sizeof(usb_buf));
74+
usb_buf[0x00] = 0x00;
75+
usb_buf[0x01] = 0x12;
76+
usb_buf[0x02] = 0x12;
77+
78+
hid_write(dev, usb_buf, 65);
79+
80+
unsigned char usb_buf_out[65];
81+
hid_read(dev, usb_buf_out, 65);
82+
83+
return(usb_buf_out[4] * 100 + usb_buf_out[5]);
84+
}
85+
86+
void AuraTUFKeyboardController::SaveMode()
87+
{
88+
unsigned char usb_save_buf[65];
89+
90+
memset(usb_save_buf, 0x00, sizeof(usb_save_buf));
91+
92+
usb_save_buf[0x00] = 0x00;
93+
usb_save_buf[0x01] = 0x50;
94+
usb_save_buf[0x02] = 0x55;
95+
96+
hid_write(dev, usb_save_buf, 65);
97+
}
98+
4799
void AuraTUFKeyboardController::UpdateSingleLed
48100
(
49101
int led,
@@ -141,7 +193,8 @@ void AuraTUFKeyboardController::UpdateDevice
141193
std::vector<RGBColor> colors,
142194
unsigned char dir,
143195
unsigned char color_mode,
144-
unsigned char speed
196+
unsigned char speed,
197+
unsigned char brightness
145198
)
146199
{
147200
unsigned char usb_buf[65];
@@ -154,21 +207,21 @@ void AuraTUFKeyboardController::UpdateDevice
154207
usb_buf[0x03] = mode;
155208
usb_buf[0x04] = 0x00;
156209
usb_buf[0x05] = speed;
157-
usb_buf[0x06] = 0x64;
210+
usb_buf[0x06] = brightness;
158211
usb_buf[0x07] = color_mode;
159212
usb_buf[0x08] = dir;
160213
usb_buf[0x09] = 0x02;
161214

162-
if(mode == 4 || mode == 5)
163-
{
164-
/*-----------------------------------------------------*\
215+
if(mode == 4 || mode == 5)
216+
{
217+
/*-----------------------------------------------------*\
165218
| If mode is Rainbow or Ripple |
166-
\*-----------------------------------------------------*/
167-
usb_buf[0x0A] = colors.size();
219+
\*-----------------------------------------------------*/
220+
usb_buf[0x0A] = colors.size();
168221

169-
/*-----------------------------------------------------*\
170-
| Loop over every color given |
171-
\*-----------------------------------------------------*/
222+
/*-----------------------------------------------------*\
223+
| Loop over every color given |
224+
\*-----------------------------------------------------*/
172225
for(unsigned int i = 0; i / 4 < colors.size(); i += 4)
173226
{
174227
if(colors[i / 4])
@@ -179,13 +232,13 @@ void AuraTUFKeyboardController::UpdateDevice
179232
usb_buf[14 + i] = RGBGetBValue(colors[i/4]);
180233
}
181234
}
182-
}
235+
}
183236
else
184237
{
185-
/*-----------------------------------------------------*\
186-
| Loop over Color1, Color2 and Background if there |
187-
\*-----------------------------------------------------*/
188-
for(unsigned int i = 0; i / 3 != colors.size(); i += 3)
238+
/*-----------------------------------------------------*\
239+
| Loop over Color1, Color2 and Background if there |
240+
\*-----------------------------------------------------*/
241+
for(unsigned int i = 0; i / 3 != colors.size(); i += 3)
189242
{
190243
if(colors[i / 3])
191244
{
@@ -194,25 +247,28 @@ void AuraTUFKeyboardController::UpdateDevice
194247
usb_buf[12 + i] = RGBGetBValue(colors[i/3]);
195248
}
196249
}
197-
198-
}
250+
251+
}
199252

200253
/*-----------------------------------------------------*\
201254
| Send packet |
202255
\*-----------------------------------------------------*/
203256
hid_write(dev, usb_buf, 65);
257+
}
204258

205-
/*-----------------------------------------------------*\
206-
| Set up and send packet save Packet |
207-
\*-----------------------------------------------------*/
208-
unsigned char usb_save_buf[65];
209-
210-
memset(usb_save_buf, 0x00, sizeof(usb_save_buf));
259+
void AuraTUFKeyboardController::AwaitResponse()
260+
{
261+
unsigned char usb_buf_out[65];
262+
hid_read(dev, usb_buf_out, 65);
263+
}
211264

212-
usb_save_buf[0x00] = 0x00;
213-
usb_save_buf[0x01] = 0x50;
214-
usb_save_buf[0x02] = 0x55;
215-
216-
hid_write(dev, usb_save_buf, 65);
265+
void AuraTUFKeyboardController::ClearResponses()
266+
{
267+
int result = 1;
268+
unsigned char usb_buf_flush[65];
269+
while(result > 0)
270+
{
271+
result = hid_read_timeout(dev, usb_buf_flush, 65, 0);
272+
}
217273
}
218274

Controllers/AsusAuraUSBController/AsusAuraTUFKeyboardController.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
\*-----------------------------------------*/
99

1010
#include "RGBController.h"
11+
#include "AsusAuraTUFKeyboardLayouts.h"
1112

1213
#include <string>
1314
#include <vector>
@@ -46,6 +47,9 @@ class AuraTUFKeyboardController
4647

4748
std::string GetDeviceLocation();
4849
std::string GetSerialString();
50+
std::string GetVersion();
51+
int GetLayout();
52+
void SaveMode();
4953

5054
void UpdateSingleLed
5155
(
@@ -55,7 +59,7 @@ class AuraTUFKeyboardController
5559
unsigned char blue
5660
);
5761

58-
void UpdateLeds
62+
void UpdateLeds
5963
(
6064
std::vector<RGBColor> colors
6165
);
@@ -66,8 +70,11 @@ class AuraTUFKeyboardController
6670
std::vector<RGBColor> colors,
6771
unsigned char dir,
6872
unsigned char color_mode,
69-
unsigned char speed
73+
unsigned char speed,
74+
unsigned char brightness
7075
);
76+
void AwaitResponse();
77+
void ClearResponses();
7178

7279
private:
7380
hid_device* dev;

0 commit comments

Comments
 (0)