]> git.ozlabs.org Git - ponghero.git/blobdiff - wiimote.c
Add wiimote.c simple test.
[ponghero.git] / wiimote.c
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;
+}