@@ -47,24 +47,121 @@ std::string AOCKeyboardController::GetSerialString()
47
47
return (return_string);
48
48
}
49
49
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
+
50
85
/* -------------------------------------------------------------------------------------------------*\
51
86
| Private packet sending functions. |
52
87
\*-------------------------------------------------------------------------------------------------*/
53
88
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
55
132
(
56
133
RGBColor* color_data
57
134
)
58
135
{
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));
65
162
}
66
163
67
- void AOCKeyboardController::SendPacket
164
+ void AOCKeyboardController::SendLightingConfigPacket
68
165
(
69
166
unsigned char mode,
70
167
unsigned char random,
@@ -82,7 +179,7 @@ void AOCKeyboardController::SendPacket
82
179
memset (buf, 0x00 , sizeof (buf));
83
180
84
181
/* -----------------------------------------------------*\
85
- | Set up RGB configuration packet |
182
+ | Set up lighting configuration packet |
86
183
\*-----------------------------------------------------*/
87
184
buf[0x00 ] = 0x14 ;
88
185
buf[0x01 ] = 0x01 ;
@@ -107,34 +204,8 @@ void AOCKeyboardController::SendPacket
107
204
buf[115 ] = checksum & 0xFF ;
108
205
buf[116 ] = checksum >> 8 ;
109
206
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
-
124
207
/* -----------------------------------------------------*\
125
208
| Send packet |
126
209
\*-----------------------------------------------------*/
127
210
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 );
140
211
}
0 commit comments