bool joystick_windows::setup_dinput_joystick(const DIDEVICEINSTANCE* instance) { HRESULT hr; int num = check_free_joy_slot(); if (have_device(instance->guidInstance) || num == -1) return false; d_joysticks[joystick_count] = dinput_gamepad(); dinput_gamepad* joy = &d_joysticks[joystick_count]; const DWORD devtype = (instance->dwDevType & 0xFF); if ((devtype != DI8DEVTYPE_JOYSTICK) && (devtype != DI8DEVTYPE_GAMEPAD) && (devtype != DI8DEVTYPE_1STPERSON)) { //printf("ignore device %s, type %x\n", instance->tszProductName, devtype); return false; } hr = dinput->CreateDevice(instance->guidInstance, &joy->di_joy, NULL); if (FAILED(hr)) { //std::wcout << "failed to create device: " << instance->tszProductName << std::endl; return false; } const GUID &guid = instance->guidProduct; char uid[128]; sprintf(uid, "%08lx%04hx%04hx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx", __builtin_bswap32(guid.Data1), guid.Data2, guid.Data3, guid.Data4[0], guid.Data4[1], guid.Data4[2], guid.Data4[3], guid.Data4[4], guid.Data4[5], guid.Data4[6], guid.Data4[7]); id_to_change = joystick_count; joy->di_joy->SetDataFormat(&c_dfDIJoystick2); joy->di_joy->SetCooperativeLevel(*hWnd, DISCL_FOREGROUND); joy->di_joy->EnumObjects(objectsCallback, this, NULL); joy->joy_axis.sort(); joy->guid = instance->guidInstance; input->joy_connection_changed(num, true, instance->tszProductName, uid); joy->attached = true; joy->id = num; attached_joysticks[num] = true; joy->confirmed = true; joystick_count++; return true; }
void JoypadOSX::_device_added(IOReturn p_res, IOHIDDeviceRef p_device) { if (p_res != kIOReturnSuccess || have_device(p_device)) { return; } joypad new_joypad; if (is_joypad(p_device)) { configure_joypad(p_device, &new_joypad); #if MAC_OS_X_VERSION_MIN_REQUIRED < 1060 if (IOHIDDeviceGetService != NULL) { #endif const io_service_t ioservice = IOHIDDeviceGetService(p_device); if ((ioservice) && (FFIsForceFeedback(ioservice) == FF_OK) && new_joypad.config_force_feedback(ioservice)) { new_joypad.ffservice = ioservice; } #if MAC_OS_X_VERSION_MIN_REQUIRED < 1060 } #endif device_list.push_back(new_joypad); } IOHIDDeviceRegisterRemovalCallback(p_device, joypad_removed_callback, (void *)(intptr_t)new_joypad.id); IOHIDDeviceScheduleWithRunLoop(p_device, CFRunLoopGetCurrent(), GODOT_JOY_LOOP_RUN_MODE); }