From 50eb11dbd0cbde2a4a2d724c4747a71e12693b37 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Thu, 17 Jan 2008 21:46:45 +1100 Subject: [PATCH] Add wiimote.c simple test. --- Makefile | 6 ++++-- wiimote.c | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 wiimote.c diff --git a/Makefile b/Makefile index df3ccae..11d33b3 100644 --- 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 index 0000000..a1fb275 --- /dev/null +++ b/wiimote.c @@ -0,0 +1,39 @@ +#include +#include +#include +#include + +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; +} -- 2.39.2