-
Notifications
You must be signed in to change notification settings - Fork 16
/
wm_print.c
265 lines (235 loc) · 8.51 KB
/
wm_print.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
#include "wm_print.h"
#include "wm_reports.h" //for now
#include <stdlib.h>
#include <stdio.h>
#include <sys/time.h>
int show_reports = 0;
int reports_truncated = 0;
uint64_t next_report_ts = 0;
uint64_t report_timeout_us = 500000;
int verbose_reports = 0;
void print_report(const uint8_t * buf, int len)
{
struct timeval tv;
int i;
struct report_data * data = (struct report_data *)buf;
uint64_t ts;
if (len == 0) return;
gettimeofday(&tv, NULL);
ts = tv.tv_sec * (uint64_t)1000000 + tv.tv_usec;
if (buf[0] == 0xa2) //report from wii
{
printf("\e[2;37m%ld.%06ld \e[1;31mWii:\e[0m ", tv.tv_sec, tv.tv_usec);
printf("\e[33m%02x\e[0m ", buf[1]);
switch (buf[1])
{
case 0x10:
{
struct report_rumble * rpt = (struct report_rumble *)data->buf;
printf("(set rumble %u)", rpt->rumble & 1);
break;
}
case 0x12: //data reporting mode
{
struct report_mode * rpt = (struct report_mode *)data->buf;
printf("(set reporting mode %02x, cont: %u)", rpt->mode, rpt->continuous & 1);
break;
}
case 0x11: //player LEDs
{
struct report_leds * rpt = (struct report_leds *)data->buf;
printf("(set player leds %u %u %u %u)", rpt->led_1 & 1, rpt->led_2 & 1,
rpt->led_3 & 1, rpt->led_4 & 1);
break;
}
case 0x13:
case 0x1a: //ir camera enable
{
struct report_ir_enable * rpt = (struct report_ir_enable *)data->buf;
printf("%02x %02x ", buf[2], buf[3]);
printf("(set ir cam enable %u)", rpt->enabled & 1);
break;
}
case 0x14:
case 0x19: //speaker enable
{
struct report_speaker_enable * rpt = (struct report_speaker_enable *)data->buf;
printf("(set speaker enable %u)", !rpt->muted & 1);
break;
}
case 0x15: //status information request
printf("(status request)");
break;
case 0x16: //write memory
{
struct report_mem_write * rpt = (struct report_mem_write *)data->buf;
printf("\x1B[35m%02x \x1B[32m%02x %02x %02x \x1B[36m%02x\033[0m ", buf[2], buf[3], buf[4], buf[5], buf[6]);
for (i = 7; i < len; i++) printf("%02x ", buf[i]);
if (rpt->source0 || rpt->source1)
{
switch (rpt->offset & 0xfe)
{
case 0xa2: printf("(write speaker register a2)"); break;
case 0xa4: printf("(write ext register a4)"); break;
case 0xa6: printf("(write wmp register a6)"); break;
case 0xb0: printf("(write ir register b0)"); break;
}
}
else
{
printf("(write eeprom)");
}
break;
}
case 0x17: //read memory
{
struct report_mem_read * rpt = (struct report_mem_read *)data->buf;
printf("\x1B[35m%02x \x1B[32m%02x %02x %02x \x1B[36m%02x %02x\033[0m ", buf[2], buf[3], buf[4], buf[5], buf[6], buf[7]);
if (rpt->source0 || rpt->source1)
{
switch (rpt->offset & 0xfe)
{
case 0xa2: printf("(read speaker register a2)"); break;
case 0xa4: printf("(read ext register a4)"); break;
case 0xa6: printf("(read wmp register a6)"); break;
case 0xb0: printf("(read ir register b0)"); break;
}
}
else
{
printf("(read eeprom)");
}
break;
}
case 0x18: //speaker data (not used)
printf("(speaker data)");
break;
default: //??
printf("(unknown report)");
break;
}
printf("\e[0m\n");
}
else
{
if (buf[1] < 0x30 || show_reports)
{
if (ts >= next_report_ts)
{
printf("\e[2;37m%ld.%06ld \e[1;34mWiimote:\e[0m ", tv.tv_sec, tv.tv_usec);
printf("\e[33m%02x\e[0m \e[0;34m%02x %02x\e[0m ", buf[1], buf[2], buf[3]);
switch(buf[1])
{
case 0x22:
printf("\e[0;35m%02x \e[0;31m%02x\e[0m ", buf[4], buf[5]);
printf("(ack report: %02x, res: %02x)", buf[4], buf[5]);
break;
case 0x21:
printf("\e[0;31m%02x \x1B[32m%02x %02x\e[0m ", buf[4], buf[5], buf[6]);
for (i = 7; i < len; i++)
{
printf("%02x ", buf[i]);
}
printf("(memory output)");
break;
case 0x20:
printf("\e[0;35m%02x\e[0m ", buf[4]);
for (i = 5; i < len; i++)
{
printf("%02x ", buf[i]);
}
printf("(status report)");
break;
default:
for (i = 4; i < len; i++)
{
printf("%02x ", buf[i]);
}
}
printf("\e[0m\n");
if (verbose_reports)
{
struct report_accelerometer * report_accel = (struct report_accelerometer *)(buf + 2);
printf(" accel %02x %02x, %02x %02x, %02x %02x\n",
report_accel->x, report_accel->buttons.accel_0 & 0x3,
report_accel->y, (report_accel->buttons.accel_1 & 0x1) << 1,
report_accel->z, (report_accel->buttons.accel_1 & 0x2));
if (buf[1] == 0x33)
{
struct report_ir_ext * report_ir = (struct report_ir_ext *)(buf + 2 + 5);
for (int i = 0; i < 4; i++)
{
printf(" object %d: %d, %d [%d]\n", i,
(((unsigned int)report_ir->obj[i].x_hi & 0x3) << 8 | report_ir->obj[i].x_lo),
(((unsigned int)report_ir->obj[i].y_hi & 0x3) << 8 | report_ir->obj[i].y_lo),
report_ir->obj[i].size);
}
}
if (buf[1] == 0x37)
{
struct report_ir_basic * report_ir = (struct report_ir_basic *)(buf + 2 + 5);
printf(" object %d: %d, %d\n", 0,
(((unsigned int)report_ir->x1_hi & 0x3) << 8 | report_ir->x1_lo),
(((unsigned int)report_ir->y1_hi & 0x3) << 8 | report_ir->y1_lo));
printf(" object %d: %d, %d\n", 1,
(((unsigned int)report_ir->x2_hi & 0x3) << 8 | report_ir->x2_lo),
(((unsigned int)report_ir->y2_hi & 0x3) << 8 | report_ir->y2_lo));
printf(" object %d: %d, %d\n", 2,
(((unsigned int)report_ir->x3_hi & 0x3) << 8 | report_ir->x3_lo),
(((unsigned int)report_ir->y3_hi & 0x3) << 8 | report_ir->y3_lo));
printf(" object %d: %d, %d\n", 3,
(((unsigned int)report_ir->x4_hi & 0x3) << 8 | report_ir->x4_lo),
(((unsigned int)report_ir->y4_hi & 0x3) << 8 | report_ir->y4_lo));
}
}
reports_truncated = 0;
next_report_ts = ts + report_timeout_us;
}
}
else
{
if (!reports_truncated)
{
printf(" \x1B[2;37mReporting 0x%x ", buf[1]);
switch (buf[1])
{
case 0x30: // core buttons
printf("(core buttons)");
break;
case 0x31: // core buttons + accelerometer
printf("(core buttons + accelerometer)");
break;
case 0x32: // core buttons + 8 extension bytes
printf("(core buttons + 8 extension bytes)");
break;
case 0x33: // core buttons + accelerometer + 12 ir bytes
printf("(core buttons + accelerometer + 12 ir bytes)");
break;
case 0x34: // core buttons + accelerometer + 19 extension bytes
printf("(core buttons + accelerometer + 19 extension bytes)");
break;
case 0x35: // core buttons + accelerometer + 16 extension bytes
printf("(core buttons + accelerometer + 16 extension bytes)");
break;
case 0x36: // core buttons + 10 ir bytes + 9 extension bytes
printf("(core buttons + 10 ir bytes + 9 extension bytes)");
break;
case 0x37: // core buttons + accelerometer + 10 ir bytes + 6 extension bytes
printf("(core buttons + accelerometer + 10 ir bytes + 6 extension bytes)");
break;
case 0x3d: // 21 extension bytes
printf("(21 extension bytes)");
break;
case 0x3e: // interleaved core buttons + accelerometer with 36 ir bytes pt I
printf("(interleaved core buttons + accelerometer with 36 ir bytes)");
break;
case 0x3f: // interleaved core buttons + accelerometer with 36 ir bytes pt II
printf("(interleaved core buttons + accelerometer with 36 ir bytes)");
break;
}
printf("\e[0m\n");
reports_truncated = 1;
}
}
}
}