static int windows_register_psmove(const char *move_addr_str, const BLUETOOTH_ADDRESS *radio_addr, const HANDLE hRadio) { /* parse controller's Bluetooth device address string */ BLUETOOTH_ADDRESS *move_addr = string_to_btaddr(move_addr_str); if (!move_addr) { WINPAIR_DEBUG("Cannot parse controller address: '%s'", move_addr_str); return 1; } if (!radio_addr) { WINPAIR_DEBUG("Invalid Bluetooth device address for radio"); return 1; } if (set_up_bluetooth_radio(hRadio) != 0) { WINPAIR_DEBUG("Failed to configure Bluetooth radio for use"); return 1; } printf("\n" \ " Unplug the controller.\n" \ "\n" " Now press the controller's PS button. The red status LED\n" \ " will start blinking. Whenever it goes off, press the\n" \ " PS button again. Repeat this until the status LED finally\n" \ " remains lit. Press Ctrl+C to cancel anytime.\n"); if (is_windows8_or_later()) { WINPAIR_DEBUG("Dealing with Windows 8 or later"); handle_windows8_and_later(move_addr, radio_addr, hRadio); } else { WINPAIR_DEBUG("Dealing with Windows version older than 8"); handle_windows_pre8(move_addr, radio_addr, hRadio); } free(move_addr); return 0; }
int windows_register_psmove(const char *move_addr_str, const HANDLE hRadio) { /* parse controller's Bluetooth device address string */ BLUETOOTH_ADDRESS *move_addr = string_to_btaddr(move_addr_str); if (!move_addr) { WINPAIR_DEBUG("Cannot parse controller address: '%s'", move_addr_str); return 1; } if (set_up_bluetooth_radio(hRadio) != 0) { WINPAIR_DEBUG("Failed to configure Bluetooth radio for use"); return 1; } /* Keep track of the number of times the loop iterates so we may timeout. */ int timeout_duration = 30; // seconds int sleep_interval = 1000; // msec int timeout_iterations = timeout_duration * 1000 / sleep_interval; int loop_count = 0; printf("\n" \ " Unplug the controller.\n" \ "\n" " Now press the controller's PS button. The red status LED\n" \ " will start blinking. Whenever it goes off, press the\n" \ " PS button again. Repeat this until the status LED finally\n" \ " remains lit. Press Ctrl+C to cancel anytime.\n"); for(;;) { BLUETOOTH_DEVICE_INFO device_info; if (get_bluetooth_device_info(hRadio, move_addr, &device_info) != 0) { WINPAIR_DEBUG("No Bluetooth device found matching the given address"); } else { if (is_move_motion_controller(&device_info)) { WINPAIR_DEBUG("Found Move Motion Controller matching the given address"); if (device_info.fConnected) { /* enable HID service only if necessary */ WINPAIR_DEBUG("Checking HID service ..."); if (!is_hid_service_enabled(hRadio, &device_info)) { WINPAIR_DEBUG("Enabling HID service ..."); GUID service = HumanInterfaceDeviceServiceClass_UUID; DWORD result = BluetoothSetServiceState(hRadio, &device_info, &service, BLUETOOTH_SERVICE_ENABLE); if (result != ERROR_SUCCESS) { WINPAIR_DEBUG("Failed to enable HID service"); } } WINPAIR_DEBUG("Verifying successful connection ..."); if (is_connection_established(hRadio, &device_info)) { /* if we have a connection, stop trying to connect this device */ printf("Connection verified.\n"); break; } } } else { WINPAIR_DEBUG("Bluetooth device matching the given address is not a Move Motion Controller"); } } if (loop_count >= timeout_iterations) { printf("\n" " A connection could not be established. This is not\n" " unusual in Windows. Please refer to the README document\n" " for your platform for more information. Press Ctrl+C to cancel."); } /* sleep for 1 second */ Sleep(1000); loop_count++; } free(move_addr); return 0; }