Hardware Reference
In-Depth Information
3.
The Z button is interpreted as the left-click button, while the
C button is the right-click button.
4.
No keystrokes are injected by this program, but it can be
modified to do so. The function uinput_postkey() on line 244
can be used for that purpose.
1 /
∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗
2
nunchuk.c: Read events from nunchuck and stuff as mouse events
3
/
∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗
4
5 #include <stdio.h>
6 #include <math.h>
7 #include <stdlib.h>
8 #include <fcntl.h>
9 #include <unistd.h>
10 #include <string.h>
11 #include <errno.h>
12 #include <signal.h>
13 #include <assert.h>
14 #include <sys/ioctl.h>
15 #include <linux/i2c−dev.h>
16 #include <linux/input.h>
17 #include <linux/uinput.h>
18
19 #include "timed_wait.c"
20
21 static int is_signaled = 0; /
Exit program if signaled
/
22 static int i2c_fd = −1; /
Open/dev/i2c−1 device
/
23 static int f_debug = 0; /
True to print debug messages
/
24
25 typedef struct {
26 unsigned char stick_x; /
Joystick X
/
27 unsigned char stick_y; /
Joystick Y
/
28 unsigned accel_x; /
Accel X
/
29 unsigned accel_y; /
Accel Y
/
30 unsigned accel_z; /
Accel Z
/
31 unsigned z_button:1; /
Z button
/
32 unsigned c_button:1; /
C button
/
33 unsigned char raw[6]; /
Raw received data
/
34 } nunchuk_t;
35
36 /
37
Open I2C bus and check capabilities:
38
/
39 static void
40 i2c_init(const char
node) {
Search WWH ::




Custom Search