Game Development Reference
In-Depth Information
1.
It gets a descriptor for the first Bluetooth device by using the BTAPI
call of hci_get_route .
/* get the id of the first bluetooth device. */
int = device_id = hci_get_route(NULL);
Then it does a device inquiry by invoking hci_inquiry .
2.
/* scan for bluetooth devices for 128 'timeout' seconds */
found_devices = hci_inquiry(device_id, timeout, 128, NULL, &scan_info,
IREQ_CACHE_FLUSH);
3.
If the number of found devices is greater than zero, then you may
have some Wiimote(s) or other Bluetooth devices. To make sure
it connects to a valid Wiimote, WiiC must check the device class
encoded as a sequence of 3 bytes (see Listing 8-5).
Listing 8-5. WiiC Device Discovery Process
int wiic_find(struct wiimote_t** wm, int max_wiimotes, int timeout) {
// ...
// Get BT devices
/* scan for bluetooth devices for 'timeout' seconds */
found_devices = hci_inquiry(device_id, timeout, 128, NULL, &scan_info, IREQ_CACHE_FLUSH);
if (found_devices < 0) {
return 0;
}
// got some potential devices. Check device class
/* display discovered devices */
for (; (i < found_devices) && (found_wiimotes < max_wiimotes); ++i) {
if ( ((scan_info[i].dev_class[0] == WM_DEV_CLASS_0) &&
(scan_info[i].dev_class[1] == WM_DEV_CLASS_1) &&
(scan_info[i].dev_class[2] == WM_DEV_CLASS_2))
)
{
/* found a wiimote */
++found_wiimotes;
}
// ...
}
In the for loop of Listing 8-5 you must now take into account the device classes for the new
Wiimote (declared in wiic_internal.h ):
// Old Wiimote RVL-CNT-01
#define WM_DEV_CLASS_0 0x04
#define WM_DEV_CLASS_1 0x25
#define WM_DEV_CLASS_2 0x00
Search WWH ::




Custom Search