9 #define BR1(x) ((((x) & 0xaa) >> 1) | (((x) & 0x55) << 1))
10 #define BR2(x) (((BR1(x) & 0xcc) >> 2) | ((BR1(x) & 0x33) << 2))
11 #define BR4(x) (((BR2(x) & 0xf0) >> 4) | ((BR2(x) & 0x0f) << 4))
13 #define O1(i) O0(i) O0((i) + 1)
14 #define O2(i) O1(i) O1((i) + 2)
15 #define O3(i) O2(i) O2((i) + 4)
16 #define O4(i) O3(i) O3((i) + 8)
17 #define O5(i) O4(i) O4((i) + 16)
18 #define O6(i) O5(i) O5((i) + 32)
19 #define O7(i) O6(i) O6((i) + 64)
20 #define O8(i) O7(i) O7((i) + 127)
43 char r1 = ditherfn(i, light->
r[i]), r2 = ditherfn(i + 1, light->
r[i + 1]);
44 char g1 = ditherfn(i, light->
g[i]), g2 = ditherfn(i + 1, light->
g[i + 1]);
45 char b1 = ditherfn(i, light->
b[i]), b2 = ditherfn(i + 1, light->
b[i + 1]);
46 r[i / 2] = (7 - r2) << 4 | (7 - r1);
47 g[i / 2] = (7 - g2) << 4 | (7 - g1);
48 b[i / 2] = (7 - b2) << 4 | (7 - b1);
50 memcpy(data_pkt[0] + 4, r, 60);
51 memcpy(data_pkt[1] + 4, r + 60, 12);
52 memcpy(data_pkt[1] + 16, g, 48);
53 memcpy(data_pkt[2] + 4, g + 48, 24);
54 memcpy(data_pkt[2] + 28, b, 36);
55 memcpy(data_pkt[3] + 4, b + 36, 36);
59 const uchar* r = light->
r, *g = light->
g, *b = light->
b;
61 memcpy(data_pkt[0] + 4, r, 60);
62 memcpy(data_pkt[1] + 4, r + 60, 60);
63 memcpy(data_pkt[2] + 4, r + 120, 60);
65 memcpy(data_pkt[4] + 4, g, 60);
66 memcpy(data_pkt[5] + 4, g + 60, 60);
67 memcpy(data_pkt[6] + 4, g + 120, 60);
69 memcpy(data_pkt[8] + 4, b, 60);
70 memcpy(data_pkt[9] + 4, b + 60, 60);
71 memcpy(data_pkt[10] + 4, b + 120, 60);
94 { 0x07, 0x05, 0x08, 0x00, 0x00 },
95 { 0x07, 0x05, 0x02, 0, 0x03 }
99 if(!
usbsend(kb, data_pkt[0], 2))
105 { 0x7f, 0x01, 0x3c, 0 },
106 { 0x7f, 0x02, 0x3c, 0 },
107 { 0x7f, 0x03, 0x18, 0 },
108 { 0x07, 0x28, 0x01, 0x03, 0x01, 0},
110 { 0x7f, 0x01, 0x3c, 0 },
111 { 0x7f, 0x02, 0x3c, 0 },
112 { 0x7f, 0x03, 0x18, 0 },
113 { 0x07, 0x28, 0x02, 0x03, 0x01, 0},
115 { 0x7f, 0x01, 0x3c, 0 },
116 { 0x7f, 0x02, 0x3c, 0 },
117 { 0x7f, 0x03, 0x18, 0 },
118 { 0x07, 0x28, 0x03, 0x03, 0x02, 0}
123 data_pkt[2][2] = 0x30;
124 data_pkt[6][2] = 0x30;
125 data_pkt[10][2] = 0x30;
128 if(!
usbsend(kb, data_pkt[0], 12))
133 { 0x7f, 0x01, 60, 0 },
134 { 0x7f, 0x02, 60, 0 },
135 { 0x7f, 0x03, 60, 0 },
136 { 0x7f, 0x04, 36, 0 },
137 { 0x07, 0x27, 0x00, 0x00, 0xD8 }
140 if(!
usbsend(kb, data_pkt[0], 5))
144 memcpy(lastlight, newlight,
sizeof(
lighting));
152 { 0x7f, 0x01, 60, 0 },
153 { 0x7f, 0x02, 60, 0 },
154 { 0x7f, 0x03, 24, 0 },
155 { 0x07, 0x14, 0x03, 0x01, 0x01, mode + 1, 0x01 },
157 { 0x7f, 0x01, 60, 0 },
158 { 0x7f, 0x02, 60, 0 },
159 { 0x7f, 0x03, 24, 0 },
160 { 0x07, 0x14, 0x03, 0x01, 0x01, mode + 1, 0x02 },
162 { 0x7f, 0x01, 60, 0 },
163 { 0x7f, 0x02, 60, 0 },
164 { 0x7f, 0x03, 24, 0 },
165 { 0x07, 0x14, 0x03, 0x01, 0x01, mode + 1, 0x03 }
168 if(!
usbsend(kb, data_pkt[0], 12))
171 uchar save_end_pkt[
MSG_SIZE] = { 0x07, 0x14, 0x04, 0x01, 0x01 };
172 if(!
usbsend(kb, save_end_pkt, 1))
177 { 0x7f, 0x01, 60, 0 },
178 { 0x7f, 0x02, 60, 0 },
179 { 0x7f, 0x03, 60, 0 },
180 { 0x7f, 0x04, 36, 0 },
181 { 0x07, 0x14, 0x02, 0x00, 0x01, mode + 1 }
184 if(!
usbsend(kb, data_pkt[0], 5))
193 { 0x0e, 0x14, 0x03, 0x01, 0x01, mode + 1, 0x01 },
194 { 0xff, 0x01, 60, 0 },
195 { 0xff, 0x02, 60, 0 },
196 { 0xff, 0x03, 24, 0 },
197 { 0x0e, 0x14, 0x03, 0x01, 0x01, mode + 1, 0x02 },
198 { 0xff, 0x01, 60, 0 },
199 { 0xff, 0x02, 60, 0 },
200 { 0xff, 0x03, 24, 0 },
201 { 0x0e, 0x14, 0x03, 0x01, 0x01, mode + 1, 0x03 },
202 { 0xff, 0x01, 60, 0 },
203 { 0xff, 0x02, 60, 0 },
204 { 0xff, 0x03, 24, 0 },
207 { 0x0e, 0x14, 0x03, 0x01 },
208 { 0xff, 0x01, 60, 0 },
209 { 0xff, 0x02, 60, 0 },
210 { 0xff, 0x03, 24, 0 },
219 uchar cmp_pkt[4][4] = {
220 { 0x0e, 0x14, 0x03, 0x01 },
221 { 0x0e, 0xff, 0x01, 60 },
222 { 0x0e, 0xff, 0x02, 60 },
223 { 0x0e, 0xff, 0x03, 24 },
226 uchar* colors[3] = { light->
r, light->
g, light->
b };
227 for(
int clr = 0; clr < 3; clr++){
228 for(
int i = 0; i < 4; i++){
229 if(!
usbrecv(kb, data_pkt[i + clr * 4], in_pkt[i]))
232 uchar* comparePacket = data_pkt[i + clr * 4];
239 comparePacket = cmp_pkt[i];
242 if (memcmp(in_pkt[i], comparePacket, 4)) {
244 ckb_err(
"color = %d, i = %d, mode = %d\nOutput (Request): %2.2x %2.2x %2.2x %2.2x\nInput(Reply): %2.2x %2.2x %2.2x %2.2x %2.2x %2.2x %2.2x %2.2x\n", clr, i, mode,
245 comparePacket[0], comparePacket[1], comparePacket[2], comparePacket[3],
246 in_pkt[i][0], in_pkt[i][1], in_pkt[i][2], in_pkt[i][3], in_pkt[i][4], in_pkt[i][5], in_pkt[i][6], in_pkt[i][7]);
251 usbrecv(kb, in_pkt[2], in_pkt[2]);
256 memcpy(colors[clr], in_pkt[1] + 4, 60);
257 memcpy(colors[clr] + 60, in_pkt[2] + 4, 60);
258 memcpy(colors[clr] + 120, in_pkt[3] + 4, 24);
262 { 0x0e, 0x14, 0x02, 0x01, 0x01, mode + 1, 0 },
263 { 0xff, 0x01, 60, 0 },
264 { 0xff, 0x02, 60, 0 },
265 { 0xff, 0x03, 60, 0 },
266 { 0xff, 0x04, 36, 0 },
269 { 0xff, 0x01, 60, 0 },
270 { 0xff, 0x02, 60, 0 },
271 { 0xff, 0x03, 60, 0 },
272 { 0xff, 0x04, 36, 0 },
275 if(!
usbsend(kb, data_pkt[0], 1))
278 for(
int i = 1; i < 5; i++){
279 if(!
usbrecv(kb, data_pkt[i],in_pkt[i - 1]))
281 if(memcmp(in_pkt[i - 1], data_pkt[i], 4)){
288 memcpy(mr, in_pkt[0] + 4, 60);
289 memcpy(mr + 60, in_pkt[1] + 4, 12);
290 memcpy(mg, in_pkt[1] + 16, 48);
291 memcpy(mg + 48, in_pkt[2] + 4, 24);
292 memcpy(mb, in_pkt[2] + 28, 36);
293 memcpy(mb + 36, in_pkt[3] + 4, 36);
301 r = 7 - (mr[i_2] >> 4);
302 g = 7 - (mg[i_2] >> 4);
303 b = 7 - (mb[i_2] >> 4);
305 r = 7 - (mr[i_2] & 0x0F);
306 g = 7 - (mg[i_2] & 0x0F);
307 b = 7 - (mb[i_2] & 0x0F);
310 light->
r[i] = r << 5 | r << 2 | r >> 1;
311 light->
g[i] = g << 5 | g << 2 | g >> 1;
312 light->
b[i] = b << 5 | b << 2 | b >> 1;
#define IS_FULLRANGE(kb)
Full color range (16.8M) vs partial color range (512)
static uchar quantize8to3(int index, uchar value)
#define ckb_err(fmt, args...)
static uchar bit_reverse_table[256]
int loadrgb_kb(usbdevice *kb, lighting *light, int mode)
static void makergb_full(const lighting *light, uchar data_pkt[12][64])
static int rgbcmp(const lighting *lhs, const lighting *rhs)
static uchar ordered8to3(int index, uchar value)
#define usbrecv(kb, out_msg, in_msg)
usbrecv macro is used to wrap _usbrecv() with debugging information (file and lineno) ...
Definitions for using USB interface.
int savergb_kb(usbdevice *kb, lighting *light, int mode)
static void makergb_512(const lighting *light, uchar data_pkt[5][64], uchar(*ditherfn)(int, uchar))
#define usbsend(kb, messages, count)
usbsend macro is used to wrap _usbsend() with debugging information (file and lineno) ...
#define IS_V2_OVERRIDE(kb)
Used when a device has a firmware with a low version number that uses the new protocol.
int updatergb_kb(usbdevice *kb, int force)