]> git.ozlabs.org Git - ponghero.git/blob - wiimote.c
Now using a real projector
[ponghero.git] / wiimote.c
1 #include <stdio.h>
2 #include <err.h>
3 #include <unistd.h>
4 #include <cwiid.h>
5
6 int main(int argc, char *argv[])
7 {
8         cwiid_wiimote_t *wiimote;
9         struct cwiid_state state;
10         bdaddr_t addr = *BDADDR_ANY;
11         unsigned int i;
12
13         printf("Put Wiimote in discoverable mode (press 1+2) and hit enter\n");
14         fgetc(stdin);
15
16         wiimote = cwiid_open(&addr, 0);
17         if (!wiimote)
18                 errx(1, "Can't find the Wiimote");
19
20         printf("Setting the IR repeat mode.\n");
21         if (cwiid_set_rpt_mode(wiimote, CWIID_RPT_IR))
22                 errx(1, "Can't set IR repeat mode");
23
24         sleep(5);
25         if (cwiid_get_state(wiimote, &state))
26                 errx(1, "No state");
27
28         printf("IR: ");
29         for (i = 0; i < CWIID_IR_SRC_COUNT; i++) {
30                 if (!state.ir_src[i].valid)
31                         continue;
32
33                 printf("(%d,%d) ",
34                        state.ir_src[i].pos[CWIID_X],
35                        state.ir_src[i].pos[CWIID_Y]);
36         }
37         printf("\n");
38         return 0;
39 }