Game Development Reference
In-Depth Information
data[i] = (data[i] ^ 0x17) + 0x17;
*/
...
}
If you don't do this, you will get garbage when the buttons on the Nunchuk are pressed or
the joystick in moved. Note that this will work for the new Wiimote only. Old Wiimotes still
send encrypted data. If you wish to support both (old and new), you need to implement a
way to check for the new Wiimote and skip the decryption. This can be done quickly using
a global variable that is set whenever the discovery process detects the new Wiimote. Thus
the previous fragment becomes
/* decrypt data for old wiimotes only*/
if ( !g_isTR ) {
for (i = 0; i < len; ++i)
data[i] = (data[i] ^ 0x17) + 0x17;
}
This code uses the global variable g_isTR , which is set during discovery if the new Wiimote
is detected. To do so, you can use the Bluetooth API call of
int hci_read_remote_name(int sock, const bdaddr_t *ba, int len, char *name, int timeout)
This API function retrieves the user-friendly name of a device associated with a Bluetooth
socket and an address obtained in the inquiry process. For example, the following fragment
is included in the file jni_wiic.c and used to check for the new Wiimote:
// loop thru devices
for ( i = 0 ; i < size ; i++) {
ba2str(&scan_info[i].bdaddr, addr);
// get bt device name
if ( ! hci_read_remote_name(hci_sock, &scan_info[i].bdaddr, WIIMOTE_CMP_LEN, dev_name,
5000) ) {
// check 4 new wiimote TR
if ( strstr(dev_name, "-TR") != NULL ) {
g_isTR = 1;
}
}
jni_send_message("Found Device %s/%s ", dev_name, addr);
}
This fragment loops through all devices received on inquiry and reads their user-friendly
name. If the name contains the string “-TR,” a new Wiimote is assumed. The WiiC library is
now ready for use with your Android app, but first you must provide a JNI interface so you
can talk to WiiC within Java.
Search WWH ::




Custom Search