-
Notifications
You must be signed in to change notification settings - Fork 8
/
nunchuck_test.c
55 lines (36 loc) · 996 Bytes
/
nunchuck_test.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
/* Makes a spinning pattern on the display */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <linux/i2c-dev.h>
#include "i2c_lib.h"
int main(int arg, char **argv) {
struct nunchuck_data n_data;
char *device="/dev/i2c-1";
int i2c_fd;
i2c_fd=init_i2c(device);
if (i2c_fd < 0) {
fprintf(stderr,"Error opening i2c dev file %s\n",device);
return -1;
}
if (init_nunchuck(i2c_fd)) {
fprintf(stderr,"Error initializing nunchuck\n");
return -1;
}
while(1) {
read_nunchuck(i2c_fd,&n_data);
printf("Joystick X: %d\n",n_data.joy_x);
printf("Joystick Y: %d\n",n_data.joy_y);
printf("Accelerometer X: %d\n",n_data.acc_x);
printf("Accelerometer Y: %d\n",n_data.acc_y);
printf("Accelerometer Z: %d\n",n_data.acc_z);
printf("Z button pressed: %d\n",n_data.z_pressed);
printf("C button pressed: %d\n",n_data.c_pressed);
usleep(100000);
}
return 0;
}