#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; }