| 87 | } |
| 88 | |
| 89 | bool GamepadControlUnitMgr::connect() |
| 90 | { |
| 91 | connected_ = false; |
| 92 | |
| 93 | // Initialize gamepad input |
| 94 | gamepad_input_ = std::make_unique<ViGEmInput>(gamepad_type_); |
| 95 | if (!gamepad_input_->connect()) { |
| 96 | LogError << "Failed to connect gamepad"; |
| 97 | return false; |
| 98 | } |
| 99 | |
| 100 | // Initialize Win32 screencap if hwnd is provided |
| 101 | if (hwnd_ && screencap_method_ != MaaWin32ScreencapMethod_None) { |
| 102 | if (!init_win32_unit()) { |
| 103 | LogWarn << "Failed to initialize Win32 screencap, screencap will not be available"; |
| 104 | // Don't fail the entire connection, gamepad input is still usable |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | connected_ = true; |
| 109 | LogInfo << "Gamepad controller connected, type:" << (gamepad_type_ == MaaGamepadType_Xbox360 ? "Xbox360" : "DualShock4"); |
| 110 | return true; |
| 111 | } |
| 112 | |
| 113 | bool GamepadControlUnitMgr::init_win32_unit() |
| 114 | { |