Game Development Reference
In-Depth Information
case WIIC_READ_DATA:
/*
* Data we requested to read was returned. Take a look at
* wiimotes[i]->read_req for the data.
*/
break;
case WIIC_NUNCHUK_INSERTED:
/*
* a nunchuk was inserted This is a good place to set any nunchuk-
* specific threshold values. By default they are the same as the
* wiimote.
*/
printf("Nunchuk inserted.\n");
jni_send_event(i, "EVT_TYPE=EXT_INSERTED|EXT_NAME=NUNCHUK");
break;
case WIIC_CLASSIC_CTRL_INSERTED:
printf("Classic controller inserted.\n");
break;
case WIIC_NUNCHUK_REMOVED:
// some expansion was removed
handle_ctrl_status(wiimotes[i]);
printf("An expansion was removed.\n");
break;
default:
break;
}
}
}
}
LOGD("Connect main loop ended. Cleanup");
wiic_cleanup(wiimotes, MAX_WIIMOTES);
wiimotes = NULL;
nmotes = 0;
sig_exit = 0;
sig_disconnect = 0;
}
Once the LED is on and the rumble stops, DiscoverAndConnect enters a blocking loop where
it polls continuously for events for all Wiimotes. If an event is received, it is dispatched to an
event handler (which will be discussed in the next section). Note that the main loop will block
execution of the main thread, thus it is critical that the Wiimote Java class start a new thread
within its connect() method, as shown in the following fragment taken from Wiimote.java :
public void connect() {
Log.d(TAG, "Starting connection thread");
new Thread(new Runnable() {
 
Search WWH ::




Custom Search