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)
41 char r1 = ditherfn(i, light->
r[i]), r2 = ditherfn(i + 1, light->
r[i + 1]);
42 char g1 = ditherfn(i, light->
g[i]), g2 = ditherfn(i + 1, light->
g[i + 1]);
43 char b1 = ditherfn(i, light->
b[i]), b2 = ditherfn(i + 1, light->
b[i + 1]);
44 r[i / 2] = (7 - r2) << 4 | (7 - r1);
45 g[i / 2] = (7 - g2) << 4 | (7 - g1);
46 b[i / 2] = (7 - b2) << 4 | (7 - b1);
48 memcpy(data_pkt[0] + 4, r, 60);
49 memcpy(data_pkt[1] + 4, r + 60, 12);
50 memcpy(data_pkt[1] + 16, g, 48);
51 memcpy(data_pkt[2] + 4, g + 48, 24);
52 memcpy(data_pkt[2] + 28, b, 36);
53 memcpy(data_pkt[3] + 4, b + 36, 36);
57 const uchar* r = light->
r, *g = light->
g, *b = light->
b;
59 memcpy(data_pkt[0] + 4, r, 60);
60 memcpy(data_pkt[1] + 4, r + 60, 60);
61 memcpy(data_pkt[2] + 4, r + 120, 24);
63 memcpy(data_pkt[4] + 4, g, 60);
64 memcpy(data_pkt[5] + 4, g + 60, 60);
65 memcpy(data_pkt[6] + 4, g + 120, 24);
67 memcpy(data_pkt[8] + 4, b, 60);
68 memcpy(data_pkt[9] + 4, b + 60, 60);
69 memcpy(data_pkt[10] + 4, b + 120, 24);
92 { 0x07, 0x05, 0x08, 0x00, 0x00 },
93 { 0x07, 0x05, 0x02, 0, 0x03 }
97 if(!
usbsend(kb, data_pkt[0], 2))
103 { 0x7f, 0x01, 0x3c, 0 },
104 { 0x7f, 0x02, 0x3c, 0 },
105 { 0x7f, 0x03, 0x18, 0 },
106 { 0x07, 0x28, 0x01, 0x03, 0x01, 0},
108 { 0x7f, 0x01, 0x3c, 0 },
109 { 0x7f, 0x02, 0x3c, 0 },
110 { 0x7f, 0x03, 0x18, 0 },
111 { 0x07, 0x28, 0x02, 0x03, 0x01, 0},
113 { 0x7f, 0x01, 0x3c, 0 },
114 { 0x7f, 0x02, 0x3c, 0 },
115 { 0x7f, 0x03, 0x18, 0 },
116 { 0x07, 0x28, 0x03, 0x03, 0x02, 0}
119 if(!
usbsend(kb, data_pkt[0], 12))
124 { 0x7f, 0x01, 60, 0 },
125 { 0x7f, 0x02, 60, 0 },
126 { 0x7f, 0x03, 60, 0 },
127 { 0x7f, 0x04, 36, 0 },
128 { 0x07, 0x27, 0x00, 0x00, 0xD8 }
131 if(!
usbsend(kb, data_pkt[0], 5))
135 memcpy(lastlight, newlight,
sizeof(
lighting));
143 { 0x7f, 0x01, 60, 0 },
144 { 0x7f, 0x02, 60, 0 },
145 { 0x7f, 0x03, 24, 0 },
146 { 0x07, 0x14, 0x03, 0x01, 0x01, mode + 1, 0x01 },
148 { 0x7f, 0x01, 60, 0 },
149 { 0x7f, 0x02, 60, 0 },
150 { 0x7f, 0x03, 24, 0 },
151 { 0x07, 0x14, 0x03, 0x01, 0x01, mode + 1, 0x02 },
153 { 0x7f, 0x01, 60, 0 },
154 { 0x7f, 0x02, 60, 0 },
155 { 0x7f, 0x03, 24, 0 },
156 { 0x07, 0x14, 0x03, 0x01, 0x01, mode + 1, 0x03 }
159 if(!
usbsend(kb, data_pkt[0], 12))
162 uchar save_end_pkt[
MSG_SIZE] = { 0x07, 0x14, 0x04, 0x01, 0x01 };
163 if(!
usbsend(kb, save_end_pkt, 1))
168 { 0x7f, 0x01, 60, 0 },
169 { 0x7f, 0x02, 60, 0 },
170 { 0x7f, 0x03, 60, 0 },
171 { 0x7f, 0x04, 36, 0 },
172 { 0x07, 0x14, 0x02, 0x00, 0x01, mode + 1 }
175 if(!
usbsend(kb, data_pkt[0], 5))
184 { 0x0e, 0x14, 0x03, 0x01, 0x01, mode + 1, 0x01 },
185 { 0xff, 0x01, 60, 0 },
186 { 0xff, 0x02, 60, 0 },
187 { 0xff, 0x03, 24, 0 },
188 { 0x0e, 0x14, 0x03, 0x01, 0x01, mode + 1, 0x02 },
189 { 0xff, 0x01, 60, 0 },
190 { 0xff, 0x02, 60, 0 },
191 { 0xff, 0x03, 24, 0 },
192 { 0x0e, 0x14, 0x03, 0x01, 0x01, mode + 1, 0x03 },
193 { 0xff, 0x01, 60, 0 },
194 { 0xff, 0x02, 60, 0 },
195 { 0xff, 0x03, 24, 0 },
198 { 0x0e, 0x14, 0x03, 0x01 },
199 { 0xff, 0x01, 60, 0 },
200 { 0xff, 0x02, 60, 0 },
201 { 0xff, 0x03, 24, 0 },
210 uchar cmp_pkt[4][4] = {
211 { 0x0e, 0x14, 0x03, 0x01 },
212 { 0x0e, 0xff, 0x01, 60 },
213 { 0x0e, 0xff, 0x02, 60 },
214 { 0x0e, 0xff, 0x03, 24 },
217 uchar* colors[3] = { light->
r, light->
g, light->
b };
218 for(
int clr = 0; clr < 3; clr++){
219 for(
int i = 0; i < 4; i++){
220 if(!
usbrecv(kb, data_pkt[i + clr * 4], in_pkt[i]))
223 uchar* comparePacket = data_pkt[i + clr * 4];
230 comparePacket = cmp_pkt[i];
233 if (memcmp(in_pkt[i], comparePacket, 4)) {
235 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,
236 comparePacket[0], comparePacket[1], comparePacket[2], comparePacket[3],
237 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]);
242 usbrecv(kb, in_pkt[2], in_pkt[2]);
247 memcpy(colors[clr], in_pkt[1] + 4, 60);
248 memcpy(colors[clr] + 60, in_pkt[2] + 4, 60);
249 memcpy(colors[clr] + 120, in_pkt[3] + 4, 24);
253 { 0x0e, 0x14, 0x02, 0x01, 0x01, mode + 1, 0 },
254 { 0xff, 0x01, 60, 0 },
255 { 0xff, 0x02, 60, 0 },
256 { 0xff, 0x03, 60, 0 },
257 { 0xff, 0x04, 36, 0 },
260 { 0xff, 0x01, 60, 0 },
261 { 0xff, 0x02, 60, 0 },
262 { 0xff, 0x03, 60, 0 },
263 { 0xff, 0x04, 36, 0 },
266 if(!
usbsend(kb, data_pkt[0], 1))
269 for(
int i = 1; i < 5; i++){
270 if(!
usbrecv(kb, data_pkt[i],in_pkt[i - 1]))
272 if(memcmp(in_pkt[i - 1], data_pkt[i], 4)){
279 memcpy(mr, in_pkt[0] + 4, 60);
280 memcpy(mr + 60, in_pkt[1] + 4, 12);
281 memcpy(mg, in_pkt[1] + 16, 48);
282 memcpy(mg + 48, in_pkt[2] + 4, 24);
283 memcpy(mb, in_pkt[2] + 28, 36);
284 memcpy(mb + 36, in_pkt[3] + 4, 36);
292 r = 7 - (mr[i_2] >> 4);
293 g = 7 - (mg[i_2] >> 4);
294 b = 7 - (mb[i_2] >> 4);
296 r = 7 - (mr[i_2] & 0x0F);
297 g = 7 - (mg[i_2] & 0x0F);
298 b = 7 - (mb[i_2] & 0x0F);
301 light->
r[i] = r << 5 | r << 2 | r >> 1;
302 light->
g[i] = g << 5 | g << 2 | g >> 1;
303 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) ...
int updatergb_kb(usbdevice *kb, int force)