Add wiimote.c simple test.
authorRusty Russell <rusty@rustcorp.com.au>
Thu, 17 Jan 2008 10:46:45 +0000 (21:46 +1100)
committerRusty Russell <rusty@rustcorp.com.au>
Thu, 17 Jan 2008 10:46:45 +0000 (21:46 +1100)
Makefile
wiimote.c [new file with mode: 0644]

index df3ccae75024e36c23736bf9c10b38d6043f81f8..11d33b33b0d3e1c3ce81ff494a8003e9a4e04e05 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,7 @@
 #! /usr/bin/make
 
-CFLAGS:=-Wall -Wmissing-prototypes -Wmissing-declarations -g #-g #-O2 -g
-LDFLAGS:=-lSDL
+CFLAGS:=-Wall -Wmissing-prototypes -Wmissing-declarations -g -I../ccan #-g #-O2 -g
+LDFLAGS:=-lSDL -lcwiid
 prpong: prpong.c stdrusty.h
+
+wiimote: wiimote.c stdrusty.h
diff --git a/wiimote.c b/wiimote.c
new file mode 100644 (file)
index 0000000..a1fb275
--- /dev/null
+++ b/wiimote.c
@@ -0,0 +1,39 @@
+#include <stdio.h>
+#include <err.h>
+#include <unistd.h>
+#include <cwiid.h>
+
+int main(int argc, char *argv[])
+{
+       cwiid_wiimote_t *wiimote;
+       struct cwiid_state state;
+       bdaddr_t addr = *BDADDR_ANY;
+       unsigned int i;
+
+       printf("Put Wiimote in discoverable mode (press 1+2) and hit enter\n");
+       fgetc(stdin);
+
+       wiimote = cwiid_open(&addr, 0);
+       if (!wiimote)
+               errx(1, "Can't find the Wiimote");
+
+       printf("Setting the IR repeat mode.\n");
+       if (cwiid_set_rpt_mode(wiimote, CWIID_RPT_IR))
+               errx(1, "Can't set IR repeat mode");
+
+       sleep(5);
+       if (cwiid_get_state(wiimote, &state))
+               errx(1, "No state");
+
+       printf("IR: ");
+       for (i = 0; i < CWIID_IR_SRC_COUNT; i++) {
+               if (!state.ir_src[i].valid)
+                       continue;
+
+               printf("(%d,%d) ",
+                      state.ir_src[i].pos[CWIID_X],
+                      state.ir_src[i].pos[CWIID_Y]);
+       }
+       printf("\n");
+       return 0;
+}