From 8d957f068792b4ee55f807930c975699c29922a2 Mon Sep 17 00:00:00 2001 From: erdgeist <> Date: Tue, 16 Sep 2008 15:40:46 +0000 Subject: Kickoff --- main.c | 172 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 172 insertions(+) create mode 100644 main.c (limited to 'main.c') diff --git a/main.c b/main.c new file mode 100644 index 0000000..e645b48 --- /dev/null +++ b/main.c @@ -0,0 +1,172 @@ +#include +#include +#include +#include +#include + +#include +#include "gm.h" +#include "display.h" + +/* Our wii's bluetooth and wii handles */ +static bdaddr_t g_bdaddr[4]; +static cwiid_wiimote_t *g_wiimotes[4]; +static int g_num_controls = 0; +static int g_samples_received = 0; +static uint32_t g_starttime; + +static volatile int g_redraw_lock = 0; + +static const int g_width = 400, g_height = 300; + +cwiid_mesg_callback_t cwiid_callback; +cwiid_err_t err; +void err(cwiid_wiimote_t *wiimote, const char *s, va_list ap) +{ + if (wiimote) printf("%d:", cwiid_get_id(wiimote)); else printf("-1:"); + vprintf(s, ap); + printf("\n"); +} + +int main( int argc, char **argv ) { + int LEDs[4] = { CWIID_LED1_ON, CWIID_LED1_ON | CWIID_LED2_ON, + CWIID_LED1_ON | CWIID_LED2_ON | CWIID_LED3_ON, + CWIID_LED1_ON | CWIID_LED2_ON | CWIID_LED3_ON | CWIID_LED4_ON }; + int i; + struct timeval now; + + signal( SIGINT, exit ); + display_init( g_width, g_height); + + cwiid_set_err(err); + + /* If no bdaddrs given on command line, just connect to + first visible wii */ + if( argc <= 1 ) { + char bt_out[64]; + g_bdaddr[0] = *BDADDR_ANY; + + while( !(g_wiimotes[g_num_controls] = cwiid_open( &g_bdaddr[0], 0 ))) + fprintf( stderr, "Unable to connect to wiimote\n" ); + + ba2str( &g_bdaddr[0], bt_out ); + fprintf( stderr, "Connected to wiimote %i (BT-Addr: %s)\n", i, bt_out ); + g_num_controls++; + } + + /* ... else try to reach every single wii */ + for( i=0; i> j ) & 1 ); + } + + break; + default: + break; + } + } + g_redraw_lock = 0; +} + -- cgit v1.2.3